Skip to content

Commit

Permalink
Merge branch 'master' into paycell-type
Browse files Browse the repository at this point in the history
  • Loading branch information
lemiorhan committed Feb 2, 2024
2 parents 6fd1b82 + 87884b7 commit f462da4
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 44 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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("<YOUR API KEY>", "<YOUR SECRET KEY>", "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
Expand Down
26 changes: 25 additions & 1 deletion adapter/craftgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}

Expand Down
7 changes: 4 additions & 3 deletions adapter/fraud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
96 changes: 61 additions & 35 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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"`
}
Expand Down
38 changes: 35 additions & 3 deletions tests/fraud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit f462da4

Please sign in to comment.