Stripe documentation on errorsを見てきましたが、これらのエラーを適切に処理/リダイレクトするのにまだ問題があります。基本的に何が起こっても、私は彼らにedit
アクション(edit_profile_path
経由)に戻り、メッセージを表示します(成功したかどうかにかかわらず)。ストリーミングエラーと例外を適切に処理するRuby with one-time charge
私はedit
アクションのフォームに、update
アクションへのPOSTがあります。これは、有効なクレジットカードで正しく機能しています(料金はストライプダッシュボードにあります)。私はStripe.jsを使用しています。あなたは今がredirect_to
にフラッシュメッセージを渡すことができますが
class ExtrasController < ApplicationController
def edit
@extras = current_user.extras
end
def update
Stripe.api_key = "hidden"
token = params[:stripeToken]
begin
charge = Stripe::Charge.create(
:amount => 5000, # amount in cents
:currency => "usd",
:card => token,
:description => current_user.email
)
rescue Stripe::CardError => e
# redirect_to edit_extras_path, notice: e.message
# What I'm trying to do, but obviously results in AbstractController::DoubleRenderError
rescue => e
# Something else happened, completely unrelated to Stripe
# Display a generic error message
end
redirect_to edit_extras_path, notice: "Card charged successfully."
end
end
チャンスが得られたら、このロジックをモデルに移動することをお勧めします。 – tommyd456
私はこれを投稿してからやっています。しかし、お勧めはありがたいです。 – gbdev
いい男 - 実際に私を専用のサービスオブジェクトに移動しましたが、それはどのモデルにも適合しないと感じました。 – tommyd456