问题描述
我在第5栏上的红宝石中拥有我的网站,并且我正在使用this link更新我的条纹支付网关,但是单击我的按钮不会将我重定向到条纹结帐,这就是我在控制器中所拥有的:
def index
Stripe.api_key = Rails.configuration.stripe[:secret_key]
session = Stripe::Checkout::Session.create(
payment_method_types: ['card'],line_items: [{
price: 'price_1HKywnBS16ZK5Vr3GYCRvTir',quantity: 1,}],mode: 'subscription',success_url: 'https://www.my_site.network/success?session_id={CHECKOUT_SESSION_ID}',cancel_url: 'https://www.my_site.network/cancel',)
end
我认为该错误可能是在替换索引视图的javascript代码中的会话ID时出现的:
<button id="checkout-button">Pay</button>
<script src="https://js.stripe.com/v3/"></script>
<script type="text/javascript">
var stripe = Stripe('<%= Rails.configuration.stripe[:publishable_key] %>');
var checkoutButton = document.getElementById('checkout-button');
checkoutButton.addEventListener('click',function() {
stripe.redirectToCheckout({
// Make the id field from the Checkout Session creation API response
// available to this file,so you can provide it as argument here
// instead of the {{CHECKOUT_SESSION_ID}} placeholder.
sessionId: '<%=session.id%>'
}).then(function (result) {
// If `redirectToCheckout` fails due to a browser or network
// error,display the localized error message to your customer
// using `result.error.message`.
});
});
</script>
解决方法
您不必使用''。 您必须使用的值是您执行以下操作时存储在会话中的全部值:控制器中的Stripe :: Checkout :: Session.create 。>