1

In my rails 4 application I am using Braintree sandbox testing transaction gateway. I am able to perform transactions and the transaction details are visible in my sandbox account.But my question is how to store the Transaction details into a table in my database ?

For example : The transaction ID, amount, Customer details etc. ?

My Code is given bellow :

def payment_process  
    @paymentamnt=@@deviceprice.to_i
    @result = Braintree::Transaction.sale(
              amount: @paymentamnt,
              payment_method_nonce: params[:payment_method_nonce])
    if @result.success?
      redirect_to payments_customers_path
    else
      flash[:alert] = "Something went wrong while processing your transaction. Please try again!"
      gon.client_token = generate_client_token
      render :new
    end
end
Praveen George
  • 9,237
  • 4
  • 26
  • 53

1 Answers1

3

The values you are looking for are stored in the transaction object of @result.

So you can access them like this:

puts @result.transaction.amount
puts @result.transaction.order_id

etc.

Mike S
  • 11,329
  • 6
  • 41
  • 76
  • 1
    For a more comprehensive list of available attributes on `@result.transaction` you can check out the [Braintree reference docs](https://developers.braintreepayments.com/reference/response/transaction/ruby). I recommend storing at least the transaction id so you can make future API calls with it. – Ryan O'Donnell Oct 23 '15 at 14:45
  • @RyanO'Donnell : Thanks for the reply, I need one more help from you if possible, I need to get the status of all the payments done from braintree sandbox account in my website. How can I implement it ? – Praveen George Oct 26 '15 at 12:09
  • @PraveenGeorge In order to implement this, you would have to [find](https://developers.braintreepayments.com/reference/request/transaction/find/ruby) each transaction via the transaction `id`. Then you can access the [Braintree::Transaction#status](https://developers.braintreepayments.com/reference/response/transaction/ruby#status). You can also perform a [search](https://developers.braintreepayments.com/reference/general/searching/search-fields/ruby) to find transactions. – Ryan O'Donnell Oct 26 '15 at 18:24
  • @RyanO'Donnell : Thanks a lot for your help. – Praveen George Oct 27 '15 at 04:02