laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.37k stars 667 forks source link

Dynamic Tax Rates for Subscriptions #1653

Closed ybert closed 6 months ago

ybert commented 6 months ago

As mentioned here : https://docs.stripe.com/billing/taxes/collect-taxes?tax-calculation=tax-rates

One strategy to calculate taxes if we don't have information about the customer location and if we don't want to use Stripe Tax and its additional cost is to use dynamic_tax_rates for each line item of the subscription.

The actual API of Cashier does not permit it :

       $user
            ->newSubscription('default',   ['price_yearly'])
            ->allowPromotionCodes()
            ->checkout([
                'billing_address_collection' => 'required',
                'success_url' => I18nWebUrlHelper::getUrl('stripe_checkout_success'),
                'cancel_url' => I18nWebUrlHelper::getUrl('stripe_checkout_cancel'),
            ], [
                'preferred_locales' => [$user->preferredLocale()],
            ]);

It could be great if we can do :

        $user
            ->newSubscription('default',   [
                [
                    'price'  => 'price_yearly',
                    'quantity' => 1,
                    'dynamic_tax_rates'  => [ 'txr_be', 'txr_fr', 'txr_uk', 'txr_de']
                ]
            ])
            ->allowPromotionCodes()
            ->checkout([
                'billing_address_collection' => 'required',
                'success_url' => I18nWebUrlHelper::getUrl('stripe_checkout_success'),
                'cancel_url' => I18nWebUrlHelper::getUrl('stripe_checkout_cancel'),
            ], [
                'preferred_locales' => [$user->preferredLocale()],
            ]);

We can already do this for the one time purchase checkout.

driesvints commented 6 months ago

I don't see a mention of dynamic_tax_rates on the page you linked to or can find it in the Stripe API docs. Could you clarify?

ybert commented 6 months ago

More precisely its here : https://docs.stripe.com/billing/taxes/collect-taxes?tax-calculation=tax-rates#adding-tax-rates-to-checkout

And then choose "Dynamic tax rates" tab.

On the stripe API documentation it's here : https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-line_items-dynamic_tax_rates

driesvints commented 6 months ago

@ybert are you sure you cannot already do what you want to do? Judging from the code this already seems possible to me.

ybert commented 6 months ago

Ok, it seems that I have something on my side that does not work properly. I think you-re right and it is already possible

Thanks for the help.