Good evening
I’m obviously getting something wrong here with the sequence of requests and responses. When I do a £1 test translation (production), it works. Any amount in sandbox works. When customers try to purchase for larger amounts I get “verification required” from the python sdk which, as I’ve currently got things set up, stops the transaction and communicates the failure clientside.
Step 1: Client asks for a serverside response
async function createPayment(token) {
const body = JSON.stringify({
locationId,
sourceId: token,
});
const paymentResponse = await fetch('/payment-req', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body,
});
if (paymentResponse.ok) {
return paymentResponse.json();
}
const errorBody = await paymentResponse.text();
throw new Error(errorBody);
}
Step 2: Serverside branches on is_error
in the response:
@csrf_exempt
def payment_req(request):
bsk = Basket.objects.get(id=get_session_id(request, Basket))
client = Client(
access_token=access_token_live,
environment='production')
idempotency_key = str(uuid.uuid4())
r = json.loads(request.body.decode())
pyt = {
'idempotency_key': idempotency_key,
'location_id': r['locationId'],
'source_id': r["sourceId"],
'amount_money': {
'amount': int(bsk.total * 100),
'currency': 'GBP'
}
}
a = client.payments.create_payment(body=pyt)
if a.is_error():
return HttpResponse(json.dumps({'success': False,
'payment': {"code": a.errors[0]['code'],
"detail": a.errors[0]['detail']}}),
status=500)
return HttpResponse(json.dumps({'success': True,
'payment': {'id': a.body['payment']['id'],
'status': a.status_code,
'receipt_url': a.body['payment']['receipt_url'],
'order_id': a.body['payment']['order_id']
}}))
If is_error
is False only then do I send the verification and transaction completes.
But on larger amounts ‘is_error’ returns True with the following:
{'code': 'CARD_DECLINED_VERIFICATION_REQUIRED', 'detail': "Authorization error: 'CARD_DECLINED_VERIFICATION_REQUIRED'", 'category': 'PAYMENT_METHOD_ERROR'}
As it’s set up, I communicate “payment failure” to the user and it’s game over. How should I handle this response?