From b84e991797b3fb9f1ae7f9afec62d28ba7dedb63 Mon Sep 17 00:00:00 2001 From: vinayak-dapi Date: Wed, 18 Jan 2023 02:11:48 +0530 Subject: [PATCH 1/6] CS-1983: Added Ach pull --- ach/ach.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++ constants/url.go | 8 ++++++ request/ach.go | 8 ++++++ request/request.go | 7 ++++++ 4 files changed, 86 insertions(+) create mode 100644 ach/ach.go create mode 100644 request/ach.go diff --git a/ach/ach.go b/ach/ach.go new file mode 100644 index 0000000..f80e81b --- /dev/null +++ b/ach/ach.go @@ -0,0 +1,63 @@ +package ach + +import ( + "encoding/json" + + "github.com/dapi-co/dapi-go/config" + "github.com/dapi-co/dapi-go/constants" + "github.com/dapi-co/dapi-go/request" + "github.com/dapi-co/dapi-go/response" +) + +// Payment is the base type that allows talking to the payment endpoints +type Ach struct { + Config *config.Config +} + +// CreatePull represents the pull transfer to be created +type CreatePull struct { + Transfer request.AchPullTransferInfo +} + +// CreatePull talks to the create pull endpoint +func (a *Ach) CreatePull( + accessToken string, + userSecret string, + pullTransfer CreatePull, + userInputs []response.UserInput, + operationID string, +) (*response.BaseResponse, error) { + + baseRequest := &request.AchPullRequest{ + BaseRequest: request.BaseRequest{ + UserSecret: userSecret, + AppSecret: a.Config.AppSecret, + UserInputs: userInputs, + OperationID: operationID, + }, + Transfer: pullTransfer.Transfer, + } + + jsonData, err := json.Marshal(baseRequest) + if err != nil { + return nil, err + } + + baseHeader := &request.BaseHeader{ + AccessToken: accessToken, + } + + body, err := request.DapiRequest(jsonData, constants.DAPI_URL.ACH_URLS.CREATE_PULL, request.GetHTTPHeader(baseHeader)) + if err != nil { + return nil, err + } + + res := response.BaseResponse{} + + err = json.Unmarshal(body, &res) + if err != nil { + return nil, err + } + + return &res, nil +} diff --git a/constants/url.go b/constants/url.go index 32afe29..4a89580 100644 --- a/constants/url.go +++ b/constants/url.go @@ -29,6 +29,10 @@ type operationEndpoints struct { OPERATION_STATUS string } +type achEndpoints struct { + CREATE_PULL string +} + type dapiEndpoints struct { BASE_URL string DATA_URLS dataEndpoints @@ -36,6 +40,7 @@ type dapiEndpoints struct { PAYMENT_URLS paymentEndpoints AUTH_URLS authEndpoints OPERATION_URLS operationEndpoints + ACH_URLS achEndpoints } const DD_URL = "https://dd.dapi.com" @@ -68,4 +73,7 @@ var DAPI_URL = &dapiEndpoints{ OPERATION_URLS: operationEndpoints{ OPERATION_STATUS: "/operation/status", }, + ACH_URLS: achEndpoints{ + CREATE_PULL: "/ach/pull/create", + }, } diff --git a/request/ach.go b/request/ach.go new file mode 100644 index 0000000..9161deb --- /dev/null +++ b/request/ach.go @@ -0,0 +1,8 @@ +package request + +// AchPullTransferInfo represents the transfer details +type AchPullTransferInfo struct { + SenderID string `json:"senderID"` + Amount float64 `json:"amount"` + Description string `json:"description,omitempty"` +} diff --git a/request/request.go b/request/request.go index 71c36f9..40c962f 100644 --- a/request/request.go +++ b/request/request.go @@ -73,6 +73,13 @@ type BeneficiaryRequest struct { CreateBeneficiaryInfo } +// AchPullRequest holds the fields that's needed by the ACH's +// transfer autoflow endpoint. +type AchPullRequest struct { + BaseRequest + Transfer AchPullTransferInfo `json:"transfer"` +} + type NoHeader struct{} // BaseHeader holds any fields that's needed in the header of the request From e2b6f699ba3cf3798e18bc3666a93b5ada20cb19 Mon Sep 17 00:00:00 2001 From: vinayak-dapi Date: Wed, 18 Jan 2023 02:16:08 +0530 Subject: [PATCH 2/6] CS-1973: Fixed comments --- ach/ach.go | 2 +- request/request.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ach/ach.go b/ach/ach.go index f80e81b..b1bc693 100644 --- a/ach/ach.go +++ b/ach/ach.go @@ -9,7 +9,7 @@ import ( "github.com/dapi-co/dapi-go/response" ) -// Payment is the base type that allows talking to the payment endpoints +// Ach is the base type that allows talking to the ach endpoints type Ach struct { Config *config.Config } diff --git a/request/request.go b/request/request.go index 40c962f..1faae21 100644 --- a/request/request.go +++ b/request/request.go @@ -74,7 +74,7 @@ type BeneficiaryRequest struct { } // AchPullRequest holds the fields that's needed by the ACH's -// transfer autoflow endpoint. +// create pull endpoint. type AchPullRequest struct { BaseRequest Transfer AchPullTransferInfo `json:"transfer"` From e5bcbab9b90ff19188b9f85cc671e208498a49a3 Mon Sep 17 00:00:00 2001 From: vinayak-dapi Date: Wed, 25 Jan 2023 18:30:32 +0530 Subject: [PATCH 3/6] CS-2169: Added getAchPull --- ach/ach.go | 38 ++++++++++++++++++++++++++++++++++++++ constants/url.go | 2 ++ response/ach.go | 7 +++++++ response/response.go | 5 +++++ 4 files changed, 52 insertions(+) create mode 100644 response/ach.go diff --git a/ach/ach.go b/ach/ach.go index b1bc693..9aecbc8 100644 --- a/ach/ach.go +++ b/ach/ach.go @@ -61,3 +61,41 @@ func (a *Ach) CreatePull( return &res, nil } + +func (a *Ach) GetPull( + accessToken string, + userSecret string, + userInputs []response.UserInput, + operationID string, +) (*response.GetAchPullResponse, error) { + + baseRequest := &request.BaseRequest{ + UserSecret: userSecret, + AppSecret: a.Config.AppSecret, + UserInputs: userInputs, + OperationID: operationID, + } + + jsonData, err := json.Marshal(baseRequest) + if err != nil { + return nil, err + } + + baseHeader := &request.BaseHeader{ + AccessToken: accessToken, + } + + body, err := request.DapiRequest(jsonData, constants.DAPI_URL.ACH_URLS.GET_PULL, request.GetHTTPHeader(baseHeader)) + if err != nil { + return nil, err + } + + res := response.GetAchPullResponse{} + + err = json.Unmarshal(body, &res) + if err != nil { + return nil, err + } + + return &res, nil +} diff --git a/constants/url.go b/constants/url.go index 4a89580..338bb66 100644 --- a/constants/url.go +++ b/constants/url.go @@ -31,6 +31,7 @@ type operationEndpoints struct { type achEndpoints struct { CREATE_PULL string + GET_PULL string } type dapiEndpoints struct { @@ -75,5 +76,6 @@ var DAPI_URL = &dapiEndpoints{ }, ACH_URLS: achEndpoints{ CREATE_PULL: "/ach/pull/create", + GET_PULL: "/ach/pull/get", }, } diff --git a/response/ach.go b/response/ach.go new file mode 100644 index 0000000..f9cdca4 --- /dev/null +++ b/response/ach.go @@ -0,0 +1,7 @@ +package response + +type GetAchPull struct { + Amount float64 `json:"amount,omitempty"` + Currency Currency `json:"currency,omitempty"` + Status string `json:"status,omitempty"` +} diff --git a/response/response.go b/response/response.go index 1b3eb9d..abaa20e 100644 --- a/response/response.go +++ b/response/response.go @@ -103,3 +103,8 @@ type AccountsMetadataResponse struct { BaseResponse AccountsMetadata GetAccountsMetadata `json:"accountsMetadata,omitempty"` } + +type GetAchPullResponse struct { + BaseResponse + Transfer *GetAchPull `json:"transfer,omitempty"` +} From 545af35fcd795f4f44737094f5e9a2c7ab33142e Mon Sep 17 00:00:00 2001 From: vinayak-dapi Date: Wed, 25 Jan 2023 18:31:56 +0530 Subject: [PATCH 4/6] CS-2169: Removed omitempty from BaseResponse --- response/response.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/response/response.go b/response/response.go index abaa20e..d6d463b 100644 --- a/response/response.go +++ b/response/response.go @@ -15,9 +15,9 @@ type IBaseResponse interface { } type BaseResponse struct { - OperationID string `json:"operationID,omitempty"` - Success bool `json:"success,omitempty"` - Status constants.ApiStatus `json:"status,omitempty"` + OperationID string `json:"operationID"` + Success bool `json:"success"` + Status constants.ApiStatus `json:"status"` UserInputs []UserInput `json:"userInputs,omitempty"` Type string `json:"type,omitempty"` Msg string `json:"msg,omitempty"` From e43302f6280ff851ac19283223a685b1e090eec7 Mon Sep 17 00:00:00 2001 From: vinayak-dapi Date: Thu, 2 Feb 2023 21:25:58 +0530 Subject: [PATCH 5/6] CS-2169: Changed name GetAchPull to ACHPull in response struct --- response/ach.go | 2 +- response/response.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/response/ach.go b/response/ach.go index f9cdca4..efabe15 100644 --- a/response/ach.go +++ b/response/ach.go @@ -1,6 +1,6 @@ package response -type GetAchPull struct { +type ACHPull struct { Amount float64 `json:"amount,omitempty"` Currency Currency `json:"currency,omitempty"` Status string `json:"status,omitempty"` diff --git a/response/response.go b/response/response.go index d6d463b..c3e03b6 100644 --- a/response/response.go +++ b/response/response.go @@ -106,5 +106,5 @@ type AccountsMetadataResponse struct { type GetAchPullResponse struct { BaseResponse - Transfer *GetAchPull `json:"transfer,omitempty"` + Transfer *ACHPull `json:"transfer,omitempty"` } From 35f36ac01688ff4af94fc626015e36567f7e3649 Mon Sep 17 00:00:00 2001 From: Ahmad Sameh <8120013+asmsh@users.noreply.github.com> Date: Fri, 10 Feb 2023 12:28:31 +0400 Subject: [PATCH 6/6] CS-2169: renamed some types --- ach/ach.go | 16 ++++++++-------- request/ach.go | 4 ++-- request/request.go | 6 +++--- response/ach.go | 2 +- response/response.go | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ach/ach.go b/ach/ach.go index 9aecbc8..c3dc905 100644 --- a/ach/ach.go +++ b/ach/ach.go @@ -9,18 +9,18 @@ import ( "github.com/dapi-co/dapi-go/response" ) -// Ach is the base type that allows talking to the ach endpoints -type Ach struct { +// ACH is the base type that allows talking to the ach endpoints +type ACH struct { Config *config.Config } // CreatePull represents the pull transfer to be created type CreatePull struct { - Transfer request.AchPullTransferInfo + Transfer request.ACHPullTransfer } // CreatePull talks to the create pull endpoint -func (a *Ach) CreatePull( +func (a *ACH) CreatePull( accessToken string, userSecret string, pullTransfer CreatePull, @@ -28,7 +28,7 @@ func (a *Ach) CreatePull( operationID string, ) (*response.BaseResponse, error) { - baseRequest := &request.AchPullRequest{ + baseRequest := &request.CreateACHPullRequest{ BaseRequest: request.BaseRequest{ UserSecret: userSecret, AppSecret: a.Config.AppSecret, @@ -62,12 +62,12 @@ func (a *Ach) CreatePull( return &res, nil } -func (a *Ach) GetPull( +func (a *ACH) GetPull( accessToken string, userSecret string, userInputs []response.UserInput, operationID string, -) (*response.GetAchPullResponse, error) { +) (*response.GetACHPullResponse, error) { baseRequest := &request.BaseRequest{ UserSecret: userSecret, @@ -90,7 +90,7 @@ func (a *Ach) GetPull( return nil, err } - res := response.GetAchPullResponse{} + res := response.GetACHPullResponse{} err = json.Unmarshal(body, &res) if err != nil { diff --git a/request/ach.go b/request/ach.go index 9161deb..73f0022 100644 --- a/request/ach.go +++ b/request/ach.go @@ -1,7 +1,7 @@ package request -// AchPullTransferInfo represents the transfer details -type AchPullTransferInfo struct { +// ACHPullTransfer represents the transfer details +type ACHPullTransfer struct { SenderID string `json:"senderID"` Amount float64 `json:"amount"` Description string `json:"description,omitempty"` diff --git a/request/request.go b/request/request.go index 1faae21..59a5ae6 100644 --- a/request/request.go +++ b/request/request.go @@ -73,11 +73,11 @@ type BeneficiaryRequest struct { CreateBeneficiaryInfo } -// AchPullRequest holds the fields that's needed by the ACH's +// CreateACHPullRequest holds the fields that's needed by the ACH's // create pull endpoint. -type AchPullRequest struct { +type CreateACHPullRequest struct { BaseRequest - Transfer AchPullTransferInfo `json:"transfer"` + Transfer ACHPullTransfer `json:"transfer"` } type NoHeader struct{} diff --git a/response/ach.go b/response/ach.go index efabe15..0b43f5e 100644 --- a/response/ach.go +++ b/response/ach.go @@ -1,6 +1,6 @@ package response -type ACHPull struct { +type ACHPullTransferInfo struct { Amount float64 `json:"amount,omitempty"` Currency Currency `json:"currency,omitempty"` Status string `json:"status,omitempty"` diff --git a/response/response.go b/response/response.go index c3e03b6..6e3d79a 100644 --- a/response/response.go +++ b/response/response.go @@ -104,7 +104,7 @@ type AccountsMetadataResponse struct { AccountsMetadata GetAccountsMetadata `json:"accountsMetadata,omitempty"` } -type GetAchPullResponse struct { +type GetACHPullResponse struct { BaseResponse - Transfer *ACHPull `json:"transfer,omitempty"` + Transfer *ACHPullTransferInfo `json:"transfer,omitempty"` }