diff --git a/README.md b/README.md index e20bb8c..d4e8fa2 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,23 @@ if err != nil { } ``` +Also, you can pass the options to make localization for API responses. You can use `tr` or `en` right now. +```go +client, _ := craftgate.New("", "", "https://api.craftgate.io", craftgate.WithLocalization("en")) + +request := craftgate.SearchInstallmentsRequest{ + BinNumber: "487074", + Price: 100, + Currency: craftgate.Currency_TRY, +} + +res, err := client.Installment.SearchInstallments(context.Background(), request) + +if err != nil { + t.Errorf("Error %s", err) +} +``` + You should use production API servers at `https://api.craftgate.io` for real world. For testing purposes, please use the sandbox URL `https://sandbox-api.craftgate.io`. ## Examples diff --git a/adapter/craftgate.go b/adapter/craftgate.go index 06a5fb4..b4311f3 100644 --- a/adapter/craftgate.go +++ b/adapter/craftgate.go @@ -65,6 +65,28 @@ func init() { type ClientOption func(*Client) error +func WithLocalization(lang string) ClientOption { + return func(client *Client) error { + if len(lang) > 0 { + client.headers["lang"] = strings.ToLower(lang) + } else { + client.headers["lang"] = "tr" + } + return nil + } +} + +func WithCustomHTTPClient(httpClient *http.Client) ClientOption { + return func(client *Client) error { + if httpClient != nil { + client.httpClient = httpClient + } else { + client.httpClient = http.DefaultClient + } + return nil + } +} + type Client struct { httpClient *http.Client baseURL *url.URL @@ -90,6 +112,8 @@ type Client struct { func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, error) { client := newClient(apiKey, apiSecret) + client.headers = make(map[string]string) + for _, option := range opts { if err := option(client); err != nil { return nil, err @@ -102,7 +126,7 @@ func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, erro if client.baseURL == nil { client.baseURL, _ = url.Parse(baseURL) } - client.headers = make(map[string]string) + return client, nil } diff --git a/adapter/fraud.go b/adapter/fraud.go index 7a3efc9..28bfce6 100644 --- a/adapter/fraud.go +++ b/adapter/fraud.go @@ -54,9 +54,10 @@ func (api *Fraud) RetrieveFraudValueList(ctx context.Context, listName string) ( return response.Data, nil } -func (api *Fraud) CreateFraudValueList(ctx context.Context, listName string) error { +func (api *Fraud) CreateFraudValueList(ctx context.Context, listName string, fraudValueType FraudValueType) error { request := FraudValueListRequest{ ListName: listName, + Type: fraudValueType, } newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/fraud/v1/value-lists", request) @@ -103,8 +104,8 @@ func (api *Fraud) AddValueToFraudValueList(ctx context.Context, request FraudVal return nil } -func (api *Fraud) RemoveValueFromFraudValueList(ctx context.Context, listName, value string) error { - newRequest, err := api.Client.NewRequest(ctx, http.MethodDelete, "/fraud/v1/value-lists/"+listName+"/values/"+value, nil) +func (api *Fraud) RemoveValueFromFraudValueList(ctx context.Context, listName, valueId string) error { + newRequest, err := api.Client.NewRequest(ctx, http.MethodDelete, "/fraud/v1/value-lists/"+listName+"/values/"+valueId, nil) if err != nil { return err } diff --git a/adapter/model.go b/adapter/model.go index 833d890..2682585 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -31,6 +31,7 @@ type TransactionPayoutStatus string type WalletTransactionRefundTransactionType string type FraudAction string type FraudCheckStatus string +type FraudValueType string type AdditionalAction string type ApmAdditionalAction string type ReportFileType string @@ -155,6 +156,11 @@ const ( Currency_IQD Currency = "IQD" Currency_AZN Currency = "AZN" Currency_KZT Currency = "KZT" + Currency_KWD Currency = "KWD" + Currency_SAR Currency = "SAR" + Currency_BHD Currency = "BHD" + Currency_RUB Currency = "RUB" + Currency_JPY Currency = "JPY" ) // payment group declaration @@ -330,6 +336,15 @@ const ( FraudCheckStatus_FRAUD FraudCheckStatus = "FRAUD" ) +// fraud value type type declaration +const ( + FraudValueType_CARD FraudValueType = "CARD" + FraudValueType_IP FraudValueType = "IP" + FraudValueType_PHONE_NUMBER FraudValueType = "PHONE_NUMBER" + FraudValueType_EMAIL FraudValueType = "EMAIL" + FraudValueType_OTHER FraudValueType = "OTHER" +) + // apm additional action type declaration const ( ApmAdditionalAction_REDIRECT_TO_URL ApmAdditionalAction = "REDIRECT_TO_URL" @@ -429,6 +444,11 @@ const ( PosIntegrator_ELEKSE PosIntegrator = "ELEKSE" PosIntegrator_ALGORITMA PosIntegrator = "ALGORITMA" PosIntegrator_PAYCELL PosIntegrator = "PAYCELL" + PosIntegrator_TAMI PosIntegrator = "TAMI" + PosIntegrator_QNB_PAY PosIntegrator = "QNB_PAY" + PosIntegrator_AKBANK_VPOS PosIntegrator = "AKBANK_VPOS" + PosIntegrator_TAP PosIntegrator = "TAP" + PosIntegrator_RUBIK PosIntegrator = "RUBIK" ) const ( @@ -468,30 +488,32 @@ const ( // 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" + 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_MOBILE_PHONE_PRICE_ABOVE_REGULATION_LIMIT BnplCartItemType = "MOBILE_PHONE_PRICE_ABOVE_REGULATION_LIMIT" + BnplCartItemType_MOBILE_PHONE_PRICE_BELOW_REGULATION_LIMIT BnplCartItemType = "MOBILE_PHONE_PRICE_BELOW_REGULATION_LIMIT" + 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 @@ -820,6 +842,7 @@ type MasterpassPaymentTokenGenerateRequest struct { BinNumber string `json:"binNumber,omitempty"` ForceThreeDS bool `json:"forceThreeDS,omitempty"` CreatePayment MasterpassCreatePayment `json:"createPayment,omitempty"` + Loyalty Loyalty `json:"loyalty,omitempty"` } type MasterpassPaymentCompleteRequest struct { @@ -1749,20 +1772,21 @@ type FraudCheckResponse struct { } type FraudPaymentData struct { - PaymentDate *time.Time `json:"paymentDate"` - ConversationId *string `json:"conversationId"` - PaidPrice *float64 `json:"paidPrice"` - Currency *Currency `json:"currency"` - CardFingerprintId *string `json:"cardFingerprintId"` - CardFingerprintExpirationDate *time.Time `json:"cardFingerprintExpirationDate"` - BuyerId *int64 `json:"buyerId"` - ClientIp *string `json:"clientIp"` + PaymentDate *time.Time `json:"paymentDate"` + ConversationId *string `json:"conversationId"` + PaidPrice *float64 `json:"paidPrice"` + Currency *Currency `json:"currency"` + BuyerId *int64 `json:"buyerId"` + ClientIp *string `json:"clientIp"` } type FraudValueListRequest struct { - ListName string `json:"listName,omitempty"` - Value string `json:"value,omitempty"` - DurationInSeconds int `json:"durationInSeconds,omitempty"` + ListName string `json:"listName,omitempty"` + Type FraudValueType `json:"type,omitempty"` + Label string `json:"label,omitempty"` + Value string `json:"value,omitempty"` + PaymentId int64 `json:"paymentId"` + DurationInSeconds int `json:"durationInSeconds,omitempty"` } type FraudValuesResponse struct { @@ -1771,6 +1795,8 @@ type FraudValuesResponse struct { } type FraudValue struct { + Id *string `json:"id"` + Label *string `json:"label"` Value *string `json:"value"` ExpireInSeconds *int `json:"expireInSeconds"` } diff --git a/tests/fraud_test.go b/tests/fraud_test.go index 86e6b25..8f62811 100644 --- a/tests/fraud_test.go +++ b/tests/fraud_test.go @@ -42,7 +42,7 @@ func Test_RetrieveFraudValueList(t *testing.T) { } func Test_CreateFraudValueList(t *testing.T) { - err := fraudClient.Fraud.CreateFraudValueList(context.Background(), "myTestList") + err := fraudClient.Fraud.CreateFraudValueList(context.Background(), "ipList", craftgate.FraudValueType_IP) if err != nil { t.Errorf("Error %s", err) @@ -60,7 +60,39 @@ func Test_DeleteFraudValueList(t *testing.T) { func Test_AddValueToFraudValueList(t *testing.T) { request := adapter.FraudValueListRequest{ ListName: "ipList", - Value: "999.999.999.999", + Type: craftgate.FraudValueType_IP, + Label: "local ip 1", + Value: "127.0.0.1", + } + err := fraudClient.Fraud.AddValueToFraudValueList(context.Background(), request) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func Test_AddTemporaryValueToFraudValueList(t *testing.T) { + request := adapter.FraudValueListRequest{ + ListName: "ipList", + Type: craftgate.FraudValueType_IP, + Label: "local ip 2", + Value: "127.0.0.2", + DurationInSeconds: 60, + } + + err := fraudClient.Fraud.AddValueToFraudValueList(context.Background(), request) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func Test_AddCardFingerprintToFraudValueList(t *testing.T) { + request := adapter.FraudValueListRequest{ + ListName: "cardList", + Type: craftgate.FraudValueType_CARD, + Label: "John Doe's Card", + PaymentId: 11675, } err := fraudClient.Fraud.AddValueToFraudValueList(context.Background(), request) @@ -70,7 +102,7 @@ func Test_AddValueToFraudValueList(t *testing.T) { } func Test_RemoveValueFromFraudValueList(t *testing.T) { - err := fraudClient.Fraud.RemoveValueFromFraudValueList(context.Background(), "ipList", "999.999.999.999") + err := fraudClient.Fraud.RemoveValueFromFraudValueList(context.Background(), "ipList", "7aac0ad8-d170-4c2b-89d3-440fcf145b35") if err != nil { t.Errorf("Error %s", err) diff --git a/tests/payment_test.go b/tests/payment_test.go index fe0544a..881d4f5 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -781,7 +781,7 @@ func TestPayment_BnplPaymentOffer(t *testing.T) { Id: "200", Name: "Test Elektronik 2", BrandName: "iphone", - Type: craftgate.BnplCartItemType_MOBILE_PHONE_BELOW_5000_TRY, + Type: craftgate.BnplCartItemType_MOBILE_PHONE_PRICE_BELOW_REGULATION_LIMIT, UnitPrice: 3000, Quantity: 2, }, @@ -841,7 +841,7 @@ func TestPayment_InitBnplPayment(t *testing.T) { Id: "100", Name: "Test Elektronik 1", BrandName: "Samsung", - Type: craftgate.BnplCartItemType_MOBILE_PHONE_OVER_5000_TRY, + Type: craftgate.BnplCartItemType_MOBILE_PHONE_PRICE_ABOVE_REGULATION_LIMIT, UnitPrice: 4000, Quantity: 1, },