#shayan-shokat_code

1 messages ¡ Page 1 of 1 (latest)

worn pelicanBOT
#

👋 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/1271092593203220582

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

uneven spoke
#

Hello

#

Can you clarify your flow here? How are you collecting a PaymentMethod currently?

neat prairie
#
          customer: customer.id,
          items: [
            {
              price: priceId,
            },
          ],
          coupon: coupon ? coupon.id : null,
          payment_behavior: "default_incomplete",
          // expand: ["latest_invoice.payment_intent"],
          metadata: {
            discount: amountOff / 100,
            for: "new subscription",
          },
        });

        const invoice = await stripe.invoices.retrieve(
          subscription.latest_invoice
        );
        const paymentIntentId = invoice.payment_intent;

        const paymentIntent = await stripe.paymentIntents.retrieve(
          paymentIntentId
        );
        await stripe.paymentIntents.update(paymentIntentId, {
          metadata: {
            discount: amountOff / 100,
            for: "new subscription",
          },
        });

        const clientSecret = paymentIntent.client_secret;
        const ephemeralKey = await stripe.ephemeralKeys.create(
          { customer: user["stripeCustomerId"] },
          { apiVersion: "2020-03-02" }
        );
#

ok so first we generate clientSecret and ephemeralKey to pass on to mobile app to open 3D secure sheet of stripe

uneven spoke
#

Okay gotcha

#

Let's pause

neat prairie
#

and in that sheet it completes the payment

#

but that subscription doesn't have default_payment_method attached with it so if we want to change the plan or at changing billing cycle, payment can't be charged

uneven spoke
#

First, you want to use expansion when you create your Subscription instead of making a separate Invoice retrieval request. So you want expand: ['latest_invoice']. See: https://docs.stripe.com/expand for more info on how expansion works

#

Do both those things, test again, and let me know if you still have any issues!