I'm trying to use laravel cashier with stripe to generate invoice and charge users immediately but it doesn't work. i'm taking reference from the sample code snippet 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); //$paymentMethod method was genearated
}
$user->invoicePrice('price_xxxxxxx', 1, [], [
'description' => 'this is a dummy description',
'currency' => 'usd',
'receipt_email' => 'john@doe.com'
]);
After running the code nothing happened, i looked at my stripe dashboard, i saw nothing. my goal is to charge users and generate invoice for them so that i can access those invoices later on in my application by doing something like this $user->invoices()
NOTE: i was previously using $user->charge(100, $paymentMethod);
which works perfectly but doesn't generate any invoice, then i decided to change and use $user->invoiceFor()
method, this method only generated an invoice but the user wasn't charged. I decided to change again and use $user->invoicePrice()
but this method didn't do anything at all. It is required that i let users manage their invoices after payment but i cannot find a method that can help me do that (generate invoice and charge). I don't know what i'm doing wrong, please help.
Sounds like the issue is laravel using a "pending_invoice_items_behavior" of "include_and_require" which has been disabled by Stripe. So items are getting excluded by default.
https://mobile.twitter.com/cjav_dev/status/1554922729081516033
I tried including a new parameter like this.
$user->invoicePrice('price_XXXXXXXXXXXXXX', 5, [], [
'pending_invoice_items_behavior' => 'include',
]);
I also however experienced the currency error, as my user had previously charged in CAD when I was trying a product in USD (Huge thanks to whoever posted that.!).
But when I created a new user instead of customer with a preexisting currency, it worked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.