From 020deb714fddd137ef04dfdc487cafcee1a26d66 Mon Sep 17 00:00:00 2001 From: Alican Akkus Date: Mon, 24 Jul 2023 08:36:30 -0400 Subject: [PATCH] adds bank account tracking adapter to retrieve bank account tracking record --- adapter/bank_account_tracking.go | 25 +++++++++++++++++++ adapter/craftgate.go | 2 ++ adapter/model.go | 37 +++++++++++++++++++++++++++++ tests/bank_account_tracking_test.go | 26 ++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 adapter/bank_account_tracking.go create mode 100644 tests/bank_account_tracking_test.go diff --git a/adapter/bank_account_tracking.go b/adapter/bank_account_tracking.go new file mode 100644 index 0000000..6067d75 --- /dev/null +++ b/adapter/bank_account_tracking.go @@ -0,0 +1,25 @@ +package adapter + +import ( + "context" + "net/http" +) + +type BankAccountTracking struct { + Client *Client +} + +func (api *BankAccountTracking) SearchRecords(ctx context.Context, request SearchBankAccountTrackingRecordRequest) (*DataResponse[BankAccountTrackingRecordResponse], error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/bank-account-tracking/v1/merchant-bank-account-trackings/records", request) + if err != nil { + return nil, err + } + response := &Response[DataResponse[BankAccountTrackingRecordResponse]]{} + err = api.Client.Do(ctx, newRequest, response) + + if err != nil { + return nil, err + } + + return response.Data, nil +} diff --git a/adapter/craftgate.go b/adapter/craftgate.go index 8199b5f..62c025b 100644 --- a/adapter/craftgate.go +++ b/adapter/craftgate.go @@ -83,6 +83,7 @@ type Client struct { FileReporting *FileReporting Fraud *Fraud Hook *Hook + BankAccountTracking *BankAccountTracking } func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, error) { @@ -117,6 +118,7 @@ func newClient(apiKey, secretKey string) *Client { client.FileReporting = &FileReporting{Client: client} client.Fraud = &Fraud{Client: client} client.Hook = &Hook{Client: client} + client.BankAccountTracking = &BankAccountTracking{Client: client} return client } diff --git a/adapter/model.go b/adapter/model.go index 892bd6b..2059f56 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -37,6 +37,8 @@ type WebhookStatus string type FileStatus string type AccountOwner string type PayoutAccountType string +type RecordType string +type BankAccountTrackingSource string const ( ApiKeyHeaderName = "x-api-key" @@ -333,6 +335,17 @@ const ( PayoutAccountTypeWISE PayoutAccountType = "WISE" ) +// RecordType declaration +const ( + SEND RecordType = "SEND" + RECEIVE Currency = "RECEIVE" +) + +// BankAccountTrackingSource declaration +const ( + YKB BankAccountTrackingSource = "YKB" +) + // requests type CreatePaymentRequest struct { Price float64 `json:"price,omitempty"` @@ -1446,6 +1459,30 @@ type WebhookData struct { PayloadId string } +type SearchBankAccountTrackingRecordRequest struct { + SenderName string `schema:"senderName,omitempty"` + SenderIban string `schema:"senderIban,omitempty"` + Description string `schema:"description,omitempty"` + Currency Currency `schema:"currency,omitempty"` + MinRecordDate time.Time `schema:"minRecordDate,omitempty"` + MaxRecordDate time.Time `schema:"maxRecordDate,omitempty"` + Page int `schema:"page,omitempty"` + Size int `schema:"size,omitempty"` +} + +type BankAccountTrackingRecordResponse struct { + Id int64 `json:"id"` + Key string `json:"key"` + SenderName string `json:"senderName"` + SenderIban string `json:"senderIban"` + Description string `json:"description"` + Currency Currency `json:"currency"` + Amount float64 `json:"amount"` + RecordDate TimeResponse `json:"recordDate"` + RecordType RecordType `json:"recordType"` + BankAccountTrackingSource BankAccountTrackingSource `json:"bankAccountTrackingSource"` +} + type RequestOptions struct { BaseURL string ApiKey string diff --git a/tests/bank_account_tracking_test.go b/tests/bank_account_tracking_test.go new file mode 100644 index 0000000..3c4f366 --- /dev/null +++ b/tests/bank_account_tracking_test.go @@ -0,0 +1,26 @@ +package tests + +import ( + "context" + "github.com/craftgate/craftgate-go-client/adapter" + craftgate "github.com/craftgate/craftgate-go-client/adapter" + "github.com/davecgh/go-spew/spew" + "testing" +) + +var bankAccountTrackingClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") + +func TestPayment_SearchBankAccountTrackingRecords(t *testing.T) { + request := adapter.SearchBankAccountTrackingRecordRequest{ + Page: 0, + Size: 10, + Currency: craftgate.Currency("TRY"), + } + + res, err := bankAccountTrackingClient.BankAccountTracking.SearchRecords(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +}