mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
rake task to sync users with stripe
This commit is contained in:
parent
60755a2c2a
commit
f50e45d2de
@ -14,6 +14,7 @@
|
|||||||
- Handle Ctrl^C in upgrade scripts
|
- Handle Ctrl^C in upgrade scripts
|
||||||
- Updated moment-timezone
|
- Updated moment-timezone
|
||||||
- Added freeCAD files as default allowed extensions
|
- Added freeCAD files as default allowed extensions
|
||||||
|
- Rake task to sync local users with Stripe
|
||||||
- Fix a bug: unable to remove the picture from a training
|
- Fix a bug: unable to remove the picture from a training
|
||||||
- Fix a bug: no alerts on errors during admin creation
|
- Fix a bug: no alerts on errors during admin creation
|
||||||
- Fix a bug: replaces all Time.now by DateTime.current to prevent time zones issues [Taiga#134]
|
- Fix a bug: replaces all Time.now by DateTime.current to prevent time zones issues [Taiga#134]
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# This worker perform various requests to the Stripe API (payment service)
|
||||||
class StripeWorker
|
class StripeWorker
|
||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
sidekiq_options :queue => :stripe
|
sidekiq_options queue: :stripe
|
||||||
|
|
||||||
def perform(action, *params)
|
def perform(action, *params)
|
||||||
send(action, *params)
|
send(action, *params)
|
||||||
@ -18,8 +21,8 @@ class StripeWorker
|
|||||||
def create_stripe_coupon(coupon_id)
|
def create_stripe_coupon(coupon_id)
|
||||||
coupon = Coupon.find(coupon_id)
|
coupon = Coupon.find(coupon_id)
|
||||||
stp_coupon = {
|
stp_coupon = {
|
||||||
id: coupon.code,
|
id: coupon.code,
|
||||||
duration: coupon.validity_per_user,
|
duration: coupon.validity_per_user
|
||||||
}
|
}
|
||||||
if coupon.type == 'percent_off'
|
if coupon.type == 'percent_off'
|
||||||
stp_coupon[:percent_off] = coupon.percent_off
|
stp_coupon[:percent_off] = coupon.percent_off
|
||||||
@ -28,13 +31,8 @@ class StripeWorker
|
|||||||
stp_coupon[:currency] = Rails.application.secrets.stripe_currency
|
stp_coupon[:currency] = Rails.application.secrets.stripe_currency
|
||||||
end
|
end
|
||||||
|
|
||||||
unless coupon.valid_until.nil?
|
stp_coupon[:redeem_by] = coupon.valid_until.to_i unless coupon.valid_until.nil?
|
||||||
stp_coupon[:redeem_by] = coupon.valid_until.to_i
|
stp_coupon[:max_redemptions] = coupon.max_usages unless coupon.max_usages.nil?
|
||||||
end
|
|
||||||
stp_coupon
|
|
||||||
unless coupon.max_usages.nil?
|
|
||||||
stp_coupon[:max_redemptions] = coupon.max_usages
|
|
||||||
end
|
|
||||||
|
|
||||||
Stripe::Coupon.create(stp_coupon)
|
Stripe::Coupon.create(stp_coupon)
|
||||||
end
|
end
|
||||||
|
@ -61,6 +61,7 @@ Retrieve them from https://dashboard.stripe.com/account/apikeys.
|
|||||||
|
|
||||||
**MANDATORY**: Even if you don't want to charge your customers, you must fill this settings.
|
**MANDATORY**: Even if you don't want to charge your customers, you must fill this settings.
|
||||||
For this purpose, you can use a stripe account in test mode, which will provide you test keys.
|
For this purpose, you can use a stripe account in test mode, which will provide you test keys.
|
||||||
|
If you change these keys during the application lifecycle, you must run `rake fablab:stripe:sync_members`, otherwise your users won't be able to do card payments.
|
||||||
<a name="STRIPE_CURRENCY"></a>
|
<a name="STRIPE_CURRENCY"></a>
|
||||||
|
|
||||||
STRIPE_CURRENCY
|
STRIPE_CURRENCY
|
||||||
@ -229,7 +230,7 @@ The check will run every weeks and if the threshold is exceeded, an alert will b
|
|||||||
ADMIN_EMAIL, ADMIN_PASSWORD
|
ADMIN_EMAIL, ADMIN_PASSWORD
|
||||||
|
|
||||||
Credentials for the first admin user created when seeding the project.
|
Credentials for the first admin user created when seeding the project.
|
||||||
By default, theses variables are not present in application.yml because they are only used once, when running the database seed with the command `rake db:seed.
|
By default, theses variables are not present in application.yml because they are only used once, when running the database seed with the command `rake db:seed`.
|
||||||
<a name="SUPERADMIN_EMAIL"></a>
|
<a name="SUPERADMIN_EMAIL"></a>
|
||||||
|
|
||||||
SUPERADMIN_EMAIL
|
SUPERADMIN_EMAIL
|
||||||
|
@ -45,5 +45,17 @@ namespace :fablab do
|
|||||||
File.write(cassette_file, cassette)
|
File.write(cassette_file, cassette)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'sync users to the stripe database'
|
||||||
|
task sync_members: :environment do
|
||||||
|
User.with_role(:member).each do |member|
|
||||||
|
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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user