支付寶小程序Serverless 支付能力API·cloud.payment.huabei.create

2020-09-18 14:33 更新

cloud.payment.huabei.create 是花唄分期的創(chuàng)建花唄分期交易接口。

入?yún)⒄f明

字段名 類型 必填 說明
subject String 訂單標(biāo)題
outTradeNo String 商戶訂單號(hào),64個(gè)字符以內(nèi),可包含字母、數(shù)字、下劃線,需保證在商戶端不重復(fù)
totalAmount String 訂單總金額,單位為元,精確到小數(shù)點(diǎn)后兩位,取值范圍[0.01,100000000]
buyerId String 買家的支付寶用戶 ID,如果為空,會(huì)從傳入的碼值信息中獲取買家 ID
extendParams HuabeiConfig 花唄交易擴(kuò)展參數(shù)
notify_url String 支付寶服務(wù)器主動(dòng)通知商戶服務(wù)器里指定的頁(yè)面http/https路徑,也可以是云函數(shù)的http觸發(fā)路徑。
appAuthToken String 三方代調(diào)用應(yīng)用訪問令牌,目前僅在云函數(shù)中調(diào)用支持。

HuabeiConfig 對(duì)象說明

字段名 類型 必填 說明
hbFqNum String 花唄分期數(shù),僅支持傳入3、6、12
hbFqSellerPercent String 代表賣家承擔(dān)收費(fèi)比例,商家承擔(dān)手續(xù)費(fèi)傳入100,用戶承擔(dān)手續(xù)費(fèi)傳入0,僅支持傳入100、0兩種

調(diào)用示例

在云函數(shù)中調(diào)用

  1. // 云函數(shù)中使用云調(diào)用無需引入其他依賴,只需要使用ctx.cloud調(diào)用
  2. module.exports = async function (ctx) {
  3. let huabeiConfig = new Object({
  4. hbFqNum: "3",
  5. hbFqSellerPercent: "100"
  6. });
  7. const res = await ctx.cloud.payment.huabei.create({
  8. // 參數(shù)接收自云函數(shù)調(diào)用端傳入的參數(shù)
  9. subject: ctx.args.subject,
  10. outTradeNo: ctx.args.outTradeNo,
  11. totalAmount: ctx.args.totalAmount,
  12. buyerId: ctx.args.buyerId,
  13. extendParams: huabeiConfig
  14. });
  15. return res;
  16. };

支持傳入notifyUrl接收支付寶服務(wù)器交易通知

  1. // 云函數(shù)中使用云調(diào)用無需引入其他依賴,只需要使用ctx.cloud調(diào)用
  2. module.exports = async function (ctx) {
  3. let huabeiConfig = new Object({
  4. hbFqNum: "3",
  5. hbFqSellerPercent: "100"
  6. });
  7. const res = await ctx.cloud.payment.huabei.create({
  8. // 參數(shù)接收自云函數(shù)調(diào)用端傳入的參數(shù)
  9. subject: ctx.args.subject,
  10. outTradeNo: ctx.args.outTradeNo,
  11. totalAmount: ctx.args.totalAmount,
  12. buyerId: ctx.args.buyerId,
  13. extendParams: huabeiConfig
  14. }, {
  15. // 傳入接收支付寶服務(wù)器交易通知的http/https路徑,也可以是云函數(shù)的http觸發(fā)路徑
  16. notify: {
  17. url: 'http://api.test.alipay.net/atinterface/receive_notify.htm'
  18. }
  19. });
  20. return res;
  21. };

支持傳入appAuthToken進(jìn)行三方代調(diào)用

  1. // 云函數(shù)中使用云調(diào)用無需引入其他依賴,只需要使用ctx.cloud調(diào)用
  2. module.exports = async function (ctx) {
  3. let huabeiConfig = new Object({
  4. hbFqNum: "3",
  5. hbFqSellerPercent: "100"
  6. });
  7. const res = await ctx.cloud.payment.huabei.create({
  8. // 參數(shù)接收自云函數(shù)調(diào)用端傳入的參數(shù)
  9. subject: ctx.args.subject,
  10. outTradeNo: ctx.args.outTradeNo,
  11. totalAmount: ctx.args.totalAmount,
  12. buyerId: ctx.args.buyerId,
  13. extendParams: huabeiConfig
  14. }, {
  15. // appAuthToken參數(shù)接收自云函數(shù)調(diào)用處傳入的參數(shù)
  16. appAuthToken: ctx.args.appAuthToken
  17. });
  18. return res;
  19. };

在小程序頁(yè)面調(diào)用

alipay-serverless-sdk 版本&=1.0.0

  1. var huabeiConfig = new Object({
  2. hbFqNum: '3',
  3. hbFqSellerPercent: '100'
  4. });
  5. const createRes = await cloud.payment.huabei.create({
  6. subject: '小程序花唄Serverless支付測(cè)試',
  7. outTradeNo: "demo" + new Date().getTime(),
  8. totalAmount: '0.01',
  9. buyerId: '2088202286335281',
  10. extendParams: huabeiConfig
  11. });

alipay-serverless-sdk 版本<1.0.0

  1. var huabeiConfig = new Object({
  2. hbFqNum: '3',
  3. hbFqSellerPercent: '100'
  4. });
  5. const createRes = await cloud.payment.huabei.create('小程序Serverless支付測(cè)試', "piwei" + new Date().getTime(), '0.03', this.data.userId, huabeiConfig);

返回?cái)?shù)據(jù)示例

  1. {
  2. "code":"10000",
  3. "msg":"Success",
  4. "out_trade_no":"20150423001001",
  5. "trade_no":"2015042321001004720200028594"
  6. }
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)