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.
$user->invoicePrice('price_tshirt', 5, [ 'discounts' => [ ['coupon' => 'SUMMER21SALE'] ], ], [ 'default_tax_rates' => ['txr_id'], ]);
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
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' ]);
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 $user->invoices()
Note: I was using $user->charge(100, $paymentMethod);
and it worked perfectly but didn't generate any invoice, then I decided to use $user instead ->invoiceFor()
method, this method only generates an invoice, but the user is not charged. I decided to change again and use $user->invoicePrice()
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.
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.
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.