#Marco
1 messages · Page 1 of 1 (latest)
Looking in to thid. Do you know what API call exactly resulted in that original error message about the PaymentMethod being consumed?
This was my first question + answer from last week:
Marco — 14-09-2023 15:59
Hi,
I have a Laravel API that handles my payments.
Here I create a Stripe Checkout Session using the ‘stripe/stripe-php’ composer package.
This all works fine, I get a checkout page and I’m able to complete the payment.
After this I listen for Stripe to send the ‘checkout.session.completed’ webhook.
If everything went correct I want to send the order to Recharge. Using their api.
What I do in Recharge is the following:
Create customer if not already exist
Create a Payment method
Create an Address
Create the Subscription or One time order
This flow work when I do this for a subscription (tested using Creditcard and SEPA payments)
However for the one time orders I get an error when creating the Payment method: ‘Invalid processor_payment_method_token’
I also see in the Stipe dashboard logs the following 400 error:
‘invalid_request_error: This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.’
Is there something I’m forgetting or just don’t get?
Dingbot heeft bismarck toegevoegd aan de thread.
— 14-09-2023 16:00
bismarck — 14-09-2023 16:00
Hello
You need to set payment_intent_data.setup_future_usage (https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-setup_future_usage) to save the PaymentMethod if it was used for a one-time payment
This happens automatically via Subscriptions
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
What you are running in to is that some of our PaymentMethods do not support being saved for future payments or recurring paymnets
When you create the Checkout Session, do you already know if the user will be making a subscription or one time payment?
yes i do
If so, we reccommend creating the Checkout Session in payment mode or subscription mode and having the user directly pay the first payment
Both modes let you save payment methods for future use if that is what you want. But doing it that way makes the process much less complicated and can prevent things like the user having to do 3DS authentication twice in a row
we already do this:
'mode' => $order->isSubscription() ? config('stripe.subscription') : config('stripe.one_time'),
if (!$order->isSubscription()) {
$session['customer_creation'] = 'always';
$session['payment_intent_data'] = [
'setup_future_usage' => 'off_session',
];
}
Ah, is that the Laravel code that calls our API?
yes
So what you are running in to is that Bancontact (and others) do not support being saved. You can optionally turn off saving just for that PaymentMethod https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_method_options-bancontact-setup_future_usage
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
And the others that have disappeared
Just keep in mind that a customer paying with those payment methods won't be able to be saved and reused
hmm that will be a problem in recharge then
recharge looks for the payment method and that resulted in the first error right?
No, the first error happened because you weren't setting up the PaymentMethod to be saved properly
Also it looks like I was a bit mistaken, bancontact does support recurring payments through SEPA.
Double checking what happened for that specific checkout session
so i now added payment_method_types ['card'. 'bancontact'];
i then get the message :
"payment_intent_data.setup_future_usage is unsupported for payment method bancontact."
so i removed it for now,
then i can do the checkout with bancontanct
But then when i handle my recharge order, i want to make a address which needs a payment method id they say its not a valid one
this is what i get back from the stripe webhook:
"payment_method" => "pm_1NrhR3CI7ahsAhgWQEjZGxDY"
"payment_method_details" => array:2 [
"bancontact" => array:8 [
"bank_code" => "VAPE"
"bank_name" => "VAN DE PUT & CO"
"bic" => "VAPEBE22"
"generated_sepa_debit" => null
"generated_sepa_debit_mandate" => null
"iban_last4" => "7061"
"preferred_language" => "en"
"verified_name" => "Jenny Rosen"
]
"type" => "bancontact"
]```
when i do a subscription the generated_sepa_debit is filled and i can use that one without any problems
this is the recharge error i get:
0 => "Invalid processor_payment_method_token"
]```
Can you send me a request ID from when you got that "Invalid processor_payment_method_token" error?
https://dashboard.stripe.com/test/logs
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
not sure which one you need:
evt_1NrhRICI7ahsAhgWbpZofFVa
cs_test_a1OX4YOtHQg18S4eQPTPAwMGlem04ljIG61zrXfO8hbpVHAWeXe4MU5h3H
oh wait
POST /v1/payment_methods/pm_1NrhR3CI7ahsAhgWQEjZGxDY/attach
So if you use setup_future_usage: off_session , in Checkout, Stripe will automatically save and attach the payment method to the customer
yes for creditcard this worked fine
but for sepa payment methods it doesnt
i did turn recurring payments on in the dashboard now:
but still the same result
Setup future usage was not used for that Checkout Session https://dashboard.stripe.com/test/logs/req_BQTpa1LAKx8SUb
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
If you try again but do pass setup_future_usage: off_session, we should automatically save and attach the created SEPA PM
no because like mentioned before i get this message then:
"payment_intent_data.setup_future_usage is unsupported for payment method bancontact."
I mean on the Checkout Session overall https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-setup_future_usage
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
$session = [
'payment_method_types' => ['card', 'bancontact'],
'client_reference_id' => $order->id,
'currency' => 'eur',
'line_items' => $this->getLineItems($order),
'mode' => $order->isSubscription() ? config('stripe.subscription') : config('stripe.one_time'),
'success_url' => config('app.frontend_url') . '/bedankt',
'cancel_url' => config('app.frontend_url') . '/bestelling',
'shipping_address_collection' => [
'allowed_countries' => [
'NL',
'DE',
'BE',
],
],
'custom_fields' => [
[
'key' => 'firstName',
'label' => [
'type' => 'custom',
'custom' => 'Voornaam',
],
'type' => 'text',
],
[
'key' => 'lastName',
'label' => [
'type' => 'custom',
'custom' => 'Achternaam',
],
'type' => 'text',
],
],
];
if (!$order->isSubscription()) {
$session['customer_creation'] = 'always';
$session['payment_intent_data'] = [
'setup_future_usage' => 'off_session',
];
}
return Session::create($session);
i then get the following error:
"payment_intent_data.setup_future_usage is unsupported for payment method bancontact."
this is the overall session right?
My apologies I mixed that up with the bancontact specific field.
I'm going to consult my colleagues on this. Our docs may be misleading when they say that Bancontact supports recurring payments like this
Are you having this issue with other payment method types or just bancontact?
ideal aswel
i think its with all sepa, but i cannot say for sure
At least thanks for looking into this! 😄
So it looks like bancontact and ideal only support setup_future_usage when Checkout is in setup or subscription mode. So it looks like we will present those PMs for your subscriptions but not your one time payments
Though as noted that setting that I pointed to earlier would let you accept bancontact without saving the PM for one-time payments https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_method_options-bancontact-setup_future_usage
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
hmm , yes if i do the noted setting i can finish the checkout :
if (!$order->isSubscription()) {
$session['customer_creation'] = 'always';
$session['payment_intent_data'] = [
'setup_future_usage' => 'off_session',
];
$session['payment_method_options'] = [
'bancontact' => [
'setup_future_usage' => 'none',
],
];
}
but when i want to add the order in recharge i still get the following errors in the logs:
POST /v1/payment_methods/pm_1NriNmCI7ahsAhgWvFm99tAI/attach
invalid_request_error PaymentMethods of type 'bancontact' cannot be saved to customers.
does this mean its just not possible?
👋 yes, the only way we support recurring payments via those payment methods is after deriving a SEPA Direct Debit payment method (which only checkout can create at the moment, PaymentIntents don't support it)
hmm okee, the stupid thing is that everything works fine for subscription orders, the charge then has a 'generated_sepa_debit' which i can use for Recharge.
the one time orders that don't even have to be recurring but are supposed to be linked to a customer are the problem for Recharge 😅
I see. the only way you'd be able to attach it is with setup mode checkout session afaik.
I will discuss internally and try to find a good solution. Thanks for the help, maybe ill be back with some more questions later 😄