tony
tony

Reputation: 614

How to properly onboard tax for Connected accounts and calculate tax for pickups?

I'm building a Stripe-based application for placing orders from warehouses. However, I'm encountering issues with properly handling taxes. Here's the process I've followed so far:

  1. Account Creation and Onboarding: I start by creating and onboarding a custom account on Stripe:
$account = $stripe->accounts->create([
    'type' => 'custom',
    'country' => 'US',
    'email' => $email,
    'capabilities' => [
        'card_payments' => ['requested' => true],
        'transfers' => ['requested' => true],
        'us_bank_account_ach_payments' => ['requested' => true],
    ],
]);

$session = $stripe->accountLinks->create([
    'account' => $account['id'],
    'refresh_url' => $url,
    'return_url' => $url,
    'type' => 'account_onboarding',
    'collection_options' => [
        'fields' => 'eventually_due',
        'future_requirements' => 'include',
    ],
]);

header('Location: ' . $session['url']);
exit();
  1. Setting Up Tax Settings: Next, I configure the tax settings for the account:
 $stripe->tax->settings->update([
    'defaults' => [
        'tax_behavior' => 'exclusive',
    ],
    'head_office' => [
        'address' => [
            'line1' => $account->company->address->line1,
            'city' => $account->company->address->city,
            'state' => $account->company->address->state,
            'postal_code' => $account->company->address->postal_code,
            'country' => $account->company->address->country,
        ]
    ],
],
  ['stripe_account' => $account->id]
);
  1. Registering for Tax: I then register the account for tax:
$stripe->tax->registrations->create([
    'country' => 'US',
    'country_options' => [
        'us' => [
            'state' => $account->company->address->state,
            'type' => 'state_sales_tax',
        ],
    ],
    'active_from' => 'now',
], ['stripe_account' => $account->id]);
  1. Checkout Process: Finally, I proceed with the checkout function, which is currently a total mess, as I temporarily set the customer's address to the tax address to calculate sales tax:
function checkout($application_fee, $amount, $customer_id, $account_id){

    global $stripe;

    $tax_settings = $stripe->tax->settings->retrieve([], ['stripe_account' => $account_id]);

    $stripe->customers->update(
        $customer_id,
        ['address' => 
            [
                'postal_code' => $tax_settings->head_office->address->postal_code,
                'country' => $tax_settings->head_office->address->country,
            ]
        ]
    );

    $invoice = $stripe->invoices->create([
        'customer' => $customer_id,
        'auto_advance' => false, // Do not auto-finalize the invoice
        'collection_method' => 'charge_automatically',
        'application_fee_amount' => $application_fee,
        'automatic_tax' => [
            'enabled' => true,
            'liability' => [
                'type' => 'account',
                'account' => $account_id
            ],
        ],
        'description' => "Order",
        'footer'    => "Thank you for using TextToTableAI!",
        'issuer' => [
            'type' => 'account',
            'account' => $account_id
        ],
        'on_behalf_of' => $account_id,
        'transfer_data' => [
            'destination' => $account_id,
        ],
    ]);

    $stripe->invoiceItems->create([
        'customer' => $customer_id,
        'currency' => 'usd',
        'description' => 'Test purchase",
        'invoice' => $invoice->id,
        'quantity' => 1,
        'unit_amount' => $amount,
        'tax_behavior' => 'exclusive',
        'tax_code' => 'txcd_41052001'
    ]);

    $finalized_invoice = $invoice->finalizeInvoice();

    $paid_invoice = $finalized_invoice->pay();

    $stripe->customers->update(
        $customer_id,
        ['address' => 
            [
                'postal_code' => null,
                'country' => null,
            ]
        ]
    );

    return $paid_invoice;

}

This can't be the proper way to handle all of this. Given the above, I have two key questions:

  1. Is there a way to streamline the process so that onboarding Connected accounts and setting up their tax configurations can be done simultaneously, rather than in separate steps?

  2. For pickup orders where shipping is not involved, what's the correct method to automatically calculate tax using the saved customer information without resorting to temporary address manipulation?

Upvotes: 0

Views: 183

Answers (1)

yuting
yuting

Reputation: 1694

Is there a way to streamline the process so that onboarding Connected accounts and setting up their tax configurations can be done simultaneously, rather than in separate steps?

Looks like you're following this integration guide. Once the account is created, you should be able to setup tax settings and initiate onboarding simultaneously with their own APIs. They can't be done with one single API.

For pickup orders where shipping is not involved, what's the correct method to automatically calculate tax using the saved customer information without resorting to temporary address manipulation?

This is the guide about address hierarchy of how tax will be calculated based on: https://docs.stripe.com/tax/customer-locations#address-hierarchy

If shipping address is not provided, billing address will be used.

Upvotes: 0

Related Questions