阅读(2606) (10)

支付宝小程序Serverless 支付能力API·cloud.payment.common.refund

2020-09-07 11:52:56 更新

cloud.payment.common.refund 是通用接口的交易退款接口。

入参说明

字段名 类型 必填 说明
outTradeNo String 交易创建时传入的商户订单号
refundAmount String 需要退款的金额,该金额不能大于订单金额,单位为元,支持两位小数
appAuthToken String 三方代调用应用访问令牌,详见应用授权概述,目前仅在云函数中调用支持。

调用示例

在云函数中调用

// 云函数中使用云调用无需引入其他依赖,只需要使用ctx.cloud调用
module.exports = async function (ctx) {
  const res = await ctx.cloud.payment.common.refund({
    // 参数接收自云函数调用端传入的参数
    outTradeNo: ctx.args.outTradeNo,
    refundAmount: ctx.args.refundAmount
  });
  return res;
};

支持传入appAuthToken进行三方代调用

// 云函数中使用云调用无需引入其他依赖,只需要使用ctx.cloud调用
module.exports = async function (ctx) {
  const res = await ctx.cloud.payment.common.refund({
    // 参数接收自云函数调用端传入的参数
    outTradeNo: ctx.args.outTradeNo,
    refundAmount: ctx.args.refundAmount
  }, {
    // appAuthToken参数接收自云函数调用处传入的参数
    appAuthToken: ctx.args.appAuthToken
  });
  return res;
};

在小程序页面调用

alipay-serverless-sdk 版本&=1.0.0

const refundResult = await cloud.payment.common.refund({
    outTradeNo: this.data.outTradeNo,
    refundAmount: '0.01'
  });

alipay-serverless-sdk 版本<1.0.0

const refundResult = await cloud.payment.common.refund(this.data.outTradeNo, '0.01');

返回数据示例

{
    "code":"10000",
    "msg":"Success",
    "trade_no":"支付宝交易号",
    "out_trade_no":"6823789339978248",
    "buyer_logon_id":"159****5620",
    "fund_change":"Y",
    "refund_fee":88.88,
    "refund_currency":"USD",
    "gmt_refund_pay":"2014-11-27 15:45:57",
    "refund_detail_item_list":[
        {
            "fund_channel":"ALIPAYACCOUNT",
            "bank_code":"CEB",
            "amount":10,
            "real_amount":11.21,
            "fund_type":"DEBIT_CARD"
        }
    ],
    "store_name":"望湘园联洋店",
    "buyer_user_id":"2088101117955611",
    "refund_preset_paytool_list":{
        "amount":[
            12.21
        ],
        "assert_type_code":"盒马礼品卡:HEMA;抓猫猫红包:T_CAT_COUPON"
    },
    "refund_settlement_id":"2018101610032004620239146945",
    "present_refund_buyer_amount":"88.88",
    "present_refund_discount_amount":"88.88",
    "present_refund_mdiscount_amount":"88.88"
}