#Pain - expand charge webhook

1 messages · Page 1 of 1 (latest)

wind remnant
#

You will always have to make the API call with the webhook event. Webhooks events don't support automatically expanding fields at the moment

raw yew
#

Oh alright, if you take a look at this request req_E3zanEMLVYwsZv you can see it has the customer as a string which links to an object

wind remnant
#

Yeah, you can expand the customer in the response to that API call, but that just tells us how to render the response for that one call. The objects themselves still just have each others IDs on them and that is what we send in events

raw yew
#

Got it, thanks. Also to confirm is this how I can set the invoice_settings.default_payment_method?

await stripe.customers.update(
    customerId,
    {"invoice_settings.default_payment_method": paymentMethodId}
);
#

or is it

await stripe.customers.update(
    customerId,
    {invoice_settings : {
      default_payment_method: paymentMethodId
    }}
);
wind remnant
#

Should be the second one I believe. If that errors out let me know and we can dig in to the syntax a bit more

raw yew
#

Got it, quick question though

#

If a payment has setup_future_usage : off_session is this specified in the event from the webhook?

#

because I am attempting to check if the customer has a default payment method already invoice_settings.default_payment_method when a charge has succeeded, if they do not and the setup_future_usage is set to off_session I wish to set that card as their default

#

Hmm, may be better to just listen to another event entirely; the payment_method.attached and then check accordingly because I do not believe the event returned from the webhook will specify this

wind remnant
#

You should be able to see info about that but I think you are correct that that would show up on the payment method rather than the payment.

#

I am bouncing around threads a bit but can look at this in a minute

raw yew
#

No worries

wind remnant
raw yew
#

Oh I would have to retrieve the payment intent from the event then

wind remnant
#

I am checking where this might be on the PaymentMethod itself too. I feel like it has to be there but I am not immediately seeing it

raw yew
#

I tried the payment_method.attached but no other info was given

wind remnant
raw yew
#

I think I got it

#

I will look up the payment_intent from the event

#

If setup_future_usage is set to off_session

#

I will set the payment method that's exposed in that intent as their default

#

I think that should work

wind remnant
#

Yep is the way to do that from that event. Glad you could find a solution!

raw yew
#

StripeInvalidRequestError: Received unknown parameter: invoice_settings.default_payment_method

#

I guess this isn't the syntax,

#

Right the second syntax was the correct one

#
async updateDefaultPayment(customerId, paymentMethodId) {
    await stripe.customers.update(
        customerId,
        {
            invoice_settings: {
                default_payment_method: paymentMethodId
            }
        }
    );
}
#

Seems like this solution works

#

Is there a way to prevent duplicate cards saving?

wind remnant
#

There isn't anything built in but you can code the logic yourself to ensure you don't have duplicates