#fitz

1 messages · Page 1 of 1 (latest)

weak duneBOT
woven pollen
#

Hi there, can you share with me the PaymentIntent ID?

red oyster
#

hi jack, sure, where exactly do i get that?

#

im using a local server and the test environment on the stripe dashboard, nothing is live

woven pollen
#

You can find the paymentIntent ID from the PaymentIntent creation response.

red oyster
#

pi_3MoH5WAg9Km0gzmp1c80lUgn

#

does that look right?

woven pollen
#

Yup, give me a sec

#

Based on the log at my end, the end to end duration for this PaymentIntent creation is around 0.3 seconds.

red oyster
#

strange, its taking 1.1 minute every time on my end, in the browser console network tab it says 'waiting for server response' takes 1.1 minutes, is this a local issue in that case?

woven pollen
#

Can you tell me how do you measure the API duration?

red oyster
#

im just going off of how long the paymentIntent takes to generate on my end, the create-payment-intent route takes 1 minute to return a 200 OK status according to the browser dev tools, and I have test messages which print 1 minute apart also:

@app.post('/create-payment-intent')
async def create_payment(request: Request):
    try:
        data = await request.json()
        items = data.get('items', [])
        amount = calculate_order_amount(items)
        print("Before payment intent create")
        intent = stripe.PaymentIntent.create(
            amount=amount,
            currency='eur',
            automatic_payment_methods={
                'enabled': True,
            },
        )
        print("After payment intent create")
        return JSONResponse({
            'clientSecret': intent['client_secret']
        })
    except Exception as e:
        return JSONResponse(content={'error': str(e)}, status_code=403)```

The before message prints instantly, and the after message prints around a minute later
woven pollen
#

Can you export the HAR file to me?

red oyster
woven pollen
red oyster
#

just run from my actual machine?

#

not sure if thats done properly but ran it using git bash

#

from my desktop

woven pollen
#

Ok, so your server can reach Stripe API. Can I suggest you to put more logs in your backend code to measure how long it takes to execute each function?

red oyster
#

i'm confused now hahaha, I did just that, added times to log each part of the process and suddenly its working again:

    total_amount = 0
    for item in items:
        total_amount += int(item['productPrice'] * 100)
    return total_amount

@app.post('/create-payment-intent')
async def create_payment(request: Request):
    try:
        start_time = time.time()
        data = await request.json()
        end_time = time.time()
        print(f"Time taken to get JSON data: {end_time - start_time:.3f} seconds")

        start_time = time.time()
        items = data.get('items', [])
        amount = calculate_order_amount(items)
        end_time = time.time()
        print(f"Time taken to calculate order amount: {end_time - start_time:.3f} seconds")

        start_time = time.time()
        print("Before payment intent create")
        intent = stripe.PaymentIntent.create(
            amount=amount,
            currency='eur',
            automatic_payment_methods={
                'enabled': True,
            },
        )
        end_time = time.time()
        print(f"Time taken to create payment intent: {end_time - start_time:.3f} seconds")
        print("After payment intent create")

        start_time = time.time()
        response = JSONResponse({
            'clientSecret': intent['client_secret']
        })
        end_time = time.time()
        print(f"Time taken to create JSON response: {end_time - start_time:.3f} seconds")

        return response
    except Exception as e:
        return JSONResponse(content={'error': str(e)}, status_code=403)```

Time taken to get JSON data: 0.000 seconds
Time taken to calculate order amount: 0.000 seconds
Before payment intent create
Time taken to create payment intent: 0.443 seconds
After payment intent create
Time taken to create JSON response: 0.000 seconds

#

no idea how its just back to normal

woven pollen
#

I'd suggest you to monitor it first and reach out to us again if you find the API request takes a long time.

red oyster
#

I will, gonna leave the time logs in for now and test it over the next few days