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

Commit

Permalink
validation/microdeposits: add a config for withdrawing from savings a…
Browse files Browse the repository at this point in the history
…ccounts

Issue: moov-io#541
  • Loading branch information
adamdecaf committed Aug 14, 2020
1 parent 77ea609 commit 28d11b6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ pipeline:
validation:
microDeposits:
[ sameyDay: <boolean> ]
withdraw:
# Regulation D from the Federal Reserve limits withdraws from savings accounts
# to six per month with fees for extra withdraws. This has been temporarily suspended in 2020.
[ fromSavingsAccounts: <boolean> ]
source:
# ID from the Customers service for the source of micro-deposit funds
customerID: <string>
Expand Down
10 changes: 7 additions & 3 deletions pkg/config/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ func (cfg Validation) Validate() error {
}

type MicroDeposits struct {
Source Source
SameDay bool
Withdraw MicroDepositWithdraw
Source Source

// Description is the default for what appears in the Online Banking
// system for end-users of PayGate. Per NACHA limits this is restricted
// to 10 characters.
Description string

SameDay bool
}

func (cfg *MicroDeposits) Validate() error {
Expand All @@ -40,6 +40,10 @@ func (cfg *MicroDeposits) Validate() error {
return nil
}

type MicroDepositWithdraw struct {
FromSavingsAccounts bool
}

type Source struct {
CustomerID string
AccountID string
Expand Down
12 changes: 12 additions & 0 deletions pkg/validation/microdeposits/micro_deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"crypto/rand"
"fmt"
"math/big"
"strings"
"time"

"github.com/moov-io/base"
customers "github.com/moov-io/customers/client"
"github.com/moov-io/paygate/pkg/client"
"github.com/moov-io/paygate/pkg/config"
"github.com/moov-io/paygate/pkg/customers/accounts"
Expand Down Expand Up @@ -57,6 +59,11 @@ func createMicroDeposits(
micro.TransferIDs = append(micro.TransferIDs, xfer.TransferID)
}

// skip the debit for Savings accounts when configured to do so
if skipDebit(cfg.Withdraw, dest.Account) {
return micro, nil
}

// originate the debit
sum, err := model.SumAmounts(amt1, amt2)
if err != nil {
Expand All @@ -75,6 +82,11 @@ func createMicroDeposits(
return micro, nil
}

func skipDebit(cfg config.MicroDepositWithdraw, acct customers.Account) bool {
isSavingsAccount := strings.EqualFold(string(acct.Type), string(customers.SAVINGS))
return isSavingsAccount && cfg.FromSavingsAccounts
}

func getMicroDepositAmounts() (string, string) {
random := func() string {
n, _ := rand.Int(rand.Reader, big.NewInt(25)) // rand.Int returns [0, N)
Expand Down
18 changes: 18 additions & 0 deletions pkg/validation/microdeposits/micro_deposits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ func TestAmounts(t *testing.T) {
}
}

func TestSkipDebit(t *testing.T) {
cfg := config.MicroDepositWithdraw{
FromSavingsAccounts: true,
}
acct := customers.Account{
Type: customers.SAVINGS,
}
if !skipDebit(cfg, acct) {
t.Error("expected to skip deibt")
}

// don't skip for Checking accounts
acct.Type = customers.CHECKING
if skipDebit(cfg, acct) {
t.Error("expected no skip")
}
}

func TestMicroDeposits__createMicroDeposits(t *testing.T) {
cfg := mockConfig()
cfg.ODFI.RoutingNumber = "123456780"
Expand Down

0 comments on commit 28d11b6

Please sign in to comment.