#eliasknudsen
1 messages ยท Page 1 of 1 (latest)
Hi ๐
Yes this is possbile. have you tested it out?
Yes, I got an error when i tested it out, let me reproduce the error and send here
Error: (node:11448) UnhandledPromiseRejectionWarning: Error: Invalid value type: {:address1=>"Vaekero Terrasse 9F", :address2=>"", :country_code_str=>"+47", :phone=>"96913407", :country=>"Norway", :shipment_method=>"STANDARD", :zip=>"0282", :state_code=>"", :city=>"Oslo", :country_code=>"NO", :name=>"Elias Knudsen"} must be a string Code: ```if (!result.error) {
const paymentIntent = await stripe.paymentIntents.create({
amount: parseInt((result.estimate.result.costs.total * 100).toFixed(0)),
currency: "usd",
automatic_payment_methods: {
enabled: true,
},
metadata: { email: req.oidc.user.email, ...result.metadata }
});
res.send({
message: "Payment intent created",
error: false,
clientSecret: paymentIntent.client_secret,
price: result,
});
} else {
res.send(result)
}```
Are you using typescript?
No, just normal js
Okay you will need to cast the nested data as a string before attempting to pass it in as metadata. I recommend creating the payload and logging in before you call the intent creation function
ok, so a json stringfy will suffice?
That should work.
Yea it worked, but now i have a character limit error, but thanks for the help, i will figure out the rest myself:)
Yeah there is a hard limit on the number of characters you can provide
Yea, it sucks a little since i am going to need to verify that the webhook was from stripe, and i have some urls that only the servers i communicate with should access, which means i am passing a privatekey. But i will figure something out. Thanks for the help
Happy to shed what ๐ก I can ๐
One more thing. What is the purpose of an idempotency key?
It is so you can make a request multiple times (in case of network failure) and only trigger a single response.
So if you attempted to confirm a charge and there was a network drop-out and you didn't get the resposne from the API, you could call it again using the same idempotency key and if we didn't receive it we would process the confirmation but if we did we would just return the result of the last request
Ok, so it is a key i need to store and compare against webhooks from stripe?
No
If you are trying to validate Stripe webhooks you should use our signature verification approach
Yea, I am already using that. But i was just wondering what the idempotency key was and if it is something i have to handle or not?
No, Stripe client libraries like stripe-node use them automatically
Ok, so it is not something i have to worry about?
Nope, not really
Some people like to define their own and use them because they run on buggy networks and that's their practice
So we expose the option
Oh ok, so it is for servers than run on unstable networks?
We have a nice explainer video here that covers it for safe retrying of API requests: https://stripe.com/docs/videos/developer-foundations?video=idempotency-and-retries&lang=python
Ok thanks for the help. Have a nice day:)