## Endpoints - MVP (Requirements)
### POST /bankAccount
> Add new bank account
_Request Header_
```
not needed
```
_Request Params_
```
not needed
```
_Request Body_
```
{
"currency": "IDR",
"bank_code": "014"
"account_number": "0123456"
"account_holder_name": "Galuh Adika Alifani"
"merchant_id": 1
}
```
_Field validations_
```
currency: ["IDR", "USD", "MYR", "PHP", "SGD"]
```
_Response (201 - created)_
```
{
"message": "Success adding IDR bank account"
"bank":
{
"id": 1
"currency": "IDR",
"bank_code": "014"
"account_number": "0123456"
"account_holder_name": "Galuh Adika Alifani"
"merchant_id": 1
}
}
```
_Response (400 - Bad Request)_
```
{
"error": "Bad Request",
"message": "Bank account already exists. Can not add duplicate account"
}
```
```
{
"error": "Bad Request",
"message": "Can not add more than one account with the same currency. Account for IDR already exists"
}
```
```
{
"error": "Bad Request - Validation Error",
"message": [
"Available currencies are IDR, USD, MYR, PHP, and SGD",
"Currency cannot be empty"
"Account Number cannot be empty",
"Acc Holder Name cannot be empty",
"Bank Code cannot be empty"
]
}
```
_Response (403 - Forbidden)_
```
{
"error": "Merchant ID Not Found",
"message": "Incorrect merchant ID / Merchant does not exist"
}
```
```
{
"error": "Database Field Error",
"message": "Incorrect bank or merchant ID"
}
```
_Response (500 - Internal Server Error)_
```
{
"error": "Internal Server Error",
"message": "Failed adding bank account"
}
```
---
### PUT /bankAccount/:bankId
> Edit existing bank account
_Request Header_
```
not needed
```
_Request Params_
```
{
"bankId": uuid (required)
}
```
_Request Body_
```
{
"bank_code": "011"
"account_number": "0987654"
"account_holder_name": "Galuh Adika Alifani"
}
```
_Response (200)_
```
{
"message": "Success modifying IDR bank account"
"bank":
{
"id": 1
"currency": "IDR",
"bank_code": "011"
"account_number": "0987654"
"account_holder_name": "Galuh Adika Alifani"
}
}
```
_Response (400 - Bad Request)_
```
{
"error": "Bad Request - Validation Error",
"message": [
"Account Number cannot be empty",
"Acc Holder Name cannot be empty",
"Bank Code cannot be empty"
]
}
```
_Response (403 - Forbidden)_
```
{
"error": "Database Field Error",
"message": "Incorrect bank or merchant ID"
}
```
_Response (404 - Not Found)_
```
{
"error": "Bank ID Not Found",
"message": "Bank account not found. Please try again or select other account"
}
```
_Response (500 - Internal Server Error)_
```
{
"error": "Internal Server Error",
"message": "Failed editing bank account"
}
```
---
### GET /withdrawal/:merchantId
> See all withdrawals
_Request Header_
```
not needed
```
_Request Params_
```
{
"merchantId": uuid (required)
}
```
_Request Query (optional)_
- Query fields
```
?currency=<currency>&year=<year>&month=<month>&limit=<pagelimit>&page=<currentpage>
```
- Query restrictions / assumptions
- _Page is the current page, Limit is the number of items displayed per page_
- _If no page or limit query is added, response will return the whole items without pagination_
- _If either one of page or limit query is entered, the default pagination will be: page = 1 and limit = 10_
- _If month is inputted without year, it will filter items for the given month in the current year_
- _If year is inputted without month, it will filter items for the whole given year_
_Request Body_
```
not needed
```
_Response (200)_
```
{
"merchantName": "Galuh Alifani"
"totalItems": 8,
"totalPages": 4,
"currentPage": 2,
"withdrawals": [
{
"amount": 100000,
"status": "pending",
"createdAt": "Wed Aug 25 2021"
"currency": "IDR",
"bank_code": "014",
"account_number": "012345",
"account_holder_name": "Galuh Alifani"
},
{
"amount": 300,
"status": "pending",
"createdAt": "Wed Aug 25 2021"
"currency": "MYR",
"bank_code": "011",
"account_number": "0987654",
"account_holder_name": "Galuh Alifani"
}
]
}
```
_Response (400 - Bad Request)_
```
{
"error": "Bad User Input",
"message": "Invalid page query"
}
```
_Response (403 - Forbidden)_
```
{
"error": "Merchant ID Not Found",
"message": "Incorrect merchant ID / Merchant does not exist"
}
```
```
{
"error": "Database Field Error",
"message": "Incorrect bank or merchant ID"
}
```
_Response (500 - Internal Server Error)_
```
{
"error": "Internal Server Error",
"message": "Error fetching withdrawals"
}
```
---
### POST /withdrawal
> Request new withdrawal
_Request Header_
```
not needed
```
_Request Params_
```
not needed
```
_Request Body_
```
{
"amount": 100000,
"bank_account_id": 1
}
```
_Field validations_
```
amount: integer only; > 0
status: [pending, completed]
```
_Response (201 - created)_
```
{
"message": "Success requesting withdrawal to IDR account. Status of withdrawal is pending"
"withdrawal_detail":
{
"amount": 100000,
"status": "pending",
"created_at": "Wed Aug 25 2021 11:13:28 GMT+0700"
"bank":
{
"id": 1
"currency": "IDR",
"bank_code": "014"
"account_number": "0123456"
"account_holder_name": "Galuh Adika Alifani"
}
}
}
```
_Response (400 - Bad Request)_
```
{
"error": "Bad Request",
"message": "You can only perform withdrawal once a day for each currency"
}
```
```
{
"error": "Bad Request",
"message": "Insufficient balance. Please select another amount"
}
```
```
{
"error": "Bad Request - Validation Error",
"message": [
"Minimum withdrawal amount is 1",
"Amount must be integer",
"Amount cannot be empty",
"Amount cannot be null"
]
}
```
_Response (403 - Forbidden)_
```
{
"error": "Database Field Error",
"message": "Incorrect bank or merchant ID"
}
```
_Response (404 - Not Found)_
```
{
"error": "Bank ID Not Found",
"message": "Bank account not found. Please try again or select other account"
}
```
_Response (500 - Internal Server Error)_
```
{
"error": "Internal Server Error",
"message": "Error adding withdrawal request"
}
```
---
## Endpoints - Additionals (Nice to Have)
### PATCH /withdrawal/status/:withdrawalId
> Update withdrawal status
_Request Header_
```
not needed
```
_Request Params_
```
{
"withdrawalId": uuid (required)
}
```
_Request Body_
```
not needed
```
_Response (200)_
```
{
"message": "Withdrawal to Jorge Roob SGD account on Tue Aug 24 2021 has been successfully changed to completed"
}
```
```
{
"message": "Withdrawal to Guillermo Beier IDR account on Fri Aug 20 2021 is already completed"
}
```
_Response (403 - Forbidden)_
```
{
"error": "Database Field Error",
"message": "Incorrect bank or merchant ID"
}
```
_Response (404 - Not Found)_
```
{
"error": "Bad Request",
"message": "Withdrawal item not found / Invalid ID"
}
```
_Response (500 - Internal Server Error)_
```
{
"error": "Internal Server Error",
"message": "Failed updating withdrawal status"
}
```
---
### GET /bankAccount/:merchantId
> Get list of bank account details of a merchant
_Request Header_
```
not needed
```
_Request Params_
```
{
"merchantId": uuid (required)
}
```
_Request Body_
```
not needed
```
_Response (200)_
```
[
{
"id": "2f810e2d-406b-4f99-bd1a-39eedb5ea3cf",
"currency": "PHP",
"bank_code": "484",
"account_number": "16629",
"account_holder_name": "Jorge Roob 2",
"merchant_id": "6a8b1fd1-6549-431c-a418-b3b639917414",
"createdAt": "2021-08-26T04:42:28.762Z",
"updatedAt": "2021-08-26T18:29:39.104Z"
},
{
"id": "60246cce-a9e8-47c3-af52-36245d14da9f",
"currency": "IDR",
"bank_code": "011",
"account_number": "099231",
"account_holder_name": "Jorge Roob Jr.",
"merchant_id": "6a8b1fd1-6549-431c-a418-b3b639917414",
"createdAt": "2021-08-26T06:10:42.949Z",
"updatedAt": "2021-08-26T20:09:05.609Z"
}
]
```
_Response (403 - Forbidden)_
```
{
"error": "Database Field Error",
"message": "Incorrect bank or merchant ID"
}
```
```
{
"error": "Merchant ID Not Found",
"message": "Incorrect merchant ID / Merchant does not exist"
}
```
_Response (500 - Internal Server Error)_
```
{
"error": "Internal Server Error",
"message": "Failed fetching bank account"
}
```
---
### POST /merchant/login
> Dummy login endpoint (without password, email, or auth key)
_Request Header_
```
not needed
```
_Request Params_
```
not needed
```
_Request Body_
```
{
"username": username
}
```
_Response (200)_
```
{
"id": "0842b956-6fec-4779-80fb-088610b8519a",
"username": "galuhalifani",
"name": "Galuh Adika Alifani",
"balance": 100000000,
"createdAt": "2021-08-26T04:41:33.772Z",
"updatedAt": "2021-08-26T04:41:33.772Z"
}
```
_Response (403 - Forbidden)_
```
{
"error": "Forbidden",
"message": "Wrong username"
}
```
_Response (500 - Internal Server Error)_
```
{
"error": "Internal Server Error",
"message": "Failed logging in"
}
```