我无法在客户已有付款方式的情况下创建订阅.仪表板在新的订阅对象旁边只有一个"不完整"标记.
下面的端点接受客户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 吗?