Skip to content
This repository has been archived by the owner on Dec 9, 2021. It is now read-only.

Commit

Permalink
validation/microdeposits: remove return_code
Browse files Browse the repository at this point in the history
This value doesn't make sense on a MicroDeposit. Only each individual
transfer underlying the model can be returned.
  • Loading branch information
adamdecaf committed Aug 14, 2020
1 parent 8a02212 commit 76aa2ef
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 24 deletions.
2 changes: 0 additions & 2 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,6 @@ components:
$ref: '#/components/schemas/Amount'
status:
$ref: '#/components/schemas/TransferStatus'
returnCode:
$ref: '#/components/schemas/ReturnCode'
processedAt:
type: string
format: date-time
Expand Down
1 change: 0 additions & 1 deletion pkg/client/docs/MicroDeposits.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Name | Type | Description | Notes
**Destination** | [**Destination**](Destination.md) | |
**Amounts** | **[]string** | |
**Status** | [**TransferStatus**](TransferStatus.md) | |
**ReturnCode** | Pointer to [**ReturnCode**](ReturnCode.md) | | [optional]
**ProcessedAt** | Pointer to [**time.Time**](time.Time.md) | | [optional]
**Created** | [**time.Time**](time.Time.md) | |

Expand Down
1 change: 0 additions & 1 deletion pkg/client/model_micro_deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type MicroDeposits struct {
Destination Destination `json:"destination"`
Amounts []string `json:"amounts"`
Status TransferStatus `json:"status"`
ReturnCode *ReturnCode `json:"returnCode,omitempty"`
ProcessedAt *time.Time `json:"processedAt,omitempty"`
Created time.Time `json:"created"`
}
4 changes: 4 additions & 0 deletions pkg/database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ var (
"add_processed_at__to__micro_deposits",
`alter table micro_deposits add column processed_at datetime;`,
),
execsql(
"drop_micro_deposit_return_code",
"alter table micro_deposits drop column return_code;",
),
)
)

Expand Down
22 changes: 2 additions & 20 deletions pkg/validation/microdeposits/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"database/sql"
"strings"

"github.com/moov-io/ach"
"github.com/moov-io/paygate/pkg/client"
)

Expand Down Expand Up @@ -36,7 +35,7 @@ func (r *sqlRepo) Close() error {
}

func (r *sqlRepo) getMicroDeposits(microDepositID string) (*client.MicroDeposits, error) {
query := `select micro_deposit_id, destination_customer_id, destination_account_id, amounts, status, return_code, processed_at, created_at from micro_deposits
query := `select micro_deposit_id, destination_customer_id, destination_account_id, amounts, status, processed_at, created_at from micro_deposits
where micro_deposit_id = ? and deleted_at is null limit 1;`
stmt, err := r.db.Prepare(query)
if err != nil {
Expand All @@ -47,7 +46,6 @@ where micro_deposit_id = ? and deleted_at is null limit 1;`
row := stmt.QueryRow(microDepositID)

var amounts string
var returnCode *string

var micro client.MicroDeposits
if err := row.Scan(
Expand All @@ -56,23 +54,13 @@ where micro_deposit_id = ? and deleted_at is null limit 1;`
&micro.Destination.AccountID,
&amounts,
&micro.Status,
&returnCode,
&micro.ProcessedAt,
&micro.Created,
); err != nil {
return nil, err
}

micro.Amounts = strings.Split(amounts, "|")
if returnCode != nil {
if rc := ach.LookupReturnCode(*returnCode); rc != nil {
micro.ReturnCode = &client.ReturnCode{
Code: rc.Code,
Reason: rc.Reason,
Description: rc.Description,
}
}
}

micro.TransferIDs, err = r.getMicroDepositTransferIDs(microDepositID)
if err != nil {
Expand Down Expand Up @@ -128,26 +116,20 @@ func (r *sqlRepo) writeMicroDeposits(micro *client.MicroDeposits) error {
return err
}

query := `insert into micro_deposits (micro_deposit_id, destination_customer_id, destination_account_id, amounts, status, return_code, created_at) values (?, ?, ?, ?, ?, ?, ?);`
query := `insert into micro_deposits (micro_deposit_id, destination_customer_id, destination_account_id, amounts, status, created_at) values (?, ?, ?, ?, ?, ?);`
stmt, err := tx.Prepare(query)
if err != nil {
tx.Rollback()
return err
}
defer stmt.Close()

var returnCode *string
if micro.ReturnCode != nil {
returnCode = &micro.ReturnCode.Code
}

_, err = stmt.Exec(
micro.MicroDepositID,
micro.Destination.CustomerID,
micro.Destination.AccountID,
strings.Join(micro.Amounts, "|"),
micro.Status,
returnCode,
micro.Created,
)
if err != nil {
Expand Down

0 comments on commit 76aa2ef

Please sign in to comment.