开发者

Braintree "shopping cart"-like implementation in rails app / finding previous params[:id]?

开发者 https://www.devze.com 2023-02-01 19:39 出处:网络
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 w

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]开发者_StackOverflow社区)
  @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!


Short answer is you should be using a Cart model, connected to this Deposit model from what i can gather here. Based on other questions, however, that feeling could change.

So, solely based on what you wrote above:

If we follow a RESTful approach, you should be creating a Deposit#new for all new deposits.

In your Deposit#create, you would then put all of your logic into the deposit.rb model file. this logic includes, going to Braintree and such.

You say you are working with the deposits you already have, in that case, they should be handled in the Deposit#edit method.

Further questions I would ask of you in this regard, are you using ActiveMerchant? If not, why not?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号