Skip to content

Commit

Permalink
adds merchant & pos operations (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlicanAkkus authored Dec 5, 2023
1 parent 1720346 commit b07f93f
Show file tree
Hide file tree
Showing 6 changed files with 446 additions and 2 deletions.
2 changes: 2 additions & 0 deletions adapter/craftgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type Client struct {
Hook *Hook
Masterpass *Masterpass
BankAccountTracking *BankAccountTracking
Merchant *Merchant
}

func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, error) {
Expand Down Expand Up @@ -121,6 +122,7 @@ func newClient(apiKey, secretKey string) *Client {
client.Hook = &Hook{Client: client}
client.Masterpass = &Masterpass{Client: client}
client.BankAccountTracking = &BankAccountTracking{Client: client}
client.Merchant = &Merchant{Client: client}

return client
}
Expand Down
116 changes: 116 additions & 0 deletions adapter/merchant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package adapter

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

type Merchant struct {
Client *Client
}

func (api *Merchant) CreateMerchantPos(ctx context.Context, request CreateMerchantPosRequest) (*MerchantPosResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/merchant/v1/merchant-poses", request)

if err != nil {
return nil, err
}

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

func (api *Merchant) RetrieveMerchantPos(ctx context.Context, id int64) (*MerchantPosResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/merchant/v1/merchant-poses/%d", id), nil)

if err != nil {
return nil, err
}

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

func (api *Merchant) SearchMerchantPos(ctx context.Context, request SearchMerchantPosRequest) (*DataResponse[MerchantPosResponse], error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/merchant/v1/merchant-poses", request)

if err != nil {
return nil, err
}

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

func (api *Merchant) UpdateMerchantPosStatus(ctx context.Context, id int64, status PosStatus) error {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPut, fmt.Sprintf("/merchant/v1/merchant-poses/%d/status/%s", id, status), nil)

if err != nil {
return err
}

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

func (api *Merchant) DeleteMerchantPosStatus(ctx context.Context, id int64) error {
newRequest, err := api.Client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("/merchant/v1/merchant-poses/%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 *Merchant) RetrieveMerchantPosCommissions(ctx context.Context, id int64) (*DataResponse[MerchantPosCommissionResponse], error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/merchant/v1/merchant-poses/%d/commissions", id), nil)

if err != nil {
return nil, err
}

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

func (api *Merchant) UpdateMerchantPosCommissions(ctx context.Context, id int64, request CreateMerchantPosCommissionRequest) (*DataResponse[MerchantPosCommissionResponse], error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("/merchant/v1/merchant-poses/%d/commissions", id), request)

if err != nil {
return nil, err
}

response := &Response[DataResponse[MerchantPosCommissionResponse]]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}
return response.Data, nil
}
168 changes: 166 additions & 2 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type PayoutAccountType string
type RecordType string
type BankAccountTrackingSource string
type BnplCartItemType string
type PaymentAuthenticationType string
type CardBrand string

const (
ApiKeyHeaderName = "x-api-key"
Expand Down Expand Up @@ -394,12 +396,13 @@ const (
PosIntegrator_AKBANK PosIntegrator = "AKBANK"
PosIntegrator_ZIRAATBANK PosIntegrator = "ZIRAATBANK"
PosIntegrator_ZIRAATBANK_INNOVA PosIntegrator = "ZIRAATBANK_INNOVA"
PosIntegrator_ZIRAATKATILIM PosIntegrator = "ZIRAATKATILIM"
PosIntegrator_KUVEYTTURK PosIntegrator = "KUVEYTTURK"
PosIntegrator_HALKBANK PosIntegrator = "HALKBANK"
PosIntegrator_DENIZBANK PosIntegrator = "DENIZBANK"
PosIntegrator_VAKIFBANK PosIntegrator = "VAKIFBANK"
PosIntegrator_VAKIFKATILIM PosIntegrator = "VAKIFKATILIM"
PosIntegrator_FINANSBANK PosIntegrator = "FINANSBANK"
PosIntegrator_FINANSBANK_ASSECO PosIntegrator = "FINANSBANK_ASSECO"
PosIntegrator_FIBABANK PosIntegrator = "FIBABANK"
PosIntegrator_FIBABANK_ASSECO PosIntegrator = "FIBABANK_ASSECO"
PosIntegrator_ANADOLUBANK PosIntegrator = "ANADOLUBANK"
Expand All @@ -416,7 +419,11 @@ const (
PosIntegrator_OZAN PosIntegrator = "OZAN"
PosIntegrator_BRAINTREE PosIntegrator = "BRAINTREE"
PosIntegrator_NKOLAY PosIntegrator = "NKOLAY"
PosIntegrator_FAKE PosIntegrator = "FAKE"
PosIntegrator_PAYTABS PosIntegrator = "PAYTABS"
PosIntegrator_PAYBULL PosIntegrator = "PAYBULL"
PosIntegrator_ELEKSE PosIntegrator = "ELEKSE"
PosIntegrator_ALGORITMA PosIntegrator = "ALGORITMA"
PosIntegrator_PAYCELL PosIntegrator = "PAYCELL"
)

const (
Expand Down Expand Up @@ -493,6 +500,23 @@ const (
BankAccountTrackingSource_YKB BankAccountTrackingSource = "YKB"
)

const (
PaymentAuthenticationType_THREE_DS PaymentAuthenticationType = "THREE_DS"
PaymentAuthenticationType_NON_THREE_DS PaymentAuthenticationType = "NON_THREE_DS"
)

const (
CardBrand_BONUS CardBrand = "Bonus"
CardBrand_AXESS CardBrand = "Axess"
CardBrand_MAXIMUM CardBrand = "Maximum"
CardBrand_WORLD CardBrand = "World"
CardBrand_PARAF CardBrand = "Paraf"
CardBrand_CARD_FINANS CardBrand = "CardFinans"
CardBrand_BANKKART_COMBO CardBrand = "Bankkart Combo"
CardBrand_ADVANTAGE CardBrand = "Advantage"
CardBrand_SAGLAM_KART CardBrand = "Sağlam Kart"
)

// requests
type CreatePaymentRequest struct {
Price float64 `json:"price,omitempty"`
Expand Down Expand Up @@ -1889,6 +1913,146 @@ type MasterpassCreatePayment struct {
AdditionalParams map[string]interface{} `json:"additionalParams,omitempty"`
}

type CreateMerchantRequest struct {
Name string `json:"name"`
LegalCompanyTitle string `json:"legalCompanyTitle"`
Email string `json:"email"`
SecretWord string `json:"secretWord,omitempty"`
Website string `json:"website"`
PhoneNumber string `json:"phoneNumber,omitempty"`
ContactName string `json:"contactName"`
ContactSurname string `json:"contactSurname"`
ContactPhoneNumber string `json:"contactPhoneNumber"`
}

type MerchantApiCredential struct {
Name string `json:"name"`
ApiKey string `json:"apiKey"`
SecretKey string `json:"secretKey"`
}

type CreateMerchantResponse struct {
Id *int64 `json:"id"`
Name *string `json:"name"`
MerchantApiCredentials []MerchantApiCredential `json:"merchantApiCredentials"`
}

type CreateMerchantPosUser struct {
PosUsername string `json:"posUsername"`
PosPassword string `json:"posPassword"`
PosUserType PosUserType `json:"posUserType"`
PosOperationType PosOperationType `json:"posOperationType"`
}

type CreateMerchantPosRequest struct {
Status PosStatus `json:"status"`
Name string `json:"name"`
ClientId string `json:"clientId"`
Currency Currency `json:"currency"`
PosnetId string `json:"posnetId,omitempty"`
TerminalId string `json:"terminalId,omitempty"`
ThreedsPosnetId string `json:"threedsPosnetId,omitempty"`
ThreedsTerminalId string `json:"threedsTerminalId,omitempty"`
ThreedsKey string `json:"threedsKey,omitempty"`
EnableForeignCard bool `json:"enableForeignCard"`
EnableInstallment bool `json:"enableInstallment"`
EnablePaymentWithoutCvc bool `json:"enablePaymentWithoutCvc"`
NewIntegration bool `json:"newIntegration"`
OrderNumber int64 `json:"orderNumber"`
PosIntegrator PosIntegrator `json:"posIntegrator"`
EnabledPaymentAuthenticationTypes []PaymentAuthenticationType `json:"enabledPaymentAuthenticationTypes"`
MerchantPosUsers []CreateMerchantPosUser `json:"merchantPosUsers"`
}

type AutopilotState struct {
IsThreeDsUp bool `json:"isThreeDsUp"`
IsNonThreeDsUp bool `json:"isNonThreeDsUp"`
}

type MerchantPosUser struct {
Id int64 `json:"id"`
PosUsername string `json:"posUsername"`
PosPassword string `json:"posPassword"`
PosUserType PosUserType `json:"posUserType"`
PosOperationType PosOperationType `json:"posOperationType"`
}
type MerchantPosResponse struct {
Id int64 `json:"id"`
Status PosStatus `json:"status"`
Name string `json:"name"`
Alias string `json:"alias"`
PosIntegrator PosIntegrator `json:"posIntegrator"`
Hostname string `json:"hostname"`
ClientId string `json:"clientId"`
PosCurrencyCode string `json:"posCurrencyCode"`
Mode string `json:"mode"`
Path string `json:"path"`
Port int64 `json:"port"`
PosnetId string `json:"posnetId"`
TerminalId string `json:"terminalId"`
ThreedsPosnetId string `json:"threedsPosnetId"`
ThreedsTerminalId string `json:"threedsTerminalId"`
ThreedsKey string `json:"threedsKey"`
ThreedsPath string `json:"threedsPath"`
EnableForeignCard bool `json:"enableForeignCard"`
EnableInstallment bool `json:"enableInstallment"`
EnablePaymentWithoutCvc bool `json:"enablePaymentWithoutCvc"`
NewIntegration bool `json:"newIntegration"`
OrderNumber int64 `json:"orderNumber"`
AutopilotState AutopilotState `json:"autopilotState"`
Currency Currency `json:"currency"`
BankId int64 `json:"bankId"`
BankName string `json:"bankName"`
IsPf bool `json:"isPf"`
MerchantPosUsers []MerchantPosUser `json:"merchantPosUsers"`
SupportedCardAssociations []CardAssociation `json:"supportedCardAssociations"`
EnabledPaymentAuthenticationTypes []PaymentAuthenticationType `json:"enabledPaymentAuthenticationTypes"`
}

type MerchantPosCommissionResponse struct {
Id int64 `json:"id"`
Status Status `json:"status"`
Installment int64 `json:"installment"`
BlockageDay int64 `json:"blockageDay"`
InstallmentLabel string `json:"installmentLabel"`
CardBrandName CardBrand `json:"cardBrandName"`
BankOnUsCreditCardCommissionRate float64 `json:"bankOnUsCreditCardCommissionRate"`
BankNotOnUsCreditCardCommissionRate float64 `json:"bankNotOnUsCreditCardCommissionRate"`
BankOnUsDebitCardCommissionRate float64 `json:"bankOnUsDebitCardCommissionRate"`
BankNotOnUsDebitCardCommissionRate float64 `json:"bankNotOnUsDebitCardCommissionRate"`
BankForeignCardCommissionRate float64 `json:"bankForeignCardCommissionRate"`
MerchantCommissionRate float64 `json:"merchantCommissionRate"`
}

type CreateMerchantPosCommission struct {
CardBrandName CardBrand `json:"cardBrandName,omitempty"`
Installment int64 `json:"installment"`
Status Status `json:"status"`
BlockageDay int64 `json:"blockageDay"`
InstallmentLabel string `json:"installmentLabel,omitempty"`
BankOnUsCreditCardCommissionRate float64 `json:"bankOnUsCreditCardCommissionRate"`
BankOnUsDebitCardCommissionRate float64 `json:"bankOnUsDebitCardCommissionRate,omitempty"`
BankNotOnUsCreditCardCommissionRate float64 `json:"bankNotOnUsCreditCardCommissionRate,omitempty"`
BankNotOnUsDebitCardCommissionRate float64 `json:"bankNotOnUsDebitCardCommissionRate,omitempty"`
BankForeignCardCommissionRate float64 `json:"bankForeignCardCommissionRate,omitempty"`
MerchantCommissionRate float64 `json:"merchantCommissionRate,omitempty"`
}

type SearchMerchantPosRequest struct {
Name string `schema:"name,omitempty"`
Alias string `schema:"alias,omitempty"`
Currency Currency `schema:"currency,omitempty"`
EnableInstallment bool `schema:"enableInstallment,omitempty"`
EnableForeignCard bool `schema:"enableForeignCard,omitempty"`
BankName string `schema:"bankName,omitempty"`
Page int64 `schema:"page,omitempty"`
Size int64 `schema:"size,omitempty"`
}

type CreateMerchantPosCommissionRequest struct {
Commissions []CreateMerchantPosCommission `json:"commissions"`
}

type PaymentError ErrorResponse

type Void struct {
Expand Down
15 changes: 15 additions & 0 deletions adapter/onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,18 @@ func (api *Onboarding) SearchMembers(ctx context.Context, request SearchMembersR

return response.Data, nil
}

func (api *Onboarding) CreateMerchant(ctx context.Context, request CreateMerchantRequest) (*CreateMerchantResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/onboarding/v1/merchants", request)

if err != nil {
return nil, err
}

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

0 comments on commit b07f93f

Please sign in to comment.