Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds bank account tracking adapter to retrieve bank account tracking record #41

Merged
merged 6 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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"
AlicanAkkus marked this conversation as resolved.
Show resolved Hide resolved
)

// BankAccountTrackingSource declaration
const (
YKB BankAccountTrackingSource = "YKB"
AlicanAkkus marked this conversation as resolved.
Show resolved Hide resolved
)

// 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"),
AlicanAkkus marked this conversation as resolved.
Show resolved Hide resolved
}

res, err := bankAccountTrackingClient.BankAccountTracking.SearchRecords(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)

if err != nil {
t.Errorf("Error %s", err)
}
}
Loading