Skip to content

Commit

Permalink
adds bank account tracking adapter to retrieve bank account tracking …
Browse files Browse the repository at this point in the history
…record
  • Loading branch information
Alican Akkus authored and Alican Akkus committed Jul 24, 2023
1 parent 95bdfa7 commit 020deb7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
25 changes: 25 additions & 0 deletions adapter/bank_account_tracking.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions adapter/craftgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
37 changes: 37 additions & 0 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions tests/bank_account_tracking_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 020deb7

Please sign in to comment.