修改capture方法异常

This commit is contained in:
wuchunlei
2024-12-23 09:36:13 +08:00
parent a90b744d45
commit 93d1ef580d
2 changed files with 22 additions and 17 deletions

View File

@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
import com.peanut.modules.common.entity.BuyOrder; import com.peanut.modules.common.entity.BuyOrder;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
@@ -116,7 +115,8 @@ public class PaypalConfig {
} }
//用户授权支付成功,进行扣款操作 //用户授权支付成功,进行扣款操作
public JSONObject capture(String paypalOrderId) throws Exception{ public JSONObject capture(String paypalOrderId){
try {
URL url = new URL(String.format(modeUrl+captureURL,paypalOrderId)); URL url = new URL(String.format(modeUrl+captureURL,paypalOrderId));
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST"); httpConn.setRequestMethod("POST");
@@ -130,6 +130,11 @@ public class PaypalConfig {
String response = s.hasNext() ? s.next() : ""; String response = s.hasNext() ? s.next() : "";
log.info(">>>>>>>>>>>palypal扣款返回的信息是 result = {}", response); log.info(">>>>>>>>>>>palypal扣款返回的信息是 result = {}", response);
return JSONObject.parseObject(response); return JSONObject.parseObject(response);
}catch (Exception e) {
log.error(">>>>>>>>>>:PayPal扣款失败 reason = {}", e.getMessage());
e.printStackTrace();
return JSONObject.parseObject("{'error':'PayPal扣款失败请联系管理员'}");
}
} }
//下单 //下单
@@ -156,8 +161,8 @@ public class PaypalConfig {
JSONObject applicationContext = new JSONObject(); JSONObject applicationContext = new JSONObject();
applicationContext.put("user_action", "PAY_NOW");//付款按钮显示立即付款 applicationContext.put("user_action", "PAY_NOW");//付款按钮显示立即付款
applicationContext.put("shipping_preference", "NO_SHIPPING");//从 PayPal 网站编辑送货地址。推荐用于数字商品。 applicationContext.put("shipping_preference", "NO_SHIPPING");//从 PayPal 网站编辑送货地址。推荐用于数字商品。
applicationContext.put("return_url", "");//客户批准付款后重定向到客户的 URL applicationContext.put("return_url", returnUrl);//客户批准付款后重定向到客户的 URL
applicationContext.put("cancel_url", "");//客户取消付款后,客户被重定向的 URL applicationContext.put("cancel_url", cancelUrl);//客户取消付款后,客户被重定向的 URL
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("intent","CAPTURE");// 用户付款了,商户立即收款 jsonObject.put("intent","CAPTURE");// 用户付款了,商户立即收款
jsonObject.put("purchase_units",purchase_units); jsonObject.put("purchase_units",purchase_units);

View File

@@ -86,7 +86,7 @@ public class PaypalController {
@RequestMapping("/capture") @RequestMapping("/capture")
@Transactional @Transactional
public R capture(@RequestBody Map<String,Object> params) throws Exception{ public R capture(@RequestBody Map<String,Object> params){
JSONObject res = paypalConfig.capture(params.get("paypalId").toString()); JSONObject res = paypalConfig.capture(params.get("paypalId").toString());
if (res.containsKey("status")&&"COMPLETED".equals(res.get("status").toString())){ if (res.containsKey("status")&&"COMPLETED".equals(res.get("status").toString())){
PayPaypalOrder payPaypalOrder = payPaypalOrderService.getOne(new LambdaQueryWrapper<PayPaypalOrder>() PayPaypalOrder payPaypalOrder = payPaypalOrderService.getOne(new LambdaQueryWrapper<PayPaypalOrder>()