【发布时间】:2020-12-17 01:36:38
【问题描述】:
我在我的 ruby on rails 5 网站上为我的支付网关计划使用条纹。我在客户端使用 api,就像它出现在 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>
【问题讨论】:
标签: javascript ruby-on-rails-4 ruby-on-rails-5 stripe-payments coupon