#bassil-multiple-charge
1 messages · Page 1 of 1 (latest)
Hi there, do you have a request id I could look at please?
If the amount is partially refunded, the fee taken is also adjusted.
Yes sure will give ID now
Payment ID right?
pi_3KBvsABStawTvwlL2yZN9FPQ
She should have been charged 1,392.13
she was charged د.إ2,364.27
So I refunded د.إ972.14
The metadata seems to be correct too, cart_subtotal_in_aed_less_code
1392.1348314606741
Can you check the payment intent update logs to see what the amount to be charged was updated to, so we can diagnose the issue
because my customer wasn't happy lol, really felt bad when this happened, we strive to provide top customer service and UI
Looking at the timeline of the PaymentIntent, there had only been a creation with the amount of 2364.27.
I was wondering how are you handling the payment on your client?
Would you be able to double check the amount for the cart_subtotal_in_aed_less_code metadata field is being passed in correctly to the PaymentIntent create function please?
Or if you could provide me with your code, I could assist you in the investigation 🙂
So no update payment was made just creation , problem might be when it initialized the payment maybe they had previous items they removed from cart and some bug happened one moment let me check 🙂
oh I think I found the issue
@csrf_exempt
def create_payment_intent(request):
stripe.api_key = STRIPE_SECRET_KEY
def calculate_order_amount(items):
total = round(float(request.session['cart_subtotal_in_aed']), 2)
return int(str(total).replace('.', ''))
try:
data = json.loads(request.body)
intent = stripe.PaymentIntent.create(
amount=calculate_order_amount(data['items']),
currency='aed',
)
request.session['payment_intent'] = intent['id']
return JsonResponse({
'clientSecret': intent['client_secret']
})
except Exception as e:
print(e)
return JsonResponse({'error': str(e), 'status': 403})
For the amount in the create payment intent it is using the cart subtotal in the session cookie but I should reiterate the cart and then provide the total
just like I do in the update payment intent function
Because in the update payment intent id function I have the following code
# Adds cart items to payment intent
cart_items_list = ''
cart_subtotal_in_aed = 0.0
cart_cogs_in_aed = 0.0
for product_id, quantity in request.session['cart'].items():
cart_items_list += (product_id + ':' + quantity + ',')
product = TyreProducts.objects.get(pk=product_id)
cart_subtotal_in_aed += (product.price_in_aed * float(quantity))
cart_cogs_in_aed += (product.cogs_in_aed * float(quantity))
need to do the same for creation of payment intent
Just updated the create payment intent function to this
@csrf_exempt
def create_payment_intent(request):
stripe.api_key = STRIPE_SECRET_KEY
def calculate_order_amount(items):
# Adds cart items to payment intent
cart_items_list = ''
cart_subtotal_in_aed = 0.0
cart_cogs_in_aed = 0.0
for product_id, quantity in request.session['cart'].items():
cart_items_list += (product_id + ':' + quantity + ',')
product = TyreProducts.objects.get(pk=product_id)
cart_subtotal_in_aed += (product.price_in_aed * float(quantity))
cart_cogs_in_aed += (product.cogs_in_aed * float(quantity))
total = round(cart_subtotal_in_aed, 2)
return int(str(total).replace('.', ''))
try:
data = json.loads(request.body)
intent = stripe.PaymentIntent.create(
amount=calculate_order_amount(data['items']),
currency='aed',
)
request.session['payment_intent'] = intent['id']
return JsonResponse({
'clientSecret': intent['client_secret']
})
except Exception as e:
print(e)
return JsonResponse({'error': str(e), 'status': 403})
Thank you so much
just to let you know there will be delays in my response, I am currently looking into another urgent incident, sorry for the inconvenience.
No worries at all
Looking at your server code where PaymentIntent is created, this only has amount and currency, how did you set the other fields? Are you calling the create PaymentIntent method within the client?