Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/go_modules/github.com/gorilla/s…
Browse files Browse the repository at this point in the history
…chema-1.2.1
  • Loading branch information
sotuzun authored Nov 14, 2023
2 parents 7c76e89 + b888490 commit b878d6d
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 0 deletions.
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
141 changes: 141 additions & 0 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type PosOperationType string
type FileStatus string
type AccountOwner string
type PayoutAccountType string
type RecordType string
type BankAccountTrackingSource string
type BnplCartItemType string

const (
ApiKeyHeaderName = "x-api-key"
Expand Down Expand Up @@ -77,6 +80,8 @@ const (
ApmType_AFTERPAY ApmType = "AFTERPAY"
ApmType_KASPI ApmType = "KASPI"
ApmType_TOMPAY ApmType = "TOMPAY"
ApmType_MASLAK ApmType = "MASLAK"
ApmType_ALFABANK ApmType = "ALFABANK"
ApmType_STRIPE ApmType = "STRIPE"
ApmType_FUND_TRANSFER ApmType = "FUND_TRANSFER"
ApmType_CASH_ON_DELIVERY ApmType = "CASH_ON_DELIVERY"
Expand Down Expand Up @@ -441,6 +446,45 @@ const (
PayoutAccountType_WISE PayoutAccountType = "WISE"
)

// BnplCartItemType type declaration
const (
BnplCartItemType_MOBILE_PHONE_OVER_5000_TRY BnplCartItemType = "MOBILE_PHONE_OVER_5000_TRY"
BnplCartItemType_MOBILE_PHONE_BELOW_5000_TRY BnplCartItemType = "MOBILE_PHONE_BELOW_5000_TRY"
BnplCartItemType_TABLET BnplCartItemType = "TABLET"
BnplCartItemType_COMPUTER BnplCartItemType = "COMPUTER"
BnplCartItemType_CONSTRUCTION_MARKET BnplCartItemType = "CONSTRUCTION_MARKET"
BnplCartItemType_GOLD BnplCartItemType = "GOLD"
BnplCartItemType_DIGITAL_PRODUCTS BnplCartItemType = "DIGITAL_PRODUCTS"
BnplCartItemType_SUPERMARKET BnplCartItemType = "SUPERMARKET"
BnplCartItemType_WHITE_GOODS BnplCartItemType = "WHITE_GOODS"
BnplCartItemType_WEARABLE_TECHNOLOGY BnplCartItemType = "WEARABLE_TECHNOLOGY"
BnplCartItemType_SMALL_HOME_APPLIANCES BnplCartItemType = "SMALL_HOME_APPLIANCES"
BnplCartItemType_TV BnplCartItemType = "TV"
BnplCartItemType_GAMES_CONSOLES BnplCartItemType = "GAMES_CONSOLES"
BnplCartItemType_AIR_CONDITIONER_AND_HEATER BnplCartItemType = "AIR_CONDITIONER_AND_HEATER"
BnplCartItemType_ELECTRONICS BnplCartItemType = "ELECTRONICS"
BnplCartItemType_ACCESSORIES BnplCartItemType = "ACCESSORIES"
BnplCartItemType_MOM_AND_BABY_AND_KIDS BnplCartItemType = "MOM_AND_BABY_AND_KIDS"
BnplCartItemType_SHOES BnplCartItemType = "SHOES"
BnplCartItemType_CLOTHING BnplCartItemType = "CLOTHING"
BnplCartItemType_COSMETICS_AND_PERSONAL_CARE BnplCartItemType = "COSMETICS_AND_PERSONAL_CARE"
BnplCartItemType_FURNITURE BnplCartItemType = "FURNITURE"
BnplCartItemType_HOME_LIVING BnplCartItemType = "HOME_LIVING"
BnplCartItemType_AUTOMOBILE_MOTORCYCLE BnplCartItemType = "AUTOMOBILE_MOTORCYCLE"
BnplCartItemType_OTHER BnplCartItemType = "OTHER"
)

// 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 @@ -755,6 +799,47 @@ type MasterpassPaymentThreeDSCompleteRequest struct {
PaymentId int64 `json:"paymentId,omitempty"`
}

type InitBnplPaymentRequest struct {
ApmType ApmType `json:"apmType"`
MerchantApmId int64 `json:"merchantApmId,omitempty"`
Price float64 `json:"price"`
PaidPrice float64 `json:"paidPrice"`
CommissionRate float64 `json:"commissionRate,omitempty"`
Currency Currency `json:"currency"`
PaymentType PaymentType `json:"paymentType"`
PaymentGroup PaymentGroup `json:"paymentGroup"`
PaymentSource PaymentSource `json:"paymentSource,omitempty"`
PaymentChannel string `json:"paymentChannel,omitempty"`
ConversationId string `json:"conversationId,omitempty"`
ExternalId string `json:"externalId,omitempty"`
CallbackUrl string `json:"callbackUrl"`
BuyerMemberId int64 `json:"buyerMemberId,omitempty"`
ApmOrderId string `json:"apmOrderId,omitempty"`
ClientIp string `json:"clientIp,omitempty"`
ApmUserIdentity string `json:"apmUserIdentity,omitempty"`
AdditionalParams map[string]interface{} `json:"additionalParams"`
Items []PaymentItem `json:"items"`
BankCode string `json:"bankCode"`
CartItems []BnplPaymentCartItem `json:"cartItems"`
}

type BnplPaymentCartItem struct {
Id string `json:"id"`
Name string `json:"name"`
BrandName string `json:"brandName"`
Type BnplCartItemType `json:"type"`
UnitPrice float64 `json:"unitPrice"`
Quantity int64 `json:"quantity"`
}

type BnplPaymentOfferRequest struct {
ApmType ApmType `json:"apmType"`
MerchantApmId int64 `json:"merchantApmId,omitempty"`
Price float64 `json:"price"`
Currency Currency `json:"currency"`
Items []BnplPaymentCartItem `json:"items"`
}

// responses
type PaymentResponse struct {
Id *int64 `json:"id"`
Expand Down Expand Up @@ -1468,6 +1553,38 @@ type ReportingPaymentTransactionResponse struct {
PayoutStatus *PayoutStatus `json:"payoutStatus"`
}

type InitBnplPaymentResponse struct {
PaymentId int64 `json:"paymentId"`
RedirectUrl string `json:"redirectUrl"`
PaymentStatus PaymentStatus `json:"paymentStatus"`
AdditionalAction ApmAdditionalAction `json:"additionalAction"`
PaymentError PaymentError `json:"paymentError"`
}

type BnplPaymentOfferResponse struct {
OfferId string `json:"offerId"`
Price *float64 `json:"price"`
BnplBankOffers *[]BnplBankOffer `json:"nnplBankOffers"`
}

type BnplBankOffer struct {
BankCode string `json:"bankCode"`
BankName string `json:"bankName"`
BankIconUrl string `json:"bankIconUrl"`
BankTableBannerMessage string `json:"bankTableBannerMessage"`
BankSmallBannerMessage string `json:"bankSmallBannerMessage"`
IsSupportNonCustomer bool `json:"isSupportNonCustomer"`
BnplBankOfferTerm *[]BnplBankOfferTerm `json:"bankOfferTerms"`
}

type BnplBankOfferTerm struct {
Term int64 `json:"term"`
Amount *float64 `json:"amount"`
TotalAmount *float64 `json:"totalAmount"`
InterestRate *float64 `json:"interestRate"`
AnnualInterestRate *float64 `json:"annualInterestRate"`
}

type Payout struct {
PaidPrice *float64 `json:"paidPrice"`
Parity *float64 `json:"parity"`
Expand Down Expand Up @@ -1637,6 +1754,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
45 changes: 45 additions & 0 deletions adapter/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,51 @@ func (api *Payment) DisapprovePaymentTransactions(ctx context.Context, request P
return response.Data, nil
}

func (api *Payment) RetrieveBnplOffers(ctx context.Context, request BnplPaymentOfferRequest) (*DataResponse[BnplPaymentOfferResponse], error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bnpl-payments/offers", request)
if err != nil {
return nil, err
}

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

return response.Data, nil
}

func (api *Payment) InitBnplPayment(ctx context.Context, request InitBnplPaymentRequest) (*InitBnplPaymentResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bnpl-payments/init", request)
if err != nil {
return nil, err
}
response := &Response[InitBnplPaymentResponse]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}

return response.Data, nil
}

func (api *Payment) ApproveBnplPayment(ctx context.Context, paymentId int64) error {

newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("/payment/v1/bnpl-payments/%d/approve", paymentId), nil)
if err != nil {
return err
}

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

return nil
}

func (c *Payment) Is3DSecureCallbackVerified(threeDSecureCallbackKey string, params map[string]string) bool {
hash := params["hash"]
hashString := strings.Join([]string{threeDSecureCallbackKey,
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

0 comments on commit b878d6d

Please sign in to comment.