Skip to content

Commit

Permalink
Merge pull request #707 from balanced/bulk-credits-sweep-account
Browse files Browse the repository at this point in the history
Bulk credits
  • Loading branch information
remear committed Dec 20, 2014
2 parents 285b6b7 + 08ad48e commit 8feb82a
Show file tree
Hide file tree
Showing 22 changed files with 1,011 additions and 23 deletions.
126 changes: 126 additions & 0 deletions features/accounts.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
Feature: Accounts
Accounts are funding instruments which are able to store a balance internally with the Balanced system.

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 accounts match:
"""
{
"links": {
"customer": ":customer_id"
}
}
"""

Scenario: Credit a customer payable account
Given I have an order with a debit
When I POST to /accounts/:customer_payable_account_id/credits with the body:
"""
{
"credits": [{
"amount": 234,
"order": "/orders/:order_id"
}]
}
"""
Then I should get a 201 Created status code
And the response is valid according to the "credits" schema

Scenario: Retrieving credits for an account
Given I have an Account with sufficient funds
When I GET to /accounts/:customer_payable_account_id/credits
Then I should get a 200 OK status code
And the response is valid according to the "credits" schema
And the fields on these credits match:
"""
{
"links": {
"destination": ":customer_payable_account_id"
}
}
"""

# Currently there are no debitable accounts
Scenario: Retrieving debits for an account
Given I have an Account with sufficient funds
When I GET to /accounts/:customer_payable_account_id/debits
Then I should get a 200 OK status code
And the fields on these debits match:
"""
{
"meta": {
"total": 0
}
}
"""

# Currently there are no debitable accounts, thus no refunds
Scenario: Retrieving refunds for an account
Given I have an Account with a credit
Then I POST to /credits/:credit_id/reversals
When I POST to /debits/:debit_id/refunds
Then I should get a 201 Created status code
And the response is valid according to the "refunds" schema

When I GET to /accounts/:customer_payable_account_id/refunds
Then I should get a 200 OK status code
And the fields on these refunds match:
"""
{
"meta": {
"total": 0
}
}
"""

Scenario: Retrieving reversals for an account
Given I have an Account with a credit
Then I POST to /credits/:credit_id/reversals
Then I should get a 201 Created status code
And the response is valid according to the "reversals" schema
When I GET to /accounts/:customer_payable_account_id/reversals
Then I should get a 200 OK status code
And the response is valid according to the "reversals" schema
And the fields on these reversals match:
"""
{
"links": {
"credit": ":credit_id"
}
}
"""

Scenario: Retrieving settlements for an account
Given I have an Account with sufficient funds
When I POST to /accounts/:customer_payable_account_id/settlements with the body:
"""
{
"settlements": [{
"funding_instrument": "/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
When I GET to /accounts/:customer_payable_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": {
"source": ":customer_payable_account_id"
}
}
"""
47 changes: 47 additions & 0 deletions features/credits.feature
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,50 @@ Feature: Credits
"category_code": "no-funding-destination"
}
"""


Scenario: Bulk credit to a customer payable account
Given I have a merchant with 2 orders with debits
When I POST to /accounts/:customer_payable_account_id/credits with the body:
"""
{
"credits": [{
"amount": 1000,
"order": "/orders/:order_id_1",
"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_payable_account_id
Then I should get a 200 OK status code
And the fields on this account match:
"""
{
"balance": 1000
}
"""

When I POST to /accounts/:customer_payable_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_payable_account_id
Then I should get a 200 OK status code
And the fields on this account match:
"""
{
"balance": 2000
}
"""
14 changes: 14 additions & 0 deletions features/customers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,17 @@ Feature: Customers
"merchant_status": "underwritten"
}
"""

Scenario: Retrieving accounts for a customer
Given I have a bank account with a settlement
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 accounts match:
"""
{
"links": {
"customer": ":customer_id"
}
}
"""
2 changes: 1 addition & 1 deletion features/debits.feature
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Feature: Debit a card or bank account
And the response is valid according to the "debits" schema
And the fields on these debits match:
"""
{ "status": "pending" }
{ "status": "succeeded" }
"""

Scenario: Debits to unverified bank accounts fail
Expand Down
6 changes: 3 additions & 3 deletions features/orders.feature
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Feature: Orders

Scenario: Checking escrow of order after creating a credit
Given I have an order with a debit
And I have tokenized a bank account and associated with the merchant
And I have tokenized a bank account associated with the merchant
And I POST to /bank_accounts/:bank_account_id/credits with the body:
"""
{
Expand All @@ -146,7 +146,7 @@ Feature: Orders

Scenario: Orders cannot be credited more than escrow balance
Given I have created an order
And I have tokenized a bank account and associated with the merchant
And I have tokenized a bank account associated with the merchant
And I have tokenized a customer card
And I make a POST request to the link "cards.debits" with the body:
"""
Expand Down Expand Up @@ -252,7 +252,7 @@ Feature: Orders
}]
}
"""
And I have tokenized a bank account and associated with the merchant
And I have tokenized a bank account associated with the merchant
Then I make a POST request to the link "bank_accounts.credits" with the body:
"""
{
Expand Down
66 changes: 66 additions & 0 deletions features/reversals.feature
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,69 @@ Feature: Reversal
"""
{ "status": "failed" }
"""

Scenario: Reverse an Account credit before settlement
Given I have an Account with sufficient funds
When I POST to /credits/:credit_id_2/reversals with the body:
"""
{
"reversals": [{
"amount": 1000
}]
}
"""
Then I should get a 201 Created status code
And the response is valid according to the "reversals" schema
And the fields on this reversal match:
"""
{ "status": "succeeded" }
"""

Scenario: Reverse an Account credit after settlement
Given I have an Account with sufficient funds
When I POST to /accounts/:customer_payable_account_id/settlements with the body:
"""
{
"settlements": [{
"funding_instrument": "/bank_accounts/:bank_account_id"
}]
}
"""
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": 30000,
"status": "succeeded"
}
"""

When I POST to /credits/:credit_id_2/reversals
Then I should get a 201 Created status code
And the response is valid according to the "reversals" schema
And the fields on this reversal match:
"""
{
"amount": 10000,
"status": "succeeded"
}
"""

When I POST to /accounts/:customer_payable_account_id/settlements with the body:
"""
{
"settlements": [{
"funding_instrument": "/bank_accounts/:bank_account_id"
}]
}
"""
Then I should get a 201 Created status code
And the response is valid according to the "settlements" schema

When I make a GET request to the link "reversals.order"
Then I should get a 200 OK status code
And the fields on this order match:
"""
{ "amount_escrowed": 10000 }
"""
Loading

0 comments on commit 8feb82a

Please sign in to comment.