Skip to content

Commit

Permalink
add possibility to record credit_note_id when voiding credits
Browse files Browse the repository at this point in the history
  • Loading branch information
annvelents committed Oct 15, 2024
1 parent 2101e44 commit 30d130c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/services/wallet_transactions/void_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

module WalletTransactions
class VoidService < BaseService
def initialize(wallet:, credits:, from_source: :manual, metadata: {})
def initialize(wallet:, credits:, from_source: :manual, metadata: {}, credit_note_id: nil)
@wallet = wallet
@credits = credits
@from_source = from_source
@metadata = metadata
@credit_note_id = credit_note_id

super
end
Expand All @@ -23,7 +24,8 @@ def call
settled_at: Time.current,
source: from_source,
transaction_status: :voided,
metadata:
metadata:,
credit_note_id:
)
Wallets::Balance::DecreaseService.new(wallet:, credits_amount:).call
result.wallet_transaction = wallet_transaction
Expand All @@ -34,7 +36,7 @@ def call

private

attr_reader :wallet, :credits, :from_source, :metadata
attr_reader :wallet, :credits, :from_source, :metadata, :credit_note_id

def credits_amount
@credits_amount ||= BigDecimal(credits)
Expand Down
12 changes: 12 additions & 0 deletions spec/services/wallet_transactions/void_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,17 @@
expect(wallet.balance_cents).to eq(0)
expect(wallet.credits_balance).to eq(0.0)
end

context 'when credit_note_id is passed' do
let(:credit_note_id) { create(:credit_note, organization: organization).id }
subject(:void_service) { described_class.call(wallet:, credits:, credit_note_id:) }

it 'saves credit_note_id in wallet_transaction' do
result = void_service
wallet_transaction = result.wallet_transaction

expect(wallet_transaction.credit_note_id).to eq(credit_note_id)
end
end
end
end

0 comments on commit 30d130c

Please sign in to comment.