Skip to content

Commit

Permalink
updates based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
deryacakmak committed Nov 9, 2023
1 parent eed5390 commit e228dad
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
14 changes: 7 additions & 7 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
}

Expand Down Expand Up @@ -1540,15 +1540,15 @@ 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"`
AdditionalAction ApmAdditionalAction `json:"additionalAction"`
PaymentError PaymentError `json:"paymentError"`
}

type BnplPaymentOfferResponse struct {
type OfferBnplPaymentResponse struct {
OfferId string `json:"offerId"`
Price *float64 `json:"price"`
BnplBankOffers *[]BnplBankOffer `json:"nnplBankOffers"`
Expand Down
14 changes: 7 additions & 7 deletions adapter/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
70 changes: 35 additions & 35 deletions tests/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit e228dad

Please sign in to comment.