9
- [Introduction](./1) - [Payment Flow and User Experience](./3) - [Quick start](./64) - [Pay Flow](./57) - [Refund Flow](./58) - [Query Flow](./59) - [Reconciliation Flow](./67) - [Secondary Merchant Maintenance Flow](./68) - [Integration](./42) - [Preparing keys](./48) - [Downloading Demo Code](./66) - [Calling APIs](./65) - [Signing the Request and Creating the Request URL](./50) - [Processing Notifications](./51) - [Verifying the Asynchronous Notification](./52) - [Verifying the Synchronous Notification](./53) - [Testing in Sandbox](./44) - [Prerequisites](./43) - [Deploying in Sandbox](./45) - [Running Demo Code in Sandbox](./46) - [Going Live](./55) - [API list](./6) - [Create_forex_trade](./6) - [Request Parameters](./6) - [Sync Response](./7) - [Samples](./8) - [Async Notification](./9) - [Error Codes](./10) - [Forex_refund](./11) - [Request Parameters](./11#Request) - [Sync Response](./11#Response) - [Samples](./11#Samples) - [Error Codes](./12#Errors) - [Async Notification](./70) - [Single_trade_query](./13) - [Request Parameters](./13#QueryRequest) - [Sync Response](./13#QueryResponse) - [Samples](./13#QuerySamples) - [Error Codes](./14#Errors) - [Forex_compare_file](./15) - [Request Parameters](./15#Forex_compare_file_Request) - [Sync Response](./15#Forex_compare_file_Response) - [Samples](./15#Forex_compare_file_Samples) - [Error Codes](./16) - [Forex_liquidation_file](./17) - [Request Parameters](./17#Forex_liquidation_file_Request) - [Sync Response](./17#Forex_liquidation_file_Response) - [Samples](./17#Forex_liquidation_file_Samples) - [Error Codes](./18) - [Forex_rate_file](./19) - [Request Parameters](./19#Forex_rate_file_Request) - [Sync Response](./19#Forex_rate_file_Response) - [Samples](./19#Forex_rate_file_Samples) - [Error Codes](./20) - [alipay.overseas.secmerchant.online.maintain](./37) - [Request Parameters](./37#request) - [Sync Response](./37#sync) - [Samples](./37#samples) - [Error Codes](./37#error) - [alipay.overseas.secmerchant.maintain.queryStatus](./73) - [Reconciliation files](./34) - [Obtaining Reconciliation Files](./35) - [API](./35#API) - [Alipay global site](./35#Global) - [SFTP](./35#SFTP) - [Reconciliation File Contents](./36) - [Transaction file](./36#TransactionFile) - [Settlement file](./36#SettlementFile) - [Digital Signature](./69) - [Preparing Keys](./48) - [Signing the Request](./50) - [Verifying the Signature of Asynchronous Response](./52) - [Verifying the Signature of Synchronous Response](./53) - [FAQ](/help/online)
New Cross-border Website Payment

Async Notification

In addition to the API response through the page redirect, the API response might also be sent to the partner asynchronously with the POST method if the merchant set 'notify_url' field in the request with the targeted URL to handle the asynchronous notification. Handling async notification is required for this payment solution.

Alipay would retry the sending asynchronous notification multiple times within a 25-hour window until the partner acknowledges the receipt of the notification by sending a string 'Success' in the response. The merchant needs to respond to avoid the further re-send of the async notification.
When handling the API response through the page redirect and the asynchronous notification, the following aspects should be considered:

  • The asynchronous notification might arrive ahead of the page redirect.
  • The duplicated asynchronous notifications.

Response Parameters in Async Notifications

Parameter

Type (length in bytes)

Description

Example

Basic Parameter

sign_type

String

Signature method. The following are supported. Must be uppercase.
DSA, RSA, and MD5.

RSA

sign

String

Signature value.

e5815a4556db338ed237f7d3fd222184

Business Parameter

notify_type

String

Notification type, value: trade_status_sync.

trade_status_sync

notify_id

String(34)

The ID for a particular notification.  It can be used by the partner system to verify the notification

92c60707dc43a5b2d648b7b4d3c2e1592g

notify_time

Timestamp

Time (Alipay’s time zone): YYYY-MM-DD hh:mm:ss

2015-06-30 09:56:02

trade_status

String(32)

One of following two values:
TRADE_FINISHED
TRADE_CLOSED

TRADE_FINISHED

trade_no

String(64)

Alipay Transaction ID.

Max length is 64 and min length is 16.

2015070800001000100080029361

out_trade_no

String(64)

out_trade_no passed in by the merchant in the request

2525759240575424

currency

String(3)

Currency code.

USD

total_fee

Number(8,2)

The amount of the payment

11.00

Asynchronous Notification Example

https://www.namesilo.com/alipay_ipn.php?notify_id=92c60707dc43a5b2d648b7b4d3c2e1592g&notify_type=trade_status_sync&sign=***&trade_no=2015063000001000080055080394&total_fee=7.99&out_trade_no=9677726c8757aea6d4df81091811b047&currency=USD&notify_time=2015-06-30 09:56:02&trade_status=TRADE_FINISHED&sign_type=MD5

http://www.namesilo.com/alipay_ipn.php?notify_id=0578bc470961e3b43fb676db616711fd2k&notify_type=trade_status_sync&sign=***&trade_no=2015061700001000100000583330&total_fee=11.00&out_trade_no=2082389608326064&currency=USD&notify_time=2015-06-17+02%3A37%3A02&trade_status=TRADE_CLOSED&sign_type=RSA

Nofitication trigger condition


Trigger condition name

Description on trigger condition

Note

TRADE_FINISHED

Trade successfully

true (trigger nofitication)

WAIT_BUYER_PAY

Trade creation

false (does not trigger nofitication)

TRADE_CLOSED

Trade closed

true (trigger nofitication)

  • Make sure the Notification Page (notify_url) is absolutely blank, without space, html tag, or any error message threw from the program system.
  • Parameters in this page can be acquired with GET method, like request.Form("out_trade_no"), $_POST['out_trade_no'].
  • This response will be used, if Alipay initiatively notify.
  • Alipay will notify when there is a real transaction in Alipay system and the status of that transaction has changed.
  • Interaction between servers, unlike interaction between websites which is visible, is usually not displayable.
  • When the first time a transaction status is changed, not only page would redirect to partner website but also would Alipay notify partner system
  • After program is executed, the page must print “success” (without quote). If not, Alipay server would keep re-sending notification, until over 24 hour 22 minutes Generally, there are 8 notifications within 25 hours (Frequency: 2m,10m,15m,1h,2h,6h,15h)
  • After program is executed, there would not be redirection operation on the page, for Alipay would not recognize a “success” string, so it would be regarded as an error, and Alipay system would keep sending notification.
  • Cookies and session would be invalid on this page, which means these data would not be captured.
  • The configuration and testing of this system must be on a server, via internet
  • The main effect of this mood is to present transaction lost, so even redirection failed, the order in partner system still update.
  • As long as the partner receives the sever asynchronous response and prints “success”, the parameter notify_id would be invalid. It means when Alipay sends the same asynchronous notification (include the re-sending notifications because of no “success”), the parameter notify_id would not change.
  • Along with the business growth, Alipay may add new parameters (existing parameters will not change). When doing notification verification, Merchants MUST use all parameters (except sign and sign_type) returned from Alipay.

Notification Verification

For the interest of system’s healthiness, it is recommended that the partner verifies if the notification is from Alipay.

The partner can only verify the notifications sent within the last 1 minute, and before sending the ‘Success’ acknowledgement back to Alipay.
For example:

https://intlmapi.alipay.com/gateway.do? service=notify_verify&partner=2088101122136241&notify_id=+4465b04e84cb6bacc2bd1b52232c0b8gjg&sign=ciSBXc7gjCfXW8KMBxFiFH2cbMZtFelfTOGKqY2NF7q98RnH3E%2BiF5Cj%2Fu%2Bl8py1D%2FOsE%2FAva1ls8A6Tw1MzhG6ideJSgh4FxWmAjEnlczdfLj%2FqzA6qGzxdKGEXaSDFmTGglOembXUqK8g8ajICD%2BBH7xoxBRY7vtfylEXtojs%3D&sign_type=RSA

For more details, please refer to the API document of notify_verify.

To verify whether all API requests and responses are correctly handled, and whether user experiences are as expected, you can test Alipay payment features integrated with your applications in sandbox environment before going live in the production environment.

Sandbox environment is an environment where you can mimic the characteristics of the production environment and create simulated responses from all APIs the application relies on before going live. You can make API tests based on your own requirements including making a transaction, cancel, or refund a transaction, and so on. Before you access the Alipay Sandbox Portal to start the test, you need to make some preparations. See Prerequisites for details.

Before you test Alipay payment features in sandbox, you need to get the following preparations:

Creating an Alipay merchant account:

  1. Go to the Alipay for Business website: https://global.alipay.com
  2. In the top-right corner of the homepage, click Sign Up.
  3. Enter your email, enter the code displayed, and then click Continue.
  4. Follow the instructions to complete the account creation.

Use your merchant account to log in to the Alipay Sandbox Portal, if you don’t have the account, see Prerequisites.

Alipay sandbox gateway

Use the Alipay sandbox gateway for testing. The URL of the sandbox gateway is:
https://openapi.alipaydev.com/gateway.do?

Alipay sandbox test accounts

There are two types of test account: merchant test account and buyer test account.

Merchant test accounts:

Find the merchant test account information in the Alipay sandbox portal under Sandbox Accounts > Merchant. More than one test accounts are provided, and the accounts are sorted by payment feature. Find the correct one to use according to the payment feature you want to test. For example, to test the Alipay Auto Debit feature, use the account information provided under Alipay Auto Debit.

  • Login password: Use this password to login to the Alipay for Business website in the sandbox environment.
  • Signature key: Only MD5 signature is supported in the sandbox environment. RSA signature is not supported at this time.

    For more information about the MD5 signature, see Digital Signature.

Buyer test account:

Use the buyer test account to login to the Alipay sandbox app.
The buyer test account information can be found in the Alipay sandbox portal under Sandbox Accounts > Buyer.

Account balance: You can click Top Up to top up the buyer test account.

Download the Alipay sandbox app

The Alipay sandbox app supports only Android at this time.

1) In the Alipay sandbox portal, click Alipay Sandbox App from the menu on the left.
2) Take one of the following steps:

To log in to the Alipay sandbox app, use the buyer test account and login password that are provided in the portal under Sandbox Accounts > Buyer.

To generate a digital signature, normally a key is required to sign the data. You must prepare the MD5 private key or the RSA/DSA private and public key pair to generate and verify a digital signature.

MD5 sign type

MD5 private key is required for generating and verifying MD5 signatures. The MD5 secret key is the 32-byte string which is composed of English letters and numbers. You can log in to the Global Portal to view the private key:

  1. Log in with your user ID.
  2. Click My Technical Service and enter your payment password. If you don't know your payment password, please contact Global Merchant Business Support
  3. Check your MD5 Key. For example, the following graphic is an example of an MD5 Key:

RSA/DSA sign type

An RSA/DSA key pair contains the private key and the public key. The private key is required for generating the signature, while the public key is used for verifying the signature. The following steps assume that you are using RSA sign type, similar steps applied for generating and uploading DSA key pair.

Generating the private/public key pair

Many tools can be used to generate the RSA key pair. The following example illustrates the steps to generate the RSA key pair by using OpenSSL.

  1. Install OpenSSL
    • For linux system, use the following command:
      sudo apt-get install openssl
    • For windows system, download and then install OpenSSL from OpenSSL site.
  2. Generate RSA key pair.
    For linux system, use the following command:
    $ openssl
    OpenSSL> genrsa -out rsa_private_key.pem 1024 ##generating  private key
    OpenSSL> pkcs8 -topk8 -inform PEM -in rsa_private_key.pem  -outform PEM -nocrypt ##transform private key into PKCS8 format
    OpenSSL> rsa -in rsa_private_key.pem -pubout -out  rsa_public_key.pem ##Generate public key
    OpenSSL> exit          
    

    For windows system, use the following command:
    C:\Users\Hammer>cd C:\OpenSSL-Win32\bin ##enter OpenSSL directory
    C:\OpenSSL-Win32\bin>openssl.exe ##enter OpenSSL
    OpenSSL> genrsa -out rsa_private_key.pem 1024  ##generating private key
    OpenSSL> pkcs8 -topk8 -inform PEM -in rsa_private_key.pem  -outform PEM -nocrypt ##transform private key into PKCS8 format
    OpenSSL> rsa -in rsa_private_key.pem -pubout -out  rsa_public_key.pem ##Generate public key
    OpenSSL> exit 

After that, you can see two files under current folder, rsaprivatekey.pem and rsapublickey.pem. The former is the private key and the latter is the public key.

Notes:

The following are the examples of the key pair:

Exchange the public key

You need to exchange your public key with Alipay. Contact Global Merchant Technical Support and provide your PID and public key information. Alipay will then make configurations accordingly, and provide you Alipay public key.

For a transaction that has been successfully paid, the customer can request the merchant for refunding as long as the refunding period is still valid, and the merchant can make use of the refunding interface to complete the refunding, as illustrated.

For the integration of the refunding service, we would like to highlight:

  1. The refunding service name is: alipay.acquire.overseas.spot.refund(REFUND);
  2. To refund a transaction, the interface REVERSE is only applicable at the same day of the payment (GMT +8, Beijing time); on the other hand, the interface REFUND is applicable as long as the refunding period has not expired yet;
  3. the refunding of a transaction can be full or partial, i.e. the refunding amount can respectively be the same as or less than the original transaction amount that has been paid; furthermore, for a transaction, multiple refunding request is allowed provided the sum of the amount of the multiple refunding request is less than or equal with the original transaction amount. 

Except for "sign" and "sign_type", all other parameters used need to be signed.

Generating the pre-sign string for request

For the following parameter array:

string[]  parameters={"partner=\"208861122157****\"",
"seller_id=\"208861122157****\"",
"out_trade_no=\"0811172929-1013\"",
"subject=\"test\"",
"body=\"test\"",
"currency=\"HKD\"",
"total_fee=\"0.1\"",
"notify_url=\"http://0ee96cd2.ngrok.io/notify.htm\"",
"service=\"mobile.securitypay.pay\"",
"payment_type=\"1\"",
"_input_charset=\"utf-8\"",
"appenv=\"system=java^version=1.8\"",
"forex_biz=\"FP\""
  };
Combine all array values in the format of key= “value” and then link them up by the character “&” in an alphabetical order. For example:

_input_charset="utf-8"&appenv="system=java^version=1.8"&body="test"¤cy="HKD"&forex_biz="FP"¬ify_url="http://0ee96cd2.ngrok.io/notify.htm"&out_trade_no="0811172929-1013"&partner="208861122157****”&payment_type="1"&seller_id="208861122157****”&service="mobile.securitypay.pay"&sign="$$$"&sign_type="RSA"&subject="test"&total_fee="0.1"

Generating the pre-sign string for synchronous notification

The following sample illustrates the content of a synchronous notification:

resultStatus={9000};memo={};result={partner="2088101568358171"&seller_id="xxx@alipay.com"&out_trade_no="0819145412-6177"&subject="test"&body="testtest"&total_fee="0.01"&notify_url="http://notify.msp.hk/notify.htm"&service="mobile.securitypay.pay"&payment_type="1"&_input_charset="utf-8"&it_b_pay="30m"&show_url="m.alipay.com"&success="true"&sign_type="RSA"&sign="hkFZr+zE9499nuqDNLZEF7W75RFFPsly876QuRSeN8WMaUgcdR00IKy5ZyBJ4eldhoJ/2zghqrD4E2G2mNjs3aE+HCLiBXrPDNdLKCZgSOIqmv46TfPTEqopYfhs+o5fZzXxt34fwdrzN4mX6S13cr3UwmEV4L3Ffir/02RBVtU="}

Take out the part of result, remove "sign" and "sign_type" parameters:

partner="2088101568358171"&seller_id="xxx@alipay.com"&out_trade_no="0819145412-6177"&subject="test"&body="testtest"&total_fee="0.01"&notify_url="http://notify.msp.hk/notify.htm"&service="mobile.securitypay.pay"&payment_type="1"&_input_charset="utf-8"&it_b_pay="30m"&show_url="m.alipay.com"&success="true"

Generating the pre-sign string for asynchronous notification

The following sample illustrates the contents of an asynchronous notification:

http://0ee96cd2.ngrok.io/notify.htm? buyer_id=208812287878****¤cy=HKD&forex_rate=0.85420000¬ify_id=e5f5c6a77034fcd111e373e7e61dcbegdy¬ify_type=trade_status_sync¬ify_time=2017-08-11 17:31:39&out_trade_no=0811172929-1013&rmb_fee=0.09&seller_id=208861122157****&trade_no=2017081121001003050274536539&total_fee=0.10&trade_status=TRADE_FINISHED&sign_type=RSA&sign=$$$

Remove sign and sign_type, sort other parameters in alphabetical order, and then link up all array values by the character of “&”:

buyer_id=208812287878****¤cy=HKD&forex_rate=0.85420000¬ify_id=e5f5c6a77034fcd111e373e7e61dcbegdy¬ify_type=trade_status_sync¬ify_time=2017-08-11 17:31:39&out_trade_no=0811172929-1013&rmb_fee=0.09&seller_id=208861122157****&trade_no=2017081121001003050274536539&total_fee=0.10&trade_status=TRADE_FINISHED

  • Parameters without value don't need to be transmitted, nor to be included in the data to be signed;
  • At signing, the character set used to change the character into byte stream must be consistent with that specified in _input_charset;
  • If the parameter _input_charset is transmitted, it shall also be included in the data to be signed.
MD5 sign type

After the pre-sign string is generated:

  1. Append the MD5 secret key to the pre-sign string to generate a new string.
  2. Calculate the new string with the MD5 signature algorithm (by using the MD5 signature function).
The result 32-byte string is the signature, which is used as the value of the “sign” parameter.

RSA/DSA sign type

After the pre-sign string is generated, perform the following steps to generate the signature:

  1. Use the RSA/DSA algorithm and the merchant private key to generate the signature.
  2. Encode the signature to a string.
Then, use the string as the value of the “sign” parameter.

MD5 sign type

After receiving the character string of the response or notification from Alipay system, similar to the steps taken in Signing the data, append the MD5 secret key to the character string to generate a new string. Then, calculate this new string with the MD5 signature algorithm. After the 32-byte signature result string is generated, verify whether the value is equal to the value passed in the sign parameter. If Yes, the verification is passed.

RSA/DSA sign type

After receiving a response or notification, perform the following steps to verify the signature:

  1. Generate the pre-sign string as described in Generating Pre-sign String.
  2. Use the RSA/DSA algorithm to calculate a message digest.
  3. Use the RSA/DSA public key to de-sign the signature (the value of the sign field) to a message digest.
  4. Compare the two message digests obtained in step 2 and step 3. If the digests are the same, then it indicates that the signed data has not been changed.

The gateway URL:

Environment HTTPS request URL
Production environment https://intlmapi.alipay.com/gateway.do
Test environment https://mapi.alipaydev.com/gateway.do

If you want to use Alipay sandbox to test the integration, see the sandbox handbook for details.

客服小机器人

NEED HELP ?