Javascript newb ie здесь. Попытка настроить новую версию Stripe checkout V3. Мне нужно получить идентификатор сеанса от HTML до моего Javascript в Rails.
HTML file:
<%= content_tag :div, id: "temp_information", data: {temp: @session.id} do %>
<% end %>
<div data-stripe="<%= @session.id %>">
<button id="checkout-button">Pay</button>
</div>
Javascript file:
var ses_id = $('#temp_information').data('temp');
alert(ses_id);
stripe.redirectToCheckout({
// Make the id field from the Checkout Session creation API response
// available to this file, so you can provide it as parameter here
// instead of the {{CHECKOUT_SESSION_ID}} placeholder.
sessionId: ses_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`.
});
Я получил неопределенное значение для ses_id. Когда я делаю
$('#temp_information').data('temp');
в консоли, он показывает правильный вывод. Но когда я делаю:
var a = $('#temp_information').data('temp');
Тогда я получаю неопределенное в консоли. Что я здесь не так делаю? Спасибо за вашу помощь!