lyhzzz пре 2 година
родитељ
комит
3c2e49fa3e

+ 3 - 0
src/main/java/com/fdkankan/pay/entity/AutopayOrder.java

@@ -51,6 +51,9 @@ public class AutopayOrder implements Serializable {
     @TableField("subscription_id")
     private String subscriptionId;
 
+    @TableField("subscription_href")
+    private String subscriptionHref;
+
     @TableField("create_time")
     private Date createTime;
 

+ 29 - 24
src/main/java/com/fdkankan/pay/util/paypal/sdk/PaypalService.java

@@ -433,39 +433,44 @@ public class PaypalService {
 
     public Object autoPay(Order order, PaypalConfig paypalConfig) {
         AutopayOrder autopayOrder = autopayOrderService.getByOrderSn(order.getOrderSn());
-        if(autopayOrder == null){
-            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);
-            autopayOrder.setPlanId(planId);
-            autopayOrder.setOrderSn(order.getOrderSn());
-            autopayOrder.setProductId(productId);
+
+        OpenPayResponse openPayResponse = new OpenPayResponse();
+        openPayResponse.setOrderSn(order.getOrderSn());
+        openPayResponse.setPayType(5);
+        openPayResponse.setAutoPay(1);
+        if(autopayOrder !=null){
+            openPayResponse.setH5Url(autopayOrder.getSubscriptionHref());
+            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);
+        autopayOrder.setPlanId(planId);
+        autopayOrder.setOrderSn(order.getOrderSn());
+        autopayOrder.setProductId(productId);
 
         SubscriptionVo subscription = restApiPaypalService.createSubscription(paypalConfig, autopayOrder.getSubscriptionId());
         log.info("创建订阅支付链接:"+subscription);
         autopayOrder.setSubscriptionId(subscription.getSubscriptionId());
+        autopayOrder.setSubscriptionHref(subscription.getSubscriptionHref());
         autopayOrderService.saveOrUpdate(autopayOrder);
 
-        OpenPayResponse openPayResponse = new OpenPayResponse();
         openPayResponse.setH5Url(subscription.getSubscriptionHref());
         openPayResponse.setQrCodeUrl(subscription.getSubscriptionHref());
-        openPayResponse.setOrderSn(order.getOrderSn());
-        openPayResponse.setPayType(5);
-        openPayResponse.setAutoPay(1);
         return openPayResponse;
     }
 }