Skip to content

Commit

Permalink
Merge branch 'master' into bkm-express-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
deryacakmak committed Jul 2, 2024
2 parents 1e90ff2 + 4573edc commit 4e70894
Show file tree
Hide file tree
Showing 11 changed files with 422 additions and 107 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Go 1.19
uses: actions/setup-go@v3
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
go-version: '1.21.0'
cache: true
cache-dependency-path: go.sum

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Go Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4

- name: Get dependencies
run: |
Expand Down
270 changes: 185 additions & 85 deletions adapter/model.go

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions adapter/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,22 @@ func (api *Payment) UpdateStoredCard(ctx context.Context, request UpdateStoredCa
return response.Data, nil
}

func (api *Payment) CloneStoredCard(ctx context.Context, request CloneStoredCardRequest) (*StoredCardResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/cards/clone", request)

if err != nil {
return nil, err
}

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

return response.Data, nil
}

func (api *Payment) DeleteStoredCard(ctx context.Context, request DeleteStoredCardRequest) error {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/cards/delete", request)
if err != nil {
Expand Down Expand Up @@ -553,6 +569,50 @@ func (api *Payment) ApproveBnplPayment(ctx context.Context, paymentId int64) err
return nil
}

func (api *Payment) RetrieveActiveBanks(ctx context.Context) (*InstantTransferBanksResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/payment/v1/instant-transfer-banks", nil)
if err != nil {
return nil, err
}
response := &Response[InstantTransferBanksResponse]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}

return response.Data, nil
}

func (api *Payment) CreateApplePayMerchantSession(ctx context.Context, request ApplePayMerchantSessionCreateRequest) (*interface{}, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/apple-pay/merchant-sessions", request)
if err != nil {
return nil, err
}

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

return response.Data, nil
}

func (api *Payment) RetrieveMultiPayment(ctx context.Context, token string) (*MultiPaymentResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/payment/v1/multi-payments/%s", token), nil)
if err != nil {
return nil, err
}

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

return response.Data, nil
}

func (c *Payment) Is3DSecureCallbackVerified(threeDSecureCallbackKey string, params map[string]string) bool {
hash := params["hash"]
hashString := strings.Join([]string{threeDSecureCallbackKey,
Expand Down
2 changes: 1 addition & 1 deletion adapter/settlement_reporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type SettlementReporting struct {
}

func (api *SettlementReporting) SearchPayoutCompletedTransactions(ctx context.Context, request SearchPayoutCompletedTransactionsRequest) (*DataResponse[SearchPayoutCompletedTransactionsResponse], error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/settlement-reporting/v1/settlement-file/payout-completed-transactions", request)
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/settlement-reporting/v2/settlement-file/payout-completed-transactions", request)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.21

require (
github.com/davecgh/go-spew v1.1.1
github.com/gorilla/schema v1.2.1
github.com/stretchr/testify v1.8.4
github.com/gorilla/schema v1.4.1
github.com/stretchr/testify v1.9.0
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/schema v1.2.1 h1:tjDxcmdb+siIqkTNoV+qRH2mjYdr2hHe5MKXbp61ziM=
github.com/gorilla/schema v1.2.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E=
github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Test_main(t *testing.T) {
binNumber, err := client.Installment.RetrieveBinNumber(context.Background(), "487074")
require.NotNil(t, err)
require.Nil(t, binNumber)
assert.Equal(t, true, strings.Contains(err.Error(), "API credential not found!"))
assert.Equal(t, true, strings.Contains(err.Error(), "API credential not found"))
})
})
}
53 changes: 53 additions & 0 deletions tests/instant_transfer_payment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package tests

import (
"context"
"testing"

"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"
)

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

func TestRetrieveActiveBanks(t *testing.T) {
res, err := instantTransferPaymentClient.Payment.RetrieveActiveBanks(context.Background())
require.NotEmpty(t, res.Items)
if err != nil {
t.Errorf("Error %s", err)
}
}

func TestInitInstantTransferAPMPayment(t *testing.T) {
additionalParams := make(map[string]string)
additionalParams["bankCode"] = "0"

request := adapter.InitApmPaymentRequest{
ApmType: craftgate.ApmType_INSTANT_TRANSFER,
Price: 1,
PaidPrice: 1,
Currency: craftgate.Currency_TRY,
PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION,
ConversationId: "foo-bar",
CallbackUrl: "https://www.your-website.com/callback",
Items: []craftgate.PaymentItem{
{
Name: "Item 1",
Price: 0.6,
},
{
Name: "Item 2",
Price: 0.4,
},
},
AdditionalParams: additionalParams,
}
res, err := instantTransferPaymentClient.Payment.InitApmPayment(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)

if err != nil {
t.Errorf("Error %s", err)
}
}
9 changes: 3 additions & 6 deletions tests/onboarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package tests
import (
"context"
"fmt"
"testing"
"time"

"github.com/craftgate/craftgate-go-client/adapter"
craftgate "github.com/craftgate/craftgate-go-client/adapter"
"github.com/davecgh/go-spew/spew"
"testing"
"time"
)

var onboardingClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io")
Expand Down Expand Up @@ -41,7 +42,6 @@ func Test_CreateSubMerchantMember(t *testing.T) {
Email: "[email protected]",
PhoneNumber: "905551111111",
Iban: "TR930006701000000001111111",
IdentityNumber: "11111111110",
LegalCompanyTitle: "Dem Zeytinyağı Üretim Ltd. Şti.",
Name: "Dem Zeytinyağı Üretim Ltd. Şti.",
MemberType: craftgate.MemberType_LIMITED_OR_JOINT_STOCK_COMPANY,
Expand All @@ -68,7 +68,6 @@ func Test_CreateBuyerAndSubMerchantMember(t *testing.T) {
Email: "[email protected]",
PhoneNumber: "905551111111",
Iban: "TR930006701000000001111111",
IdentityNumber: "11111111110",
LegalCompanyTitle: "Dem Zeytinyağı Üretim Ltd. Şti.",
Name: "Dem Zeytinyağı Üretim Ltd. Şti.",
MemberType: craftgate.MemberType_LIMITED_OR_JOINT_STOCK_COMPANY,
Expand All @@ -94,7 +93,6 @@ func Test_UpdateSubMerchantMember(t *testing.T) {
Email: "[email protected]",
PhoneNumber: "905551111111",
Iban: "TR930006701000000001111111",
IdentityNumber: "11111111110",
LegalCompanyTitle: "Dem Zeytinyağı Üretim Ltd. Şti.",
Name: "Dem Zeytinyağı Üretim Ltd. Şti.",
MemberType: craftgate.MemberType_LIMITED_OR_JOINT_STOCK_COMPANY,
Expand All @@ -121,7 +119,6 @@ func Test_UpdateBuyerMember(t *testing.T) {
Email: "[email protected]",
PhoneNumber: "905551111111",
Iban: "TR930006701000000001111111",
IdentityNumber: "11111111110",
LegalCompanyTitle: "Dem Zeytinyağı Üretim Ltd. Şti.",
Name: "Dem Zeytinyağı Üretim Ltd. Şti.",
MemberType: craftgate.MemberType_PERSONAL,
Expand Down
107 changes: 106 additions & 1 deletion tests/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,55 @@ func TestPayment_InitApmPayment(t *testing.T) {
}
}

func TestPayment_InitMetropolApmPayment(t *testing.T) {
request := adapter.InitApmPaymentRequest{
ApmType: craftgate.ApmType_METROPOL,
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",
},
},
AdditionalParams: map[string]string{
"cardNumber": "6375780115068760",
},
}
res, err := paymentClient.Payment.InitApmPayment(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)

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

func TestPayment_CompleteMetropolApmPayment(t *testing.T) {
request := adapter.CompleteApmPaymentRequest{
PaymentId: 126,
AdditionalParams: map[string]string{
"otpCode": "00000",
"productId": "1",
"walletId": "1",
},
}
res, err := paymentClient.Payment.CompleteApmPayment(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)

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

func TestPayment_InitKlarnaApmPayment(t *testing.T) {
request := adapter.InitApmPaymentRequest{
ApmType: craftgate.ApmType_KLARNA,
Expand Down Expand Up @@ -533,7 +582,7 @@ func TestPayment_CompleteApmPayment(t *testing.T) {
}
}

func TestPayment_InitPosApmPayment(t *testing.T) {
func TestPayment_InitYkbWorldPayPosApmPayment(t *testing.T) {
request := adapter.InitPosApmPaymentRequest{
Price: 1.25,
PaidPrice: 1.25,
Expand Down Expand Up @@ -566,6 +615,39 @@ func TestPayment_InitPosApmPayment(t *testing.T) {
}
}

func TestPayment_InitGarantiPayPosApmPayment(t *testing.T) {
request := adapter.InitPosApmPaymentRequest{
Price: 1.25,
PaidPrice: 1.25,
Currency: craftgate.Currency_TRY,
PaymentGroup: craftgate.PaymentGroup_LISTING_OR_SUBSCRIPTION,
ConversationId: "foo-bar",
PaymentProvider: craftgate.PosApmPaymentProvider_GARANTI_PAY,
CallbackUrl: "https://www.your-website.com/callback",
Items: []craftgate.PaymentItem{
{
Name: "Item 1",
Price: 1,
ExternalId: "1",
},
{
Name: "Item 2",
Price: 0.25,
ExternalId: "2",
},
},
AdditionalParams: map[string]string{
"integrationType": "WEB2APP",
},
}
res, err := paymentClient.Payment.InitPosApmPayment(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)

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

func TestPayment_CompletePosApmPayment(t *testing.T) {
request := adapter.CompletePosApmPaymentRequest{
PaymentId: 123,
Expand Down Expand Up @@ -671,6 +753,20 @@ func TestPayment_UpdateStoredCard(t *testing.T) {
}
}

func TestPayment_CloneStoredCard(t *testing.T) {
request := adapter.CloneStoredCardRequest{
SourceCardUserKey: "6bcbac4b-6460-418d-b060-2d9896c08156",
SourceCardToken: "aa57f470-7423-449e-87b7-afb1fba151fb",
TargetMerchantId: 1,
}
res, err := paymentClient.Payment.CloneStoredCard(context.Background(), request)
_, _ = spew.Printf("%#v\n", res)

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

func TestPayment_DeleteStoredCard(t *testing.T) {
request := adapter.DeleteStoredCardRequest{
CardUserKey: "d94018bb-baa9-4418-84f8-760942f669af",
Expand Down Expand Up @@ -903,3 +999,12 @@ func TestPayment_ApproveBnplPayment(t *testing.T) {
t.Errorf("Error %s", err)
}
}

func TestPayment_RetrieveMultiPayment(t *testing.T) {
res, err := paymentClient.Payment.RetrieveMultiPayment(context.Background(), "6d7e66b5-9b1c-4c1d-879a-2557b651096e")
_, _ = spew.Printf("%#v\n", res)

if err != nil {
t.Errorf("Error %s", err)
}
}
2 changes: 2 additions & 0 deletions tests/settlement_reporting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ func TestSettlementReporting_SearchPayoutCompletedTransactions(t *testing.T) {
request := adapter.SearchPayoutCompletedTransactionsRequest{
StartDate: time.Now().AddDate(0, 0, -180),
EndDate: time.Now(),
Page: 0,
Size: 10,
}

res, err := settlementReportingClient.SettlementReporting.SearchPayoutCompletedTransactions(context.Background(), request)
Expand Down

0 comments on commit 4e70894

Please sign in to comment.