Create New Payment

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:

HeaderDescriptionRequired
Content-Typeapplication/jsonYES
X-APP-KEYApp key - Provided by EcommerzPayYES
X-APP-SECRETApp Secret Key - Provided by EcommerzPayYES

Required Parameters

Include the following request parameters

ParameterDescriptionRequired
txn_idAn unique ID for the transaction. Must be unique for each payment (Maximum 32 characters)YES
cus_nameCustomer's full nameYES
cus_mobileCustomer's 11 digit mobile numberYES
cus_emailCustomer's valid email idYES
amountPayment amountYES
meta_dataOptional data. Must be in JSON formatNO
callback_urlURL to which gateway will redirect the customer after payment is successful or cancelled.YES
webhook_urlIPN or Instant Payment Notification URL to which the gateway will send the payment data in POST formatNO

Response

ParameterTypeDescription
statusBooleanRequest status (True or False)
statusMessageStringA message related to the status
paymentURLStringPayment 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",
}