#canadev_subs-saved-pms

1 messages Β· Page 1 of 1 (latest)

frozen lilyBOT
#

πŸ‘‹ 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.

near zodiac
#

Hm as far as I know this is supported

#

Can you share your code

scenic bison
#

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'];```
near zodiac
#

Can you share your client-side code as well

scenic bison
#
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

frozen lilyBOT
zinc wren
#

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?

scenic bison
#

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"

zinc wren
#

Can you share the request ID for the API request where you create the Subscription?

scenic bison
#

Yes req_LnXzFtLEabkPss

zinc wren
#

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?

scenic bison
#

I don't seem to have control over these parameters : payment_method_options: { card: { setup_future_usage: "on_session", }, },

zinc wren
#

Oh wait, you sent me the /confirm request from your front-end

#

I want the Subscription creation request from your server

scenic bison
#

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

zinc wren
#

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?

scenic bison
#

let options = {clientSecret: secretClient, locale: 'fr'};
if(xhr.secretClientUtilisateur)
{
    options['customerSessionClientSecret'] = xhr.secretClientUtilisateur;//here
}
let elements = stripe.elements(options);
zinc wren
#

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?

scenic bison
#

No after. I create a Customer without a payment_method

zinc wren
#

Okay so you

  • Create a Customer (no PM)
  • Create a Subscription
  • Create Customer Session
  • Create elements instance
  • Create and mount Payment Element

Do I have that in the correct order?

scenic bison
#

Yep! And a CustomerSession after Subscription

zinc wren
#

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.

scenic bison
#

Ok, so I must change my sequence?

zinc wren
#

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?

scenic bison
#

Yep!

zinc wren
scenic bison
#

Ok, thanks! I will look into it!

zinc wren
#

One of the key differences is that you create the elements instance with both the Payment Intent and Customer Session client secrets.

#

That ensures the parameters that the Payment Element uses to confirm the Payment Intent match how it was configured when you created the Subscription.