laravel cashier's invoicePrice() method does not work properly
P粉269847997
P粉269847997 2023-08-29 10:12:00
0
1
495
<p>I'm trying to use laravel cashier and stripe to generate an invoice instantly and charge the user, but it's not working. I'm referring to the example code snippets in the laravel-8 documentation to do this. </p> <pre class="brush:php;toolbar:false;">$user->invoicePrice('price_tshirt', 5, [ 'discounts' => [ ['coupon' => 'SUMMER21SALE'] ], ], [ 'default_tax_rates' => ['txr_id'], ]);</pre> <p>I created a product in my stripe dashboard and replaced 'price_tshirt' with the price ID of the product. The final code looks like this</p> <pre class="brush:php;toolbar:false;">if(!$user->hasPaymentMethod()){ $user->addPaymentMethod($paymentMethod); //The $paymentMethod method is automatically generated } $user->invoicePrice('price_xxxxxxx', 1, [], [ 'description' => 'This is a virtual description', 'currency' => 'usd', 'receipt_email' => 'john@doe.com' ]);</pre> <p>After running the code nothing happened, I looked at my stripe dashboard and saw nothing. My goal is to charge users and generate invoices for them so that I can access those invoices later via code like this <code>$user->invoices()</code></p> <p>Note: I was using <code>$user->charge(100, $paymentMethod);</code> and it worked perfectly but didn't generate any invoice, then I decided to use <code>$user instead ->invoiceFor()</code> method, this method only generates an invoice, but the user is not charged. I decided to change again and use <code>$user->invoicePrice()</code> but this method didn't work at all. I need to let users manage their invoices after payment, but I can't find a method that helps me do this (generate invoices and charges). I don't know what I'm doing wrong, please help. </p>
P粉269847997
P粉269847997

reply all(1)
P粉716228245

It sounds like the problem is that laravel uses a "pending_invoice_items_behavior" that is disabled by Stripe as "include_and_require", so the items are excluded by default.

https://mobile.twitter.com/cjav_dev/status/1554922729081516033

I tried adding a new parameter like this.

$user->invoicePrice('price_XXXXXXXXXXXXXX', 5, [], [
    'pending_invoice_items_behavior' => 'include',
]);

However, I also encountered currency errors because my users were previously charged in CAD when I tried the product in USD (big thanks to whoever posted this question before!!).

But when I create a new user with a pre-existing currency instead of a customer, it works.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template