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

invoiceFor() fails when automatic tax calculation is enabled #1204

Closed
josiasmontag opened this issue Jun 22, 2021 · 4 comments
Closed

invoiceFor() fails when automatic tax calculation is enabled #1204

josiasmontag opened this issue Jun 22, 2021 · 4 comments

Comments

@josiasmontag
Copy link
Contributor

josiasmontag commented Jun 22, 2021

  • Cashier Version: master and 13.1.0
  • Laravel Version: 8.47.0
  • PHP Version: 8.0.3
  • Database Driver & Version:

Description:

As soon as automatic tax calculation is enabled, the invoiceFor() method stops working.

This happens both with version 13.1.0 and the current master branch.

Steps To Reproduce:

Add this test case to cashier-stripe (master):

$user = $this->createCustomer('customer_can_be_invoiced');
$user->createAsStripeCustomer();
$user->updateDefaultPaymentMethod('pm_card_visa');


$invoice = $user->invoiceFor('Laracon', 49900);
// works
$this->assertInstanceOf(Invoice::class, $invoice);

Cashier::calculateTaxes();

$invoiceWithTax = $user->invoiceFor('Laracon', 49900);
// fails (returns false)
$this->assertInstanceOf(Invoice::class, $invoiceWithTax);

Reason

When using automatic tax calculation, Stripe requires that tax_behavior for the invoice item price is set.
Instead of using amount for invoice items we should switch to use price_data (Stripe docs):

$options['price_data'] = [
   'unit_amount' => ...,
   'tax_behavior' => 'exclusive',
...
];
@driesvints
Copy link
Member

@josiasmontag are you enrolled in the Stripe Tax program? It's currently invite only.

@driesvints
Copy link
Member

Also: Cashier::calculateTaxes(); isn't available in 13.1 yet. It's not yet released. Are you sure you're on the right version?

@josiasmontag
Copy link
Contributor Author

josiasmontag commented Jun 22, 2021

Yes, I am enrolled to Stripe Tax. When you submit the form on the Stipe website you get invited within a few hours.

As mentioned the same happens with 13.1.

Steps to reproduce for 13.1:

$user = $this->createCustomer('customer_can_be_invoiced');
$user->createAsStripeCustomer();
$user->updateDefaultPaymentMethod('pm_card_visa');


$invoice = $user->invoiceFor('Laracon', 49900);
// works
$this->assertInstanceOf(Invoice::class, $invoice);

$invoiceWithTax = $user->withTax()->invoiceFor('Laracon', 49900);
// fails (returns false)
$this->assertInstanceOf(Invoice::class, $invoiceWithTax);

@driesvints
Copy link
Member

Thanks for making me aware @josiasmontag. For now, in the short amount of time I have available, this is the best solution I can come up with: #1206

I'll need to think more thoroughly about the use of tax_behavior in combination with new API's. I've also updated the docs to warn about this: laravel/docs#7145

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

No branches or pull requests

2 participants