Acopay: In App Purchase
ACOINFO online payment system 翼辉支付. This payment system uses WeChat Pay or Alipay payment channels. App can use this payment system to complete on-site payments.
Functions
edger.payment.pay(order)
order
{Object} Order information.- Returns: {Promise}
Promise
object.
Create the order for payment.
The payment parameters can be found in 翼辉支付/统一下单.
Example
const order = {
'app_no': '10c9776657874fcf838f675120e8ce09',
'amount_currency': 'CNY',
'amount_total': '0.05',
'description': 'pay demo',
'extra': 'extra info',
'mch_no': 'ea887713933c42a0bd7e657b06f279d3',
'mch_trade_no': 'mp202104241700288110071055567331',
'notify_url': 'https://your.domain.com/path/to/pay/notify',
'nonce': '85817135668161040552012458403785',
'sign': 'NutY0HceITcK+ZZUmMp6eCuvQSnBF9f5WWGuiQ6Kh1rsAq6CDCl ... slpribNpcw9O2/z4EYKQ++/HJ2GbNb3Q06YuIuxEA==',
'sign_type': 'SHA256withRSA',
'time_expire': '2021-04-24T18:00:28+08:00'
};
edger.payment.pay(order).then(result => {
console.log('payment request received', result.success)
});
The obtained result
object contains the following member:
success
{Boolean} Indicates whether the payment request received.
async / await
async function payment() {
try {
const ret = await edger.payment.pay(order);
return ret.success;
} catch (error) {
console.error(error);
}
}
Events
The unified event listener provided by Web-SDK:
const listener = (payload) => {
// Event handling...
}
// add listener
edger.addEventListener('some-event', listener);
// or
// onAction() is an alias of addEventListener().
edger.onAction('some-event', listener);
// remove listener
edger.removeEventListener('some-event', listener);
// remove all listeners
edger.removeAllListeners();
pay
There is a payment event.
Payment will be a long time operation, so developers need to listen the pay
event to check payment result.
Example
const listener = (payload) => {
const { success, msg, receipt } = payload;
console.log('payment result:', success, msg, receipt);
}
edger.addEventListener('pay', listener);
The obtained payload
object contains the following members:
success
{Boolean} Indicates whether the order creation is successful.msg
{String} Error message.receipt
{Object} If payment is successful, it will contain the transaction information.transaction_no
{String} Payment unique transaction number.mch_trade_no
{String} The request trade number same as request order.