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

add payout account crud operations #39

Merged
merged 3 commits into from
Jul 21, 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
46 changes: 44 additions & 2 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 @@ -215,8 +217,9 @@ const (

// settlementEarningsDestination type declaration
const (
SettlementEarningsDestinationIBAN SettlementEarningsDestination = "IBAN"
SettlementEarningsDestinationWALLET SettlementEarningsDestination = "WALLET"
SettlementEarningsDestinationIBAN SettlementEarningsDestination = "IBAN"
SettlementEarningsDestinationWALLET SettlementEarningsDestination = "WALLET"
SettlementEarningsDestinationCROSS_BORDER SettlementEarningsDestination = "CROSS_BORDER"
)

// refundDestinationType type declaration
Expand Down Expand Up @@ -321,6 +324,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 +576,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 +718,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) {
tuncaserhat marked this conversation as resolved.
Show resolved Hide resolved
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"
tuncaserhat marked this conversation as resolved.
Show resolved Hide resolved
"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)
}
}
Loading