Rails アプリで何か変なことをする必要があります。ユーザーが create アクションを介して Product インスタンスを作成したら、それを保存してから、アカウントにまだ追加していない場合は Braintree 支払い方法フォームにリダイレクトする必要があります。製品。
商品の作成アクションは次のとおりです。
def create
@product = Product.new(product_params)
@product.set_user!(current_user)
if @product.save
if !current_user.braintree_customer_id?
redirect_to "/customer/new"
else
redirect_to view_item_path(@product.id)
end
else
flash.now[:alert] = "Woops, looks like something went wrong."
format.html {render :action => "new"}
end
end
Braintree カスタマー コントローラーの確認メソッドは次のとおりです。
def confirm
@result = Braintree::TransparentRedirect.confirm(request.query_string)
if @result.success?
current_user.braintree_customer_id = @result.customer.id
current_user.customer_added = true
current_user.first_name = @result.customer.first_name
current_user.last_name = @result.customer.last_name
current_user.save!
redirect_to ## not sure what to put here
elsif current_user.has_payment_info?
current_user.with_braintree_data!
_set_customer_edit_tr_data
render :action => "edit"
else
_set_customer_new_tr_data
render :action => "new"
end
end
私がやりたいことは可能ですか?