OPay ValU Installment

In this page, you will learn how to use ValU installment.

  • Collect your client's payment Information
  • Send ValU payment request, and return installment plan
  • Client select and confirm the installment plan
  • Client input the OTP to complete the payment

It works as follows:

  • Merchant collect your client's payment Information
  • Merchant make ValU Payment, and OPay respond the installment plans
  • Merchant select and confirm the installment plan
  • Merchant input the OTP to complete the payment

1.Send ValU payment request, and return installment plan

This API can be used to make ValU payment. In case you are still in development phase, you need to request using the POST method in our sandbox environment.
-Here is the request URL:

                    
                        https://sandboxapi.opaycheckout.com/api/v1/international/payment/create
                    
                

-Once you have a fully tested payment flow and you are ready for production, use the following production API endpoint URL instead

                    
                        https://api.opaycheckout.com/api/v1/international/payment/create
                    
                

-Request Parameters:

  1. Header: Authorization(API Calls Signature), MerchantId
  2.                         
                                Authorization    : Bearer {signature}
                                MerchantId       : 256612345678901
                            
                        
  3. Json object containing the transaction information:
  4.                         
                                {
                                 "amount": {
                                     "currency": "EGP",
                                     "total": 60000
                                 },
                                 "callbackUrl": "https://your-call-back-url",
                                 "country": "EG",
                                 "payMethod": "VALU",
                                 "product": {
                                     "description": "dd",
                                     "name": "name"
                                 },
                                 "reference": "test2022_1655372839575",
                                 "returnUrl": "https://your-return-url",
                                 "valUAccountNumber": "01066668888"
                                }
                            
                        

HTTP POST parameters

-Here is a detailed description for the parameters you need to complete the POST request:

Parameter type required Description
reference String required The unique merchant payment order number
country String required Country Code.See full list here
amount
JSON
Object
total Long required Amount(cent unit)
currency String required Currency type.See full list here
payMethod String required VALU payment method: VALU
callbackUrl String optional If you have sent callbackUrl through API, OPay will send callback notification to this callbackUrl. If you didn't send callbackUrl through API, you need to configure webhook url on the merchant dashboard, and OPay will send callback notification to this webhook url. See callback here
returnUrl String required The URL to which OPay API should return the payment processing response
product
JSON
Array
name String required Product name
description String optional Product description
valUAccountNumber String required Phone number bound to ValU account
downPayment
JSON
Object
total Long optional Amount(cent unit)
currency String optional Currency type.See full list here

-An example of make ValU payment is as follows :

                                
                                    class CreateValuInstallmentController
                                    {
                                        private $secretkey;
                                        private $merchantId;
                                        private $url;

                                        public function __construct() {
                                            $this->merchantId = '281822021180001';
                                            $this->secretkey = 'OPAYPRV1644547******513012905';
                                            $this->url = 'https://sandboxapi.opaycheckout.com/api/v1/international/payment/create';
                                        }

                                        public function test(){
                                            $data = [
                                                "amount" => [
                                                    "currency" => "EGP",
                                                    "total" => 400000
                                                ],
                                                "callbackUrl" => "https://your-call-back-url.com",
                                                "country" => "EG",
                                                "payMethod" => "VALU",
                                                "product" => ["name" => "name"],
                                                "reference" => "04123390",
                                                "returnUrl" => "https://your-return-url.com",
                                                "valUAccountNumber" => "01201297772",
                                            ];
                                            $data2 = (string) json_encode($data,JSON_UNESCAPED_SLASHES);
                                            $auth = $this->auth($data2);
                                            $header = ['Content-Type:application/json', 'Authorization:Bearer '. $auth, 'MerchantId:'.$this->merchantId];
                                            $response = $this->http_post($this->url, $header, json_encode($data));
                                            $result = $response?$response:null;
                                            return $result;
                                        }

                                        private function http_post ($url, $header, $data) {
                                            if (!function_exists('curl_init')) {
                                                throw new Exception('php not found curl', 500);
                                            }
                                            $ch = curl_init();
                                            curl_setopt($ch, CURLOPT_TIMEOUT, 60);
                                            curl_setopt($ch, CURLOPT_URL, $url);
                                            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                                            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
                                            curl_setopt($ch, CURLOPT_HEADER, false);
                                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                            curl_setopt($ch, CURLOPT_POST, true);
                                            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                                            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
                                            $response = curl_exec($ch);
                                            $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                                            $error=curl_error($ch);
                                            curl_close($ch);
                                            if (200 != $httpStatusCode) {
                                                print_r("invalid httpstatus:{$httpStatusCode} ,response:$response,detail_error:" . $error, $httpStatusCode);
                                            }
                                            return $response;
                                        }
                                        public function auth ( $data ) {
                                            $secretKey = $this->secretkey;
                                            $auth = hash_hmac('sha512', $data, $secretKey);
                                            return $auth;
                                        }

                                    }

                                
                            
                                
                                    const request = require('request');
                                    var sha512 = require('js-sha512');
                                    const formData = {
                                      "amount":{
                                          "currency":"EGP",
                                          "total":400000
                                      },
                                      "callbackUrl":"https://your-call-back-url.com",
                                      "country":"EG",
                                      "payMethod":"VALU",
                                      "product":{"name":"name"},
                                      "reference":"04123392",
                                      "returnUrl":"https://your-return-url.com",
                                      "valUAccountNumber":"01201297772"
                                    };

                                    var privateKey = "OPAYPRV1644547******513012905"

                                    var hash = sha512.hmac.create(privateKey);
                                    hash.update(JSON.stringify(formData));
                                    hmacsignature = hash.hex();
                                    console.log(hmacsignature)
                                    request({
                                        url: 'https://sandboxapi.opaycheckout.com/api/v1/international/payment/create',
                                        method: 'POST',

                                        headers: {
                                          'MerchantId': '281822021180001',
                                          'Authorization': 'Bearer '+hmacsignature
                                        },
                                        json: true,
                                        body: formData
                                      }, function (error, response, body) {
                                        console.log('body: ')
                                        console.log(body)
                                      }
                                    )

                                
                            
                                
                                    curl --location --request POST 'https://sandboxapi.opaycheckout.com/api/v1/international/payment/create' \
                                    --header 'MerchantId: 281822021180001' \
                                    --header 'Authorization: Bearer d9cbe9407522335ec052a7a9fa84bd9de2dabdf293bf41abda46fe36ae6b3c427e60823faedd276dd20c45b65c738a7aa2c3e1fd350a3813b5ec7d7445e62913' \
                                    --header 'Content-Type: application/json' \
                                    --data-raw '{
                                        "amount": {
                                            "currency": "EGP",
                                            "total": 400000
                                        },
                                        "callbackUrl": "https://your-call-back-url.com",
                                        "country": "EG",
                                        "payMethod": "VALU",
                                        "product": {
                                            "name": "name"
                                        },
                                        "reference": "04123398",
                                        "returnUrl": "https://your-return-url.com",
                                        "valUAccountNumber":"01201297772"
                                    }'
                                
                            
                            
                                import com.google.gson.Gson;
                                import org.apache.commons.codec.binary.Hex;
                                import javax.crypto.Mac;
                                import javax.crypto.spec.SecretKeySpec;
                                import java.io.BufferedReader;
                                import java.io.InputStreamReader;
                                import java.io.OutputStream;
                                import java.net.HttpURLConnection;
                                import java.net.URL;
                                import java.nio.charset.StandardCharsets;
                                import java.util.TreeMap;

                                public class CreateValuInstallment {

                                    private static final String privateKey = "OPAYPRV1644547******513012905";

                                    private static final String endpoint = "https://sandboxapi.opaycheckout.com";

                                    private static final String merchantId = "281822021180001";

                                    public static void main(String[] args) throws Exception {
                                        String addr = endpoint + "/api/v1/international/payment/create";
                                        Gson gson = new Gson();
                                        TreeMap order = new TreeMap<>();
                                        TreeMap amount = new TreeMap<>();
                                        amount.put("currency","EGP");
                                        amount.put("total",400000);
                                        order.put("amount",amount);
                                        order.put("callbackUrl","https://your-callback-url.com");
                                        order.put("country","EG");
                                        order.put("payMethod","VALU");
                                        TreeMap product = new TreeMap<>();
                                        product.put("name","name");
                                        order.put("product",product);
                                        order.put("reference","04123393");
                                        order.put("returnUrl","https://your-return-url.com");
                                        order.put("valUAccountNumber","01201297772");

                                        String requestBody = gson.toJson(order);
                                        System.out.println("--request:");
                                        System.out.println(requestBody);
                                        String oPaySignature = hmacSHA512(requestBody, privateKey);
                                        System.out.println("--signature:");
                                        System.out.println(oPaySignature);

                                        URL url = new URL(addr);
                                        HttpURLConnection con = (HttpURLConnection)url.openConnection();
                                        con.setRequestMethod("POST");
                                        con.setRequestProperty("Content-Type", "application/json; utf-8");
                                        con.setRequestProperty("Authorization", "Bearer "+oPaySignature);
                                        con.setRequestProperty("MerchantId", merchantId);
                                        con.setDoOutput(true);
                                        OutputStream os = con.getOutputStream();
                                        byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
                                        os.write(input, 0, input.length);
                                        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8));
                                        StringBuilder response = new StringBuilder();
                                        String responseLine = null;
                                        while ((responseLine = br.readLine()) != null) {
                                            response.append(responseLine.trim());
                                        }

                                        System.out.println("--response:");
                                        System.out.println(response.toString());
                                        //close your stream and connection
                                    }

                                    public static String hmacSHA512(final String data, final String secureKey) throws Exception{
                                        byte[] bytesKey = secureKey.getBytes();
                                        final SecretKeySpec secretKey = new SecretKeySpec(bytesKey, "HmacSHA512");
                                        Mac mac = Mac.getInstance("HmacSHA512");
                                        mac.init(secretKey);
                                        final byte[] macData = mac.doFinal(data.getBytes());
                                        byte[] hex = new Hex().encode(macData);
                                        return new String(hex, StandardCharsets.UTF_8);
                                    }
                                }

                            
                        


ValU payment Response

-Response Parameters:

the parameters contained in the response received whenever you call the ValU payment API as a JSON Object.

                    
                        {
                            "code":"00000",
                            "message":"SUCCESSFUL",
                            "data":{
                                "reference":"104123398",
                                "orderNo":"211004140885521681",
                                "nextAction":{
                                    "actionType":"INPUT_INSTALLMENT_MONTH",
                                    "plans":[
                                     {
                                         "months":6,
                                         "downPayment":{
                                             "total":0,
                                             "currency":"EGP"
                                         },
                                         "fee":{
                                             "total":1800,
                                             "currency":"EGP"
                                         },
                                         "emi":{
                                             "total":11400,
                                             "currency":"EGP"
                                         }
                                     },
                                     {
                                         "months":7,
                                         "downPayment":{
                                             "total":0,
                                             "currency":"EGP"
                                         },
                                         "fee":{
                                             "total":1800,
                                             "currency":"EGP"
                                         },
                                         "emi":{
                                             "total":9900,
                                             "currency":"EGP"
                                         }
                                     }
                                             ]
                                              },
                                "status":"PENDING",
                                "amount":{
                                    "total":1000,
                                    "currency":"EGP"
                                },
                                "vat":{
                                    "total":0,
                                    "currency":"EGP"
                                }
                            }
                        }
                    
                

-Here is a detailed description for the parameters received in the response:

Parameter type Description example
reference String The unique merchant payment order number 104123398
orderNo String The unique Opay payment order number. 211004140885521681
nextAction
JSONObject
plans
Json Array
plan
Json Object
months Integer The month number of installment plan 6
downPayment
JSON Object
total Long DownPayment amount 1000(cent unit)
currency String currency type EGP
fee
JSON Object
total Long Fee amount 1000(cent unit)
currency String currency type EGP
emi
JSON Object
total Long Emi amount 1000(cent unit)
currency String currency type EGP
status String Order status PENDING
amount
JSON Object
total Long Transaction amount 1000(cent unit)
currency String currency type EGP
vat
JSON Object
total Long Value Added Tax Amount 0
currency String currency type EGP

2.Confirm The Installment Plan

This API can be used to confirm the installment plan. In case you are still in development phase, you need to request using the POST method in our sandbox environment.
-Here is the request URL:

                    
                        https://sandboxapi.opaycheckout.com/api/v1/payment/action/input-installment-month
                    
                

-Once you have a fully tested payment flow and you are ready for production, use the following production API endpoint URL instead

                    
                        https://api.opaycheckout.com/api/v1/payment/action/input-installment-month
                    
                

-Request Parameters:

  1. Header: Authorization(API Calls Signature), MerchantId
  2.                         
                                Authorization    : Bearer {signature}
                                MerchantId       : 256612345678901
                            
                        
  3. Json object containing the transaction information:
  4.                         
                                {
                                     "country":"EG",
                                     "months":6,
                                     "orderNo":"220616148180902770120"
                                }
                            
                        

HTTP POST parameters

-Here is a detailed description for the parameters you need to complete the POST request:

Parameter type required Description
country String required Country Code.See full list here
orderNo String required (if no reference provide) Order id.
reference String required (if no orderNo provide) Payment reference Id.
months Integer required Installment month.

-An example of Confirm Installment Plan is as follows :

                                
                                    class CreateValuInstallmentController
                                    {
                                        private $secretkey;
                                        private $merchantId;
                                        private $url;

                                        public function __construct() {
                                            $this->merchantId = '281822021180001';
                                            $this->secretkey = 'OPAYPRV1644547******513012905';
                                            $this->url = 'https://sandboxapi.opaycheckout.com/api/v1/payment/action/input-installment-month';
                                        }

                                        public function test(){
                                            $data = [
                                                "country" => "EG",
                                                "months" => 6,
                                                "orderNo" => "220616148180902770120"
                                            ];
                                            $data2 = (string) json_encode($data,JSON_UNESCAPED_SLASHES);
                                            $auth = $this->auth($data2);
                                            $header = ['Content-Type:application/json', 'Authorization:Bearer '. $auth, 'MerchantId:'.$this->merchantId];
                                            $response = $this->http_post($this->url, $header, json_encode($data));
                                            $result = $response?$response:null;
                                            return $result;
                                        }

                                        private function http_post ($url, $header, $data) {
                                            if (!function_exists('curl_init')) {
                                                throw new Exception('php not found curl', 500);
                                            }
                                            $ch = curl_init();
                                            curl_setopt($ch, CURLOPT_TIMEOUT, 60);
                                            curl_setopt($ch, CURLOPT_URL, $url);
                                            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                                            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
                                            curl_setopt($ch, CURLOPT_HEADER, false);
                                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                            curl_setopt($ch, CURLOPT_POST, true);
                                            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                                            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
                                            $response = curl_exec($ch);
                                            $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                                            $error=curl_error($ch);
                                            curl_close($ch);
                                            if (200 != $httpStatusCode) {
                                                print_r("invalid httpstatus:{$httpStatusCode} ,response:$response,detail_error:" . $error, $httpStatusCode);
                                            }
                                            return $response;
                                        }
                                        public function auth ( $data ) {
                                            $secretKey = $this->secretkey;
                                            $auth = hash_hmac('sha512', $data, $secretKey);
                                            return $auth;
                                        }

                                    }

                                
                            
                                
                                    const request = require('request');
                                    var sha512 = require('js-sha512');
                                    const formData = {
                                      "country":"EG",
                                      "months":6,
                                      "orderNo":"220616148180902770120"
                                    };

                                    var privateKey = "OPAYPRV1644547******513012905"

                                    var hash = sha512.hmac.create(privateKey);
                                    hash.update(JSON.stringify(formData));
                                    hmacsignature = hash.hex();
                                    console.log(hmacsignature)
                                    request({
                                        url: 'https://sandboxapi.opaycheckout.com/api/v1/payment/action/input-installment-month',
                                        method: 'POST',

                                        headers: {
                                          'MerchantId': '281822021180001',
                                          'Authorization': 'Bearer '+hmacsignature
                                        },
                                        json: true,
                                        body: formData
                                      }, function (error, response, body) {
                                        console.log('body: ')
                                        console.log(body)
                                      }
                                    )

                                
                            
                                
                                    curl --location --request POST 'https://sandboxapi.opaycheckout.com/api/v1/payment/action/input-installment-month' \
                                    --header 'MerchantId: 281822021180001' \
                                    --header 'Authorization: Bearer d9cbe9407522335ec052a7a9fa84bd9de2dabdf293bf41abda46fe36ae6b3c427e60823faedd276dd20c45b65c738a7aa2c3e1fd350a3813b5ec7d7445e62913' \
                                    --header 'Content-Type: application/json' \
                                    --data-raw '{
                                      "country":"EG",
                                      "months":6,
                                      "orderNo":"220616148180902770120"
                                    }'
                                
                            
                            
                                import com.google.gson.Gson;
                                import org.apache.commons.codec.binary.Hex;
                                import javax.crypto.Mac;
                                import javax.crypto.spec.SecretKeySpec;
                                import java.io.BufferedReader;
                                import java.io.InputStreamReader;
                                import java.io.OutputStream;
                                import java.net.HttpURLConnection;
                                import java.net.URL;
                                import java.nio.charset.StandardCharsets;
                                import java.util.TreeMap;

                                public class CreateValuInstallment {

                                    private static final String privateKey = "OPAYPRV1644547******513012905";

                                    private static final String endpoint = "https://sandboxapi.opaycheckout.com";

                                    private static final String merchantId = "281822021180001";

                                    public static void main(String[] args) throws Exception {
                                        String addr = endpoint + "/api/v1/payment/action/input-installment-month";
                                        Gson gson = new Gson();
                                        TreeMap order = new TreeMap<>();
                                        TreeMap amount = new TreeMap<>()
                                        order.put("country","EG");
                                        order.put("months",6);
                                        order.put("orderNo","220616148180902770120");

                                        String requestBody = gson.toJson(order);
                                        System.out.println("--request:");
                                        System.out.println(requestBody);
                                        String oPaySignature = hmacSHA512(requestBody, privateKey);
                                        System.out.println("--signature:");
                                        System.out.println(oPaySignature);

                                        URL url = new URL(addr);
                                        HttpURLConnection con = (HttpURLConnection)url.openConnection();
                                        con.setRequestMethod("POST");
                                        con.setRequestProperty("Content-Type", "application/json; utf-8");
                                        con.setRequestProperty("Authorization", "Bearer "+oPaySignature);
                                        con.setRequestProperty("MerchantId", merchantId);
                                        con.setDoOutput(true);
                                        OutputStream os = con.getOutputStream();
                                        byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
                                        os.write(input, 0, input.length);
                                        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8));
                                        StringBuilder response = new StringBuilder();
                                        String responseLine = null;
                                        while ((responseLine = br.readLine()) != null) {
                                            response.append(responseLine.trim());
                                        }

                                        System.out.println("--response:");
                                        System.out.println(response.toString());
                                        //close your stream and connection
                                    }

                                    public static String hmacSHA512(final String data, final String secureKey) throws Exception{
                                        byte[] bytesKey = secureKey.getBytes();
                                        final SecretKeySpec secretKey = new SecretKeySpec(bytesKey, "HmacSHA512");
                                        Mac mac = Mac.getInstance("HmacSHA512");
                                        mac.init(secretKey);
                                        final byte[] macData = mac.doFinal(data.getBytes());
                                        byte[] hex = new Hex().encode(macData);
                                        return new String(hex, StandardCharsets.UTF_8);
                                    }
                                }

                            
                        


Confirm The Installment Plan Response

-Response Parameters:

the parameters contained in the response received whenever you call the Confirm Installment Plan API as a JSON Object.

                    
                        {
                            "code":"00000",
                            "message":"SUCCESSFUL",
                            "data":{
                                "reference":"104123398",
                                "orderNo":"211004140885521681",
                                "nextAction":{
                                    "actionType":"INPUT_OTP"
                                },
                                "status":"PENDING",
                                "amount":{
                                    "total":1000,
                                    "currency":"EGP"
                                }
                            }
                        }
                    
                

-Here is a detailed description for the parameters received in the response:

Parameter type Description example
reference String The unique merchant payment order number 104123398
orderNo String The unique Opay payment order number. 211004140885521681
nextAction JSON Object
actionType String Next action type, enum[INPUT_OTP] INPUT_OTP
status String Order status PENDING
amount JSON Object
total Long Transaction amount 1000(cent unit)
currency String currency type EGP
vat JSON Object
total Long Value Added Tax Amount 0
currency String currency type EGP

3.Input OTP

This API can be used to input OTP. In case you are still in development phase, you need to request using the POST method in our sandbox environment.
-Here is the request URL:

                    
                        https://sandboxapi.opaycheckout.com/api/v1/payment/action/input-otp
                    
                

-Once you have a fully tested payment flow and you are ready for production, use the following production API endpoint URL instead

                    
                        https://api.opaycheckout.com/api/v1/payment/action/input-otp
                    
                

-Request Parameters:

  1. Header: Authorization(API Calls Signature), MerchantId
  2.                         
                                Authorization    : Bearer {signature}
                                MerchantId       : 256612345678901
                            
                        
  3. Json object containing the transaction information:
  4.                         
                                {
                                     "country":"EG",
                                     "otp":"123456",
                                     "orderNo":"220616148180902770120"
                                }
                            
                        

HTTP POST parameters

-Here is a detailed description for the parameters you need to complete the POST request:

Parameter type required Description
country String required Country Code.See full list here
orderNo String required (if no reference provide) Order id.
reference String required (if no orderNo provide) Payment reference Id.
otp String required Otp.

-An example of Input Otp is as follows :

                                
                                    class CreateValuInstallmentController
                                    {
                                        private $secretkey;
                                        private $merchantId;
                                        private $url;

                                        public function __construct() {
                                            $this->merchantId = '281822021180001';
                                            $this->secretkey = 'OPAYPRV1644547******513012905';
                                            $this->url = 'https://sandboxapi.opaycheckout.com/api/v1/payment/action/input-otp';
                                        }

                                        public function test(){
                                            $data = [
                                                "country" => "EG",
                                                "otp" => "123456",
                                                "orderNo" => "220616148180902770120"
                                            ];
                                            $data2 = (string) json_encode($data,JSON_UNESCAPED_SLASHES);
                                            $auth = $this->auth($data2);
                                            $header = ['Content-Type:application/json', 'Authorization:Bearer '. $auth, 'MerchantId:'.$this->merchantId];
                                            $response = $this->http_post($this->url, $header, json_encode($data));
                                            $result = $response?$response:null;
                                            return $result;
                                        }

                                        private function http_post ($url, $header, $data) {
                                            if (!function_exists('curl_init')) {
                                                throw new Exception('php not found curl', 500);
                                            }
                                            $ch = curl_init();
                                            curl_setopt($ch, CURLOPT_TIMEOUT, 60);
                                            curl_setopt($ch, CURLOPT_URL, $url);
                                            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                                            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
                                            curl_setopt($ch, CURLOPT_HEADER, false);
                                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                            curl_setopt($ch, CURLOPT_POST, true);
                                            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                                            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
                                            $response = curl_exec($ch);
                                            $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                                            $error=curl_error($ch);
                                            curl_close($ch);
                                            if (200 != $httpStatusCode) {
                                                print_r("invalid httpstatus:{$httpStatusCode} ,response:$response,detail_error:" . $error, $httpStatusCode);
                                            }
                                            return $response;
                                        }
                                        public function auth ( $data ) {
                                            $secretKey = $this->secretkey;
                                            $auth = hash_hmac('sha512', $data, $secretKey);
                                            return $auth;
                                        }

                                    }

                                
                            
                                
                                    const request = require('request');
                                    var sha512 = require('js-sha512');
                                    const formData = {
                                      "country":"EG",
                                      "otp":"123456",
                                      "orderNo":"220616148180902770120"
                                    };

                                    var privateKey = "OPAYPRV1644547******513012905"

                                    var hash = sha512.hmac.create(privateKey);
                                    hash.update(JSON.stringify(formData));
                                    hmacsignature = hash.hex();
                                    console.log(hmacsignature)
                                    request({
                                        url: 'https://sandboxapi.opaycheckout.com/api/v1/payment/action/input-otp',
                                        method: 'POST',

                                        headers: {
                                          'MerchantId': '281822021180001',
                                          'Authorization': 'Bearer '+hmacsignature
                                        },
                                        json: true,
                                        body: formData
                                      }, function (error, response, body) {
                                        console.log('body: ')
                                        console.log(body)
                                      }
                                    )

                                
                            
                                
                                    curl --location --request POST 'https://sandboxapi.opaycheckout.com/api/v1/payment/action/input-otp' \
                                    --header 'MerchantId: 281822021180001' \
                                    --header 'Authorization: Bearer d9cbe9407522335ec052a7a9fa84bd9de2dabdf293bf41abda46fe36ae6b3c427e60823faedd276dd20c45b65c738a7aa2c3e1fd350a3813b5ec7d7445e62913' \
                                    --header 'Content-Type: application/json' \
                                    --data-raw '{
                                      "country":"EG",
                                      "otp":"1123456",
                                      "orderNo":"220616148180902770120"
                                    }'
                                
                            
                            
                                import com.google.gson.Gson;
                                import org.apache.commons.codec.binary.Hex;
                                import javax.crypto.Mac;
                                import javax.crypto.spec.SecretKeySpec;
                                import java.io.BufferedReader;
                                import java.io.InputStreamReader;
                                import java.io.OutputStream;
                                import java.net.HttpURLConnection;
                                import java.net.URL;
                                import java.nio.charset.StandardCharsets;
                                import java.util.TreeMap;

                                public class CreateValuInstallment {

                                    private static final String privateKey = "OPAYPRV1644547******513012905";

                                    private static final String endpoint = "https://sandboxapi.opaycheckout.com";

                                    private static final String merchantId = "281822021180001";

                                    public static void main(String[] args) throws Exception {
                                        String addr = endpoint + "/api/v1/payment/action/input-otp";
                                        Gson gson = new Gson();
                                        TreeMap order = new TreeMap<>();
                                        TreeMap amount = new TreeMap<>()
                                        order.put("country","EG");
                                        order.put("otp","123456");
                                        order.put("orderNo","220616148180902770120");

                                        String requestBody = gson.toJson(order);
                                        System.out.println("--request:");
                                        System.out.println(requestBody);
                                        String oPaySignature = hmacSHA512(requestBody, privateKey);
                                        System.out.println("--signature:");
                                        System.out.println(oPaySignature);

                                        URL url = new URL(addr);
                                        HttpURLConnection con = (HttpURLConnection)url.openConnection();
                                        con.setRequestMethod("POST");
                                        con.setRequestProperty("Content-Type", "application/json; utf-8");
                                        con.setRequestProperty("Authorization", "Bearer "+oPaySignature);
                                        con.setRequestProperty("MerchantId", merchantId);
                                        con.setDoOutput(true);
                                        OutputStream os = con.getOutputStream();
                                        byte[] input = requestBody.getBytes(StandardCharsets.UTF_8);
                                        os.write(input, 0, input.length);
                                        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8));
                                        StringBuilder response = new StringBuilder();
                                        String responseLine = null;
                                        while ((responseLine = br.readLine()) != null) {
                                            response.append(responseLine.trim());
                                        }

                                        System.out.println("--response:");
                                        System.out.println(response.toString());
                                        //close your stream and connection
                                    }

                                    public static String hmacSHA512(final String data, final String secureKey) throws Exception{
                                        byte[] bytesKey = secureKey.getBytes();
                                        final SecretKeySpec secretKey = new SecretKeySpec(bytesKey, "HmacSHA512");
                                        Mac mac = Mac.getInstance("HmacSHA512");
                                        mac.init(secretKey);
                                        final byte[] macData = mac.doFinal(data.getBytes());
                                        byte[] hex = new Hex().encode(macData);
                                        return new String(hex, StandardCharsets.UTF_8);
                                    }
                                }

                            
                        


Input OTP Response

-Response Parameters:

the parameters contained in the response received whenever you call the Input OTP API as a JSON Object.

                    
                        {
                            "code":"00000",
                            "message":"SUCCESSFUL",
                            "data":{
                                "reference":"104123398",
                                "orderNo":"211004140885521681",
                                "status":"SUCCESS",
                                "amount":{
                                    "total":1000,
                                    "currency":"EGP"
                                }
                            }
                        }
                    
                

-Here is a detailed description for the parameters received in the response:

Parameter type Description example
reference String The unique merchant payment order number 104123398
orderNo String The unique Opay payment order number. 211004140885521681
status String Order status PENDING
amount JSON Object
total Long Transaction amount 1000(cent unit)
currency String currency type EGP
vat JSON Object
total Long Value Added Tax Amount 0
currency String currency type EGP

Error Handling

After submitting an API call to OPay, you receive a response back to inform you that your request was received and processed. A successful OPay API should return a status code 00, meanwhile, in a situation where any payment processing error occurred, you will receive an error code with a message to describe the reason of the error. A sample error response can be found below.

                    
                        {
                            "code": "02004",
                            "message": "the payment reference already exists."
                        }
                    
                

Depending on the HTTP status code of the response, you should build some logic to handle any errors that a request or the system may return. A list of possible potential error codes that you may receive can be found below. A full list of all possible error codes can be found in the Error Codes section.

Error Code Error Message
02000 authentication failed.
02001 request parameters not valid.
02002 merchant not configured with this function.
02003 payMethod not support.
02004 the payment reference already exists.

What's Next?

User Profile 12 messages

James Jones
Application Developer
Recent Notifications
Another purpose persuade Due in 2 Days
+28%
Would be to people Due in 2 Days
+50%
-27%
The best product Due in 2 Days
+8%