Skip to content

Commit

Permalink
feat: centralize determine payment status
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomiguelpinto committed Dec 20, 2024
1 parent 36ce766 commit 3f591bc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions db/migrate/20241220095049_backfill_payable_payment_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

class BackfillPayablePaymentStatus < ActiveRecord::Migration[7.1]
def change
provider_types = PaymentProviders::BaseProvider.distinct.pluck(:type)
provider_types.each do |provider_type|
provider_class = provider_type.constantize

payments = Payment.joins(:payment_provider)
.where(payment_providers: {type: provider_type}, status: provider_class::PENDING_STATUSES)
payments.update_all(payable_payment_status: :pending)

payments = Payment.joins(:payment_provider)
.where(payment_providers: {type: provider_type}, status: provider_class::SUCCESS_STATUSES)
payments.update_all(payable_payment_status: :succeeded)

payments = Payment.joins(:payment_provider)
.where(payment_providers: {type: provider_type}, status: provider_class::FAILED_STATUSES)
payments.update_all(payable_payment_status: :failed)
end
end
end

0 comments on commit 3f591bc

Please sign in to comment.