Skip to content

Commit

Permalink
Adds Juzdan integration to Go Client (#69)
Browse files Browse the repository at this point in the history
* Adds Juzdan integration to Go CLient

* Adds Juzdan integration to Go CLient

* Adds Juzdan integration to Go CLient

* Adds Juzdan integration to Go Client

* Adds Juzdan integration to Go Client

* Adds Juzdan integration to Go Client

* fix
  • Loading branch information
beransantur authored and lemiorhan committed Feb 19, 2024
1 parent 84104aa commit 19a65f6
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions adapter/craftgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type Client struct {
Masterpass *Masterpass
BankAccountTracking *BankAccountTracking
Merchant *Merchant
Juzdan *Juzdan
}

func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, error) {
Expand Down
41 changes: 41 additions & 0 deletions adapter/juzdan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package adapter

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

type Juzdan struct {
Client *Client
}

func (api *Juzdan) InitJuzdanPayment(ctx context.Context, request InitJuzdanPaymentRequest) (*InitJuzdanPaymentResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/juzdan-payments/init", request)
if err != nil {
return nil, err
}

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

return response.Data, nil
}

func (api *Juzdan) RetrieveJuzdanPayment(ctx context.Context, referenceId string) (*PaymentResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/payment/v1/juzdan-payments/%s", referenceId), nil)

if err != nil {
return nil, err
}

response := &Response[PaymentResponse]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}
return response.Data, nil
}
28 changes: 28 additions & 0 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type BankAccountTrackingSource string
type BnplCartItemType string
type PaymentAuthenticationType string
type CardBrand string
type ClientType string

const (
ApiKeyHeaderName = "x-api-key"
Expand Down Expand Up @@ -541,6 +542,11 @@ const (
CardBrand_SAGLAM_KART CardBrand = "Sağlam Kart"
)

const (
ClientType_W ClientType = "W"
ClientType_M ClientType = "M"
)

// requests
type CreatePaymentRequest struct {
Price float64 `json:"price,omitempty"`
Expand Down Expand Up @@ -2083,6 +2089,28 @@ type CreateMerchantPosCommissionRequest struct {
Commissions []CreateMerchantPosCommission `json:"commissions"`
}

type InitJuzdanPaymentRequest struct {
Price float64 `json:"price,omitempty"`
PaidPrice float64 `json:"paidPrice,omitempty"`
Currency Currency `json:"currency,omitempty"`
PaymentGroup PaymentGroup `json:"paymentGroup,omitempty"`
ConversationId string `json:"conversationId,omitempty"`
ExternalId string `json:"externalId,omitempty"`
CallbackUrl string `json:"callbackUrl,omitempty"`
PaymentPhase PaymentPhase `json:"paymentPhase,omitempty"`
PaymentChannel string `json:"paymentChannel,omitempty"`
BuyerMemberId int64 `json:"buyerMemberId,omitempty"`
BankOrderId string `json:"bankOrderId,omitempty"`
Items []PaymentItem `json:"items"`
ClientType ClientType `json:"clientType,omitempty"`
LoanCampaignId int64 `json:"loanCampaignId,omitempty"`
}

type InitJuzdanPaymentResponse struct {
ReferenceId string `json:"referenceId"`
JuzdanQrUrl string `json:"juzdanQrUrl"`
}

type PaymentError ErrorResponse

type Void struct {
Expand Down
58 changes: 58 additions & 0 deletions tests/juzdan_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package tests

import (
"context"
"github.com/craftgate/craftgate-go-client/adapter"
craftgate "github.com/craftgate/craftgate-go-client/adapter"
"github.com/stretchr/testify/require"
"github.com/davecgh/go-spew/spew"
"testing"
)

var juzdanClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io")

func Test_InitJuzdanPayment(t *testing.T) {
request := adapter.InitJuzdanPaymentRequest{
Price: 1.25,
PaidPrice: 1.25,
Currency: craftgate.Currency_TRY,
PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION,
ConversationId: "foo-bar",
ExternalId: "115",
CallbackUrl: "www.test.com",
PaymentPhase: craftgate.PaymentPhase_AUTH,
PaymentChannel: "test",
BankOrderId: "test",
Items: []craftgate.PaymentItem{
{
Name: "Item 1",
Price: 1,
ExternalId: "1",
},
{
Name: "Item 2",
Price: 0.25,
ExternalId: "2",
},
},
ClientType: craftgate.ClientType_W,
LoanCampaignId: 1,
}

res, err := juzdanClient.Juzdan.InitJuzdanPayment(context.Background(), request)

require.NotNil(t, res.JuzdanQrUrl)
require.NotNil(t, res.ReferenceId)
if err != nil {
t.Errorf("Error %s", err)
}
}

func Test_RetrieveJuzdanPayment(t *testing.T) {
res, err := juzdanClient.Juzdan.RetrieveJuzdanPayment(context.Background(), "test-reference-id")
_, _ = spew.Printf("%#v\n", res)

if err != nil {
t.Errorf("Error %s", err)
}
}

0 comments on commit 19a65f6

Please sign in to comment.