Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
630 views
in Technique[技术] by (71.8m points)

ruby on rails - Retrieving a Braintree customer's subscriptions

I want to collect all of a Braintree Customer's subscriptions. When I browse to a customer's page in the gateway, I can see their subscriptions, but it doesn't seem that a method like subscriptions exists for Braintree::Customer, or that I can search for Braintree::Subscriptions by customer_id.

There are roundabout ways that I can access all of a customer's subscriptions, but they are very slow. For example, I can retrieve all of the customer's transactions, and for each transaction, get the subscription_id (if it exists), and then retrieve the subscription with that ID. This involves a lot of communication with the Braintree API, and I was hoping for a more efficient solution.

Oh, and I'm programming this in rails, but the question doesn't seem Rails-specific.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I work at Braintree.

Customers have a credit_cards array, and each credit card has a subscriptions array. So, if you want all the subscriptions for a customer, you can do:

customer.credit_cards.map(&:subscriptions).flatten

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...