rails 的 Braintree

Braintree for rails

我想显示我在 Braintree 中创建的计划的价格。我正在尝试通过 Braintree api 检索详细信息,方法是:Braintree::Plan.price

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

但是我收到了这个错误: undefined method price' for Braintree::Plan:Class

有人知道如何实现吗?

一种方法是通过 subscription_id(如果有)找到 Braintree::Subscription,然后从那里获取价格。

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

或者,您可以通过 plan_id 搜索 Braintree::Subscription,然后获取价格。

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

这两个例子都来自Braintree API Documentation for Subscription

最好使用类似以下内容的方法检索计划:Braintree::Plan.retrieve(plan_id),然后直接从那里获取计划的价格。但是,不幸的是,我在他们的 API Documentation for Plan.

中没有看到该选项

获取最新套餐价格:

Braintree::Plan.last.price

我明白了...只需要将参数["price"] 放入提交标签即可!!

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