#Pain - expand charge webhook
1 messages · Page 1 of 1 (latest)
You will always have to make the API call with the webhook event. Webhooks events don't support automatically expanding fields at the moment
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
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
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
}}
);
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
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
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
No worries
It turns out that it is indeed on the payment intent https://stripe.com/docs/api/payment_intents/object#payment_intent_object-setup_future_usage
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Oh I would have to retrieve the payment intent from the event then
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
I tried the payment_method.attached but no other info was given
I think you can get it by looking up the SetupAttempt related to the payment method but that requires another API call anyway
https://stripe.com/docs/api/payment_methods/object#payment_method_object-card-generated_from-setup_attempt https://stripe.com/docs/api/setup_attempts/object#setup_attempt_object-usage
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
Yep is the way to do that from that event. Glad you could find a solution!
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?
There isn't anything built in but you can code the logic yourself to ensure you don't have duplicates
For cards it is easiest to check the fingerprint which will always be the same for the same card when saved on your account https://stripe.com/docs/api/payment_methods/object#payment_method_object-card-fingerprint