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

7kqas0il  于 5个月前  发布在  Spring
关注(0)|答案(1)|浏览(83)

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

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

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

4xrmg8kj

4xrmg8kj1#

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

.setPaymentMethodConfiguration("pmc_234")

字符串

相关问题