Braintree 支付网关 - 获取客户的订阅详细信息
Braintree payment gateway - Get customer's subscriptions details
我在 Rails 应用程序中使用 Braintree 支付网关。我想知道我是否可以从中检索客户的订阅详细信息。根据文档,其中一种方法是 subscription = Braintree::Subscription.find(id)
创建订阅时,plan_id
和 amount
等基本对象被保存到数据库中。那么,如何检索与客户关联的订阅信息,例如 next_billing_date
?
假设您有一个订阅 ID:
# Find the subscription
subscription = Braintree::Subscription.find(sub_id)
# Access the subscription's next billing date
subscription.next_billing_date
Braintree::Subscription.find()
returns a Braintree::Subscription
result object.
假设您有一个客户 ID:
# Find the customer
customer = Braintree::Customer.find(cust_id)
# Retrieve the customer's first payment method
pm = customer.payment_methods.first
# Retrieve the subscriptions created with that payment method
subscriptions = pm.subscriptions
# Access the subscription's next billing date
subscriptions.first.next_billing_date
Braintree::Customer.find()
returns a Braintree::Customer
response object. The customer's payment methods can then be retrieved. Subscriptions are associated to payment methods. Once you have a payment method, you can retrieve an array of Braintree::Subscription
objects.
我在 Rails 应用程序中使用 Braintree 支付网关。我想知道我是否可以从中检索客户的订阅详细信息。根据文档,其中一种方法是 subscription = Braintree::Subscription.find(id)
创建订阅时,plan_id
和 amount
等基本对象被保存到数据库中。那么,如何检索与客户关联的订阅信息,例如 next_billing_date
?
假设您有一个订阅 ID:
# Find the subscription
subscription = Braintree::Subscription.find(sub_id)
# Access the subscription's next billing date
subscription.next_billing_date
Braintree::Subscription.find()
returns a Braintree::Subscription
result object.
假设您有一个客户 ID:
# Find the customer
customer = Braintree::Customer.find(cust_id)
# Retrieve the customer's first payment method
pm = customer.payment_methods.first
# Retrieve the subscriptions created with that payment method
subscriptions = pm.subscriptions
# Access the subscription's next billing date
subscriptions.first.next_billing_date
Braintree::Customer.find()
returns a Braintree::Customer
response object. The customer's payment methods can then be retrieved. Subscriptions are associated to payment methods. Once you have a payment method, you can retrieve an array of Braintree::Subscription
objects.