|
|
@@ -3,13 +3,12 @@ package com.fdkankan.pay.util.paypal.sdk;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fdkankan.pay.common.ResultCode;
|
|
|
-import com.fdkankan.pay.entity.AliConfig;
|
|
|
-import com.fdkankan.pay.entity.AutopayOrder;
|
|
|
+import com.fdkankan.pay.entity.*;
|
|
|
import com.fdkankan.pay.entity.Order;
|
|
|
-import com.fdkankan.pay.entity.PaypalConfig;
|
|
|
import com.fdkankan.pay.exception.BusinessException;
|
|
|
import com.fdkankan.pay.response.OpenPayResponse;
|
|
|
import com.fdkankan.pay.service.IAutopayOrderService;
|
|
|
+import com.fdkankan.pay.service.IAutopayPlanService;
|
|
|
import com.fdkankan.pay.service.IOrderService;
|
|
|
import com.fdkankan.pay.service.IPaypalConfigService;
|
|
|
import com.fdkankan.pay.util.CacheUtil;
|
|
|
@@ -105,7 +104,12 @@ public class PaypalService {
|
|
|
return false;
|
|
|
}
|
|
|
try {
|
|
|
- String paymentId = request.getParameter("paymentId");//商品名
|
|
|
+ Map<String, String[]> parameterMap = request.getParameterMap();
|
|
|
+ for (String key : parameterMap.keySet()) {
|
|
|
+ log.info("paypal-callBack--request:{},{}",key,request.getParameter(key));
|
|
|
+ }
|
|
|
+
|
|
|
+ String paymentId = request.getParameter("paymentId");//商品名
|
|
|
String payerId = request.getParameter("PayerID");//购买数量
|
|
|
PaypalConfig paypalConfig = paypalConfigService.getByServeId(order.getServeId());
|
|
|
if(paypalConfig == null){
|
|
|
@@ -430,6 +434,8 @@ public class PaypalService {
|
|
|
RestApiPaypalService restApiPaypalService;
|
|
|
@Autowired
|
|
|
IAutopayOrderService autopayOrderService;
|
|
|
+ @Autowired
|
|
|
+ IAutopayPlanService autopayPlanService;
|
|
|
|
|
|
public Object autoPay(Order order, PaypalConfig paypalConfig) {
|
|
|
AutopayOrder autopayOrder = autopayOrderService.getByOrderSn(order.getOrderSn());
|
|
|
@@ -443,26 +449,34 @@ public class PaypalService {
|
|
|
openPayResponse.setQrCodeUrl(autopayOrder.getSubscriptionHref());
|
|
|
return openPayResponse;
|
|
|
}
|
|
|
+
|
|
|
autopayOrder = new AutopayOrder();
|
|
|
- Product product = new Product();
|
|
|
- product.setName(order.getOrderType());
|
|
|
- product.setDescription(order.getGoodsInfo().toJSONString());
|
|
|
- product.setType("SERVICE");
|
|
|
- String productId = restApiPaypalService.createProduct(paypalConfig, product);
|
|
|
- log.info("创建商品:"+productId);
|
|
|
-
|
|
|
- PlanVo plan = new PlanVo();
|
|
|
- plan.setProductId(productId);
|
|
|
- plan.setPlanName(order.getOrderType());
|
|
|
- plan.setTimeUnit(order.getAutoPayTime());
|
|
|
- plan.setCurrencyCode("USD");
|
|
|
- plan.setPrice(order.getOrderMoney().toString());
|
|
|
- String planId = restApiPaypalService.createPlan(paypalConfig, plan);
|
|
|
- log.info("创建订阅计划:"+planId);
|
|
|
+ AutopayPlan autopayPlan = autopayPlanService.getByOrder(order);
|
|
|
+
|
|
|
+ if(autopayPlan == null){
|
|
|
+ Product product = new Product();
|
|
|
+ product.setName(order.getOrderType());
|
|
|
+ product.setDescription(order.getGoodsInfo().toJSONString());
|
|
|
+ product.setType("SERVICE");
|
|
|
+ String productId = restApiPaypalService.createProduct(paypalConfig, product);
|
|
|
+ log.info("创建商品:"+productId);
|
|
|
+
|
|
|
+ PlanVo plan = new PlanVo();
|
|
|
+ plan.setProductId(productId);
|
|
|
+ plan.setPlanName(order.getOrderType());
|
|
|
+ plan.setTimeUnit(order.getAutoPayTime());
|
|
|
+ plan.setCurrencyCode("USD");
|
|
|
+ plan.setPrice(order.getOrderMoney().toString());
|
|
|
+ String planId = restApiPaypalService.createPlan(paypalConfig, plan);
|
|
|
+ log.info("创建订阅计划:"+planId);
|
|
|
+
|
|
|
+ autopayPlan = new AutopayPlan(order,productId,planId);
|
|
|
+ autopayPlanService.save(autopayPlan);
|
|
|
+ }
|
|
|
|
|
|
+ autopayOrder.setProductId(autopayPlan.getProductId());
|
|
|
+ autopayOrder.setPlanId(autopayPlan.getPlanId());
|
|
|
autopayOrder.setOrderSn(order.getOrderSn());
|
|
|
- autopayOrder.setProductId(productId);
|
|
|
- autopayOrder.setPlanId(planId);
|
|
|
|
|
|
SubscriptionVo subscription = restApiPaypalService.createSubscription(paypalConfig, autopayOrder.getPlanId());
|
|
|
log.info("创建订阅支付链接:"+subscription);
|