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

问题描述 投票:0回答:1

我在 Stripe 仪表板中创建了自定义付款配置 (https://dashboard.stripe.com/test/settings/ payment_methods) Stripe 为我提供了一个以“pmc_”开头的配置 ID

我的想法是我可以在某个地方使用这个 id 作为属性,但我发现没有办法在 SessionCreateParams 中做到这一点。 我发现的唯一的东西是 SessionCreateParams.PaymentMethodType 接受枚举。

这个解决方案对我来说也很好,但不幸的是这个枚举有点有限。 我想提供 Google Pay、Apple Pay 和 PayPal,但到目前为止我只能在 Strips 仪表板上选择此类付款,但没有枚举...

这是我到目前为止的服务(我使用了代码片段,因为代码片段总是存在格式问题)

@Service
@RequiredArgsConstructor
public class StripeService implements StripeServiceInterface {
    private PaymentsRepository paymentsRepository;

    private static void init() {
        Stripe.apiKey = "censored";
    }

    @Override
    public Map<String, String> createSession(StripeCheckoutDTO stripeCheckoutDTO) throws StripeException {
        init();

        SessionCreateParams params = SessionCreateParams.builder()
                .addPaymentMethodType(SessionCreateParams.PaymentMethodType.GIROPAY)
                .addPaymentMethodType(SessionCreateParams.PaymentMethodType.KLARNA)
                .addPaymentMethodType(SessionCreateParams.PaymentMethodType.CARD)
                .setMode(SessionCreateParams.Mode.PAYMENT)
                .setSuccessUrl("http://localhost:4200/payment-successful")
                .setCancelUrl("http://localhost:4200/payment-declined")
                .addLineItem(
                        SessionCreateParams.LineItem.builder()
                                .setQuantity(stripeCheckoutDTO.getQuantity())
                                .setPriceData(
                                        SessionCreateParams.LineItem.PriceData.builder()
                                                .setCurrency(stripeCheckoutDTO.getCurrency())
                                                .setUnitAmount(stripeCheckoutDTO.getAmount())
                                                .setProductData(
                                                        SessionCreateParams.LineItem.PriceData.ProductData.builder()
                                                                .setName(stripeCheckoutDTO.getName())
                                                                .build())
                                                .build())
                                .build())
                .build();

        Session session = Session.create(params);
        Map<String, String> responseData = new HashMap<>();

        responseData.put("id", session.getId());

        return responseData;
    }
}

我希望有人能告诉我如何激活PayPal等付款方式或如何使用Configuration-ID

java spring-boot stripe-payments payment-gateway
1个回答
0
投票

看起来 Stripe Java SDK 在 版本 23.5.0 中添加了对 PaymentMethodConfiguration 的支持。我建议确保您使用此版本(或更高版本)的 SDK,以便能够使用您在仪表板中创建的 PaymentMethodConfiguration。

这个片段在他们的文档中还展示了如何将其与SessionCreateParams一起使用:

.setPaymentMethodConfiguration("pmc_234")
© www.soinside.com 2019 - 2024. All rights reserved.