All threads / How do I add the amount stored in my database to Braintree::Transaction.Sale?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I add the amount stored in my database to Braintree::Transaction.Sale?

RicePad asked in Ruby

Hi all, I'm new to this community and also new to Ruby on Rails. I recently watched the Braintree integration screencast by Chris and I've been playing around with its Sand box integration.

I was able to make a successful check out with a hard coded amount i.e:

        def checkout
            nonce = params[:payment_method_nonce]
            result = Braintree::Transaction.sale(
             ** :amount => "15.00",**
            :payment_method_nonce => nonce,
            :options => {
            :submit_for_settlement => true} )
     end

Let's say I want a current_user to be able to purchase access to my portofolio for a specific "price" which has been stored in the database. Is there a way to set the amount by pulling it from an a object's attributes from the database i.e: "<[email protected]_item.price>" ?? I've tried multiple attempts and didn't have any luck. I feel like I'm not understanding how Braintree really works.

Am not known with the BT api, but one thing to check is in what way BT expects the price, eg. Stripe expects it to be in cents ($15 would be 1500).

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 34,885+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.