Using this api, new payment request can be created
Through this API, a payment creation request is received by EcommerzPay.
Endpoint
{base_url}/payment/create
{base_url} is the api endpoint (sandbox or live)
Request Header
Include the following request headers:
| Header | Description | Required |
|---|---|---|
| Content-Type | application/json | YES |
| X-APP-KEY | App key - Provided by EcommerzPay | YES |
| X-APP-SECRET | App Secret Key - Provided by EcommerzPay | YES |
Required Parameters
Include the following request parameters
| Parameter | Description | Required |
|---|---|---|
| txn_id | An unique ID for the transaction. Must be unique for each payment (Maximum 32 characters) | YES |
| cus_name | Customer's full name | YES |
| cus_mobile | Customer's 11 digit mobile number | YES |
| cus_email | Customer's valid email id | YES |
| amount | Payment amount | YES |
| meta_data | Optional data. Must be in JSON format | NO |
| callback_url | URL to which gateway will redirect the customer after payment is successful or cancelled. | YES |
| webhook_url | IPN or Instant Payment Notification URL to which the gateway will send the payment data in POST format | NO |
Response
| Parameter | Type | Description |
|---|---|---|
| status | Boolean | Request status (True or False) |
| statusMessage | String | A message related to the status |
| paymentURL | String | Payment URL |
Example Code
<?php
$curl = curl_init();
$trxID = uniqid();
$appKey = "Your App Key";
$appSecret = "Your App Secret";
curl_setopt_array($curl, [
CURLOPT_URL => "https://sandbox.ecommerzpay.com/v1.0.2-beta/payment/create",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
"txn_id" => $trxID,
"cus_name" => "Mr. Jhonts",
"cus_mobile" => "01819******",
"cus_email" => "[email protected]",
"amount" => 1000,
"callback_url" => "https://yourdomain.com/callback.php",
"webhook_url" => "https://ecommerzpay.com/webhook.php"
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"accept: application/json",
"x-app-key:" . $appKey,
"x-app-secret:" . $appSecret
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Success Response
{
"status": true,
"statusMessage": "Payment url generated",
"paymentURL": "https://sandbox.ecommerzpay.com/payment/254663aa2a6a4a5df2aa8dc9f28aa1744a8bae9f"
}
Error Response
{
"status": false,
"statusMessage": "Transaction id is already used",
}
