Skip to content
Snippets Groups Projects
Commit bf13bf7c authored by Arnaud Levy's avatar Arnaud Levy
Browse files

fix

parent 7873f9d9
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,8 @@ class Sendinblue::SmsCreditsWarningJob < ApplicationJob
def perform
return unless ENV['APPLICATION_ENV'] == 'production'
if Sendinblue.SmsService.low?
if Sendinblue::SmsService.low?
sms_credits = Sendinblue::SmsService.sms_credits
# this message is sent to server_admins only, and server_admins are duplicated between all universities.
# so we take the first university
NotificationMailer.low_sms_credits(University.first, sms_credits).deliver_later
......
......@@ -4,10 +4,13 @@ module Sendinblue
SMS_CREDITS_LIMIT = 500
def self.low?
sms_credits.present? && sms_credits < SMS_CREDITS_LIMIT
end
def self.sms_credits
api_instance = SibApiV3Sdk::AccountApi.new
result = api_instance.get_account
sms_credits = result.plan.detect { |plan| plan.type == 'sms' }&.credits
sms_credits.present? && sms_credits < SMS_CREDITS_LIMIT
result.plan.detect { |plan| plan.type == 'sms' }&.credits
end
def self.send_mfa_code(user, code)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment