-
Notifications
You must be signed in to change notification settings - Fork 64
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
Bulk credits sweep account #707
Changes from 13 commits
c8530e8
29279bd
8471295
f42089a
172a527
306bee1
6fe13fd
a9dd0a9
18d6292
8045aba
0aeab75
1e49b4d
642370e
d3e31f8
e4d8cbf
745d043
2e3b457
f2c7675
8ef8470
d1e4036
36352e7
1365a5b
9a36b43
676ffec
8e6280e
b617c04
2b66e22
9b0f434
e988cc9
ff15533
f59e0dc
aa0cc6f
2ff55e8
8b81e3e
959a691
f75e3a0
b5538ed
ec3af70
08ad48e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Feature: Accounts | ||
Accounts are a way to have a store of some kind of value. | ||
|
||
Scenario: List accounts | ||
Given I have created a customer | ||
When I GET to /accounts | ||
Then I should get a 200 OK status code | ||
And the response is valid according to the "accounts" schema | ||
|
||
Scenario: Retrieving accounts for a customer | ||
Given I have created a customer | ||
When I GET to /customers/:customer_id/accounts | ||
Then I should get a 200 OK status code | ||
And the response is valid according to the "accounts" schema | ||
And the fields on these credits match: | ||
""" | ||
{ | ||
"links": { | ||
"customer": ":customer_id" | ||
} | ||
} | ||
""" | ||
|
||
Scenario: Credit a customer deposit account | ||
Given I have an order with a debit | ||
When I POST to /accounts/:customer_deposit_account_id/credits | ||
""" | ||
{ | ||
"credits": [{ | ||
"amount": 234, | ||
"order": "/orders/:order_id" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it return the order href? i think we return the order ID and a link href. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The response should. Most of the steps in these API specs are just written to get the ID so I followed that convention for now, but I'd like to revisit it later. |
||
}] | ||
} | ||
""" | ||
Then I should get a 201 Created status code | ||
And the response is valid according to the "credits" schema |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,3 +124,50 @@ Feature: Credits | |
"category_code": "no-funding-destination" | ||
} | ||
""" | ||
|
||
|
||
Scenario: Bulk credit to a customer deposit account | ||
Given I have a merchant with 2 orders with debits | ||
When I POST to /accounts/:customer_deposit_account_id/credits with the body: | ||
""" | ||
{ | ||
"credits": [{ | ||
"amount": 1000, | ||
"order": "/orders/:order_id_1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would the credit say its destination is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I reverse a credit before it's at the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
that's implied by the endpoint that you're POSTing to in this scenario.
it immediately goes to the sweep, i think you mean bank account. if you reverse a credit it should leave the sweep with a negative balance (if the credit has cleared to the bank account). in that case it would eventually debit the bank account to zero out the balance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mjallday What do you mean by "eventually"? When would it actually debit the bank account? What would happen if the bank account doesn't have any balance? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the sum of the transactions to the sweep account since it was last settled are less than zero then it would result in a debit to the bank account. we haven't defined how that would react in the case of the underlying bank account failing but i suspect it would cause the other transactions to go into a failed state. |
||
"appears_on_statement_as": "Payout group A" | ||
}] | ||
} | ||
""" | ||
Then I should get a 201 Created status code | ||
And the response is valid according to the "credits" schema | ||
|
||
When I make a GET request to /accounts/:customer_deposit_account_id | ||
Then I should get a 200 OK status code | ||
And the fields on this error match: | ||
""" | ||
{ | ||
"balance": 1000 | ||
} | ||
""" | ||
|
||
When I POST to /accounts/:customer_deposit_account_id/credits with the body: | ||
""" | ||
{ | ||
"credits": [{ | ||
"amount": 1000, | ||
"order": "/orders/:order_id_2", | ||
"appears_on_statement_as": "Payout group B" | ||
}] | ||
} | ||
""" | ||
Then I should get a 201 Created status code | ||
And the response is valid according to the "credits" schema | ||
|
||
When I make a GET request to /accounts/:customer_deposit_account_id/credits | ||
Then I should get a 200 OK status code | ||
And the fields on this error match: | ||
""" | ||
{ | ||
"balance": 2000 | ||
} | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
@focus | ||
Feature: Settlements | ||
Settlement is the action of moving money out of an Account to a | ||
bank account. | ||
|
||
Scenario: Create a settlement | ||
Given I have an Account with sufficient funds | ||
And I have tokenized a bank account | ||
When I POST to /accounts/:customer_deposit_account_id/settlements with the body: | ||
""" | ||
{ | ||
"settlements": [{ | ||
"destination": "/bank_accounts/:bank_account_id", | ||
"appears_on_statement_as": "Settlement Oct", | ||
"description": "Settlement for payouts from October" | ||
}] | ||
} | ||
""" | ||
Then I should get a 201 Created status code | ||
And the response is valid according to the "settlements" schema | ||
And the fields on this settlement match: | ||
""" | ||
{ | ||
"amount": "10000", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i may not understand the spec dependencies, how do you know that there was 100.00 in the account to settle beforehand? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the frustrating part of these steps. They're not yet very robust in terms of what you can pass through the many steps it takes to orchestrate an entire situation like this. Right now I know "I have an Account with sufficient funds" creates 3 orders each with a debit of 10000 and credits 10000 from each of the 3 into the customer sweep account. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. omg... ok, i understand how it works then. maybe we should change the fixture to "I have a sweep account with a balanced of $100". that way it's more explicit that what the balance is. Or maybe "I have 3 orders for $100 and I those orders for $100 to a sweep account". Hmmm, I see your frustration. |
||
"appears_on_statement_as": "BAL*Settlement Oct", | ||
"description": "Settlement for payouts from October", | ||
"links": { | ||
"destination": ":bank_account_id" | ||
} | ||
} | ||
""" | ||
|
||
Scenario: List settlements | ||
Given I have 2 settlements | ||
When I GET to /settlements | ||
Then I should get a 200 OK status code | ||
And the response is valid according to the "settlements" schema | ||
|
||
Scenario: Retrieving settlements for a bank account | ||
Given I have a bank account with a settlement | ||
When I GET to /bank_accounts/:bank_account_id/settlements | ||
Then I should get a 200 OK status code | ||
And the response is valid according to the "settlements" schema | ||
And the fields on these settlements match: | ||
""" | ||
{ | ||
"links": { | ||
"destination": ":bank_account_id" | ||
} | ||
} | ||
""" | ||
|
||
Scenario: Updating a settlement description | ||
Given I have a bank account with a settlement | ||
When I PUT to /settlements/:settlement_id with the body: | ||
""" | ||
{ | ||
"description": "A new settlement description" | ||
} | ||
""" | ||
Then I should get a 200 OK status code | ||
And the response is valid according to the "settlements" schema | ||
And the fields on this settlement match: | ||
""" | ||
{ | ||
"description": "A new settlement description" | ||
} | ||
""" | ||
|
||
Scenario: Updating a settlement meta | ||
Given I have a bank account with a settlement | ||
When I PUT to /settlements/:settlement_id with the body: | ||
""" | ||
{ | ||
"meta": { | ||
"reference_number": "546512" | ||
} | ||
} | ||
""" | ||
Then I should get a 200 OK status code | ||
And the response is valid according to the "settlements" schema | ||
And the fields on this settlement match: | ||
""" | ||
{ | ||
"meta": { | ||
"reference_number": "546512" | ||
} | ||
} | ||
""" | ||
|
||
Scenario: Creating a settlement without a funding destination leads to failure | ||
When I POST to /settlements with the body: | ||
""" | ||
{ | ||
"settlements": [{ | ||
"description": "Will this credit work? Nobody knows" | ||
}] | ||
} | ||
""" | ||
Then I should get a 400 status code | ||
And the response is valid according to the "errors" schema | ||
And the fields on this error match: | ||
""" | ||
{ | ||
"category_code": "no-funding-destination" | ||
} | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about when there's no transactions to settle? |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Given(/^I have an Account with sufficient funds$/) do | ||
step 'I have an order with a debit' | ||
@client.post("/accounts/#{@customer_deposit_account_id}/credits", { | ||
amount: 10000, | ||
order: @order_id | ||
}) | ||
@client.add_hydrate :credit_id, @client['id'] | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,13 @@ | |
) | ||
@customer_id = @client['id'] | ||
@client.add_hydrate :customer_id, @customer_id | ||
|
||
# get the deposit account | ||
@client['accounts'].each do |acct| | ||
if acct['type'] == 'deposit' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
@client.add_hydrate :customer_deposit_account_id, acct['id'] | ||
break | ||
end | ||
end | ||
@customer_url = @client['customers']['href'] | ||
|
||
# tokenize a card for them | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Given(/^I have a bank account with a settlement$/) do | ||
step 'I have an order with a debit' | ||
step 'I have created a customer' | ||
@client.post("/accounts/#{@customer_deposit_account_id}/credits", { | ||
amount: 1234, | ||
order: :order_id | ||
}) | ||
@settlement_id = @client['settlements']['id'] | ||
@client.add_hydrate :settlement_id, @settlement_id | ||
end | ||
|
||
Given(/^I have (\d) settlements$/) do | ||
num.to_i.times { step 'I have a bank account with a settlement' } | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"description": "The redeemable balance of a customer is represented as a financial instrument just like a Card or Bank Account.", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string", | ||
"pattern": "AT[a-zA-Z0-9]{16,32}" | ||
}, | ||
"href": { | ||
"type": "string", | ||
"format": "uri" | ||
}, | ||
"created_at": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"updated_at": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"balance": { | ||
"type": "integer", | ||
"minimum": 0 | ||
}, | ||
"currency": { | ||
"type": "string", | ||
"enum": [ | ||
"USD" | ||
] | ||
}, | ||
"can_debit": { | ||
"description": "Flag indicating whether this account can be debited (true) or not (false).", | ||
"type": "boolean" | ||
}, | ||
"can_credit": { | ||
"description": "Flag indicating whether this account instrument can be credited (true) or not (false).", | ||
"type": "boolean" | ||
}, | ||
"meta": { | ||
"type": "object" | ||
}, | ||
"links": { | ||
"type": "object", | ||
"properties": { | ||
"customer": { | ||
"type": "string", | ||
"pattern": "CU[a-zA-Z0-9]{16,32}" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": [ | ||
"customer" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"id", | ||
"href", | ||
"created_at", | ||
"updated_at", | ||
"balance", | ||
"currency", | ||
"can_credit", | ||
"can_debit", | ||
"meta", | ||
"links" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,14 @@ | |
"string" | ||
], | ||
"pattern": "BZ[a-zA-Z0-9]{16,32}" | ||
}, | ||
"sweep_account": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this here/necessary? |
||
"description": "A funding instrument representing a sweep account used for bulk credits", | ||
"type": [ | ||
"null", | ||
"string" | ||
], | ||
"pattern": "(AT)[a-zA-Z0-9]{16,32}" | ||
} | ||
}, | ||
"required": [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accounts are funding instruments which are able to store a balance internally with the Balanced system.