Skip to main content

Authorize / Capture Request

🔄 Authorize / Capture

⚠️Important Note

Authorize and Capture features are only available with the MPGS payment gateway service.

🔒

Two-Step Payment Process

The Authorize/Capture payment flow is a two-step process that allows merchants to authorize a transaction first (ensuring funds availability) and capture the funds later when ready to deliver the service or product.

🎯 Authorize Transaction Request

To authorize a transaction, include the following parameter in the checkout request:

🔐authorize: Boolean flag to indicate authorization

Authorize Transaction Request

🏷️ Environment📝 End Points
Sandboxhttp://sandbox.hesabe.com/api/checkout
Productionhttps://api.hesabe.com/api/checkout

To authorized transaction, send a POST request with the following parameters:

🏷️ Field📋 Type📝 Description
amount NumericAmount in currency
currency StringISO currency code
responseUrl StringRedirect URL on success
failureUrl StringRedirect URL on failure
merchantCode NumericAssigned by Hesabe
paymentType Numeric 2 (Visa/MasterCard)
version StringAPI version (e.g., 2.0)
orderReferenceNumber StringYour reference/order ID
variable1-5 StringOptional key-value pairs (Label__Value)
name StringCustomer name
mobile_number Numeric (8)Customer mobile (no country code)
email StringCustomer email
saveCard BooleanSave card for tokenization
cardId StringTokenized card ID
authorize Boolean 1 (Authorization-only transaction)
webhookUrl String Your endpoint for receiving payment status

Capture Transaction Request

🏷️ Environment📝 End Points
Sandboxhttp://sandbox.hesabe.com/api/capture
Productionhttps://api.hesabe.com/api/capture

To capture the authorized transaction, send a POST request with the following parameters:

🏷️ Parameter📝 Description
merchantCode Merchant Code is a unique identifier generated by Hesabe for each activated merchant
amount Transaction amount equal to or less than the authorized transaction amount
paymentToken Payment Token returned from the authorized transaction

Sample PHP Code for capture:

$baseUrl = 'http://sandbox.hesabe.com/api/'; // sandbox
$captureApiUrl = $baseUrl . 'capture';
$requestData = [
'merchantCode' => 842217,
'amount' => 10,
'paymentToken' => '84221717175011419773484853173'
];
$encryptedData = HesabeCrypto::encrypt($requestData, $encryptionKey, $ivKey);
$checkoutRequestData = new Request([
'data' => $encryptedData
]);
$checkoutRequest = Request::create($captureApiUrl, 'POST', $checkoutRequestData->all());
$checkoutRequest->headers->set('accessCode', $accessCode);

Response sample for capture

{
"status": true,
"message": "Your refund request is waiting for approval",
"data": {
"token": "521042117249344539468767555844",
"amount": "1.000",
"order_reference_number": "1724934434",
"transaction_status": "SUCCESSFUL",
"refund_status": "PENDING",
"payment_type": "KNET",
"service_type": "Payment Gateway",
"transaction_datetime": "2024-08-29 15:27:38",
"refund_requested_at": "2024-09-04 15:04:44"
}
}

Cancel Authorized Transaction

To cancel the Authorized transaction for further Capturing the Amount.

$baseUrl =  'http://sandbox.hesebe.com/api/' // sandbox
$CancelApiUrl = {{$baseUrl}}/cancel/{paymentToken}
$checkoutRequest = Request::create($CaptureApiUrl, 'DELETE');
$checkoutRequest->headers->set('accessCode', $accessCode);