I am trying to write a ruby rails rake task that lists all the stripe customers whose subscriptions have expired? I have looked at the stripe api but do can't see how I can retrieve this information.
Kind Regards
Gurdipe
I am trying to write a ruby rails rake task that lists all the stripe customers whose subscriptions have expired? I have looked at the stripe api but do can't see how I can retrieve this information.
Kind Regards
Gurdipe
The best thing I could think of is to get the customer subscription statuses from stripe for each customer:
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 >
In my case they are all demo customers so they all have trial status, next you should loop through this to save customers which subscription status is equal to active
or trial
and save into a variable, then using customer id from stripe you can find users in your app.
p.s. In case you need it as json (ugly, but... what can you do):
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 >
update
https://stripe.com/docs/api#pagination use starting_after
and ending_before
params to navigate trough stripe customers records.