OPay Wallet Payment

OPay Wallet Payment


For calling the API using the POST method you can use these endpoints URL:
In case you are still in the developing phase, use the following staging API endpoint URL

Note

Staging

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


Once you are ready for production, you should use the following production API endpoint URL instead

Note

Production

https://liveapi.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": "NGN",
                                     "total": 60000
                                 },
                                 "callbackUrl": "https://your-call-back-url.com",
                                 "country": "NG",
                                 "payMethod": "OpayWalletNgQR",
                                 "product": {
                                     "description": "dd",
                                     "name": "name"
                                 },
                                 "reference": "test2022_1655372839575"
                                }
                        
                    

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 OPay wallet payment method: OpayWalletNgQR
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
product
JSON
Array
name String required Product name
description String optional Product description

An example call of OPay Wallet Payment is as follows :

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

                                    public function __construct() {
                                        $this->merchantId = '278421062352020';
                                        $this->secretkey = 'OPAYPRV1641***********926';
                                        $this->url = 'https://testapi.opaycheckout.com/api/v1/international/payment/create';
                                    }

                                    public function test(){
                                        $data = [
                                                "amount" => [
                                                    "currency" => "NGN",
                                                    "total" => 400000
                                                ],
                                                "callbackUrl" => "https://your-call-back-url.com",
                                                "country" => "NG",
                                                "payMethod" => "OpayWalletNgQR",
                                                "product" => ["name" => "name"],
                                                "reference" => "04123390"
                                            ];
                                        $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":"NGN",
                                          "total":400000
                                      },
                                      "callbackUrl":"https://your-call-back-url.com",
                                      "country":"NG",
                                      "payMethod":"OpayWalletNgQR",
                                      "product":{"name":"name"},
                                      "reference":"04123392"
                                    };

                                    var privateKey = "OPAYPRV1641***********926"

                                    var hash = sha512.hmac.create(privateKey);
                                    hash.update(JSON.stringify(formData));
                                    hmacsignature = hash.hex();
                                    console.log(hmacsignature)
                                    request({
                                        url: 'https://testapi.opaycheckout.com/api/v1/international/payment/create',
                                        method: 'POST',
                                        headers: {
                                          'MerchantId': '278421062352020',
                                          'Authorization': 'Bearer '+hmacsignature
                                        },
                                        json: true,
                                        body: formData
                                      }, function (error, response, body) {
                                        console.log('body: ')
                                        console.log(body)
                                      }
                                    )
                                
                            
                                
                                    curl --location --request POST 'https://testapi.opaycheckout.com/api/v1/international/payment/create' \
                                    --header 'MerchantId: 278421062352020' \
                                    --header 'Authorization: Bearer 61bea01d6c07f2c21466addd9d3d558918998830c7f7d5784a9724992e31104d12b5aab0b8b4c6b8ce9181d8cd8189fb8838b434b4feebaa7bc68e744a7d19e1' \
                                    --header 'Content-Type: application/json' \
                                    --data-raw '{
                                       "amount": {
                                            "currency": "NGN",
                                            "total": 400000
                                        },
                                        "callbackUrl": "https://your-call-back-url.com",
                                        "country": "NG",
                                        "payMethod": "OpayWalletNgQR",
                                        "product": {
                                            "name": "name"
                                        },
                                        "reference": "04123398"
                                    }'
                                
                            
                            
                                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;
                                import java.util.UUID;

                                public class OpayWallet {

                                    private static final String privateKey = "OPAYPRV1641***********926";

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

                                    private static final String merchantId = "278421062352020";

                                    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","NGN");
                                        amount.put("total",400000);
                                        order.put("amount",amount);
                                        order.put("callbackUrl","https://your-callback-url.com");
                                        order.put("country","NG");
                                        order.put("payMethod","OpayWalletNgQR");
                                        TreeMap product = new TreeMap<>();
                                        product.put("name","name");
                                        order.put("product",product);
                                        order.put("reference","04123393");


                                        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);
                                    }
                                }

                            
                        
Note

Note

Header must contain the "Signature" , "MerchantId"

Signature is calculated using SHA-512 HMAC signed with your Private Key. See API Calls Signature section for more details.

OPay Wallet Payment Response


Response Parameters:

The parameters contained in the response received whenever you call the Transaction Create API as a JSON Object.

                    
                        {
                          "code": "00000",
                          "message": "SUCCESSFUL",
                          "data": {
                              "reference": "test2022_1657012427396",
                              "orderNo": "220705145660963050206",
                              "nextAction": {
                                  "actionType": "SCAN_QR_CODE",
                                  "qrCode": "https://qrm.operapay.com//m0000220708144522994450_macquiring_macquiring"
                              },
                              "status": "PENDING",
                              "amount": {
                                  "total": 60000,
                                  "currency": "NGN"
                              },
                              "vat": {
                                  "total": 0,
                                  "currency": "NGN"
                              }
                          }
                        }
                    
                

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 The next action type.Waiting for customer scan QR code SCAN_QR_CODE
qrCode String String required to generate QR code image. "data:https://qrm.operapay.com/......"
status String E-Wallet order status PENDING
amount JSON Object
total Long Transaction amount 1000(cent unit)
currency String currency type NGN
vat JSON Object
total Long Value Added Tax Amount 0
currency String currency type NGN

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": "00001",
                            "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.

Error Code Error Message
01575 Allowable number of PIN tries exceeded.
01631 Mobile number has not registered.
02000 authentication failed.
02001 request params not valid.
02003 payMethod not support.
00001 the payment reference already exists.
02002 merchant not configured with this function.
02007 merchant not available.
50003 service not available, please try again.

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%