Skip to content

Commit

Permalink
Add ApplePay integration (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
onurpolattimur committed Mar 26, 2024
1 parent 1e3bc06 commit 57ca2b4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
46 changes: 33 additions & 13 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type ApmType string
type PaymentProvider string
type PosApmPaymentProvider string
type PaymentStatus string
type TokenizedCardType string
type PaymentSource string
type PaymentGroup string
type PaymentPhase string
Expand Down Expand Up @@ -558,6 +559,11 @@ const (
ClientType_M ClientType = "M"
)

// tokenized card type declaration
const (
TokenizedCardType_APPLE_PAY TokenizedCardType = "APPLE_PAY"
)

// requests
type CreatePaymentRequest struct {
Price float64 `json:"price,omitempty"`
Expand Down Expand Up @@ -825,6 +831,14 @@ type StoreCardRequest struct {
CardUserKey string `json:"cardUserKey,omitempty"`
}

type ApplePayMerchantSessionCreateRequest struct {
MerchantIdentifier string `json:"merchantIdentifier,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Initiative string `json:"initiative,omitempty"`
InitiativeContext string `json:"initiativeContext,omitempty"`
ValidationUrl string `json:"validationUrl,omitempty"`
}

type CheckMasterpassUserRequest struct {
MasterpassGsmNumber string `json:"masterpassGsmNumber"`
}
Expand Down Expand Up @@ -1921,20 +1935,26 @@ type Loyalty struct {
Message *string `json:"message,omitempty"`
}

type TokenizedCard struct {
TokenizedCardType TokenizedCardType `json:"type,omitempty"`
Data map[string]interface{} `json:"data,omitempty"`
}

type Card struct {
CardHolderName string `json:"cardHolderName,omitempty"`
CardNumber string `json:"cardNumber,omitempty"`
ExpireYear string `json:"expireYear,omitempty"`
ExpireMonth string `json:"expireMonth,omitempty"`
Cvc string `json:"cvc,omitempty"`
CardAlias string `json:"cardAlias,omitempty"`
CardUserKey string `json:"cardUserKey,omitempty"`
CardToken string `json:"cardToken,omitempty"`
BinNumber string `json:"binNumber,omitempty"`
LastFourDigits string `json:"lastFourDigits,omitempty"`
CardHolderIdentityNumber string `json:"cardHolderIdentityNumber,omitempty"`
Loyalty *Loyalty `json:"loyalty,omitempty"`
StoreCardAfterSuccessPayment bool `json:"storeCardAfterSuccessPayment,omitempty"`
CardHolderName string `json:"cardHolderName,omitempty"`
CardNumber string `json:"cardNumber,omitempty"`
ExpireYear string `json:"expireYear,omitempty"`
ExpireMonth string `json:"expireMonth,omitempty"`
Cvc string `json:"cvc,omitempty"`
CardAlias string `json:"cardAlias,omitempty"`
CardUserKey string `json:"cardUserKey,omitempty"`
CardToken string `json:"cardToken,omitempty"`
BinNumber string `json:"binNumber,omitempty"`
LastFourDigits string `json:"lastFourDigits,omitempty"`
CardHolderIdentityNumber string `json:"cardHolderIdentityNumber,omitempty"`
Loyalty *Loyalty `json:"loyalty,omitempty"`
StoreCardAfterSuccessPayment bool `json:"storeCardAfterSuccessPayment,omitempty"`
TokenizedCard *TokenizedCard `json:"tokenizedCard,omitempty"`
}

type FraudCheckParameters struct {
Expand Down
15 changes: 15 additions & 0 deletions adapter/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,21 @@ func (api *Payment) RetrieveActiveBanks(ctx context.Context) (*InstantTransferBa
return response.Data, nil
}

func (api *Payment) CreateApplePayMerchantSession(ctx context.Context, request ApplePayMerchantSessionCreateRequest) (*interface{}, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/payment/v1/apple-pay/merchant-sessions", request)
if err != nil {
return nil, err
}

response := &Response[interface{}]{}
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

0 comments on commit 57ca2b4

Please sign in to comment.