Create a Charge
The last step is creating the charge. You will need the customer_id and the payment_method_id created in steps #2 and #3.
When creating a charge, there are different scenarios; in this case, we’ll see the 3DS authentication response.
API Documentation: Create Charge
Request:
curl -i -X POST \
https://sandbox-api.pathly.io/charges \
-H 'Authorization: Bearer <YOUR_JWT_HERE>' \
-H 'Content-Type: application/json' \
-d '{
"id": "ec7e1848-dc80-4ab0-8827-dd7fc0737b43",
"customer_id": "ec7e1848-dc80-4ab0-8827-dd7fc0737b43",
"payment_method_id": "ec7e1848-dc80-4ab0-8827-dd7fc0737b43",
"amount": {
"value": 99,
"currency": "USD"
},
"three_ds": {
"success_url": "https://pathly.io/acs/succeed",
"fail_url": "https://pathly.io/acs/failure"
}
}'
This is the minimum data required for 3DS operations. success_url and fail_url are your own URLs where customers will be redirected upon authentication success or failure. It is worth noting that in some cases, even if the 3DS authentication is successful, the charge might still fail (e.g., due to insufficient funds). Not all failures mean that the authentication failed.
Response:
When 3DS is enabled on your account, the response from this endpoint will always be a 202 with a message of “3DS Required”. In the response body, you will find the URL to which you should redirect your customer to complete the authentication:
{
"status": "pending",
"code": 202,
"data": {
"acs_url": "https://pathly.io/acs?sid=61cbcb99cf4598b…"
},
"message": "3DS Required"
}
If anything but a 202 is returned, it means there was a problem with creating the charge, and a description of the problem will be returned in the response body.