Skip to content

Instantly share code, notes, and snippets.

@cjdenio
Created March 22, 2023 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjdenio/acbad94521af98cf30c2201466182253 to your computer and use it in GitHub Desktop.
Save cjdenio/acbad94521af98cf30c2201466182253 to your computer and use it in GitHub Desktop.
From 7e9a3cb87ce887942dc1871c9af87c39cf40ba90 Mon Sep 17 00:00:00 2001
From: Max Wofford <max@maxwofford.com>
Date: Mon, 14 Sep 2020 20:03:55 +0000
Subject: [PATCH] Project balance includes stripe auth charges
---
app/models/event.rb | 6 +++++-
app/models/stripe_authorization.rb | 7 +++++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/app/models/event.rb b/app/models/event.rb
index 967b4c17c..42ad50fec 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -51,6 +51,7 @@ class Event < ApplicationRecord
has_many :transactions, through: :fee_relationships, source: :t_transaction
has_many :stripe_cards
+ has_many :stripe_authorizations, through: :stripe_cards
has_many :emburse_cards
has_many :emburse_card_requests
@@ -138,7 +139,10 @@ def emburse_balance
end
def balance
- transactions.sum(:amount)
+ bank_balance = transactions.sum(:amount)
+ stripe_balance = stripe_authorizations.approved.sum(:amount)
+
+ bank_balance + stripe_balance
end
# used for emburse transfers, this is the amount of money available that
diff --git a/app/models/stripe_authorization.rb b/app/models/stripe_authorization.rb
index 5907140f1..c26b4446f 100644
--- a/app/models/stripe_authorization.rb
+++ b/app/models/stripe_authorization.rb
@@ -2,8 +2,11 @@ class StripeAuthorization < ApplicationRecord
before_validation :sync_from_stripe! # pull details from stripe if we're creating it for the first time
after_create :notify_of_creation
- # TODO: remove reversed TXs from this list
- scope :awaiting_receipt, -> { includes(:receipts_attachments).where(approved: true, active_storage_attachments: { id: nil }) }
+ scope :awaiting_receipt, -> { includes(:receipts_attachments).where(approved: true, active_storage_attachments: { id: nil }) } # TODO: remove reversed TXs from this list
+ scope :approved, -> { where(approved: true) }
+ scope :pending, -> { where(stripe_status: :pending) }
+ scope :declined, -> { where(stripe_status: :declined) }
+ scope :successful, -> { where(stripe_status: :closed, approved: true) }
belongs_to :stripe_card, class_name: 'StripeCard'
alias_attribute :card, :stripe_card
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment