Skip to main content

Authorize Payment

Overview

This document provides APIs for merchants to integrate authorize payment solution to their applications.

Communication Protocols

Merchant accessing the Zalopay service and calling the API must follow the following rules:

#Describe
Transmission MethodIn order to ensure transaction security, HTTPS transmission is adopted
Submission MethodSubmit by POST method
Data FormatSubmit and return data in application/json, application/x-www-form-urlencoded format
Character EncodingUTF-8 character encoding
Authentication AlgorithmHmacSHA256
Authentication RequirementsBoth request and received data need to verify the authentication information
Process LogicFirst refer to the return of the protocol field, then refer to the code in the response message, and finally refer to the transaction status

Authentication Rules

#Describe
Authentication AlgorithmHmacSHA256
Authentication Informationmac = HMAC(hmac_algorithm, key, hmacinput)
with:
- hmac_algorithm: is a security method registered by Merchant with Zalopay, the default is HmacSHA256
- key: provided by Zalopay at registration
- hmacinput: specified by each API

APIs Description

1. API list

EnvironmentLink
Sandboxhttps://sb-openapi.zalopay.vn
Prodhttps://openapi.zalopay.vn
No.Interface NameEntry PointDirectionCard TokenizationZalopay E-Wallet
1Create Binding for Agreement/v2/agreement/bindmerchant to Zalopayxx
2Query Payment Token/v2/agreement/querymerchant to Zalopayxx
3Unbind an Agreement/v2/agreement/unbindmerchant to Zalopayxx
4Authorize/preauth/authorizemerchant to Zalopayx
5Capture/preauth/capturemerchant to Zalopayx
6Cancel/preauth/cancelmerchant to Zalopayx
7Pay Direct/preauth/paymerchant to Zalopayxx
8Get Status/preauth/querymerchant to Zalopayxx
9Get Payable/preauth/get_payablemerchant to Zalopayx
10Refund/preauth/m_refundmerchant to Zalopayxx
11Get Refund Status/preauth/query_refundmerchant to Zalopayxx
12Create Order for Card Payment/preauth/createmerchant to Zalopayx

Notification:

Interface NameEntry PointDirection
Binding NotificationProvided by the merchantZalopay to merchant
Payment NotificationProvided by the merchantZalopay to merchant

2. API parameter transfer rules

RequiredDescription
MMandatory
OOptional

3. API detail

3.1. Binding

3.1.1. Binding

Description

This API is used for creating a new binding for an agreement of a user in tokenization flow.

Sequence

Payment flow

Integration

NameDescription
ProtocolHTTPS
MethodPOST
Content-Typeapplication/x-www-form-urlencoded
application/json
URI/v2/agreement/bind

Request Parameters

NoParamsDatatypeMandatoryMax lengthDescription
1app_idIntRequiredThe app identifier is provided by Zalopay.
2binding_dataJSON StringRequired2048This field contains detail binding information for billing purposes. Default value is "{}"
3app_trans_idStringRequired40The transaction id is used to initialize a binding request, generated by merchant system, unique transaction ID of application
4binding_typeStringRequired20Specify which type of binding
- WALLET: Zalopay Wallet
- CARD: ATM
5identifierStringRequired128User's identifier on the merchant system, it can be the merchant user's id, phone number, email...
6max_amountInt64RequiredMaximum permissible amount. The default is real balance. Default value is 0
7redirect_urlStringOptional256URL of merchant binding page(web), be used in the desktop binding scenario. After the binding process finished, Zalopay auto-debit binding page will redirect to merchant binding page via redirect URL with the binding result
8redirect_deep_linkStringOptional256deep-link of merchant app, be used in the mobile binding scenario. After the binding process finished, Zalopay app will open the merchant app via redirect deep link with the binding result
9callback_urlStringOptional256After the binding process finished successfully, Zalopay auto-debit system will notify to merchant system via this URL
10req_dateInt64RequiredCurrent unix timestamp in milliseconds
11macStringRequired64Security string for request validation.
- mac = HMAC(HmacSHA256, macKey, macInput)
- macInput = app_id|apps_trans_id|binding_data|binding_type|identifier|max_amount|req_date
- macKey: key generated by Zalopay system for each merchant.

Response Fields

NoField nameDatatypeMax lengthDescriptionNote
1return_codeInt1: Success, 2: Failure
2return_messageString256Description of return code
3sub_return_codeIntDetail error code
4sub_return_messageString256Detail error message
5binding_tokenString64The token for confirming.
6deep_linkString256The deep-link for confirming the agreement in the mobile app to app scenario.Only use for wallet binding
Merchant uses the deep link to launch the Zalopay app for confirm binding
7binding_qr_linkString245The URL for the user confirming the agreement in the desktop or mobile web scenario.Use in both wallet and card binding
Merchant opens "binding_qr_link" on PC Browser or Mobile Browser
Card binding: user input card information for confirm binding
Wallet binding:
- PC Browser: user uses Zalo/Zalopay App to scan QRCode for confirm binding
- Mobile Browser: this web page will auto invoke Zalo/Zalopay app for confirm binding
8short_linkString245The URL for the user agreement in the desktop web/app scenario.
Merchant need gen QR from this link.
Only use for wallet binding:
- Merchant need gen QR code from this link and display on Merchant site.
- User uses Zalo/Zalopay App to scan QR code for confirm binding

Example

Request

{
"app_id": "2688",
"binding_data": "{}",
"app_trans_id": "221011_09171700003",
"binding_type": "WALLET",
"identifier": "NHAN",
"max_amount": 0,
"redirect_url": "",
"redirect_deep_link": "",
"callback_url": "",
"req_date": "1665454637789",
"mac": "fde19dbf326322a614094ef27e38a43601112bda2cb950539f4830d5fa0b759b"
}

Response

{
"return_code": 1,
"return_message": "Success",
"sub_return_code": 1,
"sub_return_message": "Success",
"binding_token": "221011VvZq80GobDg8gTgXPeeLMaZMy",
"deep_link": "zalopay://launch/app/732?view=authorize&b=221011VvZq80GobDg8gTgXPeeLMaZMy",
"binding_qr_link": "https://dev-binding.zalopay.vn?binding_token=221011VvZq80GobDg8gTgXPeeLMaZMy",
"short_link": "https://zlpdev-agp.zalopay.vn/oauthbe/agreement/221011VvZq80GobDg8gTgXPeeLMaZMy"
}

3.1.2. Query Binding

Description

After the binding has been created successfully, this API is used to get merchant callback data

Sequence

Payment flow

Integration

NameDescription
ProtocolHTTPS
MethodPOST
Content-Typeapplication/x-www-form-urlencoded
application/json
URI/v2/agreement/query

Request Parameters

NoParamsDatatypeMandatoryMax lengthDescription
1app_idInt64requiredThe app id of the merchant.
2app_trans_idStringrequired40The merchant's unique id for the binding (TXID of binding transaction)
3binding_typeStringrequired20Specify which type of binding
- WALLET: Zalopay Wallet
- CARD: ATM
4req_dateInt64requiredCurrent unix timestamp in milliseconds
5macStringrequired64Security string for request validation.
macInput = app_id|app_trans_id|req_date
mac = HMAC(HmacSHA256, macKey, macInput)
macKey: key generated by Zalopay system for each merchant.

Response Fields

NoField nameDatatypeMax lengthDescription
1return_codeInt1: Success, 2: Failure, 3: Waiting
Note: To get more information, get from sub_return_code
2return_messageString256Description of return_code
3sub_return_codeIntDetail error code
4sub_return_messageString256Description of sub_return_code
5dataJSON Object4096The merchant callback data
Note: See Merchant Callback Data as bellow for detailed structure

Detail of Merchant Callback Data

NoField nameDatatypeMax lengthDescription
1app_idIntThe app id of the merchant.
2binding_dataString2048The binding data was sent in bind request.
3app_trans_idString40The merchant's unique id for the binding(TXID of binding transaction)
4binding_typeString20Specify which type of binding
WALLET: Zalopay Wallet
CARD: ATM
5binding_idString64The id of binding has been confirmed in the Zalopay system.
6pay_tokenString128The public token is used when doing auto-debit.
7server_timeInt64Server timestamp in seconds.
8merchant_user_idString128The identifier field in bind request.
9statusInt1: Confirmed, 3: Cancelled, 4: Disabled
10msg_typeIntType of message:
1: The user confirms an agreement
2: The user updates the agreement
11zp_user_idString64The identifier of Zalopay user per merchant app_id.
Note: in case binding_type = WALLET
12masked_user_phoneString20Masked user phone(Ex: masked_user_phone:"****6938")
Note: in case binding_type = WALLET
13masked_card_numberString20Masked user card number(Ex: "520032****5097")
Note: in case binding_type = CARD
14issuing_bank_logoString256Url to get logo of issuing bank
Note: in case binding_type = CARD
15issuing_bank_nameString64Abbreviation name of issuing_bank(Ex: "Vietinbank")
Note:in case binding_type = CARD

Example

Scenario 1: Binding Wallet

Request

{
"app_id": "2688",
"app_trans_id": "221011_09171700003",
"req_date": "1665454943715",
"mac": "ec57c1433b39fa86eb896b7e8505a3eb89577cd0f1f67d1fee558c75ffb15d77"
}

Response

{
"return_code": 1,
"return_message": "Success",
"sub_return_code": 1,
"sub_return_message": "Success",
"data": {
"app_id": 2688,
"app_trans_id": "221011_09171700003",
"binding_type": "WALLET",
"binding_id": "221011VvZq80GobDg8gTgXPeeLMaZMy",
"pay_token": "YMVKZWQWNJCTM2YZOC0ZNZZHLTHLNMQTOTJMOGVJNZJJODIY",
"merchant_user_id": "NHAN",
"zp_user_id": "bqdM80_MO1Dt1u9ESGrQPGEVHjza57mPMDZvPpQz_t4",
"masked_user_phone": "****3801",
"server_time": 1665454943,
"status": 1,
"msg_type": 1,
"expiry_timestamp_in_ms": -62135596800000
}
}

3.1.3. Binding Notification

Description

This API is implemented on the merchant site for receiving callbacks from Zalopay for agreements that have been confirmed or updated

Request Parameters

ParameterData TypeMax LengthRequiredDescription
dataJSON String4096Data callback
macString25664Security string for request validation.
macInput = data
mac = HMAC(HmacSHA256, callbac Key, macInput)
callback Key: key generated by Zalopay system for each merchant.
typeInt256Type of callback
1: Order
2: Agreement

Detail of data parameter

ParameterData TypeMax LengthDescription
app_idIntThe app id of the merchant
binding_data2048The binding data was sent in bind request.
app_trans_idString40The merchant's unique id for the binding(TXID of binding transaction)
binding_typeString20Specify which type of binding
- WALLET: Zalopay Wallet
- CARD: ATM
binding_idString64The id of binding has been confirmed in the Zalopay system
pay_tokenString128The public token is used when doing paying
server_timeIntServer timestamp in seconds
merchant_user_idString128The identifier parameter in bind request
statusInt1: Confirmed, 3: Cancelled, 4: Disabled
msg_typeIntType of message:
1: The user confirms an agreement
2: The user updates the agreement
zp_user_idString64The identifier of Zalopay user per merchant app_id
Note: in case binding_type = WALLET
masked_user_phoneString20Masked user phone(Ex: "****6938")
Note: in case binding_type = WALLET
card_idString128The unique identifier for a payment card
Note: in case binding_type = CARD
masked_card_numberString20Masked user card number(Ex: "520032****5097")
Note: in case binding_type = CARD
issuing_bank_logoString256Url to get logo of issuing bank
Note: in case binding_type = CARD
issuing_bank_nameString64Abbreviation name of issuing_bank (Ex: "Vietinbank")
Note: in case binding_type = CARD

Response Fields

ParameterData TypeMax LengthDescription
return_codeInt1: Success
2: Failure
return_messageString256Description of return_code

3.1.4. Unbind

Description

This API will request to unbind an agreement in case a user doesn’t want to use the auto-debit feature.

Sequence

Payment flow

Integration

NameDescription
ProtocolHTTPS
MethodPOST
Content-Typeapplication/x-www-form-urlencoded
application/json
URI/v2/agreement/unbind

Request Parameters

NoParamsDatatypeMandatoryMax lengthDescription
1app_idIntRequiredapp-id provided by Zalopay, provided by Zalopay
2identifierStringRequired128user's identifier on the merchant system, it can be a merchant user's id, phone number, email...
3binding_typeStringRequired20Specify which type of binding
- WALLET: Zalopay Wallet
- CARD: ATM
4binding_idStringRequired64The ID of binding that the user wants to unbind.
5req_dateInt64RequiredCurrent unix timestamp in milliseconds.
6macStringRequired64Security string
macInput = app_id|identifier|binding_id|req_date
mac = HMAC(HmacSHA256, macKey, macInput)
macKey: key generated by Zalopay system for each merchant.

Response Fields

NoField nameDatatypeMax lengthDescription
1return_codeInt1: Success, 2: Failure
2return_messageString256Description of return code
3sub_return_codeIntDetail error code
4sub_return_messageString256Detail error message

Example

Request

{
"app_id": "2688",
"identifier": "NHAN",
"binding_type": "WALLET",
"binding_id": "221011VvZq80GobDg8gTgXPeeLMaZMy",
"req_date": "1665461267733",
"mac": "5c48aa2af0b4348fbcb1ecf9f4c90295d4f757b1eb8caa1e7c55cb27c0e9c110"
}

Response

{
"return_code": 1,
"return_message": "Success",
"sub_return_code": 1,
"sub_return_message": "Success"
}

3.2. Authorized Payment

3.2.1. Authorize

Description

This API is used to make an authorization transaction

Sequence

Payment flow

Integration

NameDescription
ProtocolHTTPS
MethodPOST
Content-Typeapplication/x-www-form-urlencoded
application/json
URI/preauth/authorize

Request Parameters

NoParamsDatatypeMandatoryMaxlengthDescription
1app_idIntRequiredThe unique ID of the application will be provided after the merchant registered successfully with Zalopay.
2app_trans_idStringRequired40Unique transaction ID of application (TXID of authorize transaction)
3binding_typeStringRequired20Specify which type of binding
WALLET: Zalopay Wallet
CARD: ATM(at present, just apply binding_type= WALLET)
4identifierStringRequired128User's unique identifier on the merchant system. It can be the merchant user's id, phone number, email...
5pay_tokenStringRequired128The public token of the payer. This value was returned after user binding success by binding notification or query binding API
6amountInt64RequiredThe Amount of money will be charged.
7itemJSON Array StringRequired2048JSON array string describes order items.The required empty value is "[]"
8embed_dataJSON StringRequired1024JSON string includes additional information (used for promotion or customer support or reporting)The required empty value is "{}"
9order_codeStringOptionalType of order. The default value is GOODS. Supported list: GOODS, TRANSPORTATION, HOTEL, FOOD, P2P, TELCARD, BILLING
10payment_idStringOptionalThis field is used for settlement goal
11req_dateInt64RequiredThe unix timestamp that the transaction was created in milliseconds. The different limit is 15 minutes.
12macStringRequiredSecurity string for request validation. macInput= app_id

Response Fields

NoField nameDatatypeDescription
1return_codeInt1: Successful, 2: Failed
2return_messageStringDescription of return code
3sub_return_codeIntDetail error code
4sub_return_messageStringDetail error message
5statusInt3: Authorizing, 4: Authorized
6zp_trans_idLongThe Zalopay transaction ID. The Merchant needs to save to use in reconciliation flow

Example

Request

{
"amount": "50000",
"app_id": "2688",
"app_trans_id": "221011_09285100004",
"embed_data": "{}",
"identifier": "NHAN",
"item": "[]",
"mac": "352b5fae50691256a610ca26da7592fb5718b32c0028a30a51d6e6de8110a51f",
"order_code": "TRANSPORTATION",
"pay_token": "YMVKZWQWNJCTM2YZOC0ZNZZHLTHLNMQTOTJMOGVJNZJJODIY",
"payment_id": "",
"req_date": "1665455331635"
}

Response

{
"return_code": 1,
"return_message": "Success",
"status": 4,
"sub_return_code": 1,
"sub_return_message": "Success",
"zp_trans_id": 230725000950036
}

3.2.2. Capture

Description

This API is designed to capture an authorized transaction, and the amount captured must be either equal to or less than the authorized amount. Each authorized transaction can only be captured once.

Sequence

Payment flow

Integration

NameDescription
ProtocolHTTPS
MethodPOST
Content-Typeapplication/x-www-form-urlencoded
application/json
URI/preauth/capture

Request Parameters

NoParamsDatatypeMax LengthMandatoryDescription
1app_idIntRequiredUnique ID generated by Zalopay to identify each merchant's application.
2app_trans_idString40RequiredTXID of the authorized transaction. This has the same value as app_trans_id in the request body of the /preauth/authorize API.
3amountInt64RequiredAmount to be captured in VND.
4req_dateInt64RequiredCurrent unix timestamp in milliseconds.
5macString64RequiredSignature for request validation.
mac = HMAC(Hmac_SHA256, macKey, macInput)
macInput = app_id|app_trans_id|amount|req_date
macKey: key generated by Zalopay system for each merchant's application

Response Body

NoField nameDatatypeDescription
1return_codeInt1: Success, 2: Failure
2return_messageStringDescription of return_code.
3sub_return_codeIntDetailed error code.
4sub_return_messageStringProvide specific information for each response case.
5statusInt5: Capturing, 6: Captured
6zp_trans_idLongThe transaction id generated by Zalopay which associated to merchant's transaction (app_trans_id). Merchant needs to save it for use during the refund and reconciliation process.

Example

RequestResponse
Authorize{"app_id":"2222","app_trans_id":"221011_09285100004","identifier":"user@merchant.com","pay_token":"YMVKZWQWNJCTM2YZOC0ZNZZHLTHLNMQTOTJMOGVJNZJJODIY","amount":"50000","item":"[]","embed_data":"{}","order_code":"TRANSPORTATION","payment_id":"","req_date":"1665455331635","mac":"352b5fae50691256a610ca26da7592fb5718b32c0028a30a51d6e6de8110a51f"}{"return_code":1,"return_message":"Giao dịch thành công.","sub_return_code":1,"sub_return_message":"Giao dịch thành công.","status":4}
Capture{"app_id":"2222","app_trans_id":"221011_09285100004","amount":"50000","req_date":"1665455571276","mac":"9a2d87e47228177a4620d8bd9bcc4f8df7cb34dee430b1bf0f188c3ceb567961"}{"return_code":1,"return_message":"Giao dịch thành công.","sub_return_code":1,"sub_return_message":"Giao dịch thành công.","status":6,"zp_trans_id":221011000002836}

3.2.3. Cancel

Description

This API is used to cancel an authorizing/authorized request.

Sequence

Payment flow

Integration

NameDescription
ProtocolHTTPS
MethodPOST
Content-Typeapplication/x-www-form-urlencoded
application/json
URI/preauth/cancel

Request Parameters

NoParamsDatatypeMandatoryDescription
1app_idIntRequiredapp-id provided by Zalopay
2app_trans_idStringRequiredTXID of the authorizing/authorized transaction.This has the same value as app_trans_id in the request body of /authorize API
3req_dateInt64RequiredCurrent unix timestamp in milliseconds
4descriptionStringRequiredCancel reason
5macStringRequiredSecurity string
macInput = app_id|app_trans_id|req_date
mac = HMAC(HmacSHA256, macKey, macInput)
macKey: key generated by Zalopay system for each merchant.

Response Fields

NoField nameDatatypeDescription
1return_codeInt1: Successful, 2: Failed
2return_messageStringDescription of return code
3sub_return_codeIntDetail error code
4sub_return_messageStringDetail error message
5statusInt7: Cancelling, 8: Cancelled

Example

APIRequestResponse
Authorize{"amount":"100000","app_id":"2688","app_trans_id":"221011_09352400005","embed_data":"{}","identifier":"NHAN","item":"[]","mac":"6336df9d632d1db9c0f0b38f271c248282e15ce9f64e0ba9cdf75e1081f16008","order_code":"","pay_token":"YMVKZWQWNJCTM2YZOC0ZNZZHLTHLNMQTOTJMOGVJNZJJODIY","payment_id":"","req_date":"1665455724639"}{"return_code":1,"return_message":"Success","status":4,"sub_return_code":1,"sub_return_message":"Success"}
Cancel{"app_id":"2688","app_trans_id":"221011_09352400005","description":"Zalopay Cancel Payment Demo","mac":"9714db9fe9c02e04935715a015eb06d518e27667020c116661dc03700a261e98","req_date":"1665455925517"}{"return_code":1,"return_message":"Success","status":8,"sub_return_code":1,"sub_return_message":"Success"}

3.2.4. Pay

Description

This API is used to make a direct payment transaction.

Sequence

Payment flow

Integration

NameDescription
ProtocolHTTPS
MethodPOST
Content-Typeapplication/x-www-form-urlencoded
application/json
URI/preauth/pay

Request Parameters

NoParamsDatatypeMandatoryMaxlengthDescription
1app_idIntRequiredThe unique ID of the application will be provided after the merchant registered successfully with Zalopay.
2app_trans_idStringRequired40Unique transaction ID of application (TXID of pay direct transaction)
3binding_typeStringRequired20Specify which type of binding
WALLET: Zalopay Wallet
CARD: ATM
4identifierStringRequired128User's unique identifier on the merchant system. It can be the merchant user's id, phone number, email...
5pay_tokenStringRequired128The public token of the payer. This value was returned after user binding success by binding notification or query binding API
6amountInt64RequiredThe Amount of money will be charged.
7itemJSON Array StringRequired2048JSON array string describes order items.The required empty value is "[]"
8embed_dataJSON StringRequired1024JSON string includes additional information (used for promotion or customer support or reporting)The required empty value is "{}"
9order_codeStringOptionalType of order. The default value is GOODS. Supported list: GOODS, TRANSPORTATION, HOTEL, FOOD, P2P, TELCARD, BILLING
10payment_idStringOptionalThis field is used for settlement goal
11req_dateInt64RequiredThe unix timestamp that the transaction was created in milliseconds. The different limit is 15 minutes.
12macStringRequiredSecurity string for request validation.
macInput = app_id|app_trans_id|identifier|pay_token|amount|item|embed_data|req_date
mac = HMAC(HmacSHA256, macKey, macInput)
macKey: key generated by Zalopay system for each merchant.

Response Fields

NoField nameDatatypeDescription
1return_codeInt1: Successful, 2: Failed
2return_messageStringDescription of return code
3sub_return_codeIntDetail error code
4sub_return_messageStringDetail error message
5statusInt9: Paying, 10: Paid
6zp_trans_idLongThe Zalopay transaction ID. The Merchant needs to save to use in reconciling and refunding flow
7verification_requiredBool= true: require a verification from User
8verification_urlStringThe verification url for user perform confirmation

Example

success case

RequestResponse
{"app_id": "2688","app_trans_id": "221011_09443000006","identifier": "NHAN","pay_token": "YMVKZWQWNJCTM2YZOC0ZNZZHLTHLNMQTOTJMOGVJNZJJODIY","amount": "150000","item": "[]","embed_data": "{}","order_code": "TRANSPORTATION","payment_id": "","req_date": "1665456270936","mac": "0f79892bdee67cd4ecd9b83298c503bfa648066a3feb07dc4e9ddc378d8b05a3"}{"return_code": 1,"return_message": "Success","sub_return_code": 1,"sub_return_message": "Success","status": 10,"zp_trans_id": 221011000002992}

need verification case

RequestResponse
{"app_id": "2688","app_trans_id": "221011_09443000006","identifier": "NHAN","pay_token": "YMVKZWQWNJCTM2YZOC0ZNZZHLTHLNMQTOTJMOGVJNZJJODIY","amount": "150000","item": "[]","embed_data": "{}","order_code": "TRANSPORTATION","payment_id": "","req_date": "1665456270936","mac": "0f79892bdee67cd4ecd9b83298c503bfa648066a3feb07dc4e9ddc378d8b05a3"}{"return_code": 1,"return_message": "Success","sub_return_code": 1,"sub_return_message": "Success","status": 1,"verification_required": true,"verification_url": "https://gateway.zalopay.vn/verify_otp"}

3.2.5. Query Status

Description

This API is used to query the status of the transaction that has been executed by the authorize/amend/capture/cancel/pay API.

Sequence

Payment flow

Integration

NameDescription
ProtocolHTTPS
MethodPOST
Content-Typeapplication/x-www-form-urlencoded
application/json
URI/preauth/query

Request Parameters

NoParamsDatatypeMandatoryDescription
1app_idIntRequiredapp-id provided by Zalopay
2app_trans_idStringRequiredTXID of the authorized or paid transaction.This has the same value as app_trans_id in the request body of /authorize API when you want to check the status of an authorized transactionThis has the same value as app_trans_id in the request body of /pay API when you want to check the status of a direct payment transaction
3req_dateInt64RequiredCurrent unix timestamp in milliseconds
4macStringRequiredSecurity string
macInput = app_id|app_trans_id|req_date
mac = HMAC(HmacSHA256, macKey, macInput)
macKey: key generated by Zalopay system for each merchant.

Response Fields

NoField nameDatatypeDescription
1return_codeInt1: Successful, 2: Failed
2return_messageStringDescription of return code
3sub_return_codeIntDetail error code
4sub_return_messageStringDetail error message
5zp_trans_idStringThe Zalopay transaction ID
6statusIntThe statuses of the transaction
1: Created
2: Failed
3: Authorizing
4: Authorized
5: Capturing
6: Captured
7: Cancelling
8: Cancelled
9: Paying
10: Paid
7refund_statusIntRefund status
0: NoRefund
1: Refunded
4: Partially_Refunded

Example

RequestResponse
{"app_id":"2688","app_trans_id":"221011_09443000006","mac":"3d44e8a5b350d0046536c587daf1d45e09e0e17e6ead9fde1b7e3fa13022ea3a","req_date":"1665456878501"}{"refund_status":0,"return_code":1,"return_message":"Success","status":10,"sub_return_code":1,"sub_return_message":"Success","zp_trans_id":221011000002992}

3.2.6. Get Payable

Description

This API to check whether an user will be able to pay or not before paying or authorizing an order. Nevertheless, it's important to understand that the success of the Get_Payable API does not guarantee a 100% success rate for the Pay or Authorize APIs. Some fund sources, particularly those where our bank partners decline to disclose the user's account balance, consistently return successful responses for the Get_Payable API, but the Pay or Authorize APIs may still encounter failures if there are insufficient funds in the user's bank account.

Sequence

Payment flow

Integration

NameDescription
ProtocolHTTPS
MethodPOST
Content-Typeapplication/x-www-form-urlencoded
application/json
URI/preauth/get_payable

Request Parameters

NoParamsDatatypeMandatoryMax lengthDescription
1app_idIntRequiredintapp-id provided by Zalopay
2identifierStringRequired128user's identifier on the merchant system, it can be a merchant user's id, phone number, email...
3pay_tokenStringRequired128The public token of the payer. This value was returned after user binding success by calling webhook or using /v2/agreement/query API
4amountInt64RequiredIntThe amount of the transaction you need to check max-pay-able
5redirect_urlStringOptional256After the reform process finished, Zalopay auto-debit reform page will redirect to merchant via redirect URL with the reform result
6req_dateInt64RequiredintCurrent unix timestamp in milliseconds
7macStringRequired64Security string
macInput = app_id|pay_token|identifier|amount|req_date
mac = HMAC(HmacSHA256, macKey, macInput)
macKey: key generated by Zalopay system for each merchant.

Response Fields

NoFiled nameDatatypeMax lengthDescription
1return_codeInt1: Successful, 2: Failed
2return_messageString256Error message
3sub_return_codeIntDetail error code
4sub_return_messageString256Detail error message
5dataJson Object ArrayThe array of channels which user can use to pay
6reform_urlStringThe url which is used to topup money in insufficient balance case or upgrade a(Open when sub_return_code = -1800 or -1010)
7payableBoolIf the user is able to pay

Example

Example 1:

RequestResponse
{"amount":"1500000","app_id":"2688","identifier":"NHAN","mac":"dc777381a45918b92991c8bbcfc24028d928932315a9906e76a76e3e9bf0bb15","pay_token":"YMVKZWQWNJCTM2YZOC0ZNZZHLTHLNMQTOTJMOGVJNZJJODIY","req_date":"1665457162811"}{"data":"[{"bank_code":"zp_app","channel":38},{"bank_code":"tktl","channel":44}]","payable":true,"return_code":1,"return_message":"Success","sub_return_code":1,"sub_return_message":"Success"}

Example 2:

RequestResponse
{"amount":"1500000","app_id":"2688","identifier":"NHAN","mac":"dc777381a45918b92991c8bbcfc24028d928932315a9906e76a76e3e9bf0bb15","pay_token":"YMVKZWQWNJCTM2YZOC0ZNZZHLTHLNMQTOTJMOGVJNZJJODIY","redirect_url":"merchant://app","req_date":"1665457162811"}{"reform_url":"https://zalo.me/qr/jp/7seo74pfsi?view=topup&app_id=2688&amount=100000&redirect_url=merchant%3A%2F%2Fapp","return_code":2,"return_message":"Failed","sub_return_code":-1010,"sub_return_message":"User has insufficient funds for payment"}

Example 3:

RequestResponse
{"amount":"1500000","app_id":"2688","identifier":"NHAN","mac":"dc777381a45918b92991c8bbcfc24028d928932315a9906e76a76e3e9bf0bb15","pay_token":"YMVKZWQWNJCTM2YZOC0ZNZZHLTHLNMQTOTJMOGVJNZJJODIY","redirect_url":"merchant://app","req_date":"1665457162811"}{"reform_url":"https://zalo.me/qr/jp/7seo74pfsi?view=kyc&app_id=2688&redirect_url=merchant%3A%2F%2Fapp","return_code":2,"return_message":"Failed","sub_return_code":-1800,"sub_return_message":"Payment limit exceeded according to KYC"}

3.2.7. Create

Description

This API is used to create an order that pay by card (and can automatically link)

Sequence

Payment flow

Integration

NameDescription
ProtocolHTTPS
MethodPOST
Content-Typeapplication/x-www-form-urlencoded
application/json
URI/preauth/create

Request Parameters

NoParamsDatatypeMandatoryMaxlengthDescription
1app_idIntRequiredThe unique ID of the application will be provided after the merchant registered successfully with Zalopay.
2app_trans_idStringRequired40Unique transaction ID of application (TXID of pay direct transaction)
3identifierStringRequired128User's unique identifier on the merchant system. It can be the merchant user's id, phone number, email...
4amountInt64RequiredThe Amount of money will be charged.
5itemJSON Array StringRequired2048JSON array string describes order items.The required empty value is "[]"
6embed_dataJSON StringRequired1024JSON string includes additional information (used for promotion or customer support or reporting)The required empty value is "{}"
7order_codeStringOptionalType of order. The default value is GOODS. Supported list: GOODS, TRANSPORTATION, HOTEL, FOOD, P2P, TELCARD, BILLING
8payment_idStringOptionalThis field is used for settlement goal
9bank_codeStringRequiredBank code of request (at present, just apply bank_code=ATM)
10callback_urlStringOptionalZalopay will notify to this URL only when the payment is success; If not provided, the default app Callback URL will be used.
11req_dateInt64RequiredThe unix timestamp that the transaction was created in milliseconds. The different limit is 15 minutes.
12macStringRequiredSecurity string for request validation.
macInput = app_id|app_trans_id|identifier|amount|item|embed_data|req_date
mac = HMAC(HmacSHA256, macKey, macInput)
macKey: key generated by Zalopay system for each merchant.

Specific embed_data fields

NameDataTypeFormatDescriptionExample
binding_infoJSON String{"field_name": "value"}binding_info must have fields as bellow:agree_to_link: the user has agreed to save the payment information for the next timebinding_type:This parameter specifies the type of bindingcallback_url:Zalopay tokenization system will notify Binding Token to merchant system via this URL."binding_info":"{"agree_to_link":true,"binding_type":"CARD","callback_url":"https://merchant.com/binding_result/?"}"}

Response Fields

NoField nameDatatypeDescription
1return_codeInt1: Successful, 2: Failed
2return_messageStringDescription of return code
3sub_return_codeIntDetail error code
4sub_return_messageStringDetail error message
5order_urlStringUsed to open Zalopay Gateway page for user input card info and submit
6zp_trans_tokenStringTransaction token

Example

RequestResponse
{"amount":"150000","app_id":"2688","app_trans_id":"221011_09443000006","bank_code":"ATM","embed_data":"{}","identifier":"NHAN","item":"[]","mac":"0f79892bdee67cd4ecd9b83298c503bfa648066a3feb07dc4e9ddc378d8b05a3","order_code":"TRANSPORTATION","payment_id":"","req_date":"1665456270936"}{"return_code":1,"return_message":"Success","status":"https://gateway.zalopay.vn/openinapp?order=eyJ6cHRyYW5zdG9rZW4iOiJBQ0hleHFtTElpQk84c1p6ZmR6S21Ra1EiLCJhcHBpZCI6MTAwMzN9","sub_return_code":1,"sub_return_message":"Success","zp_trans_token":"ACHexqmLIiBO8sZzfdzKmQkQ"}

3.3. Refund

3.3.1. Refund

Description

API refunds the transaction's amount that has been successfully paid/captured via Zalopay.

Sequence

Payment flow

Integration

NameDescription
ProtocolHTTPS
MethodPOST
Content-Typeapplication/x-www-form-urlencoded
application/json
URI/preauth/m_refund

Request Parameters

NoParamsDatatypeMandatoryMax lengthDescription
1m_refund_idStringRequired45• Merchant must be generate merchant own transaction code when submit refund requirement.
• Format: yymmdd_appid_xxxxxxxxxx
2app_idIntRequiredMerchant app_id, which was provided by Zalopay when registering.
3app_trans_idStringRequired15• TXID of the authorized or paid transaction.
4amountLongRequiredRefund amount for users
5req_dateLongRequired13• Time to refund (unix timestamp in millisecond).
• The time of making the refund, is calculated in milliseconds
6macStringRequiredAuthenticate information (See how to create authenticate information)
hmac_algorithm: is a security method registered by Merchant with Zalopay, the default is HmacSHA256
macinput = app_id +"|"+m_refund_id + "|"+app_trans_id +"|"+ amount +"|"+ description +"|"+req_date
mac = HMAC(hmac_algorithm, macKey, macinput)
macKey: key generated by Zalopay system for each merchant.
7descriptionStringRequired100Refund reason

Response Fields

NoParamsDatatypeDescription
1return_codeInt1: Successful, 2: Failed
2return_messageStringDescription of return code
3sub_return_codeIntDetail error code
4sub_return_messageStringDetail error message
5refund_statusInt1: Refunded
3:Refunding
6refund_idLongZalopay refund's transaction code, need to save for cross-check then

Example

Request

{
"app_id": "2688",
"m_refund_id": "221011_2688_10074200009",
"zp_trans_id": "221011000002992",
"amount": "150000",
"req_date": "1665457662550",
"mac": "a2adcbb09a2ec15c143eabe887a8f21bcc0f811f0764cd939354eba5b8c97d4f",
"description": "Zalopay Demo - Refund TransID 221011000002992",
"mac_key": "xmMs1kVGz4iItUFykGqvVpCi2eWNkw46"
}

Response

{
"return_code": 1,
"return_message": "Success",
"sub_return_code": 1,
"sub_return_message": "Success",
"refund_status": 1,
"refund_id": 221011000100053
}

3.3.2. Query Refund

Description

API allows merchants to query the refund status of a refund transaction

Sequence

Payment flow

Integration
NameDescription
ProtocolHTTPS
MethodPOST
Content-Typeapplication/x-www-form-urlencoded
application/json
URI/query_refund

Request Parameters

NoParamsDatatypeMandatoryMax lengthDescription
1app_idIntRequiredapp_id provided by Zalopay
2m_refund_idStringRequired45• The transaction code, which was generated by merchant when querying refund transaction.
• Format: yymmdd_appid_xxxxxxxxxx
3req_dateLongRequiredThe time call API (timestamp in millisecond)
4macStringRequired= HMAC(hmac_algorithm, key1, app_id+"|"+m_refund_id+"|"+req_date)

Response Fields

NoParamsDatatypeDescription
1return_codeInt1: Successful, 2: Failed
2return_messageStringDescription of return_code
3sub_return_codeIntError code detail
4sub_return_messageStringDescription of sub_return_code
5refund_statusIntThe statuses of the refund transaction
1: Refunded
2: Refund_Failed
3: Refunding
6refund_idLongZalopay refund's transaction code, need to save for cross-check then

Example

Request

{
"app_id": "2688",
"m_refund_id": "221011_2688_10074200009",
"req_date": "1665458480710",
"mac": "58353dd94418ade5b67825ea4a770c3dc8943875c18951ae3aaadae07809d4d6"
}

Response

{
"return_code": 1,
"return_message": "Success",
"sub_return_code": 1,
"sub_return_message": "Success",
"refund_status": 1,
"refund_id": 221011000100053
}

4. Error Code Information

4.1. Error Code

return_code value
ValueDescription
1Successful
2Failed
3Processing
sub_return_code
sub_return_codeShort DescriptionMeaningType
1SUCCESSSuccessSuccessful
-1UNKNOWNUnknown errorSystem or User Error
-54TIME_INVALIDreq_date param of request is not unix timestamp in milliseconds format or more than 15 minutes difference from current timeMerchant Error
-68DUPLICATE_APPS_TRANS_IDDuplicate transactionMerchant Error
-101ORDER_NOT_EXISTSOrder not existsMerchant Error
-102TRANS_IS_NOT_ALLOWEDEx: Call capture a transaction which has been cancelled; or capture amount exceeds authorized amountMerchant Error
-401ILLEGAL_DATA_REQUESTRequest param is illegalMerchant Error
-402ILLEGAL_APP_REQUESTAppID is invalidMerchant Error
-403ILLEGAL_SIGNATURE_REQUESTWrong mac (wrong mac key or param to create mac)Merchant Error
-500SYSTEM_ERRORZalopay System ErrorSystem Error
-1009USER_HAS_BEEN_LOCKEDUser account is lockedUser Error
-1010USER_CANNOT_PAYThe user account has no source of funds eligible for paymentUser Error
-1011PERMISSION_DENIEDToken is invalid/unlinked/expired and user needs to relink.User Error
-1012USER_IS_NOT_ELIGIBLE_FOR_PAYMENTUser is not eligible for payment due to risk rule, etcUser Error
-1013PAYMENT_AMOUNT_EXCEED_LIMITThe Order amount for payment exceeds the limitUser Error
-1800USER_EXCEED_KYC_LIMITUser has exceeded the limit according to KYC requirementUser Error
-1801SYSTEM_IS_MAINTENANCEZalopay System is in maintenanceSystem Error

4.2. Error Code mapping with scenarios

APIScenariosub_return_codesub_return_message
AllRequired parameter is missing or parameter value is invalid-401Illegal request data
AllApp ID is not allowed-402Unknown app
AllWrong mac value-403Wrong signature
Allreq_date param is not unix timestamp in milliseconds format or more than 15 minutes difference from current time-54Invalid request date
AllZalopay system is in maintenance-1801System maintenance
AllInternal error of Zalopay system-500System internal error
Bindingapp_trans_id is same as the previous one-68Duplicate app trans id
UnbindUsing BindingID does not exist-101Binding does not exist
Query BindingQuery BindingID does not exist-101Binding does not exist
Get Payable, Authorize or PayUser account has been locked-1009User account has been locked
Get Payable, Authorize or PayThe user account has no eligible source of funds eligible for payment-1010User has insufficient funds for payment
Get Payable, Authorize or PayPayment token is invalid/unlinked/expired-1011Permission denied
Get Payable, Authorize or PayUser is not eligible for payment due to risk rule, etc-1012User is not eligible for payment
Get Payable, Authorize or PayThe amount exceeds the maximum limit set by the user for this app-1013Payment limit exceeded
Get Payable, Authorize or PayUser has exceeded the limit according to KYC requirement-1800Payment limit exceeded according to KYC
Authorize or Payapp_trans_id is same as the previous one-68Duplicate merchant transaction id
Capture or CancelThe requested transaction has not been authorized before-101Transaction does not exist
Capture or CancelThe requested transaction is not in authorized state-102Transaction not allowed
QueryThe requested transaction does not exist-101Transaction does not exist
Refundm_refund_id param is not prefixed with format yyMMdd of the current day (GMT+7) & App ID-92Invalid merchant transaction id
RefundThe original transaction does not exist-101Transaction does not exist
Refund+ The original transaction is not in captured or paid state-102Transaction not allowed
Refund+ The capture amount exceeds the authorized amount-102Transaction not allowed
Refund+ Refund amount is greater than payment amount-102Transaction not allowed
Refund+ Refund time limit has passed-102Transaction not allowed
Query RefundThe requested transaction does not exist-101Transaction does not exist