Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: credit note on credit - update void credits service #2694

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_amount:, from_source: :manual, metadata: {})
def initialize(wallet:, credits_amount:, from_source: :manual, metadata: {}, credit_note_id: nil)
@wallet = wallet
@credits_amount = credits_amount
@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,6 +36,6 @@ def call

private

attr_reader :wallet, :credits_amount, :from_source, :metadata
attr_reader :wallet, :credits_amount, :from_source, :metadata, :credit_note_id
end
end
13 changes: 13 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,18 @@
expect(wallet.balance_cents).to eq(0)
expect(wallet.credits_balance).to eq(0.0)
end

context 'when credit_note_id is passed' do
subject(:void_service) { described_class.call(wallet:, credits_amount:, credit_note_id:) }

let(:credit_note_id) { create(:credit_note, organization: organization).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