|
|
@@ -4,6 +4,7 @@ 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.Order;
|
|
|
import com.fdkankan.pay.entity.PaypalConfig;
|
|
|
import com.fdkankan.pay.exception.BusinessException;
|
|
|
@@ -431,26 +432,33 @@ public class PaypalService {
|
|
|
IAutopayOrderService autopayOrderService;
|
|
|
|
|
|
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);
|
|
|
+ }
|
|
|
|
|
|
- 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);
|
|
|
-
|
|
|
- SubscriptionVo subscription = restApiPaypalService.createSubscription(paypalConfig, planId);
|
|
|
+ SubscriptionVo subscription = restApiPaypalService.createSubscription(paypalConfig, autopayOrder.getSubscriptionId());
|
|
|
log.info("创建订阅支付链接:"+subscription);
|
|
|
- autopayOrderService.saveAutoOrder(order.getOrderSn(),productId,planId,subscription.getSubscriptionId());
|
|
|
+ autopayOrder.setSubscriptionId(subscription.getSubscriptionId());
|
|
|
+ autopayOrderService.saveOrUpdate(autopayOrder);
|
|
|
|
|
|
OpenPayResponse openPayResponse = new OpenPayResponse();
|
|
|
openPayResponse.setH5Url(subscription.getSubscriptionHref());
|