com.alipay.api.request.AlipayTradeRefundRequest Java Examples

The following examples show how to use com.alipay.api.request.AlipayTradeRefundRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlipayController.java    From springboot-pay-example with Apache License 2.0 6 votes vote down vote up
/**
     * 退款
     * @param orderNo 商户订单号
     * @return
     */
    @PostMapping("/refund")
    @ResponseBody
    public String refund(String orderNo) throws AlipayApiException {
        AlipayTradeRefundRequest alipayRequest = new AlipayTradeRefundRequest();

        AlipayTradeRefundModel model=new AlipayTradeRefundModel();
        // 商户订单号
        model.setOutTradeNo(orderNo);
        // 退款金额
        model.setRefundAmount("0.01");
        // 退款原因
        model.setRefundReason("无理由退货");
        // 退款订单号(同一个订单可以分多次部分退款,当分多次时必传)
//        model.setOutRequestNo(UUID.randomUUID().toString());
        alipayRequest.setBizModel(model);

        AlipayTradeRefundResponse alipayResponse = alipayClient.execute(alipayRequest);
        System.out.println(alipayResponse.getBody());

        return alipayResponse.getBody();
    }
 
Example #2
Source File: AliPayServiceImpl.java    From common-project with Apache License 2.0 6 votes vote down vote up
@Override
public boolean refund(String orderNum) {
    //TODO 根据实际业务参数填写
    Integer orderFrom=0;
    AliPayConfig aliPayConfig= (AliPayConfig) getPayConfig(orderFrom);
    AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliPayConfig.getAppId(),aliPayConfig.getAppPrivateKey(),"json",aliPayConfig.getCharset(),aliPayConfig.getAliPayPublicKey(),"RSA2");
    AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
    Map<String,String> bizContent = new HashMap<>();
    bizContent.put("out_trade_no",orderNum);
    String refundAmount="";
    bizContent.put("refund_amount",refundAmount);
    AlipayTradeRefundResponse response = null;
    try {
        response = alipayClient.execute(request);
        if(!response.isSuccess()){
            return false;
        }
    } catch (AlipayApiException e) {
        logger.error("调用支付宝退款失败 ====> "+e.getErrMsg());
    }
    return true;
}
 
Example #3
Source File: PayController.java    From sdb-mall with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/refund/{no}")
    public void testTradeRefund(@PathVariable String no) throws Exception {
        AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY,AlipayConfig.SIGNTYPE);
        AlipayTradeRefundModel model = new AlipayTradeRefundModel();
        model.setOutTradeNo(no); //与预授权转支付商户订单号相同,代表对该笔交易退款
        model.setRefundAmount("0.01");
        model.setRefundReason("预授权退款测试");
        model.setOutRequestNo("refund0000001");//标识一次退款请求,同一笔交易多次退款需要保证唯一,如部分退款则此参数必传。
        AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
        request.setBizModel(model);
        AlipayTradeRefundResponse response = client.execute(request);
        log.info("response: {}"+response.getBody());



//退款失败的"fund_change":"N"
//        {"alipay_trade_refund_response":{"code":"10000","msg":"Success","buyer_logon_id":"mqv***@sandbox.com","buyer_user_id":"2088102171383132","fund_change":"N","gmt_refund_pay":"2018-08-30 15:39:03","out_trade_no":"13c7b574-5f54-42da-8165-e9fc0602f74e","refund_fee":"0.01","send_back_fee":"0.00","trade_no":"2018083021001004130500297310"},"sign":"LgzBU1K7056OLY0AAvFAZBVcZuXXt7PTbZDms5nB5qieslSKiKbYc22Jw4As/GdCJJuH7NVEtBABRM9UBXtTJBCGGn7By/H+vZfkulv43E4ASHvLC8OjXiPrypUO4SDleBTB4WW5h3Vnwk8q/SJ+UXv0lb5xrib84Zspsbz//3rrhzqGJ2sr/40YZIoIuevq/OAmLAkbNuAyIiC4ZxkJijF+mD3PbITTdYs/5e4cVEwriZcdLWnptblucSUtjKwEZvwaAuXuB+CEbqaMEBnpPgye0yqvY9tNb6PmVxHX7sc8sL9rfgDjK09xIXMhU9tgh0R/cgPZsRXvSs/HjHiqlA=="}

//退款成功的"fund_change":"Y"
//        {"alipay_trade_refund_response":{"code":"10000","msg":"Success","buyer_logon_id":"mqv***@sandbox.com","buyer_user_id":"2088102171383132","fund_change":"Y","gmt_refund_pay":"2018-08-30 15:42:15","out_trade_no":"2936025a-73eb-4273-8b1c-dfa8d637ff70","refund_fee":"0.01","send_back_fee":"0.00","trade_no":"2018083021001004130500297311"},"sign":"Nr6WroDGtVfWVCvqSSY7Z2SPtV68UbN9eII9GSMIZ3D4xlMRd+NoEUPl8EB9h3z2T8rR7fUrjAAjfIfC5qamaW6LW9tGXI4d8GprgU0YGx+53ZqyXJIaz3LeSJ6+U7NsC3h62/jOmgow6qAqca/XHkjHXmDTeERC+D6nqJLY28E5EKbVZK2IvupCo4sJLih8nI6BS0H5IjVIsRztAjgosrqCHic32JUel4/uyouBfRGPp5pp+3fzbxdJ1yMbUeKjuipNFS9Bhdvdt3ngTJoOAF+o7vQn7DIsJZQn5zNNP3BCEeXZIiXEfF/yha2HBlAM/ush5yZBpjMhDLXYRGuJUQ=="}
    }
 
Example #4
Source File: AbsAlipayTradeService.java    From MeetingFilm with Apache License 2.0 5 votes vote down vote up
@Override
public AlipayF2FRefundResult tradeRefund(AlipayTradeRefundRequestBuilder builder) {
    validateBuilder(builder);

    AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
    request.setNotifyUrl(builder.getNotifyUrl());
    request.putOtherTextParam("app_auth_token", builder.getAppAuthToken());
    request.setBizContent(builder.toJsonString());
    log.info("trade.refund bizContent:" + request.getBizContent());

    AlipayTradeRefundResponse response = (AlipayTradeRefundResponse) getResponse(client, request);

    AlipayF2FRefundResult result = new AlipayF2FRefundResult(response);
    if (response != null && Constants.SUCCESS.equals(response.getCode())) {
        // 退货交易成功
        result.setTradeStatus(TradeStatus.SUCCESS);

    } else if (tradeError(response)) {
        // 退货发生异常,退货状态未知
        result.setTradeStatus(TradeStatus.UNKNOWN);

    } else {
        // 其他情况表明该订单退货明确失败
        result.setTradeStatus(TradeStatus.FAILED);
    }
    return result;
}
 
Example #5
Source File: AlipayServiceImpl.java    From fast-family-master with Apache License 2.0 5 votes vote down vote up
@Override
public AlipayTradeRefundResponse refund(AlipayTradeRefundModel model) throws AlipayApiException {
    AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
    request.setBizModel(model);
    request.setNotifyUrl(aliPayProperties.getNotifyUrl());
    request.setReturnUrl(aliPayProperties.getReturnUrl());
    return alipayClient.execute(request);

}
 
Example #6
Source File: AlipayPayService.java    From AlipayWechatPlatform with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 支付宝退款接口;
 *
 * @param bizContent   支付宝退款接口的业务内容请求JSON实例
 * @param acc      企业用户账户对象
 * 异步返回 是否调用成功
 *
 * @author Leibniz
 */
public void alipayRefund(RefundBizContent bizContent, JsonObject acc, String successUrl, Handler<Boolean> callback) {
    String bizContentStr = bizContent.toString(); // 将参数bizContent转成字符串

    // 检查bizContent是否合法
    if (!bizContent.checkParameters()) {
        throw new IllegalArgumentException("错误的支付宝退款接口请求业务JSON:" + bizContentStr); // 抛出异常
    }

    String notifyUrl = zfbPayNotifyUrl; // 服务器后台回调通知的url
    AliAccountInfo aliAccountInfo = new AliAccountInfo(acc.getString(ZFBAPPID), acc.getString(ZFBPRIVKEY), acc.getString(ZFBPUBKEY), successUrl, notifyUrl, null); // 该对象保存了支付宝账号的相关信息,以及请求回调地址
    AlipayClient alipayClient = AliPayCliFactory.getAlipayClient(aliAccountInfo); // 获取支付宝连接
    AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); // 创建退款请求
    request.setBizContent(bizContentStr); // 设置请求的bizContent
    AlipayTradeRefundResponse response = null;

    try {
        response = alipayClient.execute(request); // 发送退款请求并获得响应
    } catch (AlipayApiException e) { // 捕捉异常
        log.error("调用支付宝退款接口时抛出异常,请求的JSON:" + bizContentStr, e); // 打日志
    }

    // 判断是否有响应
    if (response != null) { // 响应成功
        // 判断退款是否成功
        if (response.isSuccess()) { // 退款成功
            log.info("调用成功"); // 打日志
            callback.handle(true);
            // 退款成功,其他都是错
        } else { // 退款失败
            log.error("调用支付宝退款接口错误,code={},msg={},sub_code={},sub_msg={}", response.getCode(), response.getMsg(), response.getSubCode(), response.getSubMsg()); // 打日志
            callback.handle(false);
        }
    } else { // 响应失败
        log.error("调用支付宝退款接口时发生异常,返回响应对象为null!{}", bizContentStr); // 打日志
        callback.handle(false);
    }
}
 
Example #7
Source File: PayRefundChain.java    From alipay with Apache License 2.0 2 votes vote down vote up
/**
 * Building Refund
 * <p>
 * 构建退款
 *
 * @return String
 * @throws AlipayApiException AlipayApiException
 */
public String refund() throws AlipayApiException {
    AlipayTradeRefundRequest refundRequest = new AlipayTradeRefundRequest ();
    refundRequest.setBizModel (alipayTradeRefundModel);
    return alipayClient.execute (refundRequest).getBody ();
}
 
Example #8
Source File: PayRefundChain.java    From alipay with Apache License 2.0 2 votes vote down vote up
/**
 * Custom Build RefundRequest
 * <p>
 * 自定义构建 RefundRequest
 *
 * @param refundRequest refundRequest
 * @return String
 * @throws AlipayApiException AlipayApiException
 */
public String refund(AlipayTradeRefundRequest refundRequest) throws AlipayApiException {
    refundRequest.setBizModel (alipayTradeRefundModel);
    return alipayClient.execute (refundRequest).getBody ();
}