-1

I want to show the price of a plan I created in Braintree. I'm trying to retrieve the details via the the Braintree api by using this: Braintree::Plan.price

<%= form_tag transactions_path do%>
  <div id="dropin"></div>
  <%=submit_tag "Pay #{Braintree::Plan.price}$", class: "button mt1" %>

But I'm getting this error: undefined method price' for Braintree::Plan:Class

Does someone know how to implement this?

Theopap
  • 715
  • 1
  • 10
  • 33
  • 1
    Is price a class method? It seems like you are calling an instance method on a class... – Eric Jul 05 '17 at 20:03
  • Thanks for the reply @Eric!!! No it's not a class method. – Theopap Jul 05 '17 at 20:13
  • You are calling an instance method on a class there... try calling it on an object... ex. `Braintree::Plan.last.price` – Eric Jul 05 '17 at 20:14

2 Answers2

0

One way would be to find the Braintree::Subscription by the subscription_id (if you have one) and then get price from there.

Braintree::Subscription.find("a_subscription_id").price

Or, you can search for Braintree::Subscription by a plan_id and then get the price.

Braintree::Subscription.search do |search|
  search.plan_id.is "the_plan_id"
end.first.price

Both of these examples are taken from Braintree API Documentation for Subscription

It would be nice to retrieve a plan using something like: Braintree::Plan.retrieve(plan_id) and then get the price of the plan directly from there. But, unfortunately, I don't see that option in their API Documentation for Plan.

To get the price of the latest plan:

Braintree::Plan.last.price
K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110
0

I got it... just had to put params["price"] into the submit tag!!

<%=submit_tag "Pay #{params["price"]}$", class: "button mt1" %>

Theopap
  • 715
  • 1
  • 10
  • 33