授权转支付

名称:alipay.trade.pay (内含异步通知内容)
类型:服务端接口
功能:商户因业务原因需要解冻用户授权资金并支付给卖家时,通过该接口创建交易订单并将授权资金解冻转支付给卖家,同时解冻剩余资金。


注意:接口为通用接口,该场景下,请参考如下编写:

/**
 * 测试
 */
@Test
public void tradePay() throws AlipayApiException {
    AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do","app_id","your private_key","json","utf-8","alipay_public_key","RSA2");
    
    AlipayTradePayRequest request = new AlipayTradePayRequest();
    
    AlipayTradePayModel model = new AlipayTradePayModel();
    model.setOutTradeNo("20180412100020088982"); // 预授权转支付商户订单号,为新的商户交易流水号;如果重试发起扣款,商户订单号不要变;
    model.setProductCode("PRE_AUTH_ONLINE"); // 固定值PRE_AUTH_ONLINE
    model.setAuthNo("2018041210002001660228733635"); // 填写预授权冻结交易号
    model.setSubject("预授权转支付测试"); // 解冻转支付标题,用于展示在支付宝账单中
    model.setTotalAmount("0.01"); // 结算支付金额
    model.setSellerId(pid); // 填写卖家支付宝账户pid
    model.setBuyerId(pay_user_id); // 填写预授权用户uid,通过预授权冻结接口返回的payer_user_id字段获取
    model.setStoreId("test_store_id"); // 填写实际交易发生的终端编号,与预授权的outStoreCode保持一致即可   
    model.setBody("预授权解冻转支付测试"); // 可填写备注信息
    model.setAuthConfirmMode("COMPLETE");//必须使用COMPLETE,传入该值用户剩余金额会自动解冻
    request.setBizModel(model);
    request.setNotifyUrl(notify_url);//异步通知地址,必填,该接口只通过该参数进行异步通知
    
    AlipayTradePayResponse response = alipayClient.execute(request);
    if(response.isSuccess()){
        System.out.println("调用成功");
        logger.info("response: {}"+response.getBody());
    } else {
        System.out.println("调用失败");
    }
}


入参TIPS:
1、product_code=PRE_AUTH_ONLINE,产品码,是固定值,不要更改;
2、需要传入store_id(建议与资金授权冻结接口中extra_param参数的outStoreCode取值一致)参数。如果需返佣接入时还需要传入"extend_params":{"sys_service_provider_id":"ISV签约账户的PID"}参数用于计算返佣。

3、auth_confirm_mode传入COMPLETE,无需调用解冻接口,支付宝端在扣款成功后会自动解冻剩余金额,同时该笔授权订单完成;若auth_confirm_mode=NOT_COMPLETE,在收到支付成功通知后,商户自行调用解冻接口将余额进行解冻;

4、如果需要从一笔授权中完成多笔订单支付,保持auth_no不变,不同订单根据outTradeNo进行标识,此时auth_confirm_mode不传或者传入NOT_COMPLETE;进行到最后一笔转支付时,auth_confirm_mode传入COMPLETE由支付宝完成剩余金额自动解冻,或者商户自行调用解冻接口将剩余金额解冻。


出参处理:
1、response中的code=10000,表示接口调用成功,支付状态以异步通知为准;

2、auth_trade_pay_mode,预授权支付模式,该参数仅在信用预授权支付场景下返回。信用预授权支付:CREDIT_PREAUTH_PAY;

3、如果未收到异步通知,可以通过交易查询接口查询最新支付状态,如果返回处理中(如:trade_ status=WAIT_BUYER_PAY或ORDER SUCCESS PAY INPROGRESS)场景,商户可以调用预授权转支付(首次扣款15天内都可重试),重新发起扣款(注意:商户订单号out_trade_no保持不变)。


风险提示:

信用预授权订单转支付,可能会出现一定概率的资金或货物损失,请充分知晓相关权责,详见产品服务协议。


成功样例


{
    "alipay_trade_pay_response": {
        "code": "10000",
        "msg": "Success",
        "auth_trade_pay_mode": "CREDIT_PREAUTH_PAY",
        "buyer_logon_id": "x***@163.com",
        "buyer_pay_amount": "0.01",
        "buyer_user_id": "208822323293534",
        "gmt_payment": "2018-07-04 14:53:06",
        "invoice_amount": "0.00",
        "out_trade_no": "ZMOutTradeNoTradePay20180704145304679018382",
        "point_amount": "0.00",
        "receipt_amount": "0.01",
        "total_amount": "0.01",
        "trade_no": "2018070421001004660568415769"
    },
    "sign": "cHoNGyETgo2+L5ngyKhjRewR1KH1ZhtlaQ9+nq247/jlVm08/+o1ynIOX5ZRjCsPrDyJbwlwgpaqtN6Hdv8QY/53+UWM5NtR4EIQThvg52NRV2iWZhVNMm3jVrbNgnsmOemTYLfXAO0682K4R0QvS5cn45TGRFEq5o5cjlzFAIWx6mDVC7dYn/UF7HiF3xycqSTUbBZgjZ4EzWRSJWbnn36zRu8IKU4GNr9ArGBz3tEDXaCxSSxm9H3ErwarHdHZOfz0bA+4aJMWaxY/kV7BPRB30/ECwuOI7cFO8pwgjWbEoD6ZqwBO2YkvAKCMW4foNJ5L764Bn1QNJvkz9+2gLQ=="
}


失败样例


{
    "alipay_trade_pay_response": {
        "code": "20000",
        "msg": "Service Currently Unavailable",
        "sub_code": "isp.unknow-error",
        "sub_msg": "系统繁忙"
    },
    "sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}


异步通知

通知类型

描述

trade_status_sync

授权转支付通知


通知样例


https://www.merchant.com/receive_notify.htm?notify_type=trade_status_sync&notify_id=91722adff935e8cfa58b3aabf4dead6ibe&notify_time=2017-02-16 21:46:15&sign_type=RSA2&sign=WcO+t3D8Kg71dTlKwN7r9PzUOXeaBJwp8/FOuSxcuSkXsoVYxBpsAidprySCjHCjmaglNcjoKJQLJ28/Asl93joTW39FX6i07lXhnbPknezAlwmvPdnQuI01HZsZF9V1i6ggZjBiAd5lG8bZtTxZOJ87ub2i9GuJ3Nr/NUc9VeY=&app_id=2088102146225135&trade_no=2013112011001004330000121536&out_trade_no=6823789339978248&out_biz_no=85478536823789339978248&buyer_logon_id=159****5620&seller_id=2088102146225135&trans_currency=USD&seller_email=aa@mail.sa.com&total_amount=120.88&buyer_id=2088202954065786&settle_currency=USD&settle_amount=88.88&pay_currency=CNY&pay_amount=580.04&settle_trans_rate=1&trans_pay_rate=6.5261&trade_status=TRADE_SUCCESS&invoice_amount=88.88&receipt_amount=88.88&point_amount=88.88&refund_fee=10.23&buyer_pay_amount=88.88&subject=Iphone6 16G&body=Iphone6 16G&gmt_create=2014-11-27 15:45:57&gmt_payment=2014-11-27 15:45:57&gmt_refund=2014-11-27 14:15:57&gmt_close=2014-11-27 17:45:57&fund_bill_list="[{\"amount\":\"10000.00\",\"fundChannel\":\"ALIPAYACCOUNT\"}]"&voucher_detail_list="[{\"id\":\"20170307000730026487005X1M6V\",\"name\":\"全仓5折优惠券\"}]"&discount_goods_detail="[{\"goodsId\":\"STANDARD1026181538\",\"goodsName\":\"雪碧\",\"discountAmount\":\"10.00\"}]"&refund_preset_paytool_list=[{"amount":"1.00","assert_type_code":"HEMA"}]&notify_action_type=payByAccountAction/closeTradeAction/reverseAction/finishFPAction&discount_amount=88.88&mdiscount_amount=88.88&unfreeze_amount=18.18&auth_trade_pay_mode=CREDIT_PREAUTH_PAY


onlineServer