modify:Stripe

This commit is contained in:
2024-07-17 15:26:11 +08:00
parent b9041d9c09
commit e1b08a9979
3 changed files with 32 additions and 16 deletions

View File

@@ -3,17 +3,12 @@ package com.ai.da.common.config;
import com.paypal.core.PayPalEnvironment;
import com.paypal.core.PayPalHttpClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import java.util.Iterator;
@Configuration
@Slf4j
@PropertySource("classpath:paypal-sandbox.properties")
@PropertySource("classpath:payment.properties")
public class PayPalClient {
public PayPalHttpClient client(String mode, String clientId, String clientSecret) {

View File

@@ -20,6 +20,7 @@ import com.stripe.net.Webhook;
import com.stripe.param.*;
import com.stripe.param.checkout.SessionCreateParams;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -36,9 +37,6 @@ import java.util.Objects;
@Slf4j
public class StripeServiceImpl implements StripeService {
private static final String privateKey = "sk_test_51P4ZZL02n1TEydyN8qQHjOA9imsFU7Oxs2HMHGy2urHnnQgSHnZuu5vVP6pKhEACwUpsKNyrbZpdcg5TJWJLRHcY008dEO1fn2";
// private static final String privateKey = "pk_test_51P4ZZL02n1TEydyNluht6VDxnBMoBw8S524otzlXV3CMCZI8HmkcUr3CKy8Z0eQ2WssSJ9sAaZnIQJI04fARHHJi00pcIB4sKU";
@Resource
private OrderInfoService orderInfoService;
@Resource
@@ -50,6 +48,12 @@ public class StripeServiceImpl implements StripeService {
@Resource
private RefundInfoService refundInfoService;
@Value("${stripe.private-key}")
private String privateKey;
@Value("${stripe.webhook-sign-secret}")
private String signSecret;
@Override
@Transactional(rollbackFor = Exception.class)
public String pay(Integer quantity, String returnUrl) {
@@ -79,7 +83,8 @@ public class StripeServiceImpl implements StripeService {
//创建支付信息得到url
SessionCreateParams params3 = SessionCreateParams.builder()
.setMode(SessionCreateParams.Mode.PAYMENT)
.setSuccessUrl(returnUrl) //可自定义成功页面
.setSuccessUrl(returnUrl)
.setPaymentIntentData(SessionCreateParams.PaymentIntentData.builder().setDescription("AiDA - " + orderId).build())//可自定义成功页面
.addLineItem(
SessionCreateParams.LineItem.builder()
.setQuantity(Long.valueOf(quantity))
@@ -107,7 +112,7 @@ public class StripeServiceImpl implements StripeService {
log.info("stripe异步通知进行中");
String payload = null;
String sigHeader = null;
String endpointSecret = "whsec_e0dBiJngx6qqgJj6yPyJ2A9ouh1Cjv5w";//webhook秘钥签名
String endpointSecret = signSecret;
try {
sigHeader = request.getHeader("Stripe-Signature");
payload = payPalCheckoutService.getBody(request);
@@ -296,7 +301,7 @@ public class StripeServiceImpl implements StripeService {
// 3、创建支付 paymentIntent
// 4、确认订单
// 5、捕获金额执行扣款操作
public static String createCustomer() throws StripeException {
public String createCustomer() throws StripeException {
Stripe.apiKey = privateKey;
// Customer允许重复使用
@@ -311,7 +316,7 @@ public class StripeServiceImpl implements StripeService {
return customer.getId();
}
public static String createPaymentMethod(String customerId) throws StripeException {
public String createPaymentMethod(String customerId) throws StripeException {
Stripe.apiKey = privateKey;
@@ -334,7 +339,7 @@ public class StripeServiceImpl implements StripeService {
return paymentMethod.getId();
}
public static String createPaymentIntent(String paymentMethodId, String customerId) throws StripeException {
public String createPaymentIntent(String paymentMethodId, String customerId) throws StripeException {
Stripe.apiKey = privateKey;
Long amount = 600L;
@@ -355,7 +360,7 @@ public class StripeServiceImpl implements StripeService {
return paymentIntent.getId();
}
public static String confirmPaymentIntent(String clientSecret) throws StripeException {
public String confirmPaymentIntent(String clientSecret) throws StripeException {
Stripe.apiKey = privateKey;
PaymentIntent resource = PaymentIntent.retrieve(clientSecret);