支付宝小程序Serverless 支付能力API·cloud.payment.faceToFace.pay
cloud.payment.faceToFace.pay 是当面付的当面付交易付款接口。
使用该API前,请确认你的小程序应用已经添加 当面付 功能
入参说明
字段名 | 类型 | 必填 | 说明 |
---|---|---|---|
subject | String | 是 | 订单标题 |
outTradeNo | String | 是 | 交易创建时传入的商户订单号 |
totalAmount | String | 是 | 订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000] |
authCode | String | 是 | 支付授权码,25~30开头的长度为16~24位的数字,实际字符串长度以开发者获取的付款码长度为准 |
notify_url | String | 否 | 支付宝服务器主动通知商户服务器里指定的页面http/https路径,也可以是云函数的http触发路径。 |
appAuthToken | String | 否 | 三方代调用应用访问令牌,目前仅在云函数中调用支持。 |
调用示例
在云函数中调用
// 云函数中使用云调用无需引入其他依赖,只需要使用ctx.cloud调用
module.exports = async function (ctx) {
const res = await ctx.cloud.payment.faceToFace.pay({
// 参数接收自云函数调用端传入的参数
subject: ctx.args.subject,
outTradeNo: ctx.args.outTradeNo,
totalAmount: ctx.args.totalAmount,
authCode: ctx.args.authCode
});
return res;
};
支持传入notifyUrl接收支付宝服务器交易通知
// 云函数中使用云调用无需引入其他依赖,只需要使用ctx.cloud调用
module.exports = async function (ctx) {
const res = await ctx.cloud.payment.faceToFace.pay({
// 参数接收自云函数调用端传入的参数
subject: ctx.args.subject,
outTradeNo: ctx.args.outTradeNo,
totalAmount: ctx.args.totalAmount,
authCode: ctx.args.authCode
}, {
// 传入接收支付宝服务器交易通知的http/https路径,也可以是云函数的http触发路径
notify: {
url: 'http://api.test.alipay.net/atinterface/receive_notify.htm'
}
});
return res;
};
支持传入appAuthToken进行三方代调用
// 云函数中使用云调用无需引入其他依赖,只需要使用ctx.cloud调用
module.exports = async function (ctx) {
const res = await ctx.cloud.payment.faceToFace.pay({
// 参数接收自云函数调用端传入的参数
subject: ctx.args.subject,
outTradeNo: ctx.args.outTradeNo,
totalAmount: ctx.args.totalAmount,
authCode: ctx.args.authCode
}, { // appAuthToken参数接收自云函数调用处传入的参数
appAuthToken: ctx.args.appAuthToken
});
return res;
};
在小程序页面调用
alipay-serverless-sdk 版本&=1.0.0
const payRes = await cloud.payment.faceToFace.pay({
subject: '小程序Serverless支付测试',
outTradeNo: "demo" + new Date().getTime(),
totalAmount: '0.01',
authCode: '286532211313197763'
});
alipay-serverless-sdk 版本<1.0.0
const payResult = await cloud.payment.faceToFace.pay('小程序Serverless支付测试', this.data.outTradeNo, '0.01', '286532211313197763');
返回数据示例
{
"code":"10000",
"msg":"Success",
"trade_no":"2013112011001004330000121536",
"out_trade_no":"6823789339978248",
"buyer_logon_id":"159****5620",
"settle_amount":"88.88",
"pay_currency":"CNY",
"pay_amount":"580.04",
"settle_trans_rate":"1",
"trans_pay_rate":"6.5261",
"total_amount":120.88,
"trans_currency":"USD",
"settle_currency":"USD",
"receipt_amount":"88.88",
"buyer_pay_amount":8.88,
"point_amount":8.12,
"invoice_amount":12.5,
"gmt_payment":"2014-11-27 15:45:57",
"fund_bill_list":[
{
"fund_channel":"ALIPAYACCOUNT",
"amount":10,
"real_amount":11.21
}
],
"card_balance":98.23,
"store_name":"证大五道口店",
"buyer_user_id":"2088101117955611",
"discount_goods_detail":"[{"goods_id":"STANDARD1026181538","goods_name":"雪碧","discount_amount":"100.00","voucher_id":"2015102600073002039000002D5O"}]",
"voucher_detail_list":[
{
"id":"2015102600073002039000002D5O",
"name":"XX超市5折优惠",
"type":"ALIPAY_FIX_VOUCHER",
"amount":10,
"merchant_contribute":9,
"other_contribute":1,
"memo":"学生专用优惠",
"template_id":"20171030000730015359000EMZP0",
"purchase_buyer_contribute":2.01,
"purchase_merchant_contribute":1.03,
"purchase_ant_contribute":0.82
}
],
"advance_amount":"88.8",
"auth_trade_pay_mode":"CREDIT_PREAUTH_PAY",
"charge_amount":"8.88",
"charge_flags":"bluesea_1",
"settlement_id":"2018101610032004620239146945",
"business_params":"{"data":"123"}",
"buyer_user_type":"PRIVATE",
"mdiscount_amount":"88.88",
"discount_amount":"88.88",
"buyer_user_name":"菜鸟网络有限公司"
}