#Pain - Unset metadata
1 messages ยท Page 1 of 1 (latest)
Hi ๐
Have you tried and empty string ""?
https://stripe.com/docs/api/charges/update#update_charge-metadata
All keys can be unset by posting an empty value to metadata.
Where that gets tricky is what each programming language considers "an empty value"
I tried an empty string and it did not work, I tried changing it too.
Maybe I did something wrong; I will try again.
Can you share a request ID for one of these requests?
I was trying to update the charge metadata instead of the intent where I initially set it; would this not update the charge?
Just a moment, going to try and do it again just to make sure I'm not doing something stupid.
You should be able to update the Charge record once it is created
Okay so it works if I update the intent
๐ค
I will try again with charge
Yeah, seems like it does not work?
I am listening to the webhook callpack for charge.succeeded
Interesting. Can you share the request ID of the Payment Intent update that succeeded and the Charge update that failed?
await stripe.charges.update(
data.id,
{metadata: {renew_subscription: ''}}
)
await stripe.paymentIntents.update(
data.payment_intent,
{metadata: {renew_subscription: ''}}
);
Top does not work, bottom does
The data is just the returned construct from the webhook
const data = event.data.object;
Sorry I meant the request IDs. I want to file this as odd and those examples will help
request IDs have the format req_XXX
perfect, thanks
So in that case you provided a key and it looks like the key was not present (or was unset by this request)
Are you trying to unset all the keys?
My current flow goes as follows:
=> off session charge (currently testing 3D secure)
=> charge fails and I set the metadata
=> return user to website with client_secret and pm
=> they fulfill the payment and I dismiss that metadata
No I am only trying to unset that specific one
but it's not doing anything
It works if I use the intent but does not if I use the charge
I'm attempting to unset this piece of metadata once the charge succeeds
Hi there ๐ I'm jumping in so @high granite can take a break. I'm pulling up that request and taking a closer look.
When I look at the response to that request that you provided, I'm seeing that renew_subscription is not in the metadata returned for the Charge. Are you seeing something different?
Oh so it seems like Charge does not share the same payment metadata as the intent?
Initial request req_0nCnB8auxbuYXY
Second request for confirm req_1SUwFsWUdMOHfS
Oh wait, what.. its not in the request but it's still on the dashboard
Correct, metadata is not inherently shared between objects in the Stripe ecosystem, it remains on the object where it was set. If you want to sync the metadata between two objects then you will need to build logic to monitor for and handle that.
๐ค
I see, so I should update the payment intent where I set it originally
Since that works, was a bit confused on why I couldn't do the charge; but that makes sense.
Yup, updating that on the Payment Intent, I believe, will adjust what you're seeing in the dashboard.
Perfect, thank you for the information.
That was it, it works.
I have a question about default source
so I currently plan to charge the customers default payment source, what's the best way of getting this?
What I'm doing currently since I need the paymentMethods from the customer I'm just expanding on the customer object like so
const paymentMethods = await stripe.customers.listPaymentMethods(
customer,
{type: 'card',
expand: ['data.customer']}
);
then accessing the customer.sources
The best way to do that is to retrieve the Customer, and check the default_source field (but that's based on the assumption that default_source is being set at some point):
https://stripe.com/docs/api/customers/object#customer_object-default_source
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
If you intermingling Sources and Payment Methods, then you may need to check invoice_settings.default_payment_method instead:
https://stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I would have to set their payment method default differently if I want to access the invoice_settings.default_payment_method
Currently I just set it as default from the dashboard
and it isn't in the customer object
but it is in the sources
Ah, I'm not sure that the dashboard's default maps to a setting in the API objects.
Oh alright, then I will need to use the other path since I need to call the API to set their default payment method
as I plan to make the first card they save their default payment method
then they can adjust it accordingly if they add other cards
So if I'm not mistaken, I will check the customer.invoice_settings.default_payment_method, if it's null I will use https://stripe.com/docs/api/customers/update?lang=node#update_customer-invoice_settings-default_payment_method this endpoint to update the default_payment_method
Exactly!
Would it be possible for stripe to implement something down the line to default saved cards?
Something like off_session/confirm - a parameter that would automatically set the card as their default too
So another parameter that would be used with setup_future_usage
That's a good suggestion and I'll capture it as feedback. Typically we err on the side of caution and provide the tools to do various things but avoid doing too much by default.
I've raised that feedback to our teams, though while thinking through it, I think it would be very difficult to implement that type of functionality in a good way. For instance, if you got a scenario where there are three Payment Intents created for a Customer, each one intending to update the default payment method during confirmation, then the order in which those payments are confirmed becomes very important.