#canadev_subs-saved-pms
1 messages Β· Page 1 of 1 (latest)
π Welcome to your new thread!
β²οΈ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
β±οΈ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
π This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1354472422862225490
π Have more to share? Add more details, code, screenshots, videos, etc. below.
The back-end code : ``` $stripe->subscriptions->create($parametres);
$customer_session = $stripe->customerSessions->create([
'customer' => $cleExterne,
'components' => [
'payment_element' => [
'enabled' => true,
'features' => [
'payment_method_redisplay' => 'enabled',
'payment_method_save' => 'enabled',
'payment_method_save_usage' => 'on_session',
'payment_method_remove' => 'enabled',
],
],
],
]);```
Γ nd 'secretClient' => $sub->latest_invoice->payment_intent->client_secret, 'secretClientUtilisateur' => $sub->client_secret,
Subscription parameters ``` $parametres = [
"customer" => $cleExterne,
"default_tax_rates" => $tax,
"cancel_at_period_end" => false
];
$parametres['items'] = $forfaits;
$parametres['metadata'] = $metadonnees;
$parametres['payment_behavior'] = 'default_incomplete';
$parametres['payment_settings'] = ['save_default_payment_method' => 'on_subscription'];
$parametres['expand'] = ['latest_invoice.payment_intent'];```
Can you share your client-side code as well
let options = {clientSecret: secretClient, locale: 'fr'};
if(xhr.secretClientUtilisateur)
{
options['customerSessionClientSecret'] = xhr.secretClientUtilisateur;
}
let elements = stripe.elements(options);
const payment = elements.create("payment", {
layout: "accordion",
defaultValues: {
billingDetails: {
name: titulaire,
address: {postal_code: codePostal},
}
},
});
payment.mount("#elements-stripe");
let formStripe = document.querySelector("#form-stripe");
formStripe.addEventListener("submit", async function (e) {
e.preventDefault();
const {error} = await stripe.confirmPayment({
elements,
confirmParams: {
//I tested with or without
setup_future_usage: "off_session",
return_url: urlStripe,
},
});
//....
});
When i remove setup_future_usage in client-side, I get When setup_future_usageis set to off_session with a secret key, you can only updatesetup_future_usage to off_session using a publishable key
Hi π
I'm stepping in for my colleague as they need to go soon
In our public doc on using Customer Sessions/Saved PMs with Subscriptions, we do not show passing setup_future_usage in the Confirm params.
Just to test things out, would you be able to modify your front & back end code to follow the approach we outline there?
Hi! I just did it and I have the error above
"When setup_future_usage is set to off_session with a secret key, you can only update setup_future_usage to off_session using a publishable key"
Can you share the request ID for the API request where you create the Subscription?
Yes req_LnXzFtLEabkPss
Thanks, taking a look
Okay so you are specifying that you want to set up the payment for future usage but only with the customer on session, per these parameters:
payment_method_options: {
card: {
setup_future_usage: "on_session",
},
},
That appears to conflict with what you are trying to do on your front-end
Or do I not have that correct?
I don't seem to have control over these parameters : payment_method_options: { card: { setup_future_usage: "on_session", }, },
Oh wait, you sent me the /confirm request from your front-end
I want the Subscription creation request from your server
These are sent by Stripe Elements API. What I'm tying to do is to save the customer payment method so he sees it when he wants to do a manual renewal.
req_cZpPMHvuYC1D4k
That makes sense.
Sorry I may be missing something in all the PHP code, but where are you passing the Customer Session client secret when creating the elements instace?
let options = {clientSecret: secretClient, locale: 'fr'};
if(xhr.secretClientUtilisateur)
{
options['customerSessionClientSecret'] = xhr.secretClientUtilisateur;//here
}
let elements = stripe.elements(options);
Hmmm... okay. I'm trying to work through our doc and your code and spot where the differences may cause issues.
You are collecting the payment method data before you create the Subscription, right?
No after. I create a Customer without a payment_method
Okay so you
- Create a Customer (no PM)
- Create a Subscription
- Create Customer Session
- Create
elementsinstance - Create and mount Payment Element
Do I have that in the correct order?
Yep! And a CustomerSession after Subscription
Updated π
Okay so that is fundamentally different than our doc for saving the PM details beforehand and maybe that is where the conflict is coming from.
Ok, so I must change my sequence?
And, if I understand you correctly, the point of using this approach is so that when the Customer comes back on session and the Payment Element loads, they will see the saved PM. Is that right?
Yep!
Okay so basically this flow here: https://docs.stripe.com/payments/existing-customers?platform=web&ui=elements#display-additional-saved-payment-methods
But with Subscriptions as the source of the Payment Intent.
Ok, thanks! I will look into it!