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] 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) }