修改PayPal创建订单参数returnUrl

This commit is contained in:
wuchunlei
2024-12-18 09:59:01 +08:00
parent f08bf4acbd
commit baa76d9911
2 changed files with 12 additions and 3 deletions

View File

@@ -133,7 +133,7 @@ public class PaypalConfig {
}
//下单
public JSONObject createOrder(BuyOrder buyOrder){
public JSONObject createOrder(BuyOrder buyOrder,String returnUrl,String cancelUrl){
try{
URL u = new URL(modeUrl+createOrderURL);
HttpURLConnection connection = (HttpURLConnection) u.openConnection();

View File

@@ -53,7 +53,7 @@ public class PaypalController {
if ("point".equals(buyOrder.getOrderType())){
buyOrder.setRemark("Recharge Virtual Coin");
}
JSONObject res = paypalConfig.createOrder(buyOrder);
JSONObject res = paypalConfig.createOrder(buyOrder,params.get("returnUrl").toString(),params.get("cancelUrl").toString());
if (res.containsKey("links")&&res.containsKey("status")){
if ("CREATED".equals(res.get("status").toString())){
PayPaypalOrder payPaypalOrder = new PayPaypalOrder();
@@ -63,7 +63,16 @@ public class PaypalController {
payPaypalOrder.setPaypalOrderId(res.get("id").toString());
payPaypalOrder.setDescription(buyOrder.getRemark());
payPaypalOrderService.save(payPaypalOrder);
return R.ok().put("id",res.get("id").toString());
JSONArray array = (JSONArray)res.get("links");
String url = "";
for (int i = 0; i < array.size(); i++) {
JSONObject o = (JSONObject)array.get(i);
if ("approve".equals(o.get("rel"))){
url = o.get("href").toString();
}
}
return R.ok().put("id",res.get("id").toString()).put("url",url);
}
}
return R.error(res.get("error").toString());