我正在使用 Stripe 元素創建訂閱,一切都很好……除非數量支付意圖為 0 美元
來自 Stripe PaymentIntent 檔案:
The minimum amount is $0.50 US or equivalent in charge currency.
在這里,我有使用條紋元素創建付款意圖的方法
# 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 = "/" ;
}
});
});
簡而言之,除了付款意向為 0 美元且檔案顯示“最低為 0.50”外,一切對我來說都很好
有沒有辦法用 0 美元創建訂閱(即使金額為 0 美元,用戶也必須插入有效的信用卡/借記卡才能訂閱)?
例如:當我們訂閱herokuapp時,不花一分錢獲得更多特權,我們甚至需要一張有效的卡,這樣我們就可以訂閱heroku特權
謝謝你的時間
uj5u.com熱心網友回復:
對于使用創建的訂閱payment_behavior: default_incomplete并且第一個發票為 $0,您應該在pending_setup_intent(請參閱api ref)獲取設定意圖。您不能為此使用付款意圖,因為如果沒有付款到期,Stripe 不會為發票生成付款意圖。
您可以使用此 SetupIntent 來收集 Card 元素的付款詳細資訊,然后使用stripe.confirmCardSetup(請參閱api ref)完成卡的配置以備將來使用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/390028.html
標籤:javascript 红宝石轨道 红宝石 条纹支付
