#Verox
1 messages ยท Page 1 of 1 (latest)
Code: ```php
$request->user()->invoiceFor('"' . $validated['name'] . '" Server', $price);
Error:
``"The payment attempt failed because of an invalid payment method."``
The customer should be able to pick a currency the first time and pick a payment method from the enabled ones everytime he pays an invoice.
Sorry, I don't follow. Where does the error come from?
From invoicing a customer with Laravel Cashier:
$request->user()->invoiceFor('"' . $validated['name'] . '" Server', $price);
Okay, we don't officially support that, so you will have to contact the developer to solve this.
I'm pretty sure Stripe wants the customer to have a default payment method he can be charged with, but I just want the customer to be able to pay via mail with every enabled payment method..
That's not an error from Cashier.
.
I understand, but I don't know how ->invoiceFor method works under the hood so I don't know exactly why the error pops up. The developer will be able to solve this.
Yes, that's why I wrote you. I want to know how to do it manually with the Laravel Stripe SDK.
But I don't know how Laravel Cashier works. That's why you need to contact Laravel Cashier developer.
The main problem is that I don't want the customer to set a payment method before. He should be able to pay with every payment method that's available.
Here is the code for Native Stripe PHP:
// Create an Invoice
$invoice = Invoice::create([
'customer' => $request->user()->stripe_id,
'collection_method' => 'send_invoice',
'days_until_due' => 7,
]);
// Create an Invoice Item with the Price, and Customer you want to charge
$invoiceItem = InvoiceItem::create([
'customer' => $request->user()->stripe_id,
'price' => $price,
'invoice' => $invoice->id
]);
$invoice->send();
I'll get the error: "Nothing to invoice for the customer"
You need to finalize the invoice before sending it.
Hi there ๐ jumping in as my teammate needs to step away soon.
Thanks, I'll try that.
Is this error from the request to create the Invoice? Depending on your API version you may need to create the Invoice Item before creating the Invoice.
From $invoice->send()
And even if I finalize the invoice, the error still occurs.
Is this a Laravel Cashier function? We are not familiar with how that Stripe integration is expected to work or how to implement it, Cashier was built by Laravel and you will need to work with them for getting assistance on it.
We can help answer questions about our APIs and libraries, but we won't be able to offer insight on third-party libraries.
No, that's the normal Stripe PHP Package.
Hm, it doesn't match our sample code for sending Invoices:
https://stripe.com/docs/api/invoices/send?lang=php
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yes, because I'm using the static approach obviously.
And I also tried that code, but it gave me the same error.
Can you share the ID of a request where you saw that error being returned?
in_1N9SXhBxo62JExo2Xx2woL9I
That looks like the ID of an Invoice, using it I found this request that seems to return the error you indicated, but it has a user agent matching that of the Laravel Cashier library rather than appearing to come directly from our PHP library:
https://dashboard.stripe.com/test/logs/req_uf2vC1gbQgOv5w
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Ah, thanks. I think I found the error. It is mostly the unthinkable: Switched from Production to Test mode, where the customer doesn't exist.
No, actually not. The customer id should be correct.
But yes, that's the error.
That error indicates that there are no pending Invoice Items associated with the Customer, so there is nothing to be pulled into the Invoice you're trying to create.
But shouldn't that create the invoice item for the invoice?
No, that is a request to create an Invoice. Creating Invoice Items use a separate set of endpoints/functions.
Ah, now it works, but I get this error:
"The payment attempt failed because of an invalid payment method."
The Code is the same as here, but I'm in production mode now.
Cannot charge a customer that has no active card
https://dashboard.stripe.com/logs/req_MIk5Jyp0b0Ruz1
Is this the request you're referring to? It's being made to the endpoint to trigger the payment for an Invoice. What are you expecting/hoping to happen here if you don't want to automatically charge an existing Payment Method?
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
I want to send him the invoice and let him choose the payment method he wants to pay with.
Gotcha, so you don't want to call the pay endpoint then, and you'll want to change the collection_method you're using when creating the Invoice to send_invoice:
https://stripe.com/docs/api/invoices/create#create_invoice-collection_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Thanks! I will get it working with this guide. Don't want to disturb anymore ๐
Any time!