#cberube_error

1 messages ยท Page 1 of 1 (latest)

spiral baneBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1225569332478873601

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

viscid phoenixBOT
onyx charm
#

Hello! Idempotency keys are designed to let you retry requests safely. For example, let's say you make a request to complete a payment and you get a timeout error. You can't be sure if Stripe received the request or not, so the payment may or may not have happened. If you retry the request without an idempotency key you might cause the payment to go through twice. With an idempotency key the same exact request can be tried again safely; the key lets us match up both requests and know that you only intended to perform that operation once.

#

Using the same idempotency key for two different requests, with different parameters, doesn't make sense.

#

Does that help?

gilded thorn
#

Yes, I believe I should update the shoping cart is on every updates. idemtpotency-key = seti_${userId}_${cartId}

Make sence?

onyx charm
#

Not sure, I need more details to advise.

gilded thorn
#

So , I shouldn't care about idempotecy unless for retries or should I use them all the time?

onyx charm
#

I will say that, generally speaking, using a cart ID isn't usually a good choice for an idempotency key, as a cart ID might have many dfferent requests associated with it.

gilded thorn
#

Not sure how to implement it then.

onyx charm
#

What Stripe APIs are you using?

gilded thorn
#

Latest

#

2023-10-16

onyx charm
#

No, I mean, like are you using Payment Intents? Charges? Invoices?

#

Checkout Sessions?

gilded thorn
#

setup intents and payment intents

onyx charm
#

Are you using one of our official libraries?

gilded thorn
#

???

onyx charm
#

What programming language are you using?

gilded thorn
#

THis is the message I receive. There is an option to update the cart id. then it works.

onyx charm
#

Right, but what programming language are you using?

gilded thorn
#

Javascript

onyx charm
#

On your server? So Node?

gilded thorn
#

fetch(/create-setup-intent?clang=${lang}, {
method: 'POST',
body: JSON.stringify({ ...customer, cart }),
headers: {
'Content-Type': 'application/json',
'Idempotency-Key': seti_${customer.id}_${cart.id}
}
});

#

return fetch('/create-payment-intent', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Idempotency-Key': pi_${customer.id}_${cart.id}
},
body: JSON.stringify(cart)
})

#

yes node

onyx charm
#

That's the client-side code. What language are you using on your server to handle the /create-setup-intent URL?

gilded thorn
#

Node

onyx charm
gilded thorn
#

// Check if the request is a duplicate
const existingIntent = await retrieveIntentBy(idempotencyKey, 'setupIntents');
if (existingIntent) {
// Return the response from the original request
return res.status(200).json({
error,
existingIntent
});
}

  const setupIntent = await stripe.setupIntents.create(
    options,
    { idempotencyKey}
  );
#

"stripe": "^14.10.0",

onyx charm
#

So yeah, you're using our official library. That library generally takes care of idempotency keys for you, so you don't need to set them or worry about them in general.

gilded thorn
#

Sub..., So i just need to remove it?

onyx charm
#

Yeah.

gilded thorn
#

Thanks.
I am having issue with new Stripe and Typescript validation.

spiral baneBOT
gilded thorn
#

So need have s to use any inord er to build.

#

In the client only.
let stripe: any;

jade sage
#

Hi ๐Ÿ‘‹

I'm stepping in as my colleague needs to go

gilded thorn
#

I load stripe in the UI thoe way:

jade sage
#

Okay so it seems like your idempotentcy key issue is resolved but you are having trouble with Typescript validation?

gilded thorn
#

But I cannot make work the instanciation with
new stripe()

#

idempotency key. I will remove them...

jade sage
#

Sorry but it is really hard to understand what you are talking about

#

What is your current issue when using stripe-node? What error are you seeing?

gilded thorn
#

let stripe: any; would like to have let stripe: Stripe instead; But i was not able to make it work somehow.

jade sage
#

Sorry I'm still not sure I understand you

gilded thorn
#

is the i the right import foe a client script?
import { Stripe } from '@stripe/stripe-js';

#

Thats what copilot suggested

jade sage
gilded thorn
#

Most script you provide are not in Typescript.

#

is this the right path with npm install @stripe/stripe-js

jade sage
#

Stripe JS does support Typescript but we do not show examples in it for our docs.

gilded thorn
#

That the issue I am facing. I need to use any because I was not able to make it work differently.

#

Should I use @stripe/stripe-js or the inlibe script is Ok.

jade sage
#

What have you tried?

gilded thorn
#

new Stripe(...)

#

Chat GTP suggest using:
var stripe = Stripe('YOUR_PUBLISHABLE_KEY');

jade sage
#

Please use our published docs. I cannot help you with whatever integrations ChatGPT is suggesting