|
|
@@ -9,8 +9,10 @@ import com.cyksj.mapper.StripePayConfigMapper;
|
|
|
import com.cyksj.model.entity.GoodsDonSku;
|
|
|
import com.cyksj.model.entity.OrderDon;
|
|
|
import com.cyksj.model.entity.StripePayConfig;
|
|
|
+import com.cyksj.model.entity.VipOrderDon;
|
|
|
import com.cyksj.model.request.OrderRefundReq;
|
|
|
import com.cyksj.service.order.OrderDonService;
|
|
|
+import com.cyksj.service.order.VipOrderDonService;
|
|
|
import com.stripe.Stripe;
|
|
|
import com.stripe.exception.StripeException;
|
|
|
import com.stripe.model.*;
|
|
|
@@ -45,6 +47,8 @@ public class StripeService {
|
|
|
|
|
|
private final GoodsDonSkuMapper skuMapper;
|
|
|
|
|
|
+ private final VipOrderDonService vipOrderDonService;
|
|
|
+
|
|
|
|
|
|
|
|
|
public String checkOutStripe(Long orderId,String successUrl) throws Exception{
|
|
|
@@ -144,5 +148,74 @@ public class StripeService {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+ public String checkOutStripeVip(Long orderId,String successUrl) throws Exception{
|
|
|
+ VipOrderDon orderDon = vipOrderDonService.getById(orderId);
|
|
|
+ BigDecimal money = orderDon.getMoney();
|
|
|
+ orderDon.setType(VipOrderDon.Type.STRIPE);
|
|
|
+ vipOrderDonService.updateById(orderDon);
|
|
|
+ HashMap<String, String> responseData = new HashMap<String, String>();
|
|
|
+ if (VipOrderDon.Status.hasPayment.equals(orderDon.getStatus())) {
|
|
|
+ throw new BusinessRuntimeException(GatewayApiCode.METADATA_SYSTEM_ERROR.getCode(),"该订单已支付");
|
|
|
+ }
|
|
|
+ StripePayConfig stripePayConfig = stripePayConfigMapper.selectById(1);
|
|
|
+ try {
|
|
|
+ Stripe.apiKey = stripePayConfig.getApiKey();
|
|
|
+ SessionCreateParams params =
|
|
|
+ SessionCreateParams.builder()
|
|
|
+ .setMode(SessionCreateParams.Mode.PAYMENT)
|
|
|
+ .setSuccessUrl(successUrl)
|
|
|
+ .setCancelUrl(stripePayConfig.getCancelUrl())
|
|
|
+ .setClientReferenceId("vip_"+orderDon.getId())
|
|
|
+ .addLineItem(
|
|
|
+ SessionCreateParams.LineItem.builder()
|
|
|
+ .setQuantity(1L)
|
|
|
+ .setPriceData(
|
|
|
+ SessionCreateParams.LineItem.PriceData.builder()
|
|
|
+ .setCurrency("USD")
|
|
|
+ .setUnitAmount(money.longValue())
|
|
|
+ .setProductData(
|
|
|
+ SessionCreateParams.LineItem.PriceData.ProductData.builder()
|
|
|
+ .setName("donation")
|
|
|
+ .setDescription("donation")
|
|
|
+ .build()).build()).build()).build();
|
|
|
+ Session session = Session.create(params);
|
|
|
+ responseData.put("id", session.getId());
|
|
|
+ } catch (StripeException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return Jsons.toJson(responseData);
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ public void fulfillOrderVip(Session session) throws Exception{
|
|
|
+ if (null == session){
|
|
|
+ log.error("支付回调失败");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String orderId = session.getClientReferenceId().replace("vip","");
|
|
|
+ if (!"paid".equals(session.getPaymentStatus())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ VipOrderDon orderDon = vipOrderDonService.getById(orderId);
|
|
|
+ if (orderDon == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (orderDon.getStatus().equals(VipOrderDon.Status.hasPayment)) {
|
|
|
+ log.info("已回调,重复修改状态 id:{}", orderDon.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String paymentIntentId = session.getPaymentIntent();
|
|
|
+ PaymentIntent paymentIntent = PaymentIntent.retrieve(paymentIntentId);
|
|
|
+ String chargeId = paymentIntent.getLatestCharge();
|
|
|
+ BalanceTransaction balanceTransaction = BalanceTransaction.retrieve(Charge.retrieve(chargeId).getBalanceTransaction());
|
|
|
+ //更新订单支付状态
|
|
|
+
|
|
|
+ orderDon.setTransactionId(chargeId);
|
|
|
+ orderDon.setAbroadTransactionFee(BigDecimal.valueOf(balanceTransaction.getFee()));
|
|
|
+ orderDon.setPayTime(new Date());
|
|
|
+ vipOrderDonService.orderNotify(orderDon);
|
|
|
+ log.info("支付成功订单:"+orderId+",支付交易号:"+chargeId);
|
|
|
+ log.info("支付成功订单:"+orderId+",返回参数:"+Jsons.toJson(session));
|
|
|
+
|
|
|
+ }
|
|
|
}
|