Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ApplePay integration #49

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type PaymentType string
type ApmType string
type PaymentProvider string
type PaymentStatus string
type TokenizedCardType string
type PaymentSource string
type PaymentGroup string
type PaymentPhase string
Expand Down Expand Up @@ -350,6 +351,11 @@ const (
PayoutAccountTypeWISE PayoutAccountType = "WISE"
)

// tokenized card type declaration
const (
TokenizedCardTypeAPPLE_PAY TokenizedCardType = "APPLE_PAY"
onurpolattimur marked this conversation as resolved.
Show resolved Hide resolved
)

// requests
type CreatePaymentRequest struct {
Price float64 `json:"price,omitempty"`
Expand Down Expand Up @@ -590,6 +596,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 @@ -1550,20 +1564,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 @@ -474,6 +474,21 @@ func (api *Payment) DisapprovePaymentTransactions(ctx context.Context, request P
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
Loading