订阅折扣历史

Subscription discount history

我正在制作一个账单历史页面,以根据 braintree 订阅向客户展示。虽然 braintree api 通常具有我需要的所有信息,但我在 discounts.

方面遇到了麻烦

在 braintree 控制面板中,订阅将在交易部分下方显示一个 'history' 部分,该部分跟踪订阅 price/balance 中的变化。此部分的数据可以在 Subscription result object 下的 status_history 中找到(供参考,我使用的是 python api)。

我找不到的一个数据是打折历史。在历史部分,Add-ons/Discounts 列将显示特定历史事件的折扣次数和总折扣金额。

在订阅结果对象中,status_history列表没有折扣信息,discounts列表似乎只包含尚未应用的折扣(使其无法用于历史目的) .

所以,我想我的问题是:有没有办法通过 braintree python api 检索折扣列表,其中包含日期等历史信息 created/applied和优惠金额?

编辑:我也检查了 braintree 节点库。我获取了用于 python 库的相同订阅。当最近没有折扣时,订阅结果对象也有一个空的 discounts 列表。

编辑 2: 这是我访问订阅的方法:

在 braintree 控制面板中,在特定订阅的页面上,有一个订阅 ID 条目:

在同一页面上,在 "History" 部分的底部,我可以看到在某些时候,订阅有折扣:

所以我在 python:

抢订阅
In [1]: import braintree
In [2]: sub = braintree.Subscription.find('fkr6sr')
In [3]: sub.id
Out[3]: u'fkr6sr'
In [4]: sub.discounts
Out[4]: []

我希望 sub.discounts 正好有一个条目。

最终编辑:为了将来参考,空 sub.discounts 是预期的行为。参见 。我已将父 post 标记为答案。

完全披露:我在 Braintree 工作。如果您有任何其他问题,请随时联系 support.

订阅结果对象具有属性 add_ons and discounts,这些属性是相应对象的数组。您可以根据 Discount.current_billing_cycle 属性结合 Subscription.next_billing_date 属性推断应用修改的日期,以及根据 Discount.amountDiscount.quantity 绘制的总修改量.

一个示例实现可能如下所示:

subscription_result_object = (Subscription.search(...)).first
discount = subscription_result_object.discounts[0]
billing_period = subscription_result_object.billing_period_end_date - subscription_result_object.billing_period_start_date
discount_start_date = subscription_result_object.next_billing_date - (discount.current_billing_cycle * billing_period)
total_discount = discount.amount * discount.quantity