Step 4: Inspect a transaction
After the transaction has been created your application can retrieve the
transaction ID posted in the form submission or if you have implemented the
onComplete
callback, by inspecting the transaction object passed with the
callback.
Get transaction details
This transaction ID can be used with the SDK to fetch additional details about the transaction.
- cURL
- Node
- Python
- Go
- PHP
const response = await client.getTransaction(transaction_id);
console.log(response.data);
curl -i -X GET "https://api.{gr4vyId}.gr4vy.app/transactions/fe26475d-ec3e-4884-9553-f7356683f7f9" \
-H "Authorization: Bearer [JWT_TOKEN]"
var response *Gr4vyTransaction
response, _, err = client.GetTransaction(transactionId)
if err != nil {
t.Errorf(err.Error())
return;
}
t.Log("Retrieved transaction: " + *response.Id)
$result = $apiInstance->getTransaction($transaction_id);
echo $result;
response = client.GetTransaction(transaction_id)
print(response)
The transaction includes details about the payment method used, and the status of the transaction.
{
"type": "transaction",
"id": "fe26475d-ec3e-4884-9553-f7356683f7f9",
"status": "authorized",
"amount": 1299,
"currency": "USD",
"payment_method": {
"type": "payment-method",
"id": "77a76f7e-d2de-4bbc-ada9-d6a0015e6bd5",
"method": "card",
"status": "stored",
"token": "0123456789123458",
"details": {
"number": "XXXX XXXX XXXX 1111",
"expiration_date": "11 / 21",
"scheme": "visa"
},
...
},
...
}
API Reference
Visit the API reference documentation for full details about the transaction resource, and any other API.
Capture transaction
Although Gr4vy Embed allows for setting the intent
to capture
, in some cases
it might be desirable to capture the transaction after it has been authorized.
- cURL
- Node
- Python
- Go
- PHP
const { Client, TransactionCaptureRequest } = require("@gr4vy/node");
const request = new TransactionCaptureRequest();
request.amount = "1000";
const transaction = await client.captureTransaction(id, request);
bash curl -i -X POST https://api.{gr4vyId}.gr4vy.app/transactions/fe26475d-ec3e-4884-9553-f7356683f7f9 \
-H "Authorization: Bearer [JWT_TOKEN]" \
-H "Content-Type: application/json" \
-d '{ "amount": 10000, }'
response, _, err := client.CaptureTransaction(transactionId, req)
if err != nil {
t.Errorf(err.Error())
return;
}
t.Log("Capture status: " + *response.Status)
$result = $apiInstance->captureTransaction($transaction_id);
echo $result;
response = client.CaptureTransaction(transaction_id, transaction_capture_request)
print(response)
Partial capture
Some payment processors allow for partial processing. To capture a part of the authorized amount only, set the amount on the capture request to an amount lower than the originally authorized amount.