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 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
41 changes: 41 additions & 0 deletions adapter/bank_account_tracking.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package adapter

import (
"context"
"fmt"
"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
}

func (api *BankAccountTracking) RetrieveRecords(ctx context.Context, id int64) (*BankAccountTrackingRecordResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/bank-account-tracking/v1/merchant-bank-account-trackings/records/%d", id), nil)
if err != nil {
return nil, err
}
response := &Response[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 @@ -84,6 +84,7 @@ type Client struct {
Fraud *Fraud
Hook *Hook
Masterpass *Masterpass
BankAccountTracking *BankAccountTracking
}

func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, error) {
Expand Down Expand Up @@ -119,6 +120,7 @@ func newClient(apiKey, secretKey string) *Client {
client.Fraud = &Fraud{Client: client}
client.Hook = &Hook{Client: client}
client.Masterpass = &Masterpass{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 @@ -44,6 +44,8 @@ type PosOperationType 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 @@ -441,6 +443,17 @@ const (
PayoutAccountType_WISE PayoutAccountType = "WISE"
)

// RecordType declaration
const (
RecordType_SEND RecordType = "SEND"
RecordType_RECEIVE RecordType = "RECEIVE"
)

// BankAccountTrackingSource declaration
const (
BankAccountTrackingSource_YKB BankAccountTrackingSource = "YKB"
)

// requests
type CreatePaymentRequest struct {
Price float64 `json:"price,omitempty"`
Expand Down Expand Up @@ -1637,6 +1650,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
35 changes: 35 additions & 0 deletions tests/bank_account_tracking_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 TestBankAccountTracking_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)
}
}

func TestBankAccountTracking_RetrieveRecord(t *testing.T) {
res, err := bankAccountTrackingClient.BankAccountTracking.RetrieveRecords(context.Background(), 1)
_, _ = spew.Printf("%#v\n", res)

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