Repository navigation
Add BookPayment resource for booking transfers between accounts #66
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
433a9bb
Add BookPayment resource for booking transfers between accounts
trevornelson 81449b7
Limit BookPayment to create
trevornelson 6b20b7c
Fund source account in book payment spec and use checking in README
trevornelson 0bf3e0e
Surface book payment rejection reason and verify funding in spec
trevornelson 1be32e9
Book less than the funded amount in book payment spec
trevornelson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| module Unit | ||
| # A transfer of funds between two Unit accounts | ||
| class BookPayment < APIResource | ||
| path '/payments' | ||
|
|
||
| attribute :amount, Types::Integer # Amount to transfer in cents. | ||
| attribute :description, Types::String # Description of the payment. Max of 50 characters. | ||
| attribute :transaction_summary_override, Types::String # Optional. Overrides the transaction summary. Max of 100 characters. | ||
| attribute :idempotency_key, Types::String # Optional | ||
| attribute :tags, Types::Hash # Optional | ||
|
|
||
| attribute :direction, Types::String, readonly: true | ||
| attribute :summary, Types::String, readonly: true | ||
| attribute :status, Types::String, readonly: true | ||
| attribute :reason, Types::String, readonly: true | ||
| attribute :created_at, Types::DateTime, readonly: true | ||
|
|
||
| belongs_to :account, class_name: 'Unit::DepositAccount' | ||
| belongs_to :counterparty_account, class_name: 'Unit::DepositAccount', type: :depositAccount | ||
| belongs_to :customer, class_name: 'Unit::IndividualCustomer' | ||
| belongs_to :counterparty_customer, class_name: 'Unit::IndividualCustomer' | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| include ResourceOperations::Create | ||
| end | ||
| end | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| module Unit | ||
| VERSION = '1.1.1' | ||
| VERSION = '1.2.0' | ||
| end |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| require 'spec_helper' | ||
| require 'securerandom' | ||
|
|
||
| RSpec.describe Unit::BookPayment do | ||
| before do | ||
| establish_connection_to_api! | ||
| end | ||
|
|
||
| let(:new_individual_customer) do | ||
| Factory.create_individual_customer | ||
| end | ||
|
|
||
| let(:deposit_account) do | ||
| Factory.create_deposit_account(new_individual_customer) | ||
| end | ||
|
|
||
| let(:counterparty_deposit_account) do | ||
| Factory.create_deposit_account(new_individual_customer) | ||
| end | ||
|
|
||
| it 'serializes the counterparty account relationship as a deposit account' do | ||
| payment = Unit::BookPayment.new | ||
| payment.counterparty_account = Unit::DepositAccount.new.tap { |account| account.id = '10000' } | ||
|
|
||
| expect(payment.relationships[:counterparty_account]).to eq( | ||
| data: { type: :depositAccount, id: '10000' } | ||
| ) | ||
| end | ||
|
|
||
| it 'creates a book payment between two accounts' do | ||
| Factory.fund_deposit_account(deposit_account, 10_000) | ||
| expect(Unit::DepositAccount.find(deposit_account.id).available).to be >= 5_000 | ||
|
|
||
| payment = Unit::BookPayment.create( | ||
| amount: 5_000, | ||
| description: 'Funding', | ||
| transaction_summary_override: 'Transfer to savings', | ||
| idempotency_key: SecureRandom.uuid, | ||
| account: deposit_account, | ||
| counterparty_account: counterparty_deposit_account, | ||
| tags: { tag1: 'value1' } | ||
| ) | ||
|
|
||
| expect(payment.type).to eq 'bookPayment' | ||
|
trevornelson marked this conversation as resolved.
|
||
| expect(payment.status).to eq('Sent'), "Book payment was #{payment.status}: #{payment.reason}" | ||
| expect(payment.amount).to eq 5_000 | ||
| expect(payment.description).to eq 'Funding' | ||
| expect(payment.tags[:tag1]).to eq 'value1' | ||
| expect(payment.account.id).to eq deposit_account.id | ||
| expect(payment.counterparty_account.id).to eq counterparty_deposit_account.id | ||
| end | ||
| end | ||
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.