Create Card Token API

In this page, you will learn how to create Card Tokens for your customers to allow efficient and secure storage for your customers' cards information.

Create Card Token API

To test your Create Card Token API, you need to request using the POST method in our sandbox environment.
-Here is the request URL:

https://sandbox-cashierapi.opaycheckout.com/api/v1/international/token/create

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

https://cashierapi.opaycheckout.com/api/v1/international/token/create

-Request Parameters:

  1. Header: Bearer and private key Signature
  2. Authorization: "Bearer" + private key signature
    MerchantId   : 256612345678901
  3. Json object containing the information:
  4. {
        "cardHolderName":"DAVID",
        "cardNumber":"4508750015741019",
        "customerInfo":{
            "customerEmail":"[email protected]",
            "customerId":"123",
            "customerMobile":"2023531565",
            "customerName":"name"
        },
        "cvv":"101",
        "expiryMonth":"02",
        "expiryYear":"26",
        "reference":"123"
    }

HTTP POST Parameters

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

ParametertyperequiredDescription
referenceStringrequiredMerchant unique reference.
cardNumberStringrequiredCard Number.
expiryYearStringrequiredExpiry Year.
expiryMonthStringrequiredExpiry Month.
cvvStringrequiredcvv.
cardHolderNameStringrequiredCard Holder Name.
customerInfo
customerIdStringrequiredUser unique id.
customerNameStringoptionalUser name.
customerEmailStringoptionalUser Email .
customerMobileStringoptionalUser mobile.

Header must contain the "Bearer + Private Key Signature" and "MerchantId"

Signature is calculated using SHA-512 HMAC signed with your Private Key for the request body Json object. See Signature Calculator section for more details.

Create Card Token Response

-Response Parameters:

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

{
    "code":"00000",
    "message":"SUCCESSFUL",
    "data":{
        "opayToken":"OPAY_TOKEN_bf8593c1693546ea83743e4d433c5bf5",
        "brand":"VISA",
        "createTimestamp":1637822753,
        "lastFourDigits":"7411",
        "firstSixDigits":"450875",
        "customerInfo":{
            "customerId":"121111113",
            "customerName":"name1",
            "customerEmail":"[email protected]",
            "customerMobile":"20123111111"
        }
    }
}

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

ParametertypeDescriptionexample
opayTokenStringCard unique token.OPAY_TOKEN_bf8593c1693546ea83743e4d433c5bf5
brandStringCard brand.VISA
expiryYearStringExpiry Year.26
expiryMonthStringExpiry Month.02
createTimestampStringToken create time.1637822753
lastFourDigitsStringCard number last 4 digits.7411
firstSixDigitsStringCard number first 6 digits.450875
customerInfo
customerIdStringUser unique id.121111113
customerNameStringUser name.name1
customerEmailStringUser Email .[email protected]
customerMobileStringUser mobile.20123111111

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?