Skip to content

Commit

Permalink
add payout account crud operations
Browse files Browse the repository at this point in the history
  • Loading branch information
tuncaserhat committed Jul 17, 2023
1 parent b9dc2d4 commit d1098a2
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 11 deletions.
41 changes: 41 additions & 0 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type WalletTransactionType string
type WebhookEventType string
type WebhookStatus string
type FileStatus string
type AccountOwner string
type PayoutAccountType string

const (
ApiKeyHeaderName = "x-api-key"
Expand Down Expand Up @@ -321,6 +323,15 @@ const (
FileStatusAPPROVED FileStatus = "APPROVED"
)

const (
AccountOwnerMERCHANT AccountOwner = "MERCHANT"
AccountOwnerSUB_MERCHANT_MEMBER AccountOwner = "SUB_MERCHANT_MEMBER"
)

const (
PayoutAccountTypeWISE PayoutAccountType = "WISE"
)

// requests
type CreatePaymentRequest struct {
Price float64 `json:"price,omitempty"`
Expand Down Expand Up @@ -564,6 +575,27 @@ type CheckMasterpassUserRequest struct {
MasterpassGsmNumber string `json:"masterpassGsmNumber"`
}

type CreatePayoutAccountRequest struct {
AccountType PayoutAccountType `json:"type,omitempty"`
ExternalAccountId string `json:"externalAccountId,omitempty"`
Currency Currency `json:"currency,omitempty"`
AccountOwner AccountOwner `json:"accountOwner,omitempty"`
SubMerchantMemberId int64 `json:"subMerchantMemberId,omitempty"`
}

type UpdatePayoutAccountRequest struct {
AccountType PayoutAccountType `json:"type,omitempty"`
ExternalAccountId string `json:"externalAccountId,omitempty"`
}

type SearchPayoutAccountRequest struct {
Currency Currency `json:"currency,omitempty"`
AccountOwner AccountOwner `json:"accountOwner,omitempty"`
SubMerchantMemberId int64 `json:"subMerchantMemberId,omitempty"`
Page int `schema:"page,omitempty"`
Size int `schema:"size,omitempty"`
}

// responses
type PaymentResponse struct {
Id *int64 `json:"id"`
Expand Down Expand Up @@ -685,6 +717,15 @@ type ApmDepositPaymentResponse struct {
WalletTransaction *WalletTransaction `json:"walletTransaction"`
}

type PayoutAccountResponse struct {
Id *int64 `json:"id"`
AccountType *PayoutAccountType `json:"type"`
ExternalAccountId *string `json:"externalAccountId"`
Currency *Currency `json:"currency"`
AccountOwner *AccountOwner `json:"accountOwner"`
SubMerchantMemberId *int64 `json:"subMerchantMemberId"`
}

type RefundWalletTransactionRequest struct {
RefundPrice float64 `json:"refundPrice"`
}
Expand Down
61 changes: 61 additions & 0 deletions adapter/settlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package adapter

import (
"context"
"fmt"
"net/http"
)

Expand All @@ -23,3 +24,63 @@ func (api *Settlement) CreateInstantWalletSettlement(ctx context.Context, reques

return response.Data, nil
}

func (api *Settlement) CreatePayoutAccount(ctx context.Context, request CreatePayoutAccountRequest) (*PayoutAccountResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/settlement/v1/payout-accounts", request)
if err != nil {
return nil, err
}

response := &Response[PayoutAccountResponse]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}

return response.Data, nil
}

func (api *Settlement) UpdatePayoutAccount(ctx context.Context, id int64, request UpdatePayoutAccountRequest) error {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPut, fmt.Sprintf("/settlement/v1/payout-accounts/%d", id), request)
if err != nil {
return err
}

response := &Void{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return err
}

return nil
}

func (api *Settlement) DeletePayoutAccount(ctx context.Context, id int64) error {
newRequest, err := api.Client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("/settlement/v1/payout-accounts/%d", id), nil)
if err != nil {
return err
}

response := &Void{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return err
}

return nil
}

func (api *Settlement) SearchPayoutAccounts(ctx context.Context, request SearchPayoutAccountRequest) (*DataResponse[PayoutAccountResponse], error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/settlement/v1/payout-accounts", request)
if err != nil {
return nil, err
}

response := &Response[DataResponse[PayoutAccountResponse]]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}

return response.Data, nil
}
90 changes: 79 additions & 11 deletions tests/settlement_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,90 @@
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"
"context"
"github.com/craftgate/craftgate-go-client/adapter"
craftgate "github.com/craftgate/craftgate-go-client/adapter"
"github.com/davecgh/go-spew/spew"
"testing"
)

var settlementClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io")

func TestSettlement_CreateInstantWalletSettlement(t *testing.T) {
request := adapter.CreateInstantWalletSettlementRequest{ExcludedSubMerchantMemberIds: []int64{1, 2}}
request := adapter.CreateInstantWalletSettlementRequest{ExcludedSubMerchantMemberIds: []int64{1, 2}}

res, err := settlementClient.Settlement.CreateInstantWalletSettlement(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)
res, err := settlementClient.Settlement.CreateInstantWalletSettlement(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)

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

func TestSettlement_CreateMerchantPayoutAccount(t *testing.T) {
request := adapter.CreatePayoutAccountRequest{
AccountType: craftgate.PayoutAccountTypeWISE,
ExternalAccountId: "wiseRecipientId",
Currency: craftgate.USD,
AccountOwner: craftgate.AccountOwnerMERCHANT,
}

res, err := settlementClient.Settlement.CreatePayoutAccount(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)

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

func TestSettlement_CreateSubMerchantPayoutAccount(t *testing.T) {
request := adapter.CreatePayoutAccountRequest{
AccountType: craftgate.PayoutAccountTypeWISE,
ExternalAccountId: "wiseRecipientId",
Currency: craftgate.EUR,
AccountOwner: craftgate.AccountOwnerSUB_MERCHANT_MEMBER,
SubMerchantMemberId: 1,
}

res, err := settlementClient.Settlement.CreatePayoutAccount(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)

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

func TestSettlement_UpdatePayoutAccount(t *testing.T) {
request := adapter.UpdatePayoutAccountRequest{
AccountType: craftgate.PayoutAccountTypeWISE,
ExternalAccountId: "wiseRecipientId2",
}

err := settlementClient.Settlement.UpdatePayoutAccount(context.Background(), 18, request)

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

func TestSettlement_DeletePayoutAccount(t *testing.T) {
err := settlementClient.Settlement.DeletePayoutAccount(context.Background(), 18)

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

func TestSettlement_SearchPayoutAccounts(t *testing.T) {
request := adapter.SearchPayoutAccountRequest{
Currency: craftgate.USD,
AccountOwner: craftgate.AccountOwnerMERCHANT,
}

res, err := settlementClient.Settlement.SearchPayoutAccounts(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)

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

0 comments on commit d1098a2

Please sign in to comment.