检索Braintree客户的订阅

bis*_*sej 16 ruby ruby-on-rails braintree

我想收集所有Braintree客户的订阅.当我浏览到网关中的客户页面时,我可以看到他们的订阅,但它似乎不是一种类似于subscriptions存在的方法Braintree::Customer,或者我可以搜索Braintree::Subscriptions的方法customer_id.

我可以通过迂回的方式访问所有客户的订阅,但它们非常慢.例如,我可以检索所有客户的事务,并为每个事务获取subscription_id(如果存在),然后检索具有该ID的订阅.这涉及与Braintree API的大量沟通,我希望有一个更有效的解决方案.

哦,我正在使用rails编程,但问题似乎不是特定于Rails的.

agf*_*agf 27

我在布伦特里工作.

客户有一个credit_cards阵列,每张信用卡都有一个subscriptions阵列.因此,如果您想要客户的所有订阅,您可以:

customer.credit_cards.map(&:subscriptions).flatten
Run Code Online (Sandbox Code Playgroud)

  • @ChristophGeschwind在Ruby中,您可以执行`customer.payment_methods.map(&:subscriptions).flatten`来获取它们,或者同时使用`customer.credit_cards`和`customer.paypal_accounts`来分别获取它们. (3认同)
  • @SonnyParlin [订阅有付款方式令牌](https://developers.braintreepayments.com/android+ruby/sdk/server/recurring-billing/details),这样您就可以[找到付款方式](https:// developers.braintreepayments.com/android+ruby/sdk/server/payment-method-management/search#single-payment-method).[付款方式有客户ID](https://developers.braintreepayments.com/android+ruby/reference/objects/credit-card#string-attributes),这样您就可以[找到客户](https://开发人员. braintreepayments.com/android+ruby/sdk/server/customer-management/search#single-customer). (3认同)
  • 我正在将node.js与braintree订阅集成.Braintree提供了很好的文档.但是,它缺乏实现完整订阅的完整流程的指南,我花了一整天才弄明白.因此,我写了一份指南,帮助那些想在这里使用braintree订阅服务的人http://enormers.com/blog/a-brief-guide-to-implement-braintree-subscription-with-node-js-and -mongodb / (3认同)