|
|
@@ -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;
|
|
|
}
|
|
|
}
|