#akashpatil7596_webhooks

1 messages ยท Page 1 of 1 (latest)

spark pagodaBOT
#

๐Ÿ‘‹ 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/1224941238860386344

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

eternal hawkBOT
#

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.

gloomy stream
#

Do you mean how to call the Refund API?

umbral pasture
#

I mean after catch the webhook, I just calculate the amount of refund and just call the refunds.create API, is that it?

gloomy stream
#

Ah I see

#

When you update the Subscription from Premium to Basic plan, do you notice there are proration on the generated Invoice?

#

If you have an example Subscription Id (sub_xxx) happy to take a look

umbral pasture
#

No I don't notice

#

Ok let me see

#

is this you are talking about?

gloomy stream
#

Uhm no I don't think so. Can you share the Subscription Update request (req_xxx) or the Subscription Id sub_xxx

umbral pasture
#

sub_1P17HDIoZDVxPDhemrR25aiS

gloomy stream
#

Okie, did you update today or yesterday?

#

Seeing 2 update requests

umbral pasture
#

yesterday I upgrade, today I downgrade

gloomy stream
#

Ah okie I see what happened now

#

So yesterday you upgrade from a montly $19.99 price to annual $999.99

#

Unused on starter = -18.05, Remaining on plus = 999.99

#

Unused on plus = -999.99 and Remaining on starter = 19.99.

#

So it gives back 980 to the customer

#

This is the customer balance and it will offset any of the customer Invoice in the future

#

It's up to you to refund of not refund it It's totally ok to keep the customer balance as it and not refunding them, because you don't have a specific PI to create the refund from

umbral pasture
#

Okay please listen this,
I'm hitting an API stripe.subscription.update with old item delete which is $999.99/year and add new price $19.99/month,
1). In this case the current month will paid of by from the $999.99 ?
2). I Don't want to paid the current month or next invoices from the credit balance, but I want to give the whole remain credit balance to the customer as refund. How can I do that? I'm using NodeJS for backend.

gloomy stream
#
  1. Yes as you can observe from the Invoice above
  2. Okay then you would want to find the Invoice 981.94 (in_1P17QaIoZDVxPDhelV0BudpZ), then find its PI (pi_3P17QaIoZDVxPDhe36B4jqDn) then call Refund on it. This articles explains how to write the finding logic: https://support.stripe.com/questions/refunding-credit-balance-to-customer-after-subscription-downgrade-or-cancellation
umbral pasture
#

No I read this article, I just want to say that in refunds.create API which parameters I have to pass?

#

Like charge_id or payment_intent_id, and pass amount or not?

gloomy stream
umbral pasture
#

Okay last question

#

What is the payment_intent and how can I get that?

gloomy stream
#

It's explained in the article above ๐Ÿ™‚

  • Using the List Invoices API, pass the Subscription ID in the subscription parameter to view Invoices for that Subscription ID only
  • You'll then need to expand the associated charge
umbral pasture
#

No please I do not understand the article, My english is not good. I'm typing this using google translate.
Can you tell me how can I get the payment_intent Id API vise?

#

Hello

gloomy stream
#

What do you not understand in the article?

#

First have you tried this step? Using the List Invoices API, pass the Subscription ID in the subscription parameter to view Invoices for that Subscription ID only

umbral pasture
#

There is nothing for list Invoice or like that

umbral pasture
#

Okay I call await this.stripe.invoices.list({ subscription: subscriptionId });

Got this in response

#

Can you tell me what can I do next?

gloomy stream
#

Okie, next is modifying this request to expand the charge object

umbral pasture
#

for that which ch_xxx should I pass? in retrive charges API.

gloomy stream
#

I mean on this same Retrive Invoice API, use expand: ['charge']

umbral pasture
gloomy stream
#

Yes but on the stripe.invoices.list

umbral pasture
gloomy stream
#

Yeah but you probably want to check its amount for the logic next:

umbral pasture
#

Okay ,

 return await this.stripe.invoices.list({
      subscription: subscriptionId,
      expand: ['data.charge'],
});

Got this response

#

Now what can I do further?

gloomy stream
#

This is completely different Subscription, isn't it? Can't do it from sub_1P17HDIoZDVxPDhemrR25aiS?

umbral pasture
#

Now what to do further, please guide me

#

hello @gloomy stream

gloomy stream
#

I mean please follow the articles suggestions there. You would then iterate through the Charges amount and find any Charge which has >0 amount, compare the amount to the credit balance and refund a portion of it, or the whole Charge and move on the next one

umbral pasture
#

Okay leave it, I'm facing another issue here

#

When Downgrading from $999.99/year to $19.99/month I catch the webhook customer.subscription.updated
And in that I retrive

await this.stripe.subscriptions.retrieve(
      subscriptionID,
      {
        expand: ['latest_invoice.payment_intent'],
      },
      {
        apiKey: publishableKey,
      }
)

But in response In latest_invoice object I got charge = null. Why is that, in upgrading this problem don't occur then why in downgrading.

gloomy stream
#

Because this latest_invoice is $0, so it doesn't generate a PaymentIntent

#

You would want to list older Invoices as well

#

And find the one with > $0 amount

umbral pasture
#

But I really want the charge for further process,
like this condition that I've applied

if (
    stripeCharge.amount_captured > 0 &&
    stripeCharge.status == 'succeeded'
){
gloomy stream
#

Yes, so what is the Invoice next in the list and what is its Charge amount?

umbral pasture
#

Sorry, I don't get you

gloomy stream
umbral pasture
#

I don't get this, This is just giving me bunch of invoices, How that'll help me?

#

Cause I want the latest Invoice's charge, even If it is zero

#

I have to get some data from the charge then
like stripeCharge.receipt_url, stripeCharge.payment_method_details.card.last4;

#

Ok you can close the thread now

gloomy stream
#

But the latest Charge is 0 because it is crediting the Customer. The next one would be non-zero as it has some amount