简体   繁体   English

如何创建支付意图等于 $ 0 的条带或其他替代方案的订阅?

[英]How to create subscriptions with payment intent equal to $ 0 in stripe or some alternative to it?

I'm using Stripe element to create subscriptions and everything is fine... except when quantity payment intent is $0我正在使用 Stripe 元素创建订阅,一切都很好......除非数量支付意图是 0 美元

From the Stripe PaymentIntent docs:来自 Stripe PaymentIntent 文档:

 The minimum amount is $0.50 US or equivalent in charge currency.

Here I have the method to create a payment intention with the stripe element在这里,我有使用条纹元素创建付款意图的方法

# Here I created an object of type subscription incompletely (@subscription)
# In such a way that the user can enter their credit card and with the help of 
# @subscriptions confirm if everything is fine
def checkout
    @subscription = Stripe::Subscription.create(
      customer: current_user.stripe_customer_id, # stripe customer_id for suscription 
      items: [{
        price: params[:price] # attached price of suscription plans
      }],
      payment_behavior: 'default_incomplete', # PaymentIntent with status=incomplete
      expand: ['latest_invoice.payment_intent'] # return the payment_intent data
    )
end

And it displays a checkout.html.erb where it will allow the user to place their card and then pay

# checkout.html.erb
<form id="payment-form">
  <div class="form-row">
    <label for="card-element">
      <!-- Debit/credit card -->
    </label>

    <div id="card-element">
      <!-- a Stripe Element will be inserted here -->
    </div>

    <!-- Used to display Elements errors -->
    <div id="card-errors" role="alert"></div>
  </div>

  <button id="submit">Submit Payment</button>
</form>

<script>
   // Initialize stripe elements
   var stripe = Stripe("<%= ENV['STRIPE_PUBLISHABLE_KEY'] %>");
   var elements = stripe.elements();
   var cardElement = elements.create('card');
   cardElement.mount('#card-element');

   var formElement = document.getElementById('payment-form');

   formElement.addEventListener('submit', function(event) {
     event.preventDefault();

  # here I create the payment intention but when the plan has a subscription of $ 0 
  # it 
  # does not recognize me neither the field client_secret nor the payment_intent

  stripe.confirmCardPayment("<%= 
     @subscription.latest_invoice.payment_intent.client_secret %>", {
    payment_method: { card: cardElement }
     }).then(function(result) {
    if (result.error) {
      console.log(result.error.message);
      window.location.reload();
    } else {
      window.location.href = "/" ;
    }
  });

 });

In short, everything works fine for me except when the payment intention is $ 0 and the documentation says "the minimum is 0.50"简而言之,一切对我来说都很好,除非付款意图是 0 美元并且文档说“最低是 0.50”

Is there a way to create a subscription with $ 0 (that the user has to insert a valid credit / debit card in order to subscribe even if the amount is $ 0)?有没有办法用 0 美元创建订阅(即使金额为 0 美元,用户也必须插入有效的信用卡/借记卡才能订阅)?

For example: When we subscribe to herokuapp without putting a dollar to obtain more privileges we need even a valid card, so we can subscribe to heroku privileges例如:当我们订阅herokuapp而不花一美元获得更多权限时,我们甚至需要一张有效的卡,所以我们可以订阅heroku权限

Thanks for your time谢谢你的时间

For Subscriptions that are created with payment_behavior: default_incomplete and the first Invoice is $0 you should be getting back a Setup Intent at pending_setup_intent (see api ref ).对于使用payment_behavior: default_incomplete创建的订阅,并且第一张发票是 $0,您应该在pending_setup_intent取回设置意图(请参阅api 参考)。 You can't use a Payment Intent for this because Stripe won't generate a Payment Intent for the Invoice if no payment is due.您不能为此使用付款意向,因为如果没有到期付款,Stripe 不会为发票生成付款意向。

You can use this SetupIntent to collect payment details with the Card element and then use stripe.confirmCardSetup (see api ref ) to finish configuring the card for future usage.您可以使用此 SetupIntent 收集带有 Card 元素的付款详细信息,然后使用stripe.confirmCardSetup (请参阅api 参考)完成对卡的配置以供将来使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM