#Nick - Metered Pricing

1 messages · Page 1 of 1 (latest)

cosmic bobcat
#

How are you collecting the payment method details?

vestal flame
#

Setup intents, using the Stripe react component

cosmic bobcat
#

So you should be able to collect payment details using the finalized invoice.payment_intent.client_secret to initialize the component when you bring the user back on-session

vestal flame
#

Could you elaborate? Not sure I understand what you mean

cosmic bobcat
#

Okay so when the charge fails and you need to bring the user back on-session to provide new payment method information, you can use the subscription.latest_invoice.payment_intent.client_secret value to instantiate your Payment Element and collect the payment method information. This will automatically attach the new payment method to the Subscription and process the invoice with that payment method

#

I know you're not creating a new subscription in your case, but in the code snippet for creating a subscription you can see we show capturing the client secret and passing it to the front-end.

vestal flame
#

Thanks for the link. I guess I'm just confused because by the point that this issue comes up, the new payment method has already been setup as the subscription's default - which according to: https://stripe.com/docs/api/invoices/update#update_invoice-default_payment_method

ID of the default payment method for the invoice. It must belong to the customer associated with the invoice. If not set, defaults to the subscription’s default payment method, if any, or to the default payment method in the customer’s invoice settings.

It will attempt to charge the subscription's default if any

Shouldn't it charge the new default instead of the old one?

#

Or would the fact that a customer also has a default payment method set make that take precedence?

cosmic bobcat
#

Okay I'm a little confused, when in this process do you collect new payment information from the customer and then what is your app doing with it?

vestal flame
#

Let me elaborate a bit more

#

Basically someone signs up for a monthly subscription on Apr 1 with a credit card (attached to the subscription as the default, but there is no default at the customer level)

They accrue usage that's reported as usage records throughout the month of April

On May 1, the month is over, the upcoming invoice is converted to an invoice and auto advance is set to true. Payment is attempted, but the bank declines the payment for whatever reason

We send an email to the customer based off of the invoice.payment_failed webhook saying "Please add a new payment method"

The customer then goes in and adds a new payment method, which is setup under the customer, and the subscription's default_payment_method is set to the ID of the new one

At this point I'd expect previous unpaid invoices to attempt to charge using the newly added payment method (because it's now the subscription's default), but it seemed to still want to charge the old one

cosmic bobcat
#

The customer then goes in and adds a new payment method
This process is done without reference to the unpaid invoice, correct? You still use a setup intent here?

#

I think the problem is the invoice already exists at this point so, to have the impact you expect, you need to involve the latest invoice (and it's related payment intent) in the process of collecting new payment method details

vestal flame
#

Still use a setup intent for the second time they add the card yes

#

I think the problem is the invoice already exists at this point so, to have the impact you expect, you need to involve the latest invoice (and it's related payment intent) in the process of collecting new payment method details

So the way to do this is as you mentioned before with the payment intent secret?

cosmic bobcat
#

Yes I think that will accomplish what you are looking for.

#

Using the client_secret from the invoice.payment_intent should trigger an immediate payment of that invoice with the new method

vestal flame
#

In which call to Stripe would I pass the client secret for?

#

Not seeing anything in the setupintent or on the invoices themselves?

cosmic bobcat
#

When the user comes back on-session, you would retrieve the subscription they are paying for in your back-end. When you make that API call for the subscription you would pass in latest_invoice.payment_intent to the expand parameter.

Then your back-end would pass the subscription.latest_invoice.payment_intent.client_secret to your front-end instead of a Setup Intent client secret.

vestal flame
#

But wouldn't that just scope the payment method to that specific invoice? We'd ideally want it to be setup for future payments - ie the subscription would use the new method going forward as well

#

Or are you saying do that in addition to everything I'm doing normally

#

Also just wondering how that would work if say they had 2 months of unpaid invoices

cosmic bobcat
vestal flame
#

Cool - thanks. Only question now is how this works with multiple invoices?

Say they didn't pay for Apr 1 -> May 1, and again didn't pay for for May 1 -> June 1

I can't pass multiple client secrets AFAIK, so I'd only be able to charge the most recent one?

cosmic bobcat
#

Correct. Unless you looked up the earlier invoice via the API

vestal flame
#

To clarify - I could look up the earlier (ie, the older) invoice and have that one be paid, but wouldn't be able to do both the oldest and the most recent?

Like you'd need to do a setupintent with the first invoice's payment_intent.client_secret

And then you'd need to do another setupintent with the most recent invoice's payment_intent.client_secret?

cosmic bobcat
#

No setup intents are involved in any of these cases. The payment intent has the client secret. And I would want to test this out in conjunction with the Subscription default payment method update to see if either were automatically processed

vestal flame
#

So the problem I'm having testing this in the test dashboard is that the test cards all decline at the time they're setup

#

Is there a card number I can add that will add to the customer, but decline at the time the invoice is charged?

#

lol it's right below it, nvm

#

I'll play around with it. Thanks for your help

cosmic bobcat
#

Happy testing! I hope it goes well for you