Links

Build a Sample App

How to process an AliPay payment at the Point of Sale
This tutorial provides a step-by-step explanation of the process of accepting a payment at the Point of Sale from a consumer's AliPay digital wallet. We provide code samples in Javascript for each of the API interactions necessary to complete the payment. Code samples in other languages are available in the SDK's published on our GitHub page.

In-Store User Workflows and API Interactions

Below are the steps of the transaction itinerary in a merchant-presented QR Code payment. Imagine an in-store retail environment that features a customer checkout Point-of-Sale (POS) system. A customer approaches the POS manager who drafts an itemized bill for the ‘outgoing merchandise’. Upon inquiry, the consumer reveals that they would like to pay using a digital wallet. The POS manager selects ‘Digital Wallet’ which prompts the Point-of-Sale to call the "/add” API for the creation of a transaction ID. POST https://mapi.yuansfer.com/app-instore/v3/add

First you will need to calculate the VeriSign parameter value (instructions are available in a separate tutorial)

Follow the steps below to implement the VeriSign feature:
  1. 1.
    Sort the parameters alphabetically according to the parameter name.
  2. 2.
    Concatenate the parameter names and values using '=' and '&' characters.
  3. 3.
    Append the MD5 hash value of your API token to the end of your parameters with the '&' prefix
  4. 4.
    Calculate the MD5 hash value of the Step 3 result.

First, call the /add API to generate the transaction ID value

1
// POCKYT ADD API sandbox example
2
// Import crypto for MD5 hash calculation
3
4
var crypto = require('crypto');
5
6
// Assign all Sanbox parameters
7
8
var URL = "https://mapi.yuansfer.yunkeguan.com/app-instore/v3/add" ;
9
var merchantNo = "200043" ;
10
var storeNo = "303660" ;
11
var MyToken = "359c05eb811c7c8576f4a8a277dc6f6b" ;
12
13
// construct POS fields and assign to object
14
var myPOSParamObject = {
15
merchantNo: merchantNo,
16
storeNo: storeNo,
17
amount: "99",
18
currency: "USD",
19
settleCurrency: "USD",
20
reference: "101010"
21
}
22
23
// Calculate the VeriSign signature:
24
25
var MySignature = CalculateSignature(MyToken, myPOSParamObject)
26
27
// Add the signature to the POS parametes so we
28
// can use it in the body of the API call
29
30
var MyPocketParamObject = {
31
merchantNo: myPOSParamObject.merchantNo,
32
storeNo: myPOSParamObject.storeNo,
33
verifySign: MySignature,
34
amount: myPOSParamObject.amount,
35
currency: myPOSParamObject.currency,
36
settleCurrency: myPOSParamObject.settleCurrency,
37
reference: myPOSParamObject.reference,
38
}
39
40
// POCKYT ADD API sandbox example
41
// Import crypto for MD5 hash calculation
42
43
var crypto = require('crypto');
44
45
// Assign all Sanbox parameters
46
47
var URL = "https://mapi.yuansfer.yunkeguan.com/app-instore/v3/add" ;
48
var merchantNo = "200043" ;
49
var storeNo = "303660" ;
50
var MyToken = "359c05eb811c7c8576f4a8a277dc6f6b" ;
51
52
// construct POS fields and assign to object
53
var myPOSParamObject = {
54
merchantNo: merchantNo,
55
storeNo: storeNo,
56
amount: "99",
57
currency: "USD",
58
settleCurrency: "USD",
59
reference: "101010"
60
}
61
62
// Calculate the VeriSign signature:
63
64
var MySignature = CalculateSignature(MyToken, myPOSParamObject)
65
66
// Add the signature to the POS parametes so we
67
// can use it in the body of the API call
68
69
var MyPocketParamObject = {
70
merchantNo: myPOSParamObject.merchantNo,
71
storeNo: myPOSParamObject.storeNo,
72
verifySign: MySignature,
73
amount: myPOSParamObject.amount,
74
currency: myPOSParamObject.currency,
75
settleCurrency: myPOSParamObject.settleCurrency,
76
reference: myPOSParamObject.reference,
77
}
78
79
// Prepare JSON that will be used in the body of the API call
80
81
var MyPocketParamJason = JSON.stringify(MyPocketParamObject);
82
console.log(MyPocketParamJason);
83
84
fetch(URL, {
85
method: "POST",
86
headers: {
87
"Content-Type": "application/json"
88
},
89
body: MyPocketParamJason
90
})
91
.then(response => response.json())
92
.then(data => console.log(data))
93
.catch(error => console.error(error));

Next, receive Transaction ID and call to /PrePay

  • At the same time, the Point-of-Sale analyzes the response message from the /add API to identify and store the transaction number.
  • Once the transaction ID is created, the customer will present a QR code to the POS manager for scanning.
  • As the QR code is scanned, the POS system calls Pockyt’s “/prepay” API to process the digital wallet payment.
    • POST https://mapi.yuansfer.com/app-instore/v3/prepay
1
// POCKYT PREPAY API sandbox example
2
// Import crypto for MD5 hash calculation
3
4
var crypto = require('crypto');
5
6
// Assign all Sanbox parameters
7
8
var URL = "https://mapi.yuansfer.yunkeguan.com/app-instore/v3/prepay" ;
9
var merchantNo = "200043" ;
10
var storeNo = "303660" ;
11
var MyToken = "359c05eb811c7c8576f4a8a277dc6f6b" ;
12
13
// construct POS fields and assign to object
14
var myPOSParamObject = {
15
merchantNo: merchantNo,
16
storeNo: storeNo,
17
transactionNo: "316129873376769782",
18
paymentBarcode: "286521182446652715",
19
vendor: "alipay"
20
}
21
22
// Calculate the VeriSign signature:
23
24
var MySignature = CalculateSignature(MyToken, myPOSParamObject)
25
26
// Add the signature to the POS parametes so we
27
// can use it in the body of the API call
28
29
var MyPocketParamObject = {
30
merchantNo: myPOSParamObject.merchantNo,
31
storeNo: myPOSParamObject.storeNo,
32
verifySign: MySignature,
33
transactionNo: myPOSParamObject.transactionNo,
34
paymentBarcode: myPOSParamObject.paymentBarcode,
35
vendor: myPOSParamObject.vendor
36
}
37
38
// function that calculates the signature according to Pockyt rules
39
40
function CalculateSignature(token,parameters)
41
{
42
// calculate the hash value of the token
43
44
var ApiTokenHashvalue = crypto.createHash('md5').update(token).digest("hex")
45
46
// order parameters alphabetically
47
var SortedParams = sortObj(parameters);
48
49
// Concatenate: add '&' between key and value pair and replace:
50
51
for =
52
var MyString = '' ;
53
for (const [key, value] of Object.entries(SortedParams)) {
54
MyString += (`${key}=${value}&`);}
55
56
// add hash value of token at the and of the string
57
58
MyString += ApiTokenHashvalue ;
59
60
// create the verifySign
61
62
const MySignature = crypto.createHash('md5').update(MyString).digest("hex");
63
64
return MySignature;
65
66
67
// algabetical sort helper function
68
69
function sortObj(obj) {
70
return Object.keys(obj).sort().reduce(function (result, key) {
71
result[key] = obj[key];
72
return result;
73
}, {});
74
}
75
}
76
77
// Prepare JSON that will be used in the body of the API call
78
79
var MyPocketParamJason = JSON.stringify(MyPocketParamObject);
80
console.log(MyPocketParamJason);
81
82
fetch(URL, {
83
method: "POST",
84
headers: {
85
"Content-Type": "application/json"
86
},
87
body: MyPocketParamJason
88
})
89
.then(response => response.json())
90
.then(data => console.log(data))
91
.catch(error => console.error(error));

Call /Trans-Query API to Poll for Transaction Results

1
//Code Sample: Calling the /Trans-Query API
2
// POCKYT TRANSACT QUERY AFTER AND ADD TO CHECK RESULTS API sandbox example
3
// Import crypto for MD5 hash calculation
4
5
var crypto = require('crypto');
6
7
// Assign all Sanbox parameters
8
9
varURL="https://mapi.yuansfer.yunkeguan.com/app-data-search/v3/tran-query" ;
10
var merchantNo = "200043" ;
11
var storeNo = "303660" ;
12
var MyToken = "359c05eb811c7c8576f4a8a277dc6f6b" ;
13
14
// construct POS fields and assign to object
15
var myPOSParamObject = {
16
merchantNo: merchantNo,
17
storeNo: storeNo,
18
transactionNo: "316129873376769782",
19
// reference: No reference in this case
20
}
21
22
// Calculate the VeriSign signature:
23
24
var MySignature = CalculateSignature(MyToken, myPOSParamObject)
25
26
// Add the signature to the POS parametes so we
27
// can use it in the body of the API call
28
29
var MyPocketParamObject = {
30
merchantNo: myPOSParamObject.merchantNo,
31
storeNo: myPOSParamObject.storeNo,
32
verifySign: MySignature,
33
// transactionNo: myPOSParamObject.transactionNo,
34
// reference: myPOSParamObject.reference
35
transactionNo: myPOSParamObject.transactionNo
36
}
37
38
// function that calculates the signature according to Pockyt rules
39
function CalculateSignature(token,parameters)
40
{
41
// calculate the hash value of the token
42
43
var ApiTokenHashvalue = crypto.createHash('md5').update(token).digest("hex")
44
45
// order parameters alfabetically
46
var SortedParams = sortObj(parameters);
47
48
// Concatenate: add '&' between key and value pair and replace : for =
49
var MyString = '' ;
50
for (const [key, value] of Object.entries(SortedParams)) {
51
MyString += (`${key}=${value}&`);}
52
53
// add hash value of token at the and of the string
54
MyString += ApiTokenHashvalue ;
55
56
// create the verifySign
57
58
const MySignature = crypto.createHash('md5').update(MyString).digest("hex");
59
60
return MySignature;
61
62
63
// alphabetical sort helper function
64
function sortObj(obj) {
65
return Object.keys(obj).sort().reduce(function (result, key) {
66
result[key] = obj[key];
67
return result;
68
}, {});
69
}
70
71
// Prepare JASON that will be used in the body of the API call
72
73
var MyPocketParamJason = JSON.stringify(MyPocketParamObject);
74
console.log(MyPocketParamJason);
75
76
fetch(URL, {
77
method: "POST",
78
headers: {
79
"Content-Type": "application/json"
80
},
81
body: MyPocketParamJason
82
})
83
.then(response => response.json())
84
.then(data => console.log(data))
85
.catch(error => console.error(error));
Last modified 3mo ago