#rezamirzad

1 messages ยท Page 1 of 1 (latest)

sage lilyBOT
burnt lynx
#

Hello ๐Ÿ‘‹
The code you've shared is client-side code. The PaymentIntent is created server-side

#

because when I add it here:

body: JSON.stringify({ items: [{ productId: "productId" }], description: "some text" }),

the backend returns:
"type": "HttpError",
"message": "The request arguments are not compliant against the spec",

#

Let's keep the messages here for full context

#

can you delete the message you sent to the entire channel to keep it clean? ๐Ÿ™‚

tidal yacht
#

hello hanzo,

yes I know. but can't I just add the description from the front?

#

sure, sorry about that, i thought i was adding the message in here

burnt lynx
#

No worries ๐Ÿ™‚
Its just a guess but I think the error is coming from your own API rather than Stripe API
Your backend doesn't like you adding a description in the request you're making to /create-payment-intent path

tidal yacht
#

let me explain what I am looking to do:
once the paymentIntent request sent from the front, I need to keep an id for some data saved on my database (hence the "description")

then, when the webhook returns the payment.succeeded, i plan to use this description, to retrieve the data on my database and proceed to do what. want to do

#

here is my api on the backend

async createPaymentIntent(ctx: Context): Promise<void> {
try {
if (ctx.invalid?.body) {
throw HttpError.from(HttpErrorKind.BAD_REQUEST);
}
ctx.response.set('Access-Control-Allow-Origin', '*');
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
const {items} = ctx.request.body;
const price = await stripe.prices.search({
query: "active:'true' AND product:'" + items[0].productId + "'",
});
const paymentIntent = await stripe.paymentIntents.create({
setup_future_usage: 'off_session',
amount: price.data[0].unit_amount,
currency: 'eur',
automatic_payment_methods: {
enabled: true,
},
});
ctx.status = 200;
ctx.body = {clientSecret: aymentIntent.client_secret};
console.log('stripe paymentIntent');
console.log(paymentIntent);
} catch (error) {
this.handleError(error, ctx);
}
}

#

where would I have to add the code to catch the description sent from my frontend body?

#

and of course, will this "description" be available in the webhook response?

#

sorry, tried to reformat the code a few times

burnt lynx
#

I think the issue is with whatever ctx is in your code

Look at the following line

const {items} = ctx.request.body;

It looks like it expects only items to be passes in rather than items and description

On Stripe's end, the only thing you need to do is add description to following code

    setup_future_usage: 'off_session',
    amount: price.data[0].unit_amount,
    currency: 'eur',
    description: "YOUR DESC HERE",
    automatic_payment_methods: {
        enabled: true,
       },
   });
#

So you should really look at your backend classes and figure out where exactly is this error coming from

#

Its not something we can help with since its not stripe related

#

its your own code

#

and of course, will this "description" be available in the webhook response?
Yes it should be available on payment_intent.* events

tidal yacht
#

yes!

i had forgotten to add "description" to the fields required/expected on the api payload

my bad

i found the solution

thank you so much @burnt lynx

burnt lynx
#

NP! ๐Ÿ™‚ Happy to help

tidal yacht
#

have a nice day

burnt lynx
#

You too