#kun_api

1 messages ¡ Page 1 of 1 (latest)

ancient ruinBOT
#

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

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

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.

jolly bloom
plucky sinew
#

yes this is what I am doing and implemented it successfully

#

but I have a concern

#

as for this process 3DS is required.
which I am sending it to the customer through email

my first concern
1 once it is approved by user and subscription is paid and active for every next recurring payment do it required 3DS again and then again sending email

2 Is there another way for 3DS instead of sending the hosted URL

3 when I click on the hosted url my card fields are not populated as I already attached the paymente method when cutomer subscribe to my product to 1st time

#
 const sub = await this.stripe.subscriptions.update(
        latestSubscription.id, // Your subscription ID
        {
          items: [
            {
              id: latestSubscription.items.data[0].id, // Your subscription item ID
              price: 'price_1PZL8KFrwl37tCGiAOd8u8Pd', // Your new price ID
            },
          ],
          expand: ['latest_invoice.payment_intent'], 
        },
      );

this is the code snippet I am using and Tested successfully

jolly bloom
#
  1. 3DS request is determiend by the card issuer and your Radar rule, there's no way completely avoid it and your integration should always handle it
  2. You can also handle 3DS by yourself . You can navigate your customer to your website where you can call stripe.confirmCardPayment to initiate the 3DS flow
  3. Did you attach the payment method to the subscription?
plucky sinew
#

for your 3rd point
You can see my code snippet please

jolly bloom
#

What's the subscription ID?

plucky sinew
#

for your 1 pont:

once I did 3DS for the first time my subscription charge recurring automatocally.

but I am think it as same that once the user upgrade the subscription with new product priice_id
and after completion of 3DS the next recurring charge automatically

#
latestSubscription.id  this is my subscription id
latestSubscription.items.data[0].id  this is my subscription item id

#

??

jolly bloom
plucky sinew
#

sure

#

sub_1PsdDNFrwl37tCGiioE6hIvY

jolly bloom
#

Stripe will send an email to you customer when a payment requries confirmation

#

However we don't send such emails in test mode.

plucky sinew
#

ok I have a question here

#

will it possible with this.stripe.subscriptions.update
I can attach the payment_method
and get the client secret
and on forntend I using confirmCardPayment to apply 3DS

#

???

#

??

#

????

#

you there

#

is anyone there

jolly bloom
#

Thanks for waiting.

#

Yes you can do that if you want to handle 3DS by yourself.

ancient ruinBOT
plucky sinew
#
const sub = await this.stripe.subscriptions.update(
        latestSubscription.id, // Your subscription ID
        {
          items: [
            {
              id: latestSubscription.items.data[0].id, // Your subscription item ID
              price: 'price_1PZL8KFrwl37tCGiAOd8u8Pd', // Your new price ID
            },
          ],
          default_payment_method: paymentMethodId,
          expand: ['latest_invoice.payment_intent'], 
        },
      );

I have updated the code
will this work by sending the client_secret to frontend

jolly bloom
#

Yes, client_secret is in the expanded payment_intent object

plucky sinew
#

alright let me summarize it and lease confirm

#

1 update the subscription with new product price_id
2 attach with old payment_method (which was created first time for subscription)
3 Add this key while updating expand: ['latest_invoice.payment_intent'],

On frontend

1 send the client secret

2 use confirmCardPayment or use confirmCardSetup

3 I will using

const { error, paymentIntent } = await stripe.confirmCardPayment(clientSecret, {
  payment_method: 'pm_new_payment_method_id', // Replace with the saved payment method ID
});

on frontend

#

Please confirm it

jolly bloom
#

You don't need to specify payment_method in confirmCardPayment, just call confirmCardPayment with clientSecret will do. You can test this out in test mode

plucky sinew
#

in confirmCardPayment
I dont need card details or paymentMethod right?

jolly bloom
#

Yes you are right, the paymentIntent should already have the payment_method attached to it.

plucky sinew
#

just call it with confirmCardPayment with cleint_secret

#

ohhhh I got it

jolly bloom
#

And you only need to call confirmCardPayment if the payment_intent is in requires_action state.

plucky sinew
#

so here I should call confirmCardPayment right?

#

but confirmCardPayment takes 2 arguments
1 client_secret
2 card elements or payment methodId

jolly bloom
plucky sinew
#

got it

#

thank you very much for the information

#

really appreciate it

jolly bloom
#

Happy to help!

plucky sinew
#

hi

#

I got a problem

ocean mulch
#

How can I help?

plucky sinew
#

Hi

#

I am trying to upgrade subscription

#

well I just created two new products
one with 0.10 usd per day
other is 2 usd per day

when I use their price_id I get payment_intent null

but those products which are old and I use their price_id i get my payment_intent populated with data

#

why?

#

even my new products are active

ocean mulch
#

when I use their price_id I get payment_intent null
Could you share request ID (req_xxx) which you face payment intent as null when attempting to upgrade the subscription?

plucky sinew
#

I dont know how to get req id

#

i can share subscri[ption id?

#

??

#

or can I share the response when I update my subscription

#

are you there?

ocean mulch
#

Discord is a public channel and can be busy some time. It will take time to reply

#

Could you share your subscription ID (sub_xxx), so that I can take a look?

plucky sinew
#

sure

#

"sub_1PsdDNFrwl37tCGiioE6hIvY"

ocean mulch
#

In https://dashboard.stripe.com/logs/req_KKEPo2h0SsZbv2 when the subscription item is updated, the prorated invoice created is $0: https://dashboard.stripe.com/invoices/in_1Pt1sHFrwl37tCGiY1NnjRIy

When an invoice is $0, no payment intent will be available

plucky sinew
#

what should i do?

ocean mulch
#

You don't need to do anything since payment is not required

plucky sinew
#
  // Get the latest subscription for the customer
      const { data: subscriptions } = await this.stripe.subscriptions.list({
        customer: customerId,
      });
      const latestSubscription: any = subscriptions.reduce((latest, current) =>
        current.created > latest.created ? current : latest,
      );
      // Update the subscription to use the new payment method
      const updatedSubscription: any = await this.stripe.subscriptions.update(
        latestSubscription.id, // Your subscription ID
        {
          items: [
            {
              id: latestSubscription.items.data[0].id, // Your subscription item ID
              price: 'price_1Pt1upFrwl37tCGiM5WDfpYa', // Your new price ID
            },
          ],
          default_payment_method: paymentMethodId,
          expand: ['latest_invoice.payment_intent'],
        },
      );
ocean mulch
plucky sinew
#

but once I get the client secret then I can use confirmCardPayment on frontent and charge the customer

#

but I am attaching the price_id whose value is greater then 0 usd

ocean mulch
#

There is no amount to charge to the customer here, so confirm payment is not applicable here

plucky sinew
#

so how can I charge the customer once customer upgrade its plan?

ocean mulch
#

When there is no customer balance on the customer, then the customer will be charged for the upgrade

#

If there is customer balance on the customer, Stripe will first use the customer balance to offset the payment

plucky sinew
#

but my problem is the same

#

how can I handle it as developer

#

on frontend I am using confirmCardPayment which required client_secret

#

becuase this is how I can crharge the customer by its payment method that he saved earlier

#

Do you understand my point?

ocean mulch
#

When the Payment Intent is null, then you don't return the client secret and confirmCardPayment() is not needed to be called

#

When the payment is required, Payment Intent will be available, then your system can then return client secret to frontend and use confirmCardPayment()

#

In summary:

  1. Payment Intent is null > do nothing
  2. Payment Intent is not null > return client secret to frontend and confirm card payment
plucky sinew
#

got it
my next question is if payment_intent is null
how the customer will charged and how he can perform 3DS?

ocean mulch
#

If Payment Intent is null, no payment will be charged, thus no 3DS

#

3DS will only be performed when there is a Payment Intent

plucky sinew
#

got it

#

but the question remains the same

#

how customer will charged

#

if payment_intent = null
because he upgraded the subscription and for that he has to pay

#

do you understand my concern?

ocean mulch
#

Only when there is no customer balance on the account, then customer will be charged

#

The issue here is not with the upgrade, but the customer balance is available on this customer, so Stripe will use the credit balance to offset the upgrade amount instead of charging to customer's card

plucky sinew
#

so it mean my implementation is correct
stripe will charge the customer in the next recurring payment?

ocean mulch
plucky sinew
#

"Stripe will charge the customer with the upgraded plan amount in next month"

or the bnest recurring payment date?

#

and can I change this behavior?

#

that must use customer card to charge the payment

ocean mulch
#

or the bnest recurring payment date?
Next billing cycle to be exact

#

that must use customer card to charge the payment
I'm afraid this is not possible. If there is customer balance available, Stripe will use the customer balance first instead of charging to the card

plucky sinew
#

this is my card I am using it on live
but I dont have balance to my subscription

ocean mulch
#

The customer associated to the subscription has been deleted, so the customer balance history can't be viewed

#

So I can't view how the customer balance was credited to this customer

plucky sinew
#

I have another question

#

lets say stripe payment_intent is null
and after some time stripe try to charge oit from customer balance

I want that webhook so I can do appropiate actions
if charged failed or charged approved

ocean mulch
plucky sinew
#

can I use invoice.payment_succeeded or invoice.payment_failed

ocean mulch
#

Yes! invoice.payment_succeeded and invoice.payment_failed events should be used

plucky sinew
#

and on that I can perform downgrade or upgrade

#

by this I stop user to abuse my subscriptions

#

right?

ocean mulch
#

by this I stop user to abuse my subscriptions
I'm not sure what you meant. invoice.payment_* events indicate the payment outcome of an invoice. They can be used to determine whether a payment is made successfully, then further update to your system to keep track the payment status upon an upgrade or downgrade

plucky sinew
#

got it

ancient ruinBOT