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

Adds instant transfer with Compay integration as apm #78

Merged
merged 8 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
15 changes: 15 additions & 0 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const (
ApmType_KLARNA ApmType = "KLARNA"
ApmType_AFTERPAY ApmType = "AFTERPAY"
ApmType_KASPI ApmType = "KASPI"
ApmType_COMPAY ApmType = "COMPAY"
ApmType_TOMPAY ApmType = "TOMPAY"
ApmType_MASLAK ApmType = "MASLAK"
ApmType_ALFABANK ApmType = "ALFABANK"
Expand All @@ -109,6 +110,7 @@ const (
PaymentProvider_KLARNA PaymentProvider = "KLARNA"
PaymentProvider_AFTERPAY PaymentProvider = "AFTERPAY"
PaymentProvider_KASPI PaymentProvider = "KASPI"
PaymentProvider_COMPAY PaymentProvider = "COMPAY"
PaymentProvider_TOMPAY PaymentProvider = "TOMPAY"
PaymentProvider_APPLEPAY PaymentProvider = "APPLEPAY"
PaymentProvider_GOOGLEPAY PaymentProvider = "GOOGLEPAY"
Expand Down Expand Up @@ -188,6 +190,7 @@ const (
PaymentMethod_KLARNA PaymentMethod = "KLARNA"
PaymentMethod_AFTERPAY PaymentMethod = "AFTERPAY"
PaymentMethod_KASPI PaymentMethod = "KASPI"
PaymentMethod_COMPAY PaymentMethod = "COMPAY"
PaymentMethod_TOMPAY PaymentMethod = "TOMPAY"
PaymentMethod_STRIPE PaymentMethod = "STRIPE"
)
Expand Down Expand Up @@ -347,6 +350,7 @@ const (
const (
ApmAdditionalAction_REDIRECT_TO_URL ApmAdditionalAction = "REDIRECT_TO_URL"
ApmAdditionalAction_OTP_REQUIRED ApmAdditionalAction = "OTP_REQUIRED"
ApmAdditionalAction_SHOW_HTML_CONTENT ApmAdditionalAction = "SHOW_HTML_CONTENT"
ApmAdditionalAction_WAIT_FOR_WEBHOOK ApmAdditionalAction = "WAIT_FOR_WEBHOOK"
ApmAdditionalAction_APPROVAL_REQUIRED ApmAdditionalAction = "APPROVAL_REQUIRED"
ApmAdditionalAction_NONE ApmAdditionalAction = "NONE"
Expand Down Expand Up @@ -987,6 +991,7 @@ type InitCheckoutPaymentResponse struct {
type InitApmPaymentResponse struct {
PaymentId *int64 `json:"paymentId"`
RedirectUrl *string `json:"redirectUrl"`
HtmlContent *string `json:"htmlContent"`
PaymentStatus *PaymentStatus `json:"paymentStatus"`
ApmAdditionalAction *ApmAdditionalAction `json:"additionalAction"`
PaymentError *PaymentError `json:"paymentError"`
Expand Down Expand Up @@ -1320,6 +1325,16 @@ type InstallmentResponse struct {
InstallmentPrices []InstallmentPrice `json:"installmentPrices"`
}

type InstantTransferBanksResponse struct {
Items []InstantTransferBank `json:"items"`
}

type InstantTransferBank struct {
BankCode *string `json:"bankCode"`
BankName *string `json:"bankName"`
BankLogoUrl *string `json:"bankLogoUrl"`
}

type RetrieveBinNumberResponse struct {
BinNumber *string `json:"binNumber"`
CardType *string `json:"cardType"`
Expand Down
14 changes: 14 additions & 0 deletions adapter/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,20 @@ 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 (c *Payment) Is3DSecureCallbackVerified(threeDSecureCallbackKey string, params map[string]string) bool {
hash := params["hash"]
hashString := strings.Join([]string{threeDSecureCallbackKey,
Expand Down
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 TestInitCompayAPMPayment(t *testing.T) {
additionalParams := make(map[string]string)
additionalParams["bankCode"] = "0"

request := adapter.InitApmPaymentRequest{
ApmType: craftgate.ApmType_COMPAY,
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)
}
}
Loading