Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Received unknown parameter: default_tax_rates #1049

Closed
dalholm opened this issue Feb 4, 2021 · 3 comments · Fixed by #1050
Closed

Received unknown parameter: default_tax_rates #1049

dalholm opened this issue Feb 4, 2021 · 3 comments · Fixed by #1050
Labels

Comments

@dalholm
Copy link

dalholm commented Feb 4, 2021

  • Cashier Version: 12.7.0
  • Laravel Version: 8.2.0
  • PHP Version: 8.0.0

Description:

I do not know if I am doing anything wrong, but I can not get tax to work on subscriptions (checkout) without changing the package.

With the original code i get this error: Received unknown parameter: default_tax_rates

But if i follow stripe docs and change the package to include the default_tax_rates in subscription_data it works perfectly.

// SubscriptionBuilder.php

public function checkout(array $sessionOptions = [], array $customerOptions = [])
    {
        if (! $this->skipTrial && $this->trialExpires) {
            // Checkout Sessions are active for 24 hours after their creation and within that time frame the customer
            // can complete the payment at any time. Stripe requires the trial end at least 48 hours in the future
            // so that there is still at least a one day trial if your customer pays at the end of the 24 hours.
            $minimumTrialPeriod = Carbon::now()->addHours(48);

            $trialEnd = $this->trialExpires->gt($minimumTrialPeriod) ? $this->trialExpires : $minimumTrialPeriod;
        } else {
            $trialEnd = null;
        }


        return Checkout::create($this->owner, array_merge([
            'mode' => 'subscription',
            'line_items' => collect($this->items)->values()->all(),
            'allow_promotion_codes' => $this->allowPromotionCodes,
            'discounts' => [
                'coupon' => $this->coupon,
            ],
            // 'default_tax_rates' => $this->getTaxRatesForPayload(),  <----  Remove this, causing Received unknown parameter: default_tax_rates
            'subscription_data' => [
                'default_tax_rates' => $this->getTaxRatesForPayload(), // <---- add this referring to the docs https://stripe.com/docs/billing/subscriptions/taxes#adding-tax-rates-to-checkout
                'trial_end' => $trialEnd ? $trialEnd->getTimestamp() : null,
                'metadata' => array_merge($this->metadata, ['name' => $this->name]),
            ],
        ], $sessionOptions), $customerOptions);
    }

Alternative solution

  1. Remove taxRates() from your 'billable' model
  2. Add following to your checkout creation
$user->newSubscription()->checkout([
    'subscription_data' => [
                'default_tax_rates' => ['txr_.........'],
               'metadata' => [
                       'name' =>  'default',
                  ],
            ]
])
@driesvints
Copy link
Member

Thanks for reporting this! I've sent in a fix.

@driesvints
Copy link
Member

Released v12.7.1 with the fix.

@dalholm
Copy link
Author

dalholm commented Feb 4, 2021

@driesvints that was quick! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants