我正在尝试编写一个ruby rails rake任务,列出订阅已过期的所有条带客户?我看过条纹api,但看不清楚如何检索这些信息。
亲切的问候
Gurdipe
答案 0 :(得分:0)
我能想到的最好的事情是从每个客户的条带中获取客户订阅状态:
2.1.1 :082 > a =Stripe::Customer.all.collect{|c| c.subscriptions.collect{|s| [c.id, s.status]}}.reject(&:empty?)
=> [[["cus_5VT4xC8uCoVIV5", "trialing"]], [["cus_5VT4Oh4AX74vqN", "trialing"]], [["cus_5VT4GFL6pPvsmH", "trialing"]], [["cus_5VT4uePgqT4Rrz", "trialing"]], [["cus_5VT4F8c8iK9cG8", "trialing"]], [["cus_5VT4zO0iMjoKsu", "trialing"]], [["cus_5VT4XQkAKCmRmg", "trialing"]]]
2.1.1 :083 >
在我的情况下,他们都是演示客户,所以他们都有试用状态,接下来你应该循环这个以节省客户哪个订阅状态等于active
或trial
并保存到变量中,然后使用条带中的客户ID,您可以在应用中找到用户。
P.S。如果你需要它作为json(丑陋,但是......你能做什么):
2.1.1 :111 > b = a.map{|r| "#{r[0][0]}, #{r[0][1]}"}.join(', ').split(', ')
=> ["cus_5VT4xC8uCoVIV5", "trialing", "cus_5VT4Oh4AX74vqN", "trialing", "cus_5VT4GFL6pPvsmH", "trialing", "cus_5VT4uePgqT4Rrz", "trialing", "cus_5VT4F8c8iK9cG8", "trialing", "cus_5VT4zO0iMjoKsu", "trialing", "cus_5VT4XQkAKCmRmg", "trialing"]
2.1.1 :112 > h = Hash[*b]
=> {"cus_5VT4xC8uCoVIV5"=>"trialing", "cus_5VT4Oh4AX74vqN"=>"trialing", "cus_5VT4GFL6pPvsmH"=>"trialing", "cus_5VT4uePgqT4Rrz"=>"trialing", "cus_5VT4F8c8iK9cG8"=>"trialing", "cus_5VT4zO0iMjoKsu"=>"trialing", "cus_5VT4XQkAKCmRmg"=>"trialing"}
2.1.1 :113 >
<强>更新强>
https://stripe.com/docs/api#pagination使用starting_after
和ending_before
参数来浏览条带客户记录。