Created
October 30, 2019 20:32
-
-
Save breim/0136c6d3b7a067b8266705a3603f97d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
namespace :plans do | |
task renew: :environment do | |
users = User.where(plan_status: true, plan_date: Date.today - 1.month) | |
next if users.empty? | |
users.each do |user| | |
transaction = PlanPayment.bill_card(user.card_id) | |
if transaction.status == 'paid' | |
user.update(plan_date: Date.today) | |
PlanPayment.create(user_id: user.id, pagarme_transaction_id: transaction.id, card_brand: transaction.card.brand, | |
card_last_digits: transaction.card.last_digits, price: ENV['plan_price'].to_f / 100) | |
else | |
# Criar email informando que nao foi autorizada a transacao. Mandar no minimo 3 emails no futuro. | |
user.update(plan_status: false) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment