0
たとえば、カードを意図的に使用しないと、エラーページが表示されます。そうですね: エラーページの代わりに、フラッシュで通知する必要があります。私は以下のコードを持っていますが、なぜフラッシュを使用して警告していませんか?ストライプ検証が失敗すると、なぜフラッシュが表示されないのですか?
class ChargesController < ApplicationController
def new
end
def create
# Amount in cents
@amount = 100
# Get the credit card details submitted by the form
customer = Stripe::Customer.create(
:email => params[:email],
:source => params[:stripeToken]
)
# Create the charge on Stripe's servers - this will charge the user's card
begin
Stripe::Charge.create(
:amount => @amount,
:currency => 'usd',
:customer => customer.id,
:description => 'Example charge custom form'
)
current_user.subscribed = true
current_user.stripe_id = customer.id
current_user.expiry_date = Date.today + 30.days
current_user.save
flash[:success] = "Thank you for subscribing. Your account has been unlocked."
redirect_to root_path
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to root_path
end
end
end
私は何かが欠けていない限り、これは何も変わっていないと思います! –
あなたはそれを試しましたか?他のすべての 'レスキュー 'が何もしなかったなら、' rescue => e'は何かをキャッチすべきです。 –