I'm trying to integrate Braintree into my rails app which already has a deposits controller, model, and view. Right now basically you can specify an amount but I have its status set to "Pending". I would like it so that the user can make such a deposit but then pay for it at any time using Braintree (ala shopping cart). Would I have to create another controller and/or model to do this? (For example all the Braintree examples I've seen want the payment immediately).
Specifically, I've been trying to just work with the 'deposits' I already have. I put the form for the user's name, credit card info, etc. on the deposits "show" page and a confirm button. This seems to work fine if all fields satisfy validation, however it doesn't when there is an error and renders the show page again. In DepositsController.rb:
def confirm
@deposit = Deposit.find(params[:id])
@result = Braintree::TransparentRedirect.confirm(request.query_string)
if @result.success?
render :action => "confirm"
else
render :action => "show"
end
end
The problem is that :id
now is the Braintree transaction ID, rather than the deposits id (primary key). So of course Deposit.find(params[:id])
can't be found.
What is the best way to implement this? Should I store the previous id somehow or get it another way? Should I be using another controller? Thanks!