#abhinand_processing-time

1 messages ยท Page 1 of 1 (latest)

vivid stirrupBOT
#

๐Ÿ‘‹ 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/1440413132475469955

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

runic sonnet
#

abhinandkaippalli01_processing-time

#

๐Ÿ‘‹ hi there, I'm looking into this!

glass mango
#

abhinand_processing-time

glossy vault
#

take look on this video

glass mango
#

๐Ÿ‘‹ Most payments require talking to the banking partner for example the card issuer. So this takes some time, then we need to model the payment as successful and model money moving into your balance. All of this does take time and 4 to 6 seconds seems reasonable to me

What exactly are you trying to solve on your end?

glossy vault
#

My client is expecting this process to complete within 2โ€“3 seconds.

glass mango
#

Yeah I'm sure people expect stuff, but it's only payments so 2-3 seconds won't happen in my experience

glossy vault
#

The current processing time takes too long to complete the process โ€” it takes around 5 seconds to finish and show the payment success screen. This causes discomfort for the users.

#

Does the region we are using cause this issue?

glass mango
#

It could depending on where you are based. If you are in India then yes it can make the API a bit slower. Is that the case?

glossy vault
#

I don't think that is the issue

#

My client using it from America

glass mango
#

Then overall I would just say this is expected behaviour. It's a bit hard to say, you shared a recording wiht limited context. How do you integrate? Like what UI element, what does your code look like, what do you do when the Pay button is pressed in that video?

glossy vault
#

I will share my code

#

first method of creating the checkout link.
async createCheckoutLink (request, reply) {
try {
const userId = UserService.getUserId(request)
if (!userId) return reply.code(401).send({ message: "Token Passed with wrong CustomerID" })
let listCartItems = request.body.cart
if (listCartItems && listCartItems.length === 0) return reply.status(400).send({ message: 'Cart is empty' })
const orderId = generateOrderId()
const lineItems = await Promise.all(listCartItems.map(async (item) => {
const { drinkName, drinkDescription, drinkImageURL, drinkTotalPrice, drinkPrice, tip, taxes } = item
if (!drinkPrice || !tip || taxes === undefined || taxes === null) return reply.status(401).send({message: "You have one of this missing: Drink Price, Tips, Taxes"})
const unitAmount = Math.floor(drinkTotalPrice * 100) // in cents
return {
quantity: 1,
price_data: {
currency: 'usd',
product_data: {
name: drinkName,
description: drinkDescription,
images: [drinkImageURL],
metadata: {
...item
},
},
unit_amount: unitAmount
}
}
}))
// Create Session
const session = await stripeTest.checkout.sessions.create({
line_items: lineItems,
mode: 'payment',
success_url: ${process.env.STRIPE_SUCCESS_REDIRECT_URL}?session_id={CHECKOUT_SESSION_ID},
cancel_url: ${process.env.STRIPE_CANCEL_REDIRECT_URL}?type=cancelled,
metadata: {
customerId: userId,
orderId: orderId,
},
})
return reply.send({ clientSecret: session })
} catch (error) {
throw new Error(error)
}
}

glass mango
#

Okay so the video you used was on Hosted Checkout?

glossy vault
#

yes

#

I tested with my local server

#

same delay is also happening in my deployed server also

glass mango
#

Okay perfect. Do you listen to checkout.session.completed Event(s) on your webhook handler?

glossy vault
#

this is the method of webhook handled

async stripeWebHookEvent(request, reply) {
console.log([${new Date().toLocaleTimeString()}] Webhook Started)
const sig = request.headers['stripe-signature']
const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET
fastify.log.info(RAW BODY (first 50 bytes): ${request.rawBody.slice(0, 50).toString()})
let event
try {
event = stripeTest.webhooks.constructEvent(request.rawBody, sig, endpointSecret)
} catch (error) {
fastify.log.info(Webhook Error: ${error.message})
return reply.code(400).send(Webhook Error: ${error.message})
}
fastify.log.info(Event received: ${event.type})
switch (event.type) {
case 'checkout.session.completed':
// const response = await webHookServices.handleSessionCompleted(event, stripeTest, Order, Webhook)
const response = { skipped: false }
if (response?.skipped) {
fastify.log.info(checkout.session.completed: skipped (${response.reason}))
} else {
// await postPaymentStripeDrinkAssign(response, request, reply)
fastify.log.info(checkout.session.completed: status-success)
}
break;
case 'payment_intent.succeeded':
// await webHookServices.handlePaymentIntentSucceeded(event, stripeTest, Order)
fastify.log.info(payment_intent.succeeded: status-success)
break;
case 'charge.succeeded':
// await webHookServices.handleChargeSucceeded(event, Order)
fastify.log.info(charge.succeeded: status-success)
break;
default:
console.log(โš ๏ธ Unhandled event type: ${event.type})
}
console.log([${new Date().toLocaleTimeString()}] Webhook Closed)
return reply.send({ received: true })
}

glass mango
#

okay I guess you do since you shared the code for it

#

Checkout waits for that Event delivery to succeed before it redirects. So my guess is that part of your code is maybe a bit slower. Try just returning a 200 immediately and doing nothing just to confirm if it makes the redirect faster

glossy vault
#

checking

#

I tested like this
async stripeWebHookEvent(request, reply) {
console.log([${new Date().toLocaleTimeString()}] Webhook Started)
const sig = request.headers['stripe-signature']
const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET
fastify.log.info(RAW BODY (first 50 bytes): ${request.rawBody.slice(0, 50).toString()})
let event
try {
event = stripeTest.webhooks.constructEvent(request.rawBody, sig, endpointSecret)
} catch (error) {
fastify.log.info(Webhook Error: ${error.message})
return reply.code(400).send(Webhook Error: ${error.message})
}
fastify.log.info(Event received: ${event.type})
console.log([${new Date().toLocaleTimeString()}] Webhook Closed)
return reply.code(200).send({ received: true })
}

glass mango
#

I mean this is already doing things right? It should be fast-ish but just return a 200 and do nothing else

But usually listening for that Event does add some delay and there's nothing you can do to make this faster sadly

glossy vault
#

[00:57:30.656] INFO (11272): incoming request
[00:57:35.166] INFO (11272): Event received: charge.updated
[00:57:35.167] INFO (11272): request completed

glass mango
#

Try without the WebhookEndpoint at all to see how much faster it gets

#

just disable it in Test mode while you test

glossy vault
#

do you know why it is showing as unauthorized? this is showing when we open the stripe checkout page.
Request URL: https://api.hcaptcha.com/authenticate
Request Method: POST
Status Code: 401 Unauthorized

glass mango
#

usually means something about your computer/local network that's blocking captcha

#

Try a different browser or maybe rebooting. Sadly I can't really debug why captcha works/doesn't work on your machine

glossy vault
#

I can see 4 seconds difference.
async stripeWebHookEvent(request, reply) {
return reply.code(200).send({ received: true })
}

#

[01:13:23.415] INFO (420): incoming request
reqId: "req-3"
req: {
"method": "POST",
"url": "/transaction/webhook",
"hostname": "localhost:3000",
"remoteAddress": "127.0.0.1",
"remotePort": 58376
}
[01:13:23.416] INFO (420): request completed
reqId: "req-3"
res: {
"statusCode": 200
}
responseTime: 1.0339999794960022
[01:13:23.586] INFO (420): incoming request
reqId: "req-4"
req: {
"method": "POST",
"url": "/transaction/webhook",
"hostname": "localhost:3000",
"remoteAddress": "127.0.0.1",
"remotePort": 58376
}
[01:13:23.588] INFO (420): request completed
reqId: "req-4"
res: {
"statusCode": 200
}
responseTime: 1.0205000042915344
[01:13:23.648] INFO (420): incoming request
reqId: "req-5"
req: {
"method": "POST",
"url": "/transaction/webhook",
"hostname": "localhost:3000",
"remoteAddress": "127.0.0.1",
"remotePort": 58376
}
[01:13:23.649] INFO (420): request completed
reqId: "req-5"
res: {
"statusCode": 200
}
responseTime: 1.0230000019073486
[01:13:27.512] INFO (420): incoming request
reqId: "req-6"
req: {
"method": "POST",
"url": "/transaction/webhook",
"hostname": "localhost:3000",
"remoteAddress": "127.0.0.1",
"remotePort": 58376
}
[01:13:27.514] INFO (420): request completed
reqId: "req-6"
res: {
"statusCode": 200
}
responseTime: 1.3801000118255615

glass mango
#

yeah so I think that's sadly a known limitation. Removing the WebhookEndpoint is a bad idea since it's crucial in cases where the end customer closes the browser before being redirected but it does add this delay.

vivid stirrupBOT
glossy vault
#

but the webhook is woeking on background, right?

#

So even if we manually move out of the Stripe screen, the payment process should be work.

glass mango
#

but the webhook is woeking on background, right?
no because we wait for the delivery before we redirect

glossy vault
#

okay

#

Do you have any idea how to fix this time delay?