Ich bekomme ständigWie wird die Verwendung von stripe v2 mit benutzerdefiniertem Formular mit Schienen geladen?
Streifen :: InvalidRequestError in ChargesController # Kunden cus_8fqEmSUxnGEO6g schafft keine verknüpfte Quelle mit ID tok_18OUXYLM1r6OYriq1WcKNB79 haben.
Ich bin mir nicht sicher, was das verursacht.
Hier ist meine Form:
<%= form_tag charges_path, id:"payment-form" do %>
<article>
<label class="amount">
<span>Price: <%= number_to_currency @booking.price %></span>
</label>
</article>
<%= hidden_field_tag 'booking_id', @booking.id %>
<div class="form-group">
<%= label_tag :card_number, "Credit Card Number" %>
<%= text_field_tag :card_number, nil, name: nil, data: {stripe: "number"}, value:"4242 4242 4242 4242", class:"form-control" %>
</div>
<div class="form-group">
<%= label_tag :card_code, "Security Code on Card (CVC)" %>
<%= text_field_tag :card_code, nil, name: nil, data: {stripe: "cvc"}, value:"123", class:"form-control" %>
</div>
<div class="form-group">
<%= label_tag :card_month, "Card Expiration" %>
<%= text_field_tag :card_month, nil, name: nil, data: {stripe: "exp"}, value:"12/17", class:"form-control" %>
</div>
<div class="card-errors">
</div>
<%= submit_tag 'Submit', class: "button round", id: "pay_now", class:"btn btn-success" %>
<% end %>
Hier mein Controller ist:
class ChargesController < ApplicationController
before_action :authenticate_user!
def create
token = params[:stripeToken]
# Amount in cents
@amount = (current_booking.price * 100).to_i
customer = Stripe::Customer.create(
:email => params[:stripeEmail]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => @amount,
:description => 'Content',
:currency => 'usd',
:source => token
)
redirect_to booking_path(current_booking), notice:"Thanks, your purchase was successful!"
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to "/bookings/new/?space_listing_id=#{@current_booking.space_listing_id}"
end
private
def current_booking
@current_booking ||= Booking.find(params[:booking_id])
end
end
Hier ist meine jQuery:
jQuery(function($) {
$('#payment-form').submit(function(event) {
var $form = $(this);
// Disable the submit button to prevent repeated clicks
$form.find('#pay_now').prop('disabled', true);
Stripe.card.createToken($form, stripeResponseHandler);
// Prevent the form from submitting with the default action
return false;
});
});
function stripeResponseHandler(status, response) {
var $form = $('#payment-form');
if (response.error) {
$("div.card-errors").text(response.error.message);
$form.find('#pay_now').prop('disabled', false);
} else {
// response contains id and card, which contains additional card details
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();
}
};
Es ist Arbeiten. Vielen Dank. –