1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

sync members on stripe after keys update

This commit is contained in:
Sylvain 2020-06-09 14:27:18 +02:00
parent d5939a9de5
commit a70668f52a
5 changed files with 23 additions and 12 deletions

View File

@ -11,5 +11,8 @@ class SettingService
# notify about a change in privacy policy
NotifyPrivacyUpdateWorker.perform_async(id) if setting.name == 'privacy_body'
# sync all users on stripe
StripeWorker.perform_async(:sync_members) if %w[stripe_public_key stripe_secret_key].include? setting.name
end
end

View File

@ -5,6 +5,8 @@ class StripeWorker
include Sidekiq::Worker
sidekiq_options queue: :stripe
LOGGER = Sidekiq.logger.level == Logger::DEBUG ? Sidekiq.logger : nil
def perform(action, *params)
send(action, *params)
end
@ -41,4 +43,19 @@ class StripeWorker
cpn = Stripe::Coupon.retrieve(coupon_code)
cpn.delete
end
def sync_members
LOGGER&.debug ['StripeWorker', 'SyncMembers', 'We create all non-existing customers on stripe. This may take a while...']
total = User.online_payers.count
User.online_payers.each_with_index do |member, index|
LOGGER&.debug ['StripeWorker', 'SyncMembers' "#{index} / #{total}"]
begin
stp_customer = Stripe::Customer.retrieve member.stp_customer_id
create_stripe_customer(member.id) if stp_customer.nil? || stp_customer[:deleted]
rescue Stripe::InvalidRequestError
create_stripe_customer(member.id)
end
end
LOGGER&.debug ['StripeWorker', 'SyncMembers', 'Sync is done']
end
end

View File

@ -620,7 +620,7 @@ en:
online_payment_info_html: "You can enable your members to book directly online, paying by card. Alternatively, you can restrict the booking and payment processes for administrators and managers."
enable_online_payment: "Enable online payment"
stripe_keys: "Stripe keys"
stripe_keys_info_html: "<p>To be able to collect online payments, you must configure the <a href='https://stripe.com' target='_blank'>Stripe</a> API keys.</p><p>Retrieve them from <a href='https://dashboard.stripe.com/account/apikeys' target='_blank'>your dashboard</a>.</p>"
stripe_keys_info_html: "<p>To be able to collect online payments, you must configure the <a href='https://stripe.com' target='_blank'>Stripe</a> API keys.</p><p>Retrieve them from <a href='https://dashboard.stripe.com/account/apikeys' target='_blank'>your dashboard</a>.</p><p>Updating these keys will trigger a synchronization of all users on Stripe, this may take some time. You'll receive a notification when it's done.</p>"
public_key: "Public key"
secret_key: "Secret key"
error_check_keys: "Error: please check your Stripe keys."

View File

@ -620,7 +620,7 @@ fr:
online_payment_info_html: "Vous pouvez permettre à vos membres de réserver directement en ligne, en payment par carte bancaire. De manière alternative, vous pouvez restreindre les processus de réservation et de paiement aux administrateurs et aux gestionnaires."
enable_online_payment: "Activer le paiement en ligne"
stripe_keys: "Clefs Stripe"
stripe_keys_info_html: "<p>Pour pouvoir encaisser des paiements en ligne, vous devez configurer les clefs d'API <a href='https://stripe.com' target='_blank'>Stripe</a>.</p><p>Retrouvez les dans <a href='https://dashboard.stripe.com/account/apikeys' target='_blank'>votre tableau de bord</a>.</p>"
stripe_keys_info_html: "<p>Pour pouvoir encaisser des paiements en ligne, vous devez configurer les clefs d'API <a href='https://stripe.com' target='_blank'>Stripe</a>.</p><p>Retrouvez les dans <a href='https://dashboard.stripe.com/account/apikeys' target='_blank'>votre tableau de bord</a>.</p><p>Mettre à jour ces clefs entrainera une synchronisation de tous les utilisateurs vers Stripe, ceci peut prendre du temps. Vous recevrez une notification lorsque cela sera terminé.</p>"
public_key: "Clef publique"
secret_key: "Clef secrète"
error_check_keys: "Erreur : veuillez vérifier vos clefs Stripe."

View File

@ -49,16 +49,7 @@ namespace :fablab do
desc 'sync users to the stripe database'
task sync_members: :environment do
puts 'We create all non-existing customers on stripe. This may take a while, please wait...'
total = User.online_payers.count
User.online_payers.each_with_index do |member, index|
print_on_line "#{index} / #{total}"
begin
stp_customer = Stripe::Customer.retrieve member.stp_customer_id
StripeWorker.perform_async(:create_stripe_customer, member.id) if stp_customer.nil? || stp_customer[:deleted]
rescue Stripe::InvalidRequestError
StripeWorker.perform_async(:create_stripe_customer, member.id)
end
end
StripeWorker.perform(:sync_members)
puts 'Done'
end