Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BKM Express Integration #97

Merged
merged 8 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions adapter/bkm_express.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package adapter

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

type BkmExpress struct {
Client *Client
}

func (api *BkmExpress) Init(ctx context.Context, request InitBkmExpressRequest) (*InitBkmExpressResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bkm-express/init", request)
if err != nil {
return nil, err
}

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

return response.Data, nil
}

func (api *BkmExpress) Complete(ctx context.Context, request CompleteBkmExpressRequest) (*PaymentResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bkm-express/complete", request)
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
}

func (api *BkmExpress) RetrievePayment(ctx context.Context, ticketId string) (*PaymentResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/payment/v1/card-payments/%s", ticketId), 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
}
3 changes: 3 additions & 0 deletions adapter/craftgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type Client struct {
BankAccountTracking *BankAccountTracking
Merchant *Merchant
Juzdan *Juzdan
BkmExpress *BkmExpress
deryacakmak marked this conversation as resolved.
Show resolved Hide resolved
}

func New(apiKey, apiSecret, baseURL string, opts ...ClientOption) (*Client, error) {
Expand Down Expand Up @@ -148,6 +149,8 @@ func newClient(apiKey, secretKey string) *Client {
client.Masterpass = &Masterpass{Client: client}
client.BankAccountTracking = &BankAccountTracking{Client: client}
client.Merchant = &Merchant{Client: client}
client.Juzdan = &Juzdan{Client: client}
client.BkmExpress = &BkmExpress{Client: client}

return client
}
Expand Down
26 changes: 26 additions & 0 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ const (
const (
PaymentAuthenticationType_THREE_DS PaymentAuthenticationType = "THREE_DS"
PaymentAuthenticationType_NON_THREE_DS PaymentAuthenticationType = "NON_THREE_DS"
PaymentAuthenticationType_BKM_EXPRESS PaymentAuthenticationType = "BKM_EXPRESS"
)

const (
Expand Down Expand Up @@ -1344,6 +1345,12 @@ type CheckMasterpassUserResponse struct {
AccountStatus *string `json:"accountStatus"`
}

type InitBkmExpressResponse struct {
Id *string `json:"id"`
Path *string `json:"path"`
Token *string `json:"token"`
}

type InstallmentPrice struct {
InstallmentPrice *float64 `json:"installmentPrice"`
BankCommissionRate *float64 `json:"bankCommissionRate"`
Expand Down Expand Up @@ -2037,6 +2044,19 @@ type MasterpassCreatePayment struct {
AdditionalParams map[string]interface{} `json:"additionalParams,omitempty"`
}

type InitBkmExpressRequest 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"`
PaymentPhase PaymentPhase `json:"paymentPhase,omitempty"`
BuyerMemberId int64 `json:"buyerMemberId,omitempty"`
BankOrderId string `json:"bankOrderId,omitempty"`
Items []PaymentItem `json:"items"`
EnabledInstallment bool `json:"enabledInstallments"`
}

type CreateMerchantRequest struct {
Name string `json:"name"`
LegalCompanyTitle string `json:"legalCompanyTitle"`
Expand All @@ -2049,6 +2069,12 @@ type CreateMerchantRequest struct {
ContactPhoneNumber string `json:"contactPhoneNumber"`
}

type CompleteBkmExpressRequest struct {
Status bool `json:"status"`
Message string `json:"message"`
TicketId string `json:"ticketId"`
}

type MerchantApiCredential struct {
Name string `json:"name"`
ApiKey string `json:"apiKey"`
Expand Down
66 changes: 66 additions & 0 deletions tests/bkm_express_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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"
"github.com/stretchr/testify/require"
"testing"
)

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

func TestBkm_Express_Init(t *testing.T) {
request := adapter.InitBkmExpressRequest{
Price: 1.25,
PaidPrice: 1.25,
Currency: craftgate.Currency_TRY,
PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION,
ConversationId: "foo-bar",
Items: []craftgate.PaymentItem{
{
Name: "Item 1",
Price: 1,
ExternalId: "1",
},
{
Name: "Item 2",
Price: 0.25,
ExternalId: "2",
},
},
}
res, err := bkmExpressClient.BkmExpress.Init(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)

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

func TestBkm_Express_Complete(t *testing.T) {
request := adapter.CompleteBkmExpressRequest{
Status: true,
Message: "İşlem Başarılı",
TicketId: "404308dcfdc163-0545-46d7-8f86-5a11718e56ec",
}

res, err := bkmExpressClient.BkmExpress.Complete(context.Background(), request)

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

func TestBkm_Express_RetrievePayment(t *testing.T) {
ticketId := "dcfdc163-0545-46d7-8f86-5a11718e56ec"
res, err := bkmExpressClient.BkmExpress.RetrievePayment(context.Background(), ticketId)

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