Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions ach/ach.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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"
)

// 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.ACHPullTransfer
}

// 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.CreateACHPullRequest{
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
}

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
}
10 changes: 10 additions & 0 deletions constants/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ type operationEndpoints struct {
OPERATION_STATUS string
}

type achEndpoints struct {
CREATE_PULL string
GET_PULL string
}

type dapiEndpoints struct {
BASE_URL string
DATA_URLS dataEndpoints
METADATA_URLS metadataEndpoints
PAYMENT_URLS paymentEndpoints
AUTH_URLS authEndpoints
OPERATION_URLS operationEndpoints
ACH_URLS achEndpoints
}

const DD_URL = "https://dd.dapi.com"
Expand Down Expand Up @@ -68,4 +74,8 @@ var DAPI_URL = &dapiEndpoints{
OPERATION_URLS: operationEndpoints{
OPERATION_STATUS: "/operation/status",
},
ACH_URLS: achEndpoints{
CREATE_PULL: "/ach/pull/create",
GET_PULL: "/ach/pull/get",
},
}
8 changes: 8 additions & 0 deletions request/ach.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package request

// ACHPullTransfer represents the transfer details
type ACHPullTransfer struct {
SenderID string `json:"senderID"`
Amount float64 `json:"amount"`
Description string `json:"description,omitempty"`
}
7 changes: 7 additions & 0 deletions request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ type BeneficiaryRequest struct {
CreateBeneficiaryInfo
}

// CreateACHPullRequest holds the fields that's needed by the ACH's
// create pull endpoint.
type CreateACHPullRequest struct {
BaseRequest
Transfer ACHPullTransfer `json:"transfer"`
}

type NoHeader struct{}

// BaseHeader holds any fields that's needed in the header of the request
Expand Down
7 changes: 7 additions & 0 deletions response/ach.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package response

type ACHPullTransferInfo struct {
Amount float64 `json:"amount,omitempty"`
Currency Currency `json:"currency,omitempty"`
Status string `json:"status,omitempty"`
}
11 changes: 8 additions & 3 deletions response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -103,3 +103,8 @@ type AccountsMetadataResponse struct {
BaseResponse
AccountsMetadata GetAccountsMetadata `json:"accountsMetadata,omitempty"`
}

type GetACHPullResponse struct {
BaseResponse
Transfer *ACHPullTransferInfo `json:"transfer,omitempty"`
}