com.alipay.api.response.AlipayTradeRefundResponse Java Examples
The following examples show how to use
com.alipay.api.response.AlipayTradeRefundResponse.
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: AliPayServiceImpl.java From common-project with Apache License 2.0 | 6 votes |
@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 #2
Source File: PayController.java From sdb-mall with Apache License 2.0 | 6 votes |
@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 #3
Source File: AliPayService.java From java-pay with Apache License 2.0 | 5 votes |
/** * 支付宝退款 * * @param orderId * @param servletRequest * @return */ public Result aliRefund(Long orderId, HttpServletRequest servletRequest) throws Exception { // 校验订单信息 Order order = orderService.findOne(orderId); if (order.getStatus() < OrderStatus.PAY.getStatus()) { log.error(ExceptionMessage.ORDER_STATUS_INCORRECTNESS + " orderId: {}", orderId); throw new ValidateException(ExceptionMessage.ORDER_STATUS_INCORRECTNESS); } // 创建退款请求builder,设置请求参数 AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); Map<String, String> params = new TreeMap<>(); // 必须 商户订单号 params.put("out_trade_no", order.getOutTradeNo()); // 必须 支付宝交易号 params.put("trade_no", order.getTotalFee().toString()); // 必须 退款金额 params.put("refund_amount", order.getTotalFee().toString()); // 可选 代表 退款的原因说明 params.put("refund_reason", "退款的原因说明"); // 可选 标识一次退款请求,同一笔交易多次退款需要保证唯一(就是out_request_no在2次退款一笔交易时,要不一样),如需部分退款,则此参数必传 params.put("out_request_no", 1 + RandomUtil.randomNum(11)); // 可选 代表 商户的门店编号 params.put("store_id", "90m"); request.setBizContent(objectMapper.writeValueAsString(params)); AlipayTradeRefundResponse responseData = alipayClient.execute(request); if (responseData.isSuccess()) { log.info("ali refund success tradeNo:{}", order.getOutTradeNo()); return Result.success(ExceptionMessage.SUCCESS); } log.info("ali refund failed tradeNo:{}", order.getOutTradeNo()); return Result.error(ExceptionMessage.ALI_PAY_REFUND_FAILED); }
Example #4
Source File: AlipayServiceImpl.java From fast-family-master with Apache License 2.0 | 5 votes |
@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 #5
Source File: AliPayApi.java From AlipayWechatPlatform with GNU General Public License v3.0 | 5 votes |
/** * 支付宝退款接口; * * @param bizContent 支付宝退款接口的业务内容请求JSON实例 * @return 是否调用成功 * @author Leibniz */ public static boolean refund(RefundBizContent bizContent, Account wxAccount){ String bizContentStr = bizContent.toString(); // 将参数bizContent转成字符串 // 检查bizContent是否合法 if(!bizContent.checkParameters()){ throw new IllegalArgumentException("错误的支付宝退款接口请求业务JSON:" + bizContentStr); // 抛出异常 } AliAccountInfo aliAccountInfo = new AliAccountInfo(wxAccount.getZfbappid(), wxAccount.getZfbprivkey(), wxAccount.getZfbpubkey(), null, null, 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("调用成功"); // 打日志 return true; // 退款成功 } else { // 退款失败 LOG.error("调用支付宝退款接口错误,code={},msg={},sub_code={},sub_msg={}", new Object[]{response.getCode(), response.getMsg(), response.getSubCode(), response.getSubMsg()}); // 打日志 } } else { // 响应失败 LOG.error("调用支付宝退款接口时发生异常,返回响应对象为null!{}", bizContentStr); // 打日志 } return false; // 退款失败 }
Example #6
Source File: AlipayPayService.java From AlipayWechatPlatform with GNU General Public License v3.0 | 5 votes |
/** * 支付宝退款接口; * * @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: AlipayF2FRefundResult.java From MeetingFilm with Apache License 2.0 | 4 votes |
public AlipayF2FRefundResult(AlipayTradeRefundResponse response) { this.response = response; }
Example #8
Source File: AlipayF2FRefundResult.java From MeetingFilm with Apache License 2.0 | 4 votes |
public void setResponse(AlipayTradeRefundResponse response) { this.response = response; }
Example #9
Source File: AlipayF2FRefundResult.java From MeetingFilm with Apache License 2.0 | 4 votes |
public AlipayTradeRefundResponse getResponse() { return response; }
Example #10
Source File: AlipayTradeRefundRequest.java From alipay-sdk-java-all with Apache License 2.0 | 4 votes |
public Class<AlipayTradeRefundResponse> getResponseClass() { return AlipayTradeRefundResponse.class; }
Example #11
Source File: AlipayTradeRefundRequest.java From alipay-sdk with Apache License 2.0 | 4 votes |
public Class<AlipayTradeRefundResponse> getResponseClass() { return AlipayTradeRefundResponse.class; }
Example #12
Source File: PayChannel4AliServiceImpl.java From xxpay-master with MIT License | 4 votes |
@Override public Map doAliRefundReq(String jsonParam) { String logPrefix = "【支付宝退款】"; BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class); Map<String, Object> bizParamMap = baseParam.getBizParamMap(); if (ObjectValidUtil.isInvalid(bizParamMap)) { _log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam); return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND); } JSONObject refundOrderObj = baseParam.isNullValue("refundOrder") ? null : JSONObject.parseObject(bizParamMap.get("refundOrder").toString()); RefundOrder refundOrder = JSON.toJavaObject(refundOrderObj, RefundOrder.class); if (ObjectValidUtil.isInvalid(refundOrder)) { _log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam); return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID); } String refundOrderId = refundOrder.getRefundOrderId(); String mchId = refundOrder.getMchId(); String channelId = refundOrder.getChannelId(); PayChannel payChannel = baseService4PayOrder.baseSelectPayChannel(mchId, channelId); alipayConfig.init(payChannel.getParam()); AlipayClient client = new DefaultAlipayClient(alipayConfig.getUrl(), alipayConfig.getApp_id(), alipayConfig.getRsa_private_key(), AlipayConfig.FORMAT, AlipayConfig.CHARSET, alipayConfig.getAlipay_public_key(), AlipayConfig.SIGNTYPE); AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); AlipayTradeRefundModel model = new AlipayTradeRefundModel(); model.setOutTradeNo(refundOrder.getPayOrderId()); model.setTradeNo(refundOrder.getChannelPayOrderNo()); model.setOutRequestNo(refundOrderId); model.setRefundAmount(AmountUtil.convertCent2Dollar(refundOrder.getRefundAmount().toString())); model.setRefundReason("正常退款"); request.setBizModel(model); Map<String, Object> map = new HashMap<>(); map.put("refundOrderId", refundOrderId); map.put("isSuccess", false); try { AlipayTradeRefundResponse response = client.execute(request); if(response.isSuccess()){ map.put("isSuccess", true); map.put("channelOrderNo", response.getTradeNo()); }else { _log.info("{}返回失败", logPrefix); _log.info("sub_code:{},sub_msg:{}", response.getSubCode(), response.getSubMsg()); map.put("channelErrCode", response.getSubCode()); map.put("channelErrMsg", response.getSubMsg()); } } catch (AlipayApiException e) { _log.error(e, ""); } return RpcUtil.createBizResult(baseParam, map); }
Example #13
Source File: AlipayTradeRefundRequest.java From pay with Apache License 2.0 | 4 votes |
public Class<AlipayTradeRefundResponse> getResponseClass() { return AlipayTradeRefundResponse.class; }
Example #14
Source File: AlipayService.java From fast-family-master with Apache License 2.0 | 2 votes |
/** * 退款 * * @param model * @return * @throws AlipayApiException */ AlipayTradeRefundResponse refund(AlipayTradeRefundModel model) throws AlipayApiException;