Transaction Refund Status

Stay informed with the status of the requested and Processed refunds by using the Transaction Refund Status API.

Transaction Refund Status

you can get the status of a requested refund by using the Transaction Refund Status API. 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

https://sandbox-cashierapi.opayweb.com/api/v1/egypt/transaction/refund/status

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

https://cashierapi.opayweb.com/api/v1/egypt/transaction/refund/status

-Request Parameters:

  1. Header: Bearer PUBLIC_KEY and merchant ID
  2. Authorization: Bearer PUBLIC_KEY
    MerchantId   : 256612345678901
  3. Json object containing the transaction information:
  4. {
      "reference": "12312321324",
      "refundNo": "10343543543532432"
    }

HTTP POST Parameters

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

ParametertyperequiredDescription
referenceStringrequiredreferenceid and refundNo either-or.
refundNoStringrequiredrefund order id and reference either-or.

-An example call of Transaction Refund Status API is as follows :

function Cashier(transaction_data) {
          const PaymentData = {
                                  reference: transaction_data.reference,
                                  refundNo  : transaction_data.refundNo,

                                };
          const response = await fetch('https://sandbox-cashierapi.opayweb.com/api/v1/egypt/transaction/refund/status ', {
            method: 'POST',
            headers: {
              'Content-Type': 'application/json',
              'Authorization' : 'Bearer PUBLIC_KEY',
              'MerchantId' : '256612345678901'
            },
            body: JSON.stringify(PaymentData),
          });
          // Return and display the result of the charge.
          return response.json();
        }
$reference    = '12312321324';
$refundNo = '11212134400034123';
$httpClient = new \GuzzleHttp\Client(); // guzzle 6.3
$response = $httpClient->request('POST', 'https://sandbox-cashierapi.opayweb.com/api/v1/egypt/transaction/refund/status ', [
            'headers' => [
                'Content-Type' => 'application/json',
                'Accept'       => 'application/json',
                'Authorization' : 'Bearer PUBLIC_KEY',
                'MerchantId' : '256612345678901'
            ],
            'body' => json_encode( [
                            'reference' => $reference,
                            'orderNo' => $orderNo,
                        ] , true)
]);
$response = json_decode($response->getBody()->getContents(), true);
$paymentStatus = $response['type']; // get response values
# importing the requests library
import requests
# CashierAPI Endpoint
URL = "https://sandbox-cashierapi.opayweb.com/api/v1/egypt/transaction/refund/status "

# defining a params dict for the parameters to be sent to the API
PaymentData = {
    'reference'    : '12312321324',
    'refundNo'  : '11212134400034123',
}
# sending post request and saving the response as response object
status_request = requests.post(url = URL, params = json.dumps(PaymentData))

# extracting data in json format
status_response = status_request.json()
function Cashier() {
              axios.post('https://sandbox-cashierapi.opayweb.com/api/v1/egypt/transaction/refund/status ', {
                              'reference'    : '12312321324',
                              'refundNo'  : '10343543543532432',
                          })
                              .then(response => {
                                  // Get Response Contents
                                  let type          = response.data.type;
                                  let paymentStatus = response.data.paymentStatus;
                                  //
                              })
                              .catch(error => {
                                  console.log(error.response.data)
                              })
              }
$ curl https://sandbox-cashierapi.opayweb.com/api/v1/egypt/transaction/refund/status  \
        -H "content-type: application/json , Authorization: Bearer PUBLIC_KEY , MerchantId: 256612345678901" \
        -X POST \
        -d "{
                'reference'    : '12312321324',
                'refundNo'  : '10343543543532432',
            }"
URL url = new URL ("https://sandbox-cashierapi.opayweb.com/api/v1/egypt/transaction/refund/status ");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Authorization", "Bearer PUBLIC_KEY");
con.setRequestProperty("MerchantId", "256612345678901");
con.setDoOutput(true);
String jsonInputString = "{
                            'reference'    : '12312321324',
                            'refundNo'  : '10343543543532432'
                        }";
try(OutputStream os = con.getOutputStream()) {
    byte[] input = jsonInputString.getBytes("utf-8");
    os.write(input, 0, input.length);
}
try(BufferedReader br = new BufferedReader(
  new InputStreamReader(con.getInputStream(), "utf-8"))) {
    StringBuilder response = new StringBuilder();
    String responseLine = null;
    while ((responseLine = br.readLine()) != null) {
        response.append(responseLine.trim());
    }
    System.out.println(response.toString());
}
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Newtonsoft.Json;
namespace OPayRequest
{
    public class Program
    {
        static void Main(string[] args)
        {
            PostJson("https://sandbox-cashierapi.opayweb.com/api/v1/egypt/transaction/refund/status ", new opay_request
            {
                reference    = '12312321324',
                refundNo  = '10343543543532432',
            });
        }

        private static void PostJson(string uri, opay_request postParameters)
        {
            string postData = JsonConvert.SerializeObject(postParameters);
            byte[] bytes = Encoding.UTF8.GetBytes(postData);
            var httpWebRequest = (HttpWebRequest) WebRequest.Create(uri);
            httpWebRequest.Method = "POST";
            httpWebRequest.ContentLength = bytes.Length;
            httpWebRequest.ContentType = "text/json";
            using (Stream requestStream = httpWebRequest.GetRequestStream())
            {
                requestStream.Write(bytes, 0, bytes.Count());
            }
            var httpWebResponse = (HttpWebResponse) httpWebRequest.GetResponse();
            if (httpWebResponse.StatusCode != HttpStatusCode.OK)
            {
                string message = String.Format("GET failed. Received HTTP {0}", httpWebResponse.StatusCode);
                throw new ApplicationException(message);
            }
        }
    }

    public class opay_request
    {
        public string reference { get; set; }
        public string refundNo { get; set; }
    }
}

Header must contain the "Bearer PUBLIC_KEY" and "MerchantId"

Transaction Status 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": "test_123456",
    "originalReference": "1001000001",
    "orderNo": "10212100000034000",
    "refundNo": "11212134400034123",
    "status": "INITIAL"
  }
}

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

ParametertypeDescriptionexample
referenceStringreference Id.1001000
originalReferenceStringoriginal order originalReference id.1001000001
orderNoStringoriginal order id.10212100000034000
refundNoStringrefund order id.11212134400034123
statusStringINITIAL:initial PENDING:pending SUCCESS:success FAIL:fail CLOSE:close

"INITIAL"

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": "20000",
    "message": "Duplicate merchant order number",
    "data": null
}

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 CodeError Message
09Time out.
90System failure.
91Refund error, please try again later.
96Search order error, please try again later.
97Create checkout session failed.
98Invalid request header with requestId.
99Request channel parameters are not valid.
20000Duplicate merchant order number.

What's Next?