#ruul_api

1 messages ¡ Page 1 of 1 (latest)

prime vortexBOT
#

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

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

scenic mapleBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

spice blade
#

hello

#

I was planning to remove the setup session to add cards from our flow but seems like in this case we might need it but I'm not sure if that's the way to go since it was having issues even though we set it up it required additional security for some

#

for the initial purchase checkout works fine handling the extra verification part but

#

what if user wants to switch to a new card when subscription is active that is not added before via checkout session

raven wasp
spice blade
#

will it work with additional verification if required?

#
   * Creates a Stripe Checkout Session for setting up a customer card
   * without specifying any currency or price.
   * @param customerId - The ID of the customer for whom the card is being saved.
   * @returns The URL of the Checkout Session for setting up the card.
   */
  public async createSetupCheckoutSession(
    customerId: string,
    success_url: string,
    cancel_url: string
  ): Promise<Stripe.Checkout.Session> {
    const session = await this.stripe.checkout.sessions.create({
      payment_method_types: ["card"],
      mode: "setup",
      customer: customerId,
      success_url,
      cancel_url,
    });

    return session;
  }
#

we had this before

#

for saving cards

#

but when we actually tried to use them for purchasing subscriptions

#

some required additional steps for verification/security

#

when I posted it here, I was told depending on webhooks wasn't the best way to solve this using the webhook for when subscription requires additional steps to complete

raven wasp
#

yes it handles 3D Secure

spice blade
#

we are already using this code on prod though and it happened

#
   * Purchase subscription
   * @param customer customer id
   * @param price stripe price id
   * @param paymentMethodId id of the payment method (optional)
   * @param quantity number of items (optional)
   * @param trialDays trial days (optional)
   * @returns subscription object
   */
  public async purchaseSubscriptionWithPaymentMethodPresent(input: {
    customer: string;
    price: string;
    paymentMethodId: string;
    quantity?: number;
    trialDays?: number;
    coupon?: string;
  }): Promise<Stripe.Subscription> {
    const { customer, price, paymentMethodId, quantity, trialDays, coupon } =
      input;

    return this.stripe.subscriptions.create({
      customer,
      items: [{ price, ...(quantity && { quantity }) }],
      default_payment_method: paymentMethodId,
      ...(trialDays && { trial_period_days: trialDays }),
      ...(coupon && { coupon }),
    });
  }```
raven wasp
#

sure, and that's normal. any payment any time can require 3D Secure

spice blade
#

after we capture the card with that

#

we use it through this

raven wasp
spice blade
#

this is before the subscription is created

raven wasp
#

if you're doing "save card with a Setup CheckoutSession -> immediately create a Subscription to charge that saved card" then sure, that is not a good way of doing it and can lead to double-3DS

spice blade
#

setup -> and then this

#

there are three flows

#

first is when you try to purchase something if you don't have a card you use setup & then purchase

#

second when you want to add a new card just the setup

#

third is when you set a card default we try to charge every open invoice on the new default

#

when making the switch

raven wasp
#

which of those three flows are we discussing in this thread?

spice blade
#

all of them since they can lead up to charge one way or another

#

from the way it looks we need to depend on that specific webhook event ( I can't remember which one it was)

#

but I was advised against it

#

this one

raven wasp
#

ok. Well at a high level my recommendations are this.

first is when you try to purchase something if you don't have a card you use setup & then purchase
normal flow of create Subscription and confirm latest_invoice->payment_intent on the frontend. https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements

second when you want to add a new card just the setup
there are multiple ways, https://docs.stripe.com/payments/checkout/subscriptions/update-payment-details is one of them for example, to save a new card and mark it as default future future payments. Or the customer can do it in the portal (https://docs.stripe.com/customer-management/configure-portal) too

third is when you set a card default we try to charge every open invoice on the new default
do the above, and then while the customer is still present on your site after adding that card, grab the PaymentIntent of the Invoices you're interested in and call https://docs.stripe.com/js/payment_intents/confirm_card_payment#stripe_confirm_card_payment-existing on the frontend, to attempt payment of each one and handle 3D Secure if needed. I think this flow isn't one we really have an explicit guidance for.

#

that event you're mentioning is mainly useful for handing when 3D Secure is required on an off-session recurring payment and you need to contact the customer, which is different than the 3 flows we're discussing here.

spice blade
#

will it require 3d secure after the initial purchase or is that a possibility?

raven wasp
#

if the first payment/setup was authenticated there are exemptions for recurring payments (https://stripe.com/guides/strong-customer-authentication#:~:text=for our users.-,Recurring transactions,-This exemption can) but it's at the bank's discretion and you need to handle the case where the exemption is not granted, 3D Secure is required, and the customer needs to come back to authenticate the payment(we have a setting in the Dashboard to automatically email the customer a link to the hosted invoice page when that hapens, or you can listen to that webhook and handle it yourself).

spice blade
#

oh my god

#

if the email confirmation is a thing

#

I was doing this for nothing -.-

#

that was the only problem that we had

#

so client can configure it on dashboard ?

spice blade
#

tyvm

#

this was what I needed in the end

#

have a great day