我无法在客户已有付款方式的情况下创建订阅.仪表板在新的订阅对象旁边只有一个"不完整"标记.

下面的端点接受客户ID和支付方法ID.其中大部分是从他们的示例中提取出来的,但我在其中添加了".setDefaultPaymentMethod"

@GetMapping("/subscriptions/create/{customerId}/{defaultPaymentMethod}")
public void createSubscription(@PathVariable String customerId, @PathVariable String defaultPaymentMethod) throws StripeException {

    Stripe.apiKey = "sk_test_XXXXX";
    String priceId = "XXXXX";

    // Automatically save the payment method to the subscription
    // when the first payment is successful.
    SubscriptionCreateParams.PaymentSettings paymentSettings =
            SubscriptionCreateParams.PaymentSettings
                    .builder()
                    .setSaveDefaultPaymentMethod(SubscriptionCreateParams.PaymentSettings.SaveDefaultPaymentMethod.ON_SUBSCRIPTION)
                    .build();

    // Create the subscription. Note we're expanding the Subscription's
    // latest invoice and that invoice's payment_intent
    // so we can pass it to the front end to confirm the payment
    SubscriptionCreateParams.Builder subCreateParams = SubscriptionCreateParams.builder()
            .setCustomer(customerId)
            .addItem(
                    SubscriptionCreateParams
                            .Item.builder()
                            .setPrice(priceId)
                            .build()
            )
            .setPaymentSettings(paymentSettings)
            .setDefaultPaymentMethod(defaultPaymentMethod)
            .setPaymentBehavior(SubscriptionCreateParams.PaymentBehavior.DEFAULT_INCOMPLETE)
            .setCollectionMethod(SubscriptionCreateParams.CollectionMethod.CHARGE_AUTOMATICALLY)
            .addAllExpand(Arrays.asList("latest_invoice.payment_intent"));

    Subscription subscription = Subscription.create(subCreateParams.build());
}

请注意,如果我最初从我的终结点创建订阅,并获得客户端秘密,该秘密用于通过Stride JavaScript/Reaction库收集支付信息,并让用户通过"stripe.confirmCardPayment"提交这些支付详细信息,则我能够创建成功的订阅.终结点如下:

@GetMapping("/subscriptions/create/{customerId}")
public void receiveCreateSubscriptionRequestWithoutPaymentMethod(@PathVariable String customerId) throws StripeException {

    Stripe.apiKey = "sk_test_XXXXX";
    String priceId = "XXXXX";

    // Automatically save the payment method to the subscription
    // when the first payment is successful.
    SubscriptionCreateParams.PaymentSettings paymentSettings =
            SubscriptionCreateParams.PaymentSettings
                    .builder()
                    .setSaveDefaultPaymentMethod(SubscriptionCreateParams.PaymentSettings.SaveDefaultPaymentMethod.ON_SUBSCRIPTION)
                    .build();

    // Create the subscription. Note we're expanding the Subscription's
    // latest invoice and that invoice's payment_intent
    // so we can pass it to the front end to confirm the payment
    SubscriptionCreateParams.Builder subCreateParams = SubscriptionCreateParams.builder()
            .setCustomer(customerId)
            .addItem(
                    SubscriptionCreateParams
                            .Item.builder()
                            .setPrice(priceId)
                            .build()
            )
            .setPaymentSettings(paymentSettings)
            .setPaymentBehavior(SubscriptionCreateParams.PaymentBehavior.DEFAULT_INCOMPLETE)
            .setCollectionMethod(SubscriptionCreateParams.CollectionMethod.CHARGE_AUTOMATICALLY)
            .addAllExpand(Arrays.asList("latest_invoice.payment_intent"));

    Subscription subscription = Subscription.create(subCreateParams.build());
}

有什么 idea 吗?

推荐答案

您将传入payment_behavior=default_incomplete-在订阅过渡到status=active之前,您需要确认第一张发票上的PaymentIntent.

https://stripe.com/docs/api/subscriptions/create#create_subscription-payment_behavior

Java相关问答推荐

为什么JFrame paint()多次绘制同一点(或根本不绘制)?

如何计算内循环的时间复杂度?

Javascript在边界中心调整ImageView大小

Apache POI:使用反射获取zoom 级别

如何使用AWS CLI从S3存储桶中的所有对象中删除用户定义的元数据?

第二次按下按钮后,我需要将按钮恢复到其原始状态,以便它可以再次工作

Com.google.firebase.database.DatabaseException:无法将类型为java.lang.Boolean的值转换为字符串.这是关于什么的?

在JDK 1.8源代码中,为什么使用A-B 0来确定哪个更大,而不是A B?

对字符串长度进行排序,但颠倒了顺序(最长字符串在前)

Docker不支持弹性APM服务器

声明带有泛型的函数以用作查找映射中的值

如何在一行中使用Dijkstra中的Java Stream

Java页面筛选器问题

Dijkstra搜索算法的实现

为什么创建Java动态代理需要接口参数

模拟JUnit未检测到返回字符串的方法的任何声纳覆盖

如何在Struts2中使用操作类中的结果注释重定向到不同的命名空间

Intellij 2023 IDE:始终在顶部显示菜单栏

如何在MPAndroidChart中的条形图上正确添加标签

java.exe如何执行java源代码?