Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module StripeCustomersHelper
- PLANS = [
- :new_member_monthly,
- :current_member_monthly,
- :new_member_annual,
- :current_member_annual
- ]
- def get_stripe_customers
- each_customer do |customer|
- unless has_member_subscription?(customer)
- puts customer.email
- end
- end
- end
- private
- def has_member_subscription?(customer)
- subscription_presence = false
- card_presence = false
- customer.sources.data.each do |source|
- if source.object == 'card'
- card_presence = true
- break
- end
- end
- return true unless card_presence
- customer.subscriptions.data.each do |subscription|
- if PLANS.include?(subscription.plan.id.to_sym)
- subscription_presence = true
- break
- end
- end
- subscription_presence
- end
- def each_customer
- starting_after = nil
- loop do
- customers = Stripe::Customer.all(limit: 100, starting_after: starting_after)
- break if customers.data.length == 0
- customers.each do |customer|
- yield customer
- end
- starting_after = customers.data.last.id
- end
- end
- end
Add Comment
Please, Sign In to add comment