我正在使用我的ruby on rails 5网站上的条纹为我的支付网关计划。我在客户端使用的应用程序接口与在this link中显示的一样。我需要将优惠券添加到我的计划中,我可以像计划一样在测试模式中的条纹仪表板中创建它,但将id添加到代码中并不会将我重定向到条纹结帐页面。这是我的javascript代码:
<script src="https://js.stripe.com/v3"></script>
<script type="text/javascript">
$(document).ready(function() {
var stripe = Stripe('<%= Rails.configuration.stripe[:publishable_key] %>');
$('.payment-action').on('click', function() {
const data = $(this).data();
const user_email = '<%= current_user ? current_user.email : ""%>'
const user = '<%= current_user.id%>'
stripe.redirectToCheckout({
lineItems: [{
// Define the product and price in the Dashboard first, and use the price
// ID in your client-side code. You may also pass a SKU id into the `price`
// field
price: data['plankey'],
quantity: 1
}],
customerEmail: user_email,
mode: 'subscription',
subscriptionData: {
coupon: 'WaS5wFHC'
},
successUrl: 'https://www.my_web.network/success_payment?session_id={CHECKOUT_SESSION_ID}&p_i='+data['plan']+'&us='+user,
cancelUrl: 'https://www.my_web.network/update_plan'
});
});
});
</script>
我一直在尝试使用subscription_data或subscriptionData让它出现在this page上,但仍然不能工作,我还会遗漏什么呢?
<script type="text/javascript">
$(document).ready(function() {
var stripe = Stripe('<%= Rails.configuration.stripe[:publishable_key] %>');
$('.payment-action').on('click', function() {
const data = $(this).data();
const user_email = '<%= current_user ? current_user.email : ""%>'
const user = '<%= current_user.id%>'
stripe.redirectToCheckout({
lineItems: [{
// Define the product and price in the Dashboard first, and use the price
// ID in your client-side code. You may also pass a SKU id into the `price`
// field
price: data['plankey'],
quantity: 1
}],
customerEmail: user_email,
mode: 'subscription',
subscription_data: {
coupon: 'WaS5wFHC'
},
successUrl: 'https://www.my_web.network/success_payment?session_id={CHECKOUT_SESSION_ID}&p_i='+data['plan']+'&us='+user,
cancelUrl: 'https://www.my_web.network/update_plan'
});
});
});
</script>
发布于 2020-08-28 14:20:57
这是不可能使用优惠券订阅在客户端唯一的结帐。您必须在传递优惠券ID:https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-coupon的服务器上创建一个结帐会话
https://stackoverflow.com/questions/63628351
复制相似问题