1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

task to reset the stripe payment methods in test mode

This commit is contained in:
Sylvain 2021-05-31 16:15:57 +02:00
parent d0011a10f0
commit 28e41de9ad
3 changed files with 22 additions and 1 deletions

View File

@ -8,6 +8,8 @@
- Improved the style of the titles of the subscription page
- Check the status of the assets' compilation during the upgrade
- Footprints are now generated in a more reproductible way
- Task to reset the stripe payment methods in test mode
- Validate on server side the reservation of slots restricted to subscribers
- Fix a bug: build status badge is not working
- Fix a bug: unable to set date formats during installation
- Fix a bug: unable to cancel the upgrade before it begins

View File

@ -11,7 +11,7 @@ class SyncMembersOnStripeWorker
User.online_payers.each_with_index do |member, index|
logger.debug "#{index} / #{total}"
begin
stp_customer = member.payment_gateway_objects.gateway_object.retrieve
stp_customer = member.payment_gateway_object.gateway_object.retrieve
StripeWorker.new.create_stripe_customer(member.id) if stp_customer.nil? || stp_customer[:deleted]
rescue Stripe::InvalidRequestError
StripeWorker.new.create_stripe_customer(member.id)

View File

@ -78,6 +78,25 @@ namespace :fablab do
end
end
# in test, we may reach a point when the maximum number of payment methods attachable to a customer is reached.
# Use this task to reset them all and be able to run the test suite again.
desc 'remove cards payment methods from all customers'
task reset_cards: :environment do
unless Rails.env.test?
print "You're about to detach all payment cards from all customers. This was only made for test mode. Are you sure? (y/n) "
confirm = STDIN.gets.chomp
next unless confirm == 'y'
end
User.all.each do |user|
stp_customer = user.payment_gateway_object.gateway_object.retrieve
cards = Stripe::PaymentMethod.list({ customer: stp_customer, type: 'card' }, { api_key: Setting.get('stripe_secret_key') })
cards.each do |card|
pm = Stripe::PaymentMethod.retrieve(card.id, api_key: Setting.get('stripe_secret_key'))
pm.detach
end
end
end
def print_on_line(str)
print "#{str}\r"
$stdout.flush