Spring Boot Stripe -如何在Sping Boot 应用程序中使用配置ID

7kqas0il  于 2024-01-06  发布在  Spring
关注(0)|答案(1)|浏览(195)

我在Stripe Jmeter 板(https://dashboard.stripe.com/test/settings/payment_methods)中创建了一个自定义支付配置Stripe为我提供了一个以“pmc_”开头的配置ID
我的想法是,我可以在某个地方使用这个id作为属性,但我发现在会话参数中没有办法做到这一点。我唯一找到的是接受枚举的会话参数。PaymentMethodType。
这个解决方案也会对我来说很好,但不幸的是,这个枚举是有点有限.我想提供谷歌支付,苹果支付和贝宝,但到目前为止,我只能选择这样的付款条 Jmeter 板,但没有枚举它.
这是我的服务到目前为止(我使用了一个代码片段bcs代码片段总是有格式问题)

  1. @Service
  2. @RequiredArgsConstructor
  3. public class StripeService implements StripeServiceInterface {
  4. private PaymentsRepository paymentsRepository;
  5. private static void init() {
  6. Stripe.apiKey = "censored";
  7. }
  8. @Override
  9. public Map<String, String> createSession(StripeCheckoutDTO stripeCheckoutDTO) throws StripeException {
  10. init();
  11. SessionCreateParams params = SessionCreateParams.builder()
  12. .addPaymentMethodType(SessionCreateParams.PaymentMethodType.GIROPAY)
  13. .addPaymentMethodType(SessionCreateParams.PaymentMethodType.KLARNA)
  14. .addPaymentMethodType(SessionCreateParams.PaymentMethodType.CARD)
  15. .setMode(SessionCreateParams.Mode.PAYMENT)
  16. .setSuccessUrl("http://localhost:4200/payment-successful")
  17. .setCancelUrl("http://localhost:4200/payment-declined")
  18. .addLineItem(
  19. SessionCreateParams.LineItem.builder()
  20. .setQuantity(stripeCheckoutDTO.getQuantity())
  21. .setPriceData(
  22. SessionCreateParams.LineItem.PriceData.builder()
  23. .setCurrency(stripeCheckoutDTO.getCurrency())
  24. .setUnitAmount(stripeCheckoutDTO.getAmount())
  25. .setProductData(
  26. SessionCreateParams.LineItem.PriceData.ProductData.builder()
  27. .setName(stripeCheckoutDTO.getName())
  28. .build())
  29. .build())
  30. .build())
  31. .build();
  32. Session session = Session.create(params);
  33. Map<String, String> responseData = new HashMap<>();
  34. responseData.put("id", session.getId());
  35. return responseData;
  36. }
  37. }

字符串
我希望有人能告诉我如何激活付款,如贝宝或如何使用的验证码

4xrmg8kj

4xrmg8kj1#

看起来Stripe Java SDK在版本23.5.0中添加了对PaymentMethodConfiguration的支持。我建议您确保使用此版本(或更高版本)的SDK,以便能够使用您在 Jmeter 板中创建的PaymentMethodConfiguration。
他们的文档中的这个片段也展示了如何将其与会话参数一起使用:

  1. .setPaymentMethodConfiguration("pmc_234")

字符串

相关问题