Skip to content

Commit

Permalink
add pay by link multi payment support (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuncaserhat committed Apr 16, 2024
1 parent d18bbcd commit 1559604
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
20 changes: 20 additions & 0 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type CardAssociation string
type CardExpiryStatus string
type Currency string
type LoyaltyType string
type MultiPaymentStatus string
type PaymentRefundStatus string
type RefundStatus string
type RefundType string
Expand Down Expand Up @@ -239,6 +240,12 @@ const (
LoyaltyType_POSTPONING_STATEMENT LoyaltyType = "POSTPONING_STATEMENT"
)

// multi payment status declaration
const (
MultiPaymentStatus_CREATED MultiPaymentStatus = "CREATED"
MultiPaymentStatus_COMPLETED MultiPaymentStatus = "COMPLETED"
)

// payment refund status declaration
const (
PaymentRefundStatus_NO_REFUND PaymentRefundStatus = "NO_REFUND"
Expand Down Expand Up @@ -1450,6 +1457,7 @@ type CreateProductRequest struct {
Price float64 `json:"price"`
Currency Currency `json:"currency"`
Description string `json:"description,omitempty"`
MultiPayment bool `json:"multiPayment,omitempty"`
EnabledInstallments []int `json:"enabledInstallments"`
}

Expand Down Expand Up @@ -2109,6 +2117,18 @@ type MerchantPosCommissionResponse struct {
MerchantCommissionRate float64 `json:"merchantCommissionRate"`
}

type MultiPaymentResponse struct {
Id *int64 `json:"id"`
MultiPaymentStatus *MultiPaymentStatus `json:"multiPaymentStatus"`
Token *string `json:"token"`
ConversationId *string `json:"conversationId"`
ExternalId *string `json:"externalId"`
PaidPrice *float64 `json:"paidPrice"`
RemainingAmount *float64 `json:"remainingAmount"`
TokenExpireDate *TimeResponse `json:"tokenExpireDate"`
PaymentIds []int64 `json:"paymentIds"`
}

type CreateMerchantPosCommission struct {
CardBrandName CardBrand `json:"cardBrandName,omitempty"`
Installment int64 `json:"installment"`
Expand Down
15 changes: 15 additions & 0 deletions adapter/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,21 @@ func (api *Payment) CreateApplePayMerchantSession(ctx context.Context, request A
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
9 changes: 9 additions & 0 deletions tests/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,3 +950,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)
}
}

0 comments on commit 1559604

Please sign in to comment.