Skip to content

Alipay

Alipay

Payment process

The payment interface adopts server-side integration, namely Server To Server mode. The specific process is as follows:

  1. The user places an order on the mini program/APP/browser website
  2. The online store submits the order information to this interface
  3. FireAnt submit the order to the Alipay server, and then return the result of creating the order and redirect url to the online store
  4. The online store redirects to the Alipay payment link and calls up Alipay payment (different payment methods are called up in different scenarios, such as displaying payment QR codes in PC browser and calls up Alipay applications in mobile browser)
  5. After the user completes the payment, FireAnt will notify the online store of the result through notifyUrl

Among them, steps 2-3 involve the server submitting data and do not involve the browser. There may be some differences in the specific programming language used, Payment Submission Example

Form parameter format description

NameTypeMax LengthRequiredDescription
Order information
merNoString5YesMerchant ID number
Explanation: PSP assigns a unique identifier to merchants
gatewayNoString8YesMerchant gateway number
Explanation: PSP assigns a unique identifier to sub merchants
orderNoString50YesMerchant Order Number
Rule: Merchant order number. Unique identifier, do not duplicate order numbers in the same online store system
orderCurrencyString3YesOrder currency
Explanation: 3-digit ISO 4217 code, currency code can be found in the appendix.
orderAmountString10YesOrder amount
Rule: No more than two decimal places
shipFeeString100NoShipping fee
Rule: No more than two decimal places
discountString100Nodiscount
Discounts default to negative values
It can only be a number and is limited to 2 decimal places
goodsInfoString5000YesDetailed information of goods
Including the name, ID, unit price, and quantity of the goods
Please refer to Appendix: Goods Information
Local payment information
paymentMethodString50YesPayment method, fixed Alipay
tradeTypeString50YesTransaction type
WEB: PC website payment
WAP: Mobile website payment
APP: App payment
MINI_APP: Mini program payment
limitPayString50NoSpecify payment method
only MINI-APP requires specification, such as TRUEMONEY, ALIPAY_HK, TNG, ALIPAY_CN, GCASH, DANA, TOSS
ipString50NoUser IP
osString50NoOperating System: IOS or ANDROID, provided under WAP or APP
Shipping information
shipFirstNameString100NoConsignee's first name
shipLastNameString100NoConsignee's last name
shipEmailString100NoConsignee's email
shipPhoneString100NoConsignee's phone
shipCountryString100NoConsignee's country
ISO 3166-1 country code, such as US.
shipStateString100NoConsignee's state
shipCityString100NoConsignee's city
shipAddressString100NoConsignee's address
shipZipString100NoConsignee's zip
Other information
notifyUrlString200YesAsynchronous notification url.
After the payment is completed, the platform will notify this address of the payment result through server-side POST. The asynchronous address will return OK upon receiving the request, otherwise it will return up to 3 times within a period of time
signInfoString32YesEncrypt signature information
Combine the payment submission parameters and then perform sha256 encryption. The specific parameter combination order is as follows, and the order cannot be changed:merNo + gatewayNo +orderNo + orderCurrency +orderAmount + notifyUrl + merKey(secret key, can be queried in the merchant's backend),the order of these parameters cannot be modified, and there should be no spaces or + in between
Please refer to Appendix: SHA256 Encryption
remarkString500NoOrder remark information.

Payment Submission Example

java
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "merNo=30000&gatewayNo=30000001&orderNo=12345678&orderCurrency=USD&orderAmount=100.00&goodsInfo=Good1-Name#,#123#,#50.00#,#2&paymentMethod=Alipay&tradeType=WAP&os=ANDROID&ip=127.0.0.1&notifyUrl=https://xxx.com/notifyurl&signInfo=61be55a8e2f6b4e172338b...");
Request request = new Request.Builder()
  .url("https://sandbox.fireantspay.com/AlipayInterface")
  .method("POST", body)
  .addHeader("Content-Type", "application/x-www-form-urlencoded")
  .build();
Response response = client.newCall(request).execute();
php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://sandbox.fireantspay.com/AlipayInterface',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => 'merNo=30000&gatewayNo=30000001&orderNo=12345678&orderCurrency=USD&orderAmount=100.00&goodsInfo=Good1-Name%23%2C%23123%23%2C%2350.00%23%2C%232&paymentMethod=Alipay&tradeType=WAP&os=ANDROID&ip=127.0.0.1&notifyUrl=https%3A%2F%2Fxxx.com%2Fnotifyurl&signInfo=61be55a8e2f6b4e172338b...',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/x-www-form-urlencoded'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
js
var request = require('request')
var options = {
  method: 'POST',
  url: 'https://sandbox.fireantspay.com/AlipayInterface',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  form: {
    merNo: '30000',
    gatewayNo: '30000001',
    orderNo: '12345678',
    orderCurrency: 'USD',
    orderAmount: '100.00',
    goodsInfo: 'Good1-Name#,#123#,#50.00#,#2',
    paymentMethod: 'Alipay',
    tradeType: 'WAP',
    os: 'ANDROID',
    ip: '127.0.0.1',
    notifyUrl: 'https://xxx.com/notifyurl',
    signInfo: '61be55a8e2f6b4e172338b...'
  }
}
request(options, function (error, response) {
  if (error) throw new Error(error)
  console.log(response.body)
})
js
var settings = {
  url: 'https://sandbox.fireantspay.com/AlipayInterface',
  method: 'POST',
  timeout: 0,
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  data: {
    merNo: '30000',
    gatewayNo: '30000001',
    orderNo: '12345678',
    orderCurrency: 'USD',
    orderAmount: '100.00',
    goodsInfo: 'Good1-Name#,#123#,#50.00#,#2',
    paymentMethod: 'Alipay',
    tradeType: 'WAP',
    os: 'ANDROID',
    ip: '127.0.0.1',
    notifyUrl: 'https://xxx.com/notifyurl',
    signInfo: '61be55a8e2f6b4e172338b...'
  }
}

$.ajax(settings).done(function (response) {
  console.log(response)
})
perl
curl --location 'https://sandbox.fireantspay.com/AlipayInterface' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'merNo=30000' \
--data-urlencode 'gatewayNo=30000001' \
--data-urlencode 'orderNo=12345678' \
--data-urlencode 'orderCurrency=USD' \
--data-urlencode 'orderAmount=100.00' \
--data-urlencode 'goodsInfo=Good1-Name#,#123#,#50.00#,#2' \
--data-urlencode 'paymentMethod=Alipay' \
--data-urlencode 'tradeType=WAP' \
--data-urlencode 'os=ANDROID' \
--data-urlencode 'ip=127.0.0.1' \
--data-urlencode 'notifyUrl=https://xxx.com/notifyurl' \
--data-urlencode 'signInfo=61be55a8e2f6b4e172338b...'

Alipay Interface Response

Response data description

The payment return data is in XML format, which needs to be parsed first before determining the payment result of the order. The specific XML parameters are as follows: Payment Response Example.

Parameter format description

NameTypeMax LengthDescription
merNoString5Merchant ID number
Explanation: PSP assigns a unique identifier to merchants
gatewayNoString8Merchant gateway number
Explanation: PSP assigns a unique identifier to sub merchants
tradeNoString50Merchant Order Number
orderNoString50Transaction order number.
Unique identifier of the order generated by PSP
orderCurrencyString3Order currency
orderAmountString10Order amount
orderStatusString1Transaction status:
-1: Pending
0: Failed
1: Success
orderInfoString100Payment result description
billAddressString100Billing descriptor
Return the billing descriptor of the transaction when the payment is successful
returnTypeString1Return type
1: Browser real-time return
2: Server real-time return
3: Server asynchronous return
The data format returned by the server in real-time is XML, while the data format returned by the server asynchronously and by the browser is NVP.
orderErrorCodeString50Error Code
Error codes corresponding to various reasons for failure. When successful, it is usually 00.
paymentMethodString50Payment method, fixed Alipay
signInfoString32Encrypt signature information
Combine the payment submission parameters and then perform sha256 encryption. The specific parameter combination order is as follows, and the order cannot be changed.
sha256(merNo + gatewayNo + tradeNo+orderNo + orderCurrency + orderAmount + orderStatus+orderInfo + merKey)
remarkString500Remark
redirectUrlString500Redirect url. Only exists when the transaction is returned for processing , and the user redirects to this link for payment
Description of redirectUrl

Payment Response Example

Transaction Pending, merchants need to proceed with the next steps:

xml
<?xml version="1.0" encoding="UTE-8"?>  
<respon>  
    <merNo>10000</merNo>  
    <gatewayNo>10000001</gatewayNo>  
    <tradeNo>HY024111317280195515514</tradeNo>  
    <orderNo>12345</orderNo>  
    <orderAmount>10.00</orderAmount>  
    <orderCurrency>USD</orderCurrency>  
    <orderStatus>-1</orderStatus>  
    <orderErrorCode>PENGDING</orderErrorCode>  
    <orderInfo></orderInfo>  
    <paymentMethod>Alipay</paymentMethod>  
    <returnType>2</returnType>  
    <billAddress></billAddress>  
    <redirectUrl>https://open-sea.alipayplus.com/api/...</redirectUrl>  
    <signInfo>C6EB2353B92CFEA3698CE2F5332CB882...</signInfo>  
    <remark></remark>  
</respon>

Transaction failed (parameter validation failed):

xml
<?xm1 version="1.0" encoding="UTE-8"?>
<respon>
    <merNo>10000</merNo>  
    <gatewayNo>10000001</gatewayNo>  
    <tradeNo>HY024111317280195515514</tradeNo>  
    <orderNo>12345</orderNo>  
    <orderAmount>10.00</orderAmount>  
    <orderCurrency>USD</orderCurrency>  
    <orderStatus>0</orderStatus>  
    <orderErrorCode>I0133</orderErrorCode>  
    <orderInfo>交易类型只能为WEB,WAP,APP,MINI_APP</orderInfo>  
    <paymentMethod>Alipay</paymentMethod>  
    <returnType>2</returnType>  
    <billAddress></billAddress>  
    <redirectUrl></redirectUrl>  
    <signInfo>C6EB2353B92CFEA3698CE2F5332CB882...</signInfo>  
    <remark></remark>  
</respon>

Transaction failed (Alipay server error):

xml
<?xm1 version="1.0" encoding="UTE-8"?>
<respon>
    <merNo>10000</merNo>  
    <gatewayNo>10000001</gatewayNo>  
    <tradeNo>HY024111317280195515514</tradeNo>  
    <orderNo>12345</orderNo>  
    <orderAmount>10.00</orderAmount>  
    <orderCurrency>USD</orderCurrency>  
    <orderStatus>0</orderStatus>  
    <orderErrorCode>PARAM_ILLEGAL</orderErrorCode>  
    <orderInfo>env.terminalType should be correct Type.</orderInfo>  
    <paymentMethod>Alipay</paymentMethod>  
    <returnType>2</returnType>  
    <billAddress></billAddress>  
    <redirectUrl></redirectUrl>  
    <signInfo>C6EB2353B92CFEA3698CE2F5332CB882...</signInfo>  
    <remark></remark>
</respon>

Asynchronous notification (Success):

txt
orderErrorCode=00&signInfo=4EF256E175307636299F6559C3F89CD94585D3E42DA33985BE400DCBE5FFF779&orderNo=12345&gatewayNo=10000001&tradeNo=HY024111317280195515514&orderCurrency=USD&orderStatus=1&remark=备注&orderAmount=10.00&merNo=10000&billAddress=LARTIN&orderInfo=Approved&paymentMethod=Alipay&returnType=3

Description of redirectUrl

RedirectUrl is a Alipay payment link, which will show different payment effects in different scenarios.

Description of redirectUrl