From 761e3b5076a56684a666853d6d87f218952c1647 Mon Sep 17 00:00:00 2001 From: Derya Cakmak <97deryacakmak@gmail.com> Date: Mon, 6 Nov 2023 10:18:42 +0300 Subject: [PATCH 1/9] bnpl payment integration --- adapter/model.go | 128 ++++++++++++++++++++++++++++++++++++++++++ adapter/payment.go | 45 +++++++++++++++ tests/payment_test.go | 95 ++++++++++++++++++++++++++++++- 3 files changed, 267 insertions(+), 1 deletion(-) diff --git a/adapter/model.go b/adapter/model.go index 9277308..f11d707 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -44,6 +44,7 @@ type PosOperationType string type FileStatus string type AccountOwner string type PayoutAccountType string +type BnplCartItemType string const ( ApiKeyHeaderName = "x-api-key" @@ -77,6 +78,8 @@ const ( ApmType_AFTERPAY ApmType = "AFTERPAY" ApmType_KASPI ApmType = "KASPI" ApmType_TOMPAY ApmType = "TOMPAY" + ApmType_MASLAK ApmType = "MASLAK" + ApmType_ALFABANK ApmType = "ALFABANK" ApmType_STRIPE ApmType = "STRIPE" ApmType_FUND_TRANSFER ApmType = "FUND_TRANSFER" ApmType_CASH_ON_DELIVERY ApmType = "CASH_ON_DELIVERY" @@ -441,6 +444,34 @@ const ( PayoutAccountType_WISE PayoutAccountType = "WISE" ) +// 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" +) + // requests type CreatePaymentRequest struct { Price float64 `json:"price,omitempty"` @@ -755,6 +786,47 @@ type MasterpassPaymentThreeDSCompleteRequest struct { PaymentId int64 `json:"paymentId,omitempty"` } +type BnplPaymentInitRequest struct { + ApmType ApmType `json:"apmType"` + MerchantApmId int64 `json:"merchantApmId,omitempty"` + Price float64 `json:"price"` + PaidPrice float64 `json:"paidPrice"` + CommissionRate float64 `json:"commissionRate,omitempty"` + Currency Currency `json:"currency"` + PaymentType PaymentType `json:"paymentType"` + PaymentGroup PaymentGroup `json:"paymentGroup"` + PaymentSource PaymentSource `json:"paymentSource,omitempty"` + PaymentChannel string `json:"paymentChannel,omitempty"` + ConversationId string `json:"conversationId,omitempty"` + ExternalId string `json:"externalId,omitempty"` + CallbackUrl string `json:"callbackUrl"` + BuyerMemberId int64 `json:"buyerMemberId,omitempty"` + ApmOrderId string `json:"apmOrderId,omitempty"` + ClientIp string `json:"clientIp,omitempty"` + ApmUserIdentity string `json:"apmUserIdentity,omitempty"` + AdditionalParams map[string]interface{} `json:"additionalParams"` + Items []PaymentItem `json:"items"` + BankCode string `json:"bankCode"` + CartItems []BnplPaymentCartItem `json:"cartItems"` +} + +type BnplPaymentCartItem struct { + Id string `json:"id"` + Name string `json:"name"` + BrandName string `json:"brandName"` + Type BnplCartItemType `json:"type"` + UnitPrice float64 `json:"unitPrice"` + Quantity int64 `json:"quantity"` +} + +type BnplPaymentOfferRequest struct { + ApmType ApmType `json:"apmType,omitempty"` + MerchantApmId int64 `json:"merchantApmId,omitempty"` + Price float64 `json:"price,omitempty"` + Currency Currency `json:"currency,omitempty"` + Items []BnplPaymentCartItem `json:"items"` +} + // responses type PaymentResponse struct { Id *int64 `json:"id"` @@ -1468,6 +1540,38 @@ type ReportingPaymentTransactionResponse struct { PayoutStatus *PayoutStatus `json:"payoutStatus"` } +type BnplPaymentInitResponse struct { + PaymentId int64 `json:"paymentId"` + RedirectUrl string `json:"redirectUrl"` + PaymentStatus PaymentStatus `json:"paymentStatus"` + AdditionalAction ApmAdditionalAction `json:"additionalAction"` + PaymentError PaymentError `json:"paymentError"` +} + +type BnplPaymentOfferResponse struct { + OfferId string `json:"offerId"` + Price *float64 `json:"price"` + BnplBankOffers *[]BnplBankOffer `json:"nnplBankOffers"` +} + +type BnplBankOffer struct { + BankCode string `json:"bankCode"` + BankName string `json:"bankName"` + BankIconUrl string `json:"bankIconUrl"` + BankTableBannerMessage string `json:"bankTableBannerMessage"` + BankSmallBannerMessage string `json:"bankSmallBannerMessage"` + IsSupportNonCustomer bool `json:"isSupportNonCustomer"` + BnplBankOfferTerm *[]BnplBankOfferTerm `json:"bankOfferTerms"` +} + +type BnplBankOfferTerm struct { + Term int64 `json:"term"` + Amount *float64 `json:"amount"` + TotalAmount *float64 `json:"totalAmount"` + InterestRate *float64 `json:"interestRate"` + AnnualInterestRate *float64 `json:"annualInterestRate"` +} + type Payout struct { PaidPrice *float64 `json:"paidPrice"` Parity *float64 `json:"parity"` @@ -1476,6 +1580,30 @@ type Payout struct { SubMerchantMemberPayoutAmount *float64 `json:"subMerchantMemberPayoutAmount"` } +type ApmPaymentResponse struct { + Id *int64 `json:"id"` + CreatedDate *TimeResponse `json:"createdDate"` + Price *float64 `json:"price"` + PaidPrice *float64 `json:"paidPrice"` + WalletPrice *float64 `json:"walletPrice"` + Currency *Currency `json:"currency"` + BuyerMemberId *int64 `json:"buyerMemberId"` + ConversationId *string `json:"conversationId"` + ExternalId *string `json:"externalId"` + PaymentType *PaymentType `json:"paymentType"` + PaymentProvider *PaymentProvider `json:"paymentProvider"` + PaymentSource *PaymentSource `json:"paymentSource"` + PaymentGroup *PaymentGroup `json:"paymentGroup"` + PaymentStatus *PaymentStatus `json:"paymentStatus"` + PaymentChannel *string `json:"paymentChannel"` + OrderId *string `json:"orderId"` + PaymentError *PaymentError `json:"paymentError"` + ApmType ApmType `json:"apmType,apmType"` + TransactionId string `json:"transactionId"` + RedirectUrl *Currency `json:"redirectUrl"` + PaymentTransactions *[]PaymentTransactionResponse `json:"paymentTransactions"` +} + type PayoutStatus struct { MerchantStatus *TransactionPayoutStatus `json:"merchantStatus"` MerchantStatusDate *TimeResponse `json:"merchantStatusDate"` diff --git a/adapter/payment.go b/adapter/payment.go index 0053931..b9ff4c5 100644 --- a/adapter/payment.go +++ b/adapter/payment.go @@ -508,6 +508,51 @@ func (api *Payment) DisapprovePaymentTransactions(ctx context.Context, request P return response.Data, nil } +func (api *Payment) InitBnplPayment(ctx context.Context, request BnplPaymentInitRequest) (*BnplPaymentInitResponse, error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bnpl-payments/init", request) + if err != nil { + return nil, err + } + response := &Response[BnplPaymentInitResponse]{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return nil, err + } + + return response.Data, nil +} + +func (api *Payment) OfferBnplPayment(ctx context.Context, request BnplPaymentOfferRequest) (*DataResponse[BnplPaymentOfferResponse], error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bnpl-payments/offers", request) + if err != nil { + return nil, err + } + + response := &Response[DataResponse[BnplPaymentOfferResponse]]{} + err = api.Client.Do(ctx, newRequest, response) + if err != nil { + return nil, err + } + + return response.Data, nil +} + +func (api *Payment) ApproveBnplPayment(ctx context.Context, paymentId int64) (*ApmPaymentResponse, error) { + + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("/payment/v1/bnpl-payments/%d/approve", paymentId), nil) + if err != nil { + return nil, err + } + + response := &Response[ApmPaymentResponse]{} + 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, diff --git a/tests/payment_test.go b/tests/payment_test.go index ff3346a..c67c106 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -9,7 +9,7 @@ import ( "testing" ) -var paymentClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") +var paymentClient, _ = craftgate.New("sandbox-BMSPbGKBaMOcmOiVpyjDZOIfSzLAuXsb", "sandbox-LpvzxnyrFkOCRRiUpQHUUZUpeQuXNntd", "https://sandbox-api.craftgate.io") func TestPayment_CreatePayment(t *testing.T) { request := adapter.CreatePaymentRequest{ @@ -770,3 +770,96 @@ func TestPayment_NotVerify3DSCallback(t *testing.T) { require.False(t, is3DSecureCallbackVerified) } + +func TestPayment_InitBnplPayment(t *testing.T) { + request := adapter.BnplPaymentInitRequest{ + ApmType: craftgate.ApmType_MASLAK, + Price: 10000, + PaidPrice: 10000, + PaymentType: craftgate.PaymentType_APM, + Currency: craftgate.Currency_TRY, + ApmOrderId: "order_id", + PaymentGroup: craftgate.PaymentGroup_PRODUCT, + ConversationId: "29393-mXld92ko3", + ExternalId: "external_id-345", + CallbackUrl: "callback", + BankCode: "103", + Items: []craftgate.PaymentItem{ + { + Name: "Item 1", + Price: 3000, + ExternalId: "38983903", + }, + { + Name: "Item 2", + Price: 7000, + ExternalId: "92983294", + }, + }, + CartItems: []craftgate.BnplPaymentCartItem{ + { + Id: "200", + Name: "Test Elektronik 2", + BrandName: "iphone", + Type: craftgate.BnplCartItemType_OTHER, + UnitPrice: 4000, + Quantity: 2, + }, + { + Id: "100", + Name: "Test Elektronik 1", + BrandName: "Samsung", + Type: craftgate.BnplCartItemType_MOBILE_PHONE_OVER_5000_TRY, + UnitPrice: 3000, + Quantity: 1, + }, + }, + } + res, err := paymentClient.Payment.InitBnplPayment(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func TestPayment_OfferBnplPayment(t *testing.T) { + request := adapter.BnplPaymentOfferRequest{ + ApmType: craftgate.ApmType_MASLAK, + Price: 10000, + Currency: craftgate.Currency_TRY, + Items: []craftgate.BnplPaymentCartItem{ + { + Id: "200", + Name: "Test Elektronik 2", + BrandName: "iphone", + Type: craftgate.BnplCartItemType_MOBILE_PHONE_BELOW_5000_TRY, + UnitPrice: 3000, + Quantity: 2, + }, + { + Id: "100", + Name: "Test Elektronik 1", + BrandName: "Samsung", + Type: craftgate.BnplCartItemType_OTHER, + UnitPrice: 4000, + Quantity: 1, + }, + }, + } + res, err := paymentClient.Payment.OfferBnplPayment(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + +func TestPayment_ApproveBnplPayment(t *testing.T) { + res, err := paymentClient.Payment.ApproveBnplPayment(context.Background(), 407016) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} From cd7c4da608c261f058871967933583f05eeaa9e2 Mon Sep 17 00:00:00 2001 From: Derya Cakmak <97deryacakmak@gmail.com> Date: Mon, 6 Nov 2023 11:17:26 +0300 Subject: [PATCH 2/9] bnpl payment integration --- adapter/payment.go | 10 +++++----- tests/payment_test.go | 4 +--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/adapter/payment.go b/adapter/payment.go index b9ff4c5..be896d0 100644 --- a/adapter/payment.go +++ b/adapter/payment.go @@ -537,20 +537,20 @@ func (api *Payment) OfferBnplPayment(ctx context.Context, request BnplPaymentOff return response.Data, nil } -func (api *Payment) ApproveBnplPayment(ctx context.Context, paymentId int64) (*ApmPaymentResponse, error) { +func (api *Payment) ApproveBnplPayment(ctx context.Context, paymentId int64) error { newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("/payment/v1/bnpl-payments/%d/approve", paymentId), nil) if err != nil { - return nil, err + return err } - response := &Response[ApmPaymentResponse]{} + response := &Void{} err = api.Client.Do(ctx, newRequest, response) if err != nil { - return nil, err + return err } - return response.Data, nil + return nil } func (c *Payment) Is3DSecureCallbackVerified(threeDSecureCallbackKey string, params map[string]string) bool { diff --git a/tests/payment_test.go b/tests/payment_test.go index c67c106..42712e2 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -856,9 +856,7 @@ func TestPayment_OfferBnplPayment(t *testing.T) { } func TestPayment_ApproveBnplPayment(t *testing.T) { - res, err := paymentClient.Payment.ApproveBnplPayment(context.Background(), 407016) - _, _ = spew.Printf("%#v\n", res) - + err := paymentClient.Payment.ApproveBnplPayment(context.Background(), 407016) if err != nil { t.Errorf("Error %s", err) } From 9c0c13d9a865bb79a70ecc566a32bccc3e9f876e Mon Sep 17 00:00:00 2001 From: Derya Cakmak <97deryacakmak@gmail.com> Date: Mon, 6 Nov 2023 11:25:38 +0300 Subject: [PATCH 3/9] bnpl payment integration --- tests/payment_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/payment_test.go b/tests/payment_test.go index 42712e2..2d163f6 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -9,7 +9,7 @@ import ( "testing" ) -var paymentClient, _ = craftgate.New("sandbox-BMSPbGKBaMOcmOiVpyjDZOIfSzLAuXsb", "sandbox-LpvzxnyrFkOCRRiUpQHUUZUpeQuXNntd", "https://sandbox-api.craftgate.io") +var paymentClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") func TestPayment_CreatePayment(t *testing.T) { request := adapter.CreatePaymentRequest{ @@ -778,7 +778,7 @@ func TestPayment_InitBnplPayment(t *testing.T) { PaidPrice: 10000, PaymentType: craftgate.PaymentType_APM, Currency: craftgate.Currency_TRY, - ApmOrderId: "order_id", + ApmOrderId: "order_iddfgdfg", PaymentGroup: craftgate.PaymentGroup_PRODUCT, ConversationId: "29393-mXld92ko3", ExternalId: "external_id-345", From ab31c0a379c2a27dcd354bcfa7696c987d9eab48 Mon Sep 17 00:00:00 2001 From: Derya Cakmak <97deryacakmak@gmail.com> Date: Mon, 6 Nov 2023 11:29:34 +0300 Subject: [PATCH 4/9] bnpl payment integration --- adapter/model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapter/model.go b/adapter/model.go index f11d707..0630333 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -1598,7 +1598,7 @@ type ApmPaymentResponse struct { PaymentChannel *string `json:"paymentChannel"` OrderId *string `json:"orderId"` PaymentError *PaymentError `json:"paymentError"` - ApmType ApmType `json:"apmType,apmType"` + ApmType ApmType `json:"apmType"` TransactionId string `json:"transactionId"` RedirectUrl *Currency `json:"redirectUrl"` PaymentTransactions *[]PaymentTransactionResponse `json:"paymentTransactions"` From eed5390c0065203b610e696a244c26b14c518f0e Mon Sep 17 00:00:00 2001 From: Derya Cakmak <97deryacakmak@gmail.com> Date: Mon, 6 Nov 2023 11:30:32 +0300 Subject: [PATCH 5/9] bnpl payment integration --- adapter/model.go | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/adapter/model.go b/adapter/model.go index 0630333..71d1321 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -1580,30 +1580,6 @@ type Payout struct { SubMerchantMemberPayoutAmount *float64 `json:"subMerchantMemberPayoutAmount"` } -type ApmPaymentResponse struct { - Id *int64 `json:"id"` - CreatedDate *TimeResponse `json:"createdDate"` - Price *float64 `json:"price"` - PaidPrice *float64 `json:"paidPrice"` - WalletPrice *float64 `json:"walletPrice"` - Currency *Currency `json:"currency"` - BuyerMemberId *int64 `json:"buyerMemberId"` - ConversationId *string `json:"conversationId"` - ExternalId *string `json:"externalId"` - PaymentType *PaymentType `json:"paymentType"` - PaymentProvider *PaymentProvider `json:"paymentProvider"` - PaymentSource *PaymentSource `json:"paymentSource"` - PaymentGroup *PaymentGroup `json:"paymentGroup"` - PaymentStatus *PaymentStatus `json:"paymentStatus"` - PaymentChannel *string `json:"paymentChannel"` - OrderId *string `json:"orderId"` - PaymentError *PaymentError `json:"paymentError"` - ApmType ApmType `json:"apmType"` - TransactionId string `json:"transactionId"` - RedirectUrl *Currency `json:"redirectUrl"` - PaymentTransactions *[]PaymentTransactionResponse `json:"paymentTransactions"` -} - type PayoutStatus struct { MerchantStatus *TransactionPayoutStatus `json:"merchantStatus"` MerchantStatusDate *TimeResponse `json:"merchantStatusDate"` From e228dad43e04fa6197d101f5e082b5e0520d4531 Mon Sep 17 00:00:00 2001 From: Derya Cakmak <97deryacakmak@gmail.com> Date: Thu, 9 Nov 2023 15:41:40 +0300 Subject: [PATCH 6/9] updates based on comments --- adapter/model.go | 14 ++++----- adapter/payment.go | 14 ++++----- tests/payment_test.go | 70 +++++++++++++++++++++---------------------- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/adapter/model.go b/adapter/model.go index 71d1321..ee05967 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -786,7 +786,7 @@ type MasterpassPaymentThreeDSCompleteRequest struct { PaymentId int64 `json:"paymentId,omitempty"` } -type BnplPaymentInitRequest struct { +type InitBnplPaymentRequest struct { ApmType ApmType `json:"apmType"` MerchantApmId int64 `json:"merchantApmId,omitempty"` Price float64 `json:"price"` @@ -819,11 +819,11 @@ type BnplPaymentCartItem struct { Quantity int64 `json:"quantity"` } -type BnplPaymentOfferRequest struct { - ApmType ApmType `json:"apmType,omitempty"` +type OfferBnplPaymentRequest struct { + ApmType ApmType `json:"apmType"` MerchantApmId int64 `json:"merchantApmId,omitempty"` - Price float64 `json:"price,omitempty"` - Currency Currency `json:"currency,omitempty"` + Price float64 `json:"price"` + Currency Currency `json:"currency"` Items []BnplPaymentCartItem `json:"items"` } @@ -1540,7 +1540,7 @@ type ReportingPaymentTransactionResponse struct { PayoutStatus *PayoutStatus `json:"payoutStatus"` } -type BnplPaymentInitResponse struct { +type InitBnplPaymentResponse struct { PaymentId int64 `json:"paymentId"` RedirectUrl string `json:"redirectUrl"` PaymentStatus PaymentStatus `json:"paymentStatus"` @@ -1548,7 +1548,7 @@ type BnplPaymentInitResponse struct { PaymentError PaymentError `json:"paymentError"` } -type BnplPaymentOfferResponse struct { +type OfferBnplPaymentResponse struct { OfferId string `json:"offerId"` Price *float64 `json:"price"` BnplBankOffers *[]BnplBankOffer `json:"nnplBankOffers"` diff --git a/adapter/payment.go b/adapter/payment.go index be896d0..97b9c04 100644 --- a/adapter/payment.go +++ b/adapter/payment.go @@ -508,12 +508,13 @@ func (api *Payment) DisapprovePaymentTransactions(ctx context.Context, request P return response.Data, nil } -func (api *Payment) InitBnplPayment(ctx context.Context, request BnplPaymentInitRequest) (*BnplPaymentInitResponse, error) { - newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bnpl-payments/init", request) +func (api *Payment) RetrieveBnplOffers(ctx context.Context, request OfferBnplPaymentRequest) (*DataResponse[OfferBnplPaymentResponse], error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bnpl-payments/offers", request) if err != nil { return nil, err } - response := &Response[BnplPaymentInitResponse]{} + + response := &Response[DataResponse[OfferBnplPaymentResponse]]{} err = api.Client.Do(ctx, newRequest, response) if err != nil { return nil, err @@ -522,13 +523,12 @@ func (api *Payment) InitBnplPayment(ctx context.Context, request BnplPaymentInit return response.Data, nil } -func (api *Payment) OfferBnplPayment(ctx context.Context, request BnplPaymentOfferRequest) (*DataResponse[BnplPaymentOfferResponse], error) { - newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bnpl-payments/offers", request) +func (api *Payment) InitBnplPayment(ctx context.Context, request InitBnplPaymentRequest) (*InitBnplPaymentResponse, error) { + newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bnpl-payments/init", request) if err != nil { return nil, err } - - response := &Response[DataResponse[BnplPaymentOfferResponse]]{} + response := &Response[InitBnplPaymentResponse]{} err = api.Client.Do(ctx, newRequest, response) if err != nil { return nil, err diff --git a/tests/payment_test.go b/tests/payment_test.go index 2d163f6..4c8e837 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -771,14 +771,46 @@ func TestPayment_NotVerify3DSCallback(t *testing.T) { require.False(t, is3DSecureCallbackVerified) } +func TestPayment_OfferBnplPayment(t *testing.T) { + request := adapter.OfferBnplPaymentRequest{ + ApmType: craftgate.ApmType_MASLAK, + Price: 10000, + Currency: craftgate.Currency_TRY, + Items: []craftgate.BnplPaymentCartItem{ + { + Id: "200", + Name: "Test Elektronik 2", + BrandName: "iphone", + Type: craftgate.BnplCartItemType_MOBILE_PHONE_BELOW_5000_TRY, + UnitPrice: 3000, + Quantity: 2, + }, + { + Id: "100", + Name: "Test Elektronik 1", + BrandName: "Samsung", + Type: craftgate.BnplCartItemType_OTHER, + UnitPrice: 4000, + Quantity: 1, + }, + }, + } + res, err := paymentClient.Payment.RetrieveBnplOffers(context.Background(), request) + _, _ = spew.Printf("%#v\n", res) + + if err != nil { + t.Errorf("Error %s", err) + } +} + func TestPayment_InitBnplPayment(t *testing.T) { - request := adapter.BnplPaymentInitRequest{ + request := adapter.InitBnplPaymentRequest{ ApmType: craftgate.ApmType_MASLAK, Price: 10000, PaidPrice: 10000, PaymentType: craftgate.PaymentType_APM, Currency: craftgate.Currency_TRY, - ApmOrderId: "order_iddfgdfg", + ApmOrderId: "order_idfgfgfgfjj", PaymentGroup: craftgate.PaymentGroup_PRODUCT, ConversationId: "29393-mXld92ko3", ExternalId: "external_id-345", @@ -823,40 +855,8 @@ func TestPayment_InitBnplPayment(t *testing.T) { } } -func TestPayment_OfferBnplPayment(t *testing.T) { - request := adapter.BnplPaymentOfferRequest{ - ApmType: craftgate.ApmType_MASLAK, - Price: 10000, - Currency: craftgate.Currency_TRY, - Items: []craftgate.BnplPaymentCartItem{ - { - Id: "200", - Name: "Test Elektronik 2", - BrandName: "iphone", - Type: craftgate.BnplCartItemType_MOBILE_PHONE_BELOW_5000_TRY, - UnitPrice: 3000, - Quantity: 2, - }, - { - Id: "100", - Name: "Test Elektronik 1", - BrandName: "Samsung", - Type: craftgate.BnplCartItemType_OTHER, - UnitPrice: 4000, - Quantity: 1, - }, - }, - } - res, err := paymentClient.Payment.OfferBnplPayment(context.Background(), request) - _, _ = spew.Printf("%#v\n", res) - - if err != nil { - t.Errorf("Error %s", err) - } -} - func TestPayment_ApproveBnplPayment(t *testing.T) { - err := paymentClient.Payment.ApproveBnplPayment(context.Background(), 407016) + err := paymentClient.Payment.ApproveBnplPayment(context.Background(), 1) if err != nil { t.Errorf("Error %s", err) } From 7b2ea6cc7d9750f8acafdf7f1ddce4b9fe5b69ae Mon Sep 17 00:00:00 2001 From: Derya Cakmak <97deryacakmak@gmail.com> Date: Thu, 9 Nov 2023 16:22:33 +0300 Subject: [PATCH 7/9] updates based on comments --- tests/payment_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/payment_test.go b/tests/payment_test.go index 4c8e837..9755165 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -9,7 +9,7 @@ import ( "testing" ) -var paymentClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") +var paymentClient, _ = craftgate.New("sandbox-BMSPbGKBaMOcmOiVpyjDZOIfSzLAuXsb", "sandbox-LpvzxnyrFkOCRRiUpQHUUZUpeQuXNntd", "https://sandbox-api.craftgate.io") func TestPayment_CreatePayment(t *testing.T) { request := adapter.CreatePaymentRequest{ @@ -810,7 +810,7 @@ func TestPayment_InitBnplPayment(t *testing.T) { PaidPrice: 10000, PaymentType: craftgate.PaymentType_APM, Currency: craftgate.Currency_TRY, - ApmOrderId: "order_idfgfgfgfjj", + ApmOrderId: "order_id", PaymentGroup: craftgate.PaymentGroup_PRODUCT, ConversationId: "29393-mXld92ko3", ExternalId: "external_id-345", @@ -819,12 +819,12 @@ func TestPayment_InitBnplPayment(t *testing.T) { Items: []craftgate.PaymentItem{ { Name: "Item 1", - Price: 3000, + Price: 6000, ExternalId: "38983903", }, { Name: "Item 2", - Price: 7000, + Price: 4000, ExternalId: "92983294", }, }, @@ -834,7 +834,7 @@ func TestPayment_InitBnplPayment(t *testing.T) { Name: "Test Elektronik 2", BrandName: "iphone", Type: craftgate.BnplCartItemType_OTHER, - UnitPrice: 4000, + UnitPrice: 3000, Quantity: 2, }, { @@ -842,7 +842,7 @@ func TestPayment_InitBnplPayment(t *testing.T) { Name: "Test Elektronik 1", BrandName: "Samsung", Type: craftgate.BnplCartItemType_MOBILE_PHONE_OVER_5000_TRY, - UnitPrice: 3000, + UnitPrice: 4000, Quantity: 1, }, }, From f3d2a2a7711f21074a117de56095d06ed5ddcfed Mon Sep 17 00:00:00 2001 From: Derya Cakmak <97deryacakmak@gmail.com> Date: Thu, 9 Nov 2023 17:08:15 +0300 Subject: [PATCH 8/9] updates based on comments --- tests/payment_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/payment_test.go b/tests/payment_test.go index 9755165..eca62b0 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -9,7 +9,7 @@ import ( "testing" ) -var paymentClient, _ = craftgate.New("sandbox-BMSPbGKBaMOcmOiVpyjDZOIfSzLAuXsb", "sandbox-LpvzxnyrFkOCRRiUpQHUUZUpeQuXNntd", "https://sandbox-api.craftgate.io") +var paymentClient, _ = craftgate.New("api-key", "secret-key", "https://sandbox-api.craftgate.io") func TestPayment_CreatePayment(t *testing.T) { request := adapter.CreatePaymentRequest{ From 33bda32160fc5925fc8abbeb80b3e8fe9d0b62a4 Mon Sep 17 00:00:00 2001 From: Derya Cakmak <97deryacakmak@gmail.com> Date: Fri, 10 Nov 2023 09:55:25 +0300 Subject: [PATCH 9/9] updates based on comments --- adapter/model.go | 4 ++-- adapter/payment.go | 4 ++-- tests/payment_test.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/adapter/model.go b/adapter/model.go index ee05967..fdb6eab 100644 --- a/adapter/model.go +++ b/adapter/model.go @@ -819,7 +819,7 @@ type BnplPaymentCartItem struct { Quantity int64 `json:"quantity"` } -type OfferBnplPaymentRequest struct { +type BnplPaymentOfferRequest struct { ApmType ApmType `json:"apmType"` MerchantApmId int64 `json:"merchantApmId,omitempty"` Price float64 `json:"price"` @@ -1548,7 +1548,7 @@ type InitBnplPaymentResponse struct { PaymentError PaymentError `json:"paymentError"` } -type OfferBnplPaymentResponse struct { +type BnplPaymentOfferResponse struct { OfferId string `json:"offerId"` Price *float64 `json:"price"` BnplBankOffers *[]BnplBankOffer `json:"nnplBankOffers"` diff --git a/adapter/payment.go b/adapter/payment.go index 97b9c04..5ca00ea 100644 --- a/adapter/payment.go +++ b/adapter/payment.go @@ -508,13 +508,13 @@ func (api *Payment) DisapprovePaymentTransactions(ctx context.Context, request P return response.Data, nil } -func (api *Payment) RetrieveBnplOffers(ctx context.Context, request OfferBnplPaymentRequest) (*DataResponse[OfferBnplPaymentResponse], error) { +func (api *Payment) RetrieveBnplOffers(ctx context.Context, request BnplPaymentOfferRequest) (*DataResponse[BnplPaymentOfferResponse], error) { newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/bnpl-payments/offers", request) if err != nil { return nil, err } - response := &Response[DataResponse[OfferBnplPaymentResponse]]{} + response := &Response[DataResponse[BnplPaymentOfferResponse]]{} err = api.Client.Do(ctx, newRequest, response) if err != nil { return nil, err diff --git a/tests/payment_test.go b/tests/payment_test.go index eca62b0..0970b7d 100644 --- a/tests/payment_test.go +++ b/tests/payment_test.go @@ -771,8 +771,8 @@ func TestPayment_NotVerify3DSCallback(t *testing.T) { require.False(t, is3DSecureCallbackVerified) } -func TestPayment_OfferBnplPayment(t *testing.T) { - request := adapter.OfferBnplPaymentRequest{ +func TestPayment_BnplPaymentOffer(t *testing.T) { + request := adapter.BnplPaymentOfferRequest{ ApmType: craftgate.ApmType_MASLAK, Price: 10000, Currency: craftgate.Currency_TRY,