如何创建支付意向等于 0 美元的条带或其他替代方案的订阅?
How to create subscriptions with payment intent equal to $ 0 in stripe or some alternative to it?
我正在使用 Stripe 元素创建订阅,一切正常...除非数量支付意向为 0 美元
来自 Stripe PaymentIntent 文档:
The minimum amount is [=10=].50 US or equivalent in charge currency.
这里我有使用stripe元素创建支付意向的方法
# 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特权
感谢您的宝贵时间
我正在使用 Stripe 元素创建订阅,一切正常...除非数量支付意向为 0 美元
来自 Stripe PaymentIntent 文档:
The minimum amount is [=10=].50 US or equivalent in charge currency.
这里我有使用stripe元素创建支付意向的方法
# 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特权
感谢您的宝贵时间