0
我能夠保存一個新客戶到我的網絡應用程序,但我無法給該客戶的信用卡。我相信我正確地遵循stripe.com的指示,但我似乎無法弄清楚。我使用的Ruby/Rails和HAML條紋卡沒有存儲,但客戶是
我的代碼如下
payment.html.haml:
= form_tag("", method: "POST", id: "payment-form") do
%span.payment-errors
.field
= label_tag :card_number, "Credit Card Number", class: "labelTag"
= text_field_tag :card_number, nil, {:class => "ss-form-control", :name => nil, "data-stripe" => "number"}
.field
= label_tag :card_code, "Security Code on Card (CVC)", class: "labelTag"
= text_field_tag :card_code, nil, {:class => "ss-form-control minilabel", :name => nil, "data-stripe" => "cvc"}
.field
= label_tag :card_month, "Card Expiration", class: "labelTag"
= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month", class: 'minilabel', "data-stripe" => 'exp-month'}
= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year", "data-stripe" => 'exp-year'}
%button.standardButton.btn.btn-sumbit{type: "submit"} Submit Payment
的application.js
Stripe.setPublishableKey('mykey');
$('#payment-form').submit(function(event) {
var $form = $(this);
alert('first')
// Disable the submit button to prevent repeated clicks
$form.find('button').prop('disabled', true);
Stripe.card.createToken($form, stripeResponseHandler);
// Prevent the form from submitting with the default action
return false;
});
var stripeResponseHandler = function(status, response) {
var $form = $('#payment-form');
if (response.error) {
// Show the errors on the form
$form.find('.payment-errors').text(response.error.message);
$form.find('button').prop('disabled', false);
} else {
alert('second');
// token contains id, last4, and card type
var token = response.id;
// Insert the token into the form so it gets submitted to the server
$form.append($('<input type="hidden" name="stripeToken" />').val(token));
// and submit
$form.get(0).submit();
}
};
user_controller。 rb
# Get the credit card details submitted by the form
token = params[:stripeToken]
# Create a Customer
customer = Stripe::Customer.create(
:card => token,
:description => current_user.email
)
能否請您發佈正在提交的PARAMS?這將有助於查看令牌是否通過表單提交。 –
@MartinLang這是我擁有的所有代碼。我是ruby/rails的新手,那麼如何通過params? –
不用擔心 - 在這裏提供幫助。 - 當您提交表格時,您的終端應該顯示您要提交的參數。參數是或多或少是請求的「主體」。在你的代碼中,你調用了token = params [:stripeToken],這意味着你正試圖從params中獲取stripeToken。 –