Stripe客户支付方法应用于其订阅者。

huangapple go评论68阅读模式
英文:

Stripe Customer paymentMethod applied to its subscribers

问题

以下是您要翻译的内容:

这是一个次要的问题,因为我认为我的之前的问题已经解决了。

这是我的用例:

  1. 客户(办公室)购买实体产品。我们在移动应用上收集信息,然后服务器创建一个Stripe客户和一个PaymentIntent。这成功了,正如Stripe门户所证明的那样。
  2. 当付款完成时,我的Web钩子事件会捕获“charge.succeeded”事件,我理解现在我有了一个paymentMethod,可以使用确认和重定向URL自动支付。然而,我一直没有成功尝试。
  3. 然后,我创建了一个订阅者,并且我想使用上述客户的付款方式来管理订阅支付。这个支付显示为不完整,我必须手动确认它。

以下是我在服务器端的处理方式:

  1. 创建支付意向:
Stripe.apiKey = API_SECRET_KEY;
long totalCharge = calcTotalCharge(purchaseRequest.getRequestedProducts());
PaymentIntentCreateParams paymentIntentCreateParams = PaymentIntentCreateParams.builder()
                .setCustomer(customer.getId())
                .setAmount(totalCharge)
                .setCurrency("usd")
                .setDescription(OFFICE_PURCHASE)
                .setSetupFutureUsage(SetupFutureUsage.OFF_SESSION)
                .setAutomaticPaymentMethods(PaymentIntentCreateParams.AutomaticPaymentMethods.builder()
                                .setEnabled(true)
                                .build())
                .build();

PaymentIntent paymentIntent = PaymentIntent.create(paymentIntentCreateParams);
SetupIntentCreateParams setupIntentParms =
                SetupIntentCreateParams.builder()
                                       .setCustomer(customer.getId())
                                       .addPaymentMethodType("card")
                                       .build();                                     

SetupIntent setupIntent = SetupIntent.create(setupIntentParms);

这一切似乎都是正确的。我使用paymentIntento与Stripe Elements完成订单。此时我无法设置确认或自动付款,因为我没有支付方法。

  1. Webhook事件 - 这会抛出异常:java.lang.RuntimeException: com.stripe.exception.InvalidRequestException: 收到未知参数:enabled、returnUrl、confirm;代码:parameter_unknown;请求ID:req_My6nCQVFVNbsSgtry
try {
  PaymentIntent paymentIntent = PaymentIntent.retrieve(charge.getPaymentIntent());
  Map<String, Object> automaticPaymentMethods = new HashMap<>();
  automaticPaymentMethods.put("enabled", true);
  automaticPaymentMethods.put("confirm", true);
  automaticPaymentMethods.put("returnUrl", "https://cnn.com"); // 这只是为了Stripe的要求,没有实际作用
  logger.info("webhook updating paymentIntent.automatic payment method as {}", paymentIntent);
} catch (StripeException e) {
throw new RuntimeException(e);
}

所以我卡住的地方是如何设置客户的paymentMethod以自动确认,因为订阅者将无法确认付款。我也不确定自定义URL方案或通用链接,尽管您提供了链接。

更新以回答回复

当客户付款收到时,Webhook会执行以下操作:
(我不再尝试设置automaticPaymentMethods)

PaymentIntent paymentIntent = PaymentIntent.retrieve(charge.getPaymentIntent());
paymentIntent.getAutomaticPaymentMethods().setEnabled(true);

String paymentMethod = charge.getPaymentMethod();
String customerId = charge.getCustomer();
Long chargeAmount = charge.getAmountCaptured();
// 现在我们可以使用paymentMethod更新待处理订单
try {
   Customer customer = Customer.retrieve(customerId);
   customer.update(CustomerUpdateParams.builder()
   .setInvoiceSettings(InvoiceSettings.builder()
   .setDefaultPaymentMethod(paymentMethod)
   .build())
   .build());
} catch (StripeException se) {
    logger.error("无法为客户{}设置paymentMethod{}", customerId, paymentMethod);
}
英文:

This is a secondary question as I thought my previously answered question was resolved.

Here is my use case:

  1. Customer (office) buys physical products. We collect the
    information on the mobile app and then the server creates a Stripe
    Customer and a PaymentIntent. This succeeds, as evidenced by
    Stripe portal
  2. When the payment is finalized, my web hook event captures the “charge.succeeded”
    event and it is my understanding that now that I have a
    paymentMethod I can set it up pay automatically with the confirm and
    redirect-url. However, no attempt by me has been successful.
  3. I then create a subscriber, and I want to use the above customer payment
    method to manage the subscription payment. The payment for this
    shows as incomplete, and I have to manually confirm it.

Here is how I am handling the server side:

  1. Create payment Intent:
Stripe.apiKey = API_SECRET_KEY;
long totalCharge = calcTotalCharge(purchaseRequest.getRequestedProducts());
PaymentIntentCreateParams paymentIntentCreateParams = PaymentIntentCreateParams.builder()
                .setCustomer(customer.getId())
                .setAmount(totalCharge)
                .setCurrency(&quot;usd&quot;)
                .setDescription(OFFICE_PURCHASE)
                .setSetupFutureUsage(SetupFutureUsage.OFF_SESSION)
                .setAutomaticPaymentMethods(PaymentIntentCreateParams.AutomaticPaymentMethods.builder()
                                .setEnabled(true)
                                .build())
                .build();

PaymentIntent paymentIntent = PaymentIntent.create(paymentIntentCreateParams);
SetupIntentCreateParams setupIntentParms =
                SetupIntentCreateParams.builder()
                                       .setCustomer(customer.getId())
                                       .addPaymentMethodType(&quot;card&quot;)
                                       .build();                                     

SetupIntent setupIntent = SetupIntent.create(setupIntentParms);

This all appears to be correct. I use the paymentIntento with the Stripe Elements to complete the order. I I cannot set the confirm or auto payment because I don’t have the payment method at this point.

  1. Webhook event - this throws an exception: java.lang.RuntimeException: com.stripe.exception.InvalidRequestException: Received unknown parameters: enabled, returnUrl, confirm; code: parameter_unknown; request-id: req_My6nCQVFVNbsSgtry
try {
  PaymentIntent paymentIntent = PaymentIntent.retrieve(charge.getPaymentIntent());
  Map&lt;String, Object&gt; automaticPaymentMethods = new HashMap&lt;&gt;();
  automaticPaymentMethods.put(&quot;enabled&quot;, true);
  automaticPaymentMethods.put(&quot;confirm&quot;, true);
  automaticPaymentMethods.put(&quot;returnUrl&quot;, &quot;https://cnn.com”); &lt;== this is just for Stripe   requirement, it does nothing
  logger.info(&quot;webhook updating paymentIntent.automatic payment method as {} &quot;, paymentIntent);
} catch (StripeException e) {
throw new RuntimeException(e);
}

So where I appear to be stuck is how do I set the customer paymentMethod to be applied as confirm automatically since the subscriber will not have the ability to confirm the payment. I also was uncertain about a custom URL scheme or an universal link, despite the links you provided.

Update to answer responses:

Webhook does this when customer payment is received:
(I am no longer trying to set the automaticPaymentMethods)

 PaymentIntent paymentIntent = PaymentIntent.retrieve(charge.getPaymentIntent());
paymentIntent.getAutomaticPaymentMethods().setEnabled(true);

 String paymentMethod = charge.getPaymentMethod();
 String customerId = charge.getCustomer();
 Long chargeAmount = charge.getAmountCaptured();
 // now we can update the pending order with the paymentMethod
 try {
   Customer customer = Customer.retrieve(customerId);
   customer.update(CustomerUpdateParams.builder()
   .setInvoiceSettings(InvoiceSettings.builder()
   .setDefaultPaymentMethod(paymentMethod)
   .build())
   .build());
  } catch (StripeException se) {
    logger.error(&quot;unable to customer {} the paymentMethod {}&quot;, customerId, paymentMethod);
 }

答案1

得分: 1

为了创建附加到客户的支付方式的订阅,您需要将其设置为客户的默认支付方式。具体来说,在customer.invoice_settings.default_payment_method 参数 上设置它。

一旦您这样做,订阅应该在创建时向默认支付方式收费。

至于您的第二个问题,我不完全理解您到底想做什么。支付意向的自动支付方式 参数 仅支持enabled属性。所以我不确定您为什么要在那里设置confirmreturnUrl。您是否在按照某个指南操作?

英文:

In order to create Subscriptions with customer's attached payment method, you need to set it as default payment method for the customer. Specifically on customer.invoice_settings.default_payment_method parameter

Once you do that, the subscription should charge the default payment method on creation.

For your second question, I don't fully understand what you're trying to do exactly. Automatic Payment Methods parameter on a PaymentIntent only supports enabled property. So not sure why you're trying to set confirm and returnUrl there. Are you following a guide for this?

huangapple
  • 本文由 发表于 2023年6月1日 22:35:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76383032.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定