@tap-payments/apple-pay-button 0.0.85-development → 0.0.87-development

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
+ import { type ButtonSDKProps } from '@tap-payments/acceptance-sdk';
1
2
  import { CheckoutProfileResponse } from './checkoutProfile';
2
- import { Locale, ThemeMode, Edges, Scope, MerchantCapabilities, SupportedNetworks, ButtonType, ColorStyle } from './enums';
3
+ import { MerchantCapabilities, SupportedNetworks, IntegrationType } from './enums';
3
4
  export interface ApplePayRequestData {
4
5
  countryCode: string;
5
6
  currencyCode: string;
@@ -19,101 +20,26 @@ export interface ApplePayRequestData {
19
20
  export interface ApplePayDataToLunchSDKFromMerchantSide {
20
21
  headers: Record<string, any>;
21
22
  BASE_URL: string;
22
- merchant: Record<string, string>;
23
+ merchant: Record<string, any>;
23
24
  applePayRequestData: ApplePayRequestData;
24
25
  debug?: boolean;
25
26
  applePaySDKVersion?: number;
26
27
  }
27
- export interface Interface {
28
- locale?: Locale;
29
- theme?: ThemeMode;
30
- edges?: Edges;
31
- type?: ButtonType;
32
- colorStyle?: ColorStyle;
33
- loader?: boolean;
34
- }
35
- export interface Customer {
36
- id?: string;
37
- name?: {
38
- lang: Locale;
39
- first: string;
40
- last: string;
41
- middle?: string;
42
- }[];
43
- contact?: {
44
- email?: string;
45
- phone?: {
46
- countryCode: string;
47
- number: string;
48
- };
49
- };
50
- }
51
- export interface Acceptance {
52
- supportedSchemes?: Array<SupportedNetworks>;
53
- supportedFundSource?: string[];
54
- supportedPaymentAuthentications?: string[];
55
- }
56
- export interface ApplePayButtonProps {
57
- operator: {
58
- publicKey: string;
59
- hashstring?: string;
60
- };
61
- merchant: {
62
- id: string;
28
+ export type Acceptance = Exclude<ButtonSDKProps['acceptance'], undefined>;
29
+ export type ProfileData = Exclude<Exclude<ButtonSDKProps['metadata'], undefined>['profileData'], undefined>;
30
+ export type Transaction = Exclude<ButtonSDKProps['transaction'], undefined>;
31
+ export interface ApplePayButtonProps extends ButtonSDKProps {
32
+ merchant: ButtonSDKProps['merchant'] & {
63
33
  identifier?: string;
64
34
  };
65
- scope: Scope;
66
- interface?: Interface;
67
- customer?: Customer;
68
- acceptance?: Acceptance;
69
- transaction?: {
70
- authentication?: boolean;
71
- authorize?: {
72
- auto: {
73
- type: string;
74
- time: number;
75
- };
76
- };
77
- metadata?: Record<string, string>;
78
- reference?: string;
79
- paymentAgreement?: {
80
- id: string;
81
- contract?: {
82
- id: string;
83
- };
84
- };
85
- destinations?: Record<string, any>;
86
- };
87
- invoice?: {
88
- id: string;
89
- };
90
- order: {
91
- amount: number;
92
- currency: string;
93
- id?: string;
94
- description?: string;
95
- metadata?: Record<string, string>;
96
- reference?: string;
97
- };
98
- post?: {
99
- url: string;
100
- };
101
- redirect?: {
102
- url: string;
103
- };
104
- onOrderCreated?: (orderId: string) => void;
105
- onCancel?: () => void;
106
- onError?: (error: any) => void;
107
- onSuccess?: (data: Record<string, any>) => Promise<void>;
108
35
  onClick?: (data?: ApplePayDataToLunchSDKFromMerchantSide) => void;
109
- onReady?: () => void;
110
- metaData?: MetaData;
111
- debug?: boolean;
112
- integration?: 'sdk' | 'iframe' | 'webview';
113
- headers?: {
114
- mdn: string;
115
- application: string;
116
- };
36
+ integration?: IntegrationType;
37
+ }
38
+ export interface MerchantValidationRequestData {
39
+ validationUrl: string;
40
+ origin: string;
41
+ merchantId: string;
42
+ merchantName: string;
117
43
  }
118
44
  export interface MerchantResponse {
119
45
  id: string;
@@ -52,6 +52,6 @@ export interface ChargeRequestBody {
52
52
  export interface AuthorizeRequestBody extends ChargeRequestBody {
53
53
  auto?: {
54
54
  type: string;
55
- time: number;
55
+ time: string;
56
56
  };
57
57
  }
@@ -1,28 +1,3 @@
1
- export declare enum Locale {
2
- EN = "en",
3
- AR = "ar",
4
- DYNAMIC = "dynamic"
5
- }
6
- export declare enum ThemeMode {
7
- DARK = "dark",
8
- LIGHT = "light",
9
- DYNAMIC = "dynamic"
10
- }
11
- export declare enum Edges {
12
- STRAIGHT = "straight",
13
- CURVED = "curved",
14
- CIRCULAR = "circular"
15
- }
16
- export declare enum ColorStyle {
17
- COLORED = "colored",
18
- MONOCHROME = "monochrome"
19
- }
20
- export declare enum Scope {
21
- CHARGE = "charge",
22
- AUTHORIZE = "authorize",
23
- TAP_TOKEN = "taptoken",
24
- APPLE_PAY_TOKEN = "applepaytoken"
25
- }
26
1
  export declare enum ButtonStyle {
27
2
  Black = "black",
28
3
  White = "white",
@@ -63,3 +38,8 @@ export declare enum SupportedNetworks {
63
38
  Jcb = "jcb",
64
39
  Maestro = "maestro"
65
40
  }
41
+ export declare enum IntegrationType {
42
+ SDK = "sdk",
43
+ IFRAME = "iframe",
44
+ WEBVIEW = "webview"
45
+ }
@@ -1,33 +1,3 @@
1
- export var Locale;
2
- (function (Locale) {
3
- Locale["EN"] = "en";
4
- Locale["AR"] = "ar";
5
- Locale["DYNAMIC"] = "dynamic";
6
- })(Locale || (Locale = {}));
7
- export var ThemeMode;
8
- (function (ThemeMode) {
9
- ThemeMode["DARK"] = "dark";
10
- ThemeMode["LIGHT"] = "light";
11
- ThemeMode["DYNAMIC"] = "dynamic";
12
- })(ThemeMode || (ThemeMode = {}));
13
- export var Edges;
14
- (function (Edges) {
15
- Edges["STRAIGHT"] = "straight";
16
- Edges["CURVED"] = "curved";
17
- Edges["CIRCULAR"] = "circular";
18
- })(Edges || (Edges = {}));
19
- export var ColorStyle;
20
- (function (ColorStyle) {
21
- ColorStyle["COLORED"] = "colored";
22
- ColorStyle["MONOCHROME"] = "monochrome";
23
- })(ColorStyle || (ColorStyle = {}));
24
- export var Scope;
25
- (function (Scope) {
26
- Scope["CHARGE"] = "charge";
27
- Scope["AUTHORIZE"] = "authorize";
28
- Scope["TAP_TOKEN"] = "taptoken";
29
- Scope["APPLE_PAY_TOKEN"] = "applepaytoken";
30
- })(Scope || (Scope = {}));
31
1
  export var ButtonStyle;
32
2
  (function (ButtonStyle) {
33
3
  ButtonStyle["Black"] = "black";
@@ -74,3 +44,9 @@ export var SupportedNetworks;
74
44
  SupportedNetworks["Jcb"] = "jcb";
75
45
  SupportedNetworks["Maestro"] = "maestro";
76
46
  })(SupportedNetworks || (SupportedNetworks = {}));
47
+ export var IntegrationType;
48
+ (function (IntegrationType) {
49
+ IntegrationType["SDK"] = "sdk";
50
+ IntegrationType["IFRAME"] = "iframe";
51
+ IntegrationType["WEBVIEW"] = "webview";
52
+ })(IntegrationType || (IntegrationType = {}));
package/build/api.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { MerchantResponse, CheckoutProfileRequest, ChargeRequestBody, AuthorizeRequestBody } from './@types';
2
- export declare const setAxiosGlobalHeaders: (headers: Record<string, string>) => void;
1
+ import { CheckoutProfileRequest, ChargeRequestBody, AuthorizeRequestBody, MerchantValidationRequestData } from './@types';
2
+ export declare const setAxiosGlobalHeaders: (headers: {
3
+ [x: string]: string | undefined;
4
+ }) => void;
3
5
  export declare const getAxiosGlobalHeaders: () => {
4
6
  [x: string]: import("axios").AxiosHeaderValue | undefined;
5
7
  Accept?: import("axios").AxiosHeaderValue | undefined;
@@ -20,7 +22,7 @@ declare class APPService {
20
22
  merchant: any;
21
23
  payment_options: any;
22
24
  }>;
23
- appleSession(merchant: Pick<MerchantResponse, 'name' | 'id'>, validationURL: string, merchantRegisteredDomain: string, merchantIdentifier: string): Promise<any>;
25
+ appleSession(body: MerchantValidationRequestData): Promise<any>;
24
26
  tapTokenization(applePaymentData: Record<string, string>): Promise<any>;
25
27
  createCharge(request: ChargeRequestBody): Promise<any>;
26
28
  createAuthorize(request: AuthorizeRequestBody): Promise<any>;
package/build/api.js CHANGED
@@ -149,20 +149,12 @@ var APPService = (function () {
149
149
  enumerable: false,
150
150
  configurable: true,
151
151
  writable: true,
152
- value: function (merchant, validationURL, merchantRegisteredDomain, merchantIdentifier) {
152
+ value: function (body) {
153
153
  return __awaiter(this, void 0, void 0, function () {
154
- var body, data;
154
+ var data;
155
155
  return __generator(this, function (_a) {
156
156
  switch (_a.label) {
157
- case 0:
158
- body = {
159
- validationUrl: validationURL,
160
- origin: merchantRegisteredDomain,
161
- merchantIdentifier: merchantIdentifier,
162
- merchantId: merchant.id,
163
- merchantName: merchant.name
164
- };
165
- return [4, axiosInstance.post('/validatemerchant', body)];
157
+ case 0: return [4, axiosInstance.post('/validatemerchant', body)];
166
158
  case 1:
167
159
  data = (_a.sent()).data;
168
160
  if (data.errors)
@@ -12,12 +12,11 @@ var __assign = (this && this.__assign) || function () {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import * as React from 'react';
14
14
  import { createRoot } from 'react-dom/client';
15
- import { findOrCreateElementAndInject } from '../../utils';
16
15
  import { useApplePay } from '../../hooks/useApplePay';
17
- import { Locale, PayButton } from '@tap-payments/acceptance-sdk';
16
+ import { findOrCreateElementAndInject, Locale, PayButton } from '@tap-payments/acceptance-sdk';
18
17
  var ApplePay = React.memo(function (props) {
19
18
  var _a, _b, _c;
20
- var _d = useApplePay({ buttonProps: props }), onClick = _d.onClick, initialLoading = _d.initialLoading, mappedProps = _d.mappedProps, theme = _d.theme, isRounded = _d.isRounded, success = _d.success, error = _d.error, applePayPaymentMethodOptions = _d.applePayPaymentMethodOptions, profileData = _d.profileData;
19
+ var _d = useApplePay({ buttonProps: props }), onClick = _d.onClick, mappedProps = _d.mappedProps, theme = _d.theme, isRounded = _d.isRounded, success = _d.success, error = _d.error, applePayPaymentMethodOptions = _d.applePayPaymentMethodOptions, profileData = _d.profileData;
21
20
  React.useEffect(function () {
22
21
  if (props.debug) {
23
22
  console.log('ApplePayButtonProps', props);
@@ -27,7 +26,7 @@ var ApplePay = React.memo(function (props) {
27
26
  width: '100%',
28
27
  display: 'flex',
29
28
  justifyContent: 'center'
30
- } }, { children: _jsx(PayButton, { shimmerLoader: !profileData || initialLoading || !applePayPaymentMethodOptions, locale: ((_a = mappedProps.interface) === null || _a === void 0 ? void 0 : _a.locale) || Locale.EN, theme: theme, edges: (_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.edges, colorStyle: (_c = mappedProps.interface) === null || _c === void 0 ? void 0 : _c.colorStyle, isFailed: error, isRounded: isRounded, isSuccess: success, onClick: onClick, buttonStyle: applePayPaymentMethodOptions === null || applePayPaymentMethodOptions === void 0 ? void 0 : applePayPaymentMethodOptions.button_style }) })));
29
+ } }, { children: _jsx(PayButton, { shimmerLoader: !profileData || !applePayPaymentMethodOptions, locale: ((_a = mappedProps.interface) === null || _a === void 0 ? void 0 : _a.locale) || Locale.EN, theme: theme, edges: (_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.edges, colorStyle: (_c = mappedProps.interface) === null || _c === void 0 ? void 0 : _c.colorStyle, isFailed: error, isRounded: isRounded, isSuccess: success, onClick: onClick, buttonStyle: applePayPaymentMethodOptions === null || applePayPaymentMethodOptions === void 0 ? void 0 : applePayPaymentMethodOptions.button_style }) })));
31
30
  });
32
31
  export function ApplePayButton(props) {
33
32
  return _jsx(ApplePay, __assign({}, props));
@@ -1,8 +1,8 @@
1
- import { ApplePayButtonProps, ApplePayDataToLunchSDKFromMerchantSide, ApplePayRequestData, MetaData, Scope } from '../@types';
2
- interface UsaApplePayProps {
3
- buttonProps: ApplePayButtonProps;
1
+ import { ApplePayDataToLunchSDKFromMerchantSide, ApplePayRequestData } from '../@types';
2
+ interface UseApplePayParams {
3
+ buttonProps: any;
4
4
  }
5
- export declare const useApplePay: ({ buttonProps }: UsaApplePayProps) => {
5
+ export declare const useApplePay: ({ buttonProps }: UseApplePayParams) => {
6
6
  onClick: () => void;
7
7
  loading: boolean;
8
8
  isIframeIntegration: boolean;
@@ -10,84 +10,12 @@ export declare const useApplePay: ({ buttonProps }: UsaApplePayProps) => {
10
10
  disabled: boolean;
11
11
  applePayRequestData: ApplePayRequestData | undefined;
12
12
  applePayRequestConfiguration: Omit<ApplePayDataToLunchSDKFromMerchantSide, "applePayRequestData"> | undefined;
13
- mappedProps: {
14
- interface: {
15
- locale?: import("@tap-payments/acceptance-sdk").Locale | undefined;
16
- theme?: import("@tap-payments/acceptance-sdk").ThemeMode | undefined;
17
- edges?: import("@tap-payments/acceptance-sdk").Edges | undefined;
18
- colorStyle?: import("@tap-payments/acceptance-sdk").ColorStyle | undefined;
19
- loader?: boolean | undefined;
20
- userExperience?: "popup" | "page" | undefined;
21
- powered?: boolean | undefined;
22
- direction?: import("@tap-payments/acceptance-sdk").Direction | undefined;
23
- cardDirection?: import("@tap-payments/acceptance-sdk").Direction | undefined;
24
- } | undefined;
25
- operator: {
26
- publicKey: string;
27
- hashstring?: string | undefined;
28
- };
29
- merchant: {
30
- id: string;
31
- identifier?: string | undefined;
32
- };
33
- scope: Scope;
34
- customer?: import("../@types").Customer | undefined;
35
- acceptance?: import("../@types").Acceptance | undefined;
36
- transaction?: {
37
- authentication?: boolean | undefined;
38
- authorize?: {
39
- auto: {
40
- type: string;
41
- time: number;
42
- };
43
- } | undefined;
44
- metadata?: Record<string, string> | undefined;
45
- reference?: string | undefined;
46
- paymentAgreement?: {
47
- id: string;
48
- contract?: {
49
- id: string;
50
- } | undefined;
51
- } | undefined;
52
- destinations?: Record<string, any> | undefined;
53
- } | undefined;
54
- invoice?: {
55
- id: string;
56
- } | undefined;
57
- order: {
58
- amount: number;
59
- currency: string;
60
- id?: string | undefined;
61
- description?: string | undefined;
62
- metadata?: Record<string, string> | undefined;
63
- reference?: string | undefined;
64
- };
65
- post?: {
66
- url: string;
67
- } | undefined;
68
- redirect?: {
69
- url: string;
70
- } | undefined;
71
- onOrderCreated?: ((orderId: string) => void) | undefined;
72
- onCancel?: (() => void) | undefined;
73
- onError?: ((error: any) => void) | undefined;
74
- onSuccess?: ((data: Record<string, any>) => Promise<void>) | undefined;
75
- onClick?: ((data?: ApplePayDataToLunchSDKFromMerchantSide | undefined) => void) | undefined;
76
- onReady?: (() => void) | undefined;
77
- metaData?: MetaData | undefined;
78
- debug?: boolean | undefined;
79
- integration?: "iframe" | "sdk" | "webview" | undefined;
80
- headers?: {
81
- mdn: string;
82
- application: string;
83
- } | undefined;
84
- };
85
- theme: import("../@types").ThemeMode;
86
- initialLoading: boolean;
13
+ mappedProps: any;
14
+ theme: import("@tap-payments/acceptance-sdk").ThemeMode;
87
15
  isRounded: boolean;
88
16
  success: boolean;
89
17
  error: boolean;
90
- applePayPaymentMethodOptions: import("../@types").PaymentMethod | null;
91
- profileData: Pick<MetaData, "merchant" | "payment_options"> | undefined;
18
+ applePayPaymentMethodOptions: import("@tap-payments/acceptance-sdk").PaymentMethod | null;
19
+ profileData: import("@tap-payments/acceptance-sdk").CheckoutProfileResponse | undefined;
92
20
  };
93
21
  export {};
@@ -45,41 +45,28 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
- var __rest = (this && this.__rest) || function (s, e) {
49
- var t = {};
50
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
- t[p] = s[p];
52
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
- t[p[i]] = s[p[i]];
56
- }
57
- return t;
58
- };
59
48
  import { useCallback, useEffect, useMemo, useState } from 'react';
60
49
  import { ApplePayVersion, MW_BASE_URL } from '../constants';
61
50
  import { prepareApplePayRequest, shallRenderApplePay } from '../utils/config';
62
- import { Scope } from '../@types';
51
+ import { IntegrationType } from '../@types';
63
52
  import { useMerchantApplePay } from './useMerchantApplePay';
64
53
  import { getApplePayPaymentMethod, getDefaultThemeMode } from '../utils';
65
54
  import appService, { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api';
66
- import { ChargeCode, mappingInterface } from '@tap-payments/acceptance-sdk';
55
+ import { areAllTheObjectStringValuesValid, ChargeCode, mappingInterface, Scope } from '@tap-payments/acceptance-sdk';
67
56
  export var useApplePay = function (_a) {
68
- var _b;
69
57
  var buttonProps = _a.buttonProps;
70
- var _c = useState(), applePayRequestData = _c[0], setApplePayRequestData = _c[1];
71
- var _d = useState(), applePayRequestConfiguration = _d[0], setApplePayRequestConfiguration = _d[1];
72
- var _e = useState(), profileData = _e[0], setProfile = _e[1];
73
- var _f = useState(false), disabled = _f[0], setDisabled = _f[1];
74
- var _g = useState(false), initialLoading = _g[0], setInitialLoading = _g[1];
75
- var _h = useState(false), error = _h[0], setError = _h[1];
76
- var _j = useState(false), success = _j[0], setSuccess = _j[1];
77
- var _k = useState(false), loading = _k[0], setLoading = _k[1];
78
- var _l = useState(false), isRounded = _l[0], setIsRounded = _l[1];
58
+ var _b = useState(), applePayRequestData = _b[0], setApplePayRequestData = _b[1];
59
+ var _c = useState(), applePayRequestConfiguration = _c[0], setApplePayRequestConfiguration = _c[1];
60
+ var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
61
+ var _e = useState(false), error = _e[0], setError = _e[1];
62
+ var _f = useState(false), success = _f[0], setSuccess = _f[1];
63
+ var _g = useState(false), loading = _g[0], setLoading = _g[1];
64
+ var _h = useState(false), isRounded = _h[0], setIsRounded = _h[1];
79
65
  var mappedProps = __assign(__assign({}, buttonProps), { interface: mappingInterface(buttonProps.interface) });
80
- var interfaceObj = mappedProps.interface, merchant = mappedProps.merchant, customer = mappedProps.customer, acceptance = mappedProps.acceptance, scope = mappedProps.scope, debug = mappedProps.debug, onError = mappedProps.onError, onSuccess = mappedProps.onSuccess, onCancel = mappedProps.onCancel, onReady = mappedProps.onReady, metaData = mappedProps.metaData, headers = mappedProps.headers, operator = mappedProps.operator, order = mappedProps.order, onOrderCreated = mappedProps.onOrderCreated, transaction = mappedProps.transaction, post = mappedProps.post, redirect = mappedProps.redirect, integration = mappedProps.integration;
81
- var isIframeIntegration = integration === 'iframe';
82
- var isWebViewIntegration = integration === 'webview';
66
+ var _j = mappedProps, interfaceObj = _j.interface, merchant = _j.merchant, customer = _j.customer, acceptance = _j.acceptance, scope = _j.scope, debug = _j.debug, onError = _j.onError, onSuccess = _j.onSuccess, onCancel = _j.onCancel, onReady = _j.onReady, metadata = _j.metadata, operator = _j.operator, order = _j.order, onOrderCreated = _j.onOrderCreated, transaction = _j.transaction, post = _j.post, redirect = _j.redirect, integration = _j.integration;
67
+ var _k = metadata || {}, profileData = _k.profileData, headers = _k.headers;
68
+ var isIframeIntegration = integration === IntegrationType.IFRAME;
69
+ var isWebViewIntegration = integration === IntegrationType.WEBVIEW;
83
70
  useMerchantApplePay({
84
71
  isIframeIntegration: isIframeIntegration,
85
72
  onError: onError,
@@ -97,99 +84,76 @@ export var useApplePay = function (_a) {
97
84
  setSuccess: setSuccess,
98
85
  setLoading: setLoading
99
86
  });
100
- var theme = getDefaultThemeMode((_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.theme);
87
+ var theme = useMemo(function () { return getDefaultThemeMode(interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.theme); }, [interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.theme]);
101
88
  var applePayPaymentMethodOptions = useMemo(function () {
102
89
  if (!profileData)
103
90
  return null;
104
91
  return getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
105
92
  }, [profileData]);
106
- var initialize = function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
107
- var headers_1, rest, applePayPreparedData_1, data, applePayPreparedData, err_1;
108
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
109
- return __generator(this, function (_o) {
110
- switch (_o.label) {
93
+ var merchantValidationRequestData = useMemo(function () {
94
+ if (!profileData)
95
+ return null;
96
+ return {
97
+ merchantId: merchant.id || (profileData === null || profileData === void 0 ? void 0 : profileData.merchant.id),
98
+ merchantName: profileData.merchant.name,
99
+ validationUrl: '',
100
+ origin: (isWebViewIntegration ? applePayPaymentMethodOptions === null || applePayPaymentMethodOptions === void 0 ? void 0 : applePayPaymentMethodOptions.identifier : merchant.identifier || merchant.id) ||
101
+ profileData.merchant.id
102
+ };
103
+ }, [merchant, profileData === null || profileData === void 0 ? void 0 : profileData.merchant, isWebViewIntegration, applePayPaymentMethodOptions === null || applePayPaymentMethodOptions === void 0 ? void 0 : applePayPaymentMethodOptions.identifier]);
104
+ var initialize = function () { return __awaiter(void 0, void 0, void 0, function () {
105
+ var session, _a, id, api_version, contact, applePayPreparedData, err_1;
106
+ var _b, _c, _d;
107
+ return __generator(this, function (_e) {
108
+ switch (_e.label) {
111
109
  case 0:
112
- setInitialLoading(true);
113
- _o.label = 1;
114
- case 1:
115
- _o.trys.push([1, 7, , 8]);
110
+ _e.trys.push([0, 5, , 6]);
116
111
  if (!shallRenderApplePay()) {
117
112
  throw new Error('The device/customer is not eligible to use ApplePay');
118
113
  }
119
- if (metaData) {
120
- headers_1 = metaData.headers, rest = __rest(metaData, ["headers"]);
121
- setAxiosGlobalHeaders(__assign({}, headers_1));
122
- setProfile(rest);
123
- applePayPreparedData_1 = prepareApplePayRequest(__assign(__assign({}, rest), { order: order, acceptance: acceptance, customer: customer }));
124
- setApplePayRequestData(applePayPreparedData_1.applePaySessionRequest);
125
- setInitialLoading(false);
126
- return [2];
114
+ if (!profileData) {
115
+ throw new Error('000::Profile data is not available');
127
116
  }
128
- if (!headers) return [3, 3];
117
+ session = headers === null || headers === void 0 ? void 0 : headers.session;
118
+ setAxiosGlobalHeaders({ session: session });
119
+ if (!(headers && areAllTheObjectStringValuesValid(headers))) return [3, 2];
129
120
  return [4, appService.setHttpHeaders(__assign(__assign({}, headers), { authorization: operator.publicKey }))];
130
- case 2:
131
- _o.sent();
132
- return [3, 5];
133
- case 3: return [4, appService.setBrowserHeaders({
121
+ case 1:
122
+ _e.sent();
123
+ return [3, 4];
124
+ case 2: return [4, appService.setBrowserHeaders({
134
125
  locale: interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale,
135
126
  domain: window.location.origin,
136
127
  pk: operator.publicKey
137
128
  })];
129
+ case 3:
130
+ _e.sent();
131
+ _e.label = 4;
138
132
  case 4:
139
- _o.sent();
140
- _o.label = 5;
141
- case 5: return [4, appService.checkoutProfile({
142
- supported_payment_methods: ['APPLE_PAY'],
143
- supported_currencies: [order.currency],
144
- transaction_mode: scope === Scope.AUTHORIZE ? 'AUTHORIZE_CAPTURE' : 'PURCHASE',
145
- currency: order.currency,
146
- merchant_id: merchant === null || merchant === void 0 ? void 0 : merchant.id,
147
- total_amount: Number(order.amount),
148
- order: __assign(__assign({ id: order === null || order === void 0 ? void 0 : order.id, amount: Number(order.amount), currency: order.currency, description: order === null || order === void 0 ? void 0 : order.description, metadata: order === null || order === void 0 ? void 0 : order.metadata }, (customer && {
149
- customer: {
150
- id: customer === null || customer === void 0 ? void 0 : customer.id,
151
- email: (_a = customer.contact) === null || _a === void 0 ? void 0 : _a.email,
152
- first_name: ((_b = customer.name) === null || _b === void 0 ? void 0 : _b.length) ? customer.name[0].first : '',
153
- last_name: ((_c = customer.name) === null || _c === void 0 ? void 0 : _c.length) ? customer.name[0].last : '',
154
- phone: {
155
- country_code: (_f = (_e = (_d = customer.contact) === null || _d === void 0 ? void 0 : _d.phone) === null || _e === void 0 ? void 0 : _e.countryCode) !== null && _f !== void 0 ? _f : '',
156
- number: (_j = (_h = (_g = customer.contact) === null || _g === void 0 ? void 0 : _g.phone) === null || _h === void 0 ? void 0 : _h.number) !== null && _j !== void 0 ? _j : ''
157
- }
158
- }
159
- })), { merchant: {
160
- id: merchant === null || merchant === void 0 ? void 0 : merchant.id
161
- }, items: [
162
- {
163
- amount: Number(order.amount),
164
- currency: order.currency,
165
- name: "apple pay sdk button order item",
166
- quantity: 1,
167
- description: "apple pay sdk button order item description"
168
- }
169
- ] })
170
- })];
171
- case 6:
172
- data = _o.sent();
173
- if (debug)
174
- console.log('merchant configuration: ', data);
175
- setProfile(data);
176
- applePayPreparedData = prepareApplePayRequest(__assign(__assign({}, data), { order: order, acceptance: acceptance, customer: customer }));
133
+ if (debug) {
134
+ _a = profileData.merchant, id = _a.id, api_version = _a.api_version, contact = _a.contact;
135
+ console.log('merchant configuration: ', {
136
+ id: id,
137
+ api_version: api_version,
138
+ contact: contact
139
+ });
140
+ }
141
+ applePayPreparedData = prepareApplePayRequest(__assign(__assign({}, profileData), { order: order, acceptance: acceptance, customer: customer }));
177
142
  setApplePayRequestData(applePayPreparedData.applePaySessionRequest);
178
- onOrderCreated === null || onOrderCreated === void 0 ? void 0 : onOrderCreated((_l = (_k = data.payment_options) === null || _k === void 0 ? void 0 : _k.order) === null || _l === void 0 ? void 0 : _l.id);
143
+ onOrderCreated === null || onOrderCreated === void 0 ? void 0 : onOrderCreated((_c = (_b = profileData.payment_options) === null || _b === void 0 ? void 0 : _b.order) === null || _c === void 0 ? void 0 : _c.id);
179
144
  setApplePayRequestConfiguration({
180
145
  BASE_URL: MW_BASE_URL,
181
146
  headers: getAxiosGlobalHeaders(),
182
- merchant: __assign(__assign({}, data.merchant), { id: merchant.id || ((_m = data.merchant) === null || _m === void 0 ? void 0 : _m.id) })
147
+ merchant: __assign(__assign({}, profileData.merchant), { id: merchant.id || ((_d = profileData.merchant) === null || _d === void 0 ? void 0 : _d.id) })
183
148
  });
184
- setInitialLoading(false);
185
149
  onReady === null || onReady === void 0 ? void 0 : onReady();
186
- return [3, 8];
187
- case 7:
188
- err_1 = _o.sent();
150
+ return [3, 6];
151
+ case 5:
152
+ err_1 = _e.sent();
189
153
  onError === null || onError === void 0 ? void 0 : onError(err_1.errors || err_1);
190
154
  console.log('error in initialize', err_1);
191
- return [3, 8];
192
- case 8: return [2];
155
+ return [3, 6];
156
+ case 6: return [2];
193
157
  }
194
158
  });
195
159
  }); };
@@ -234,8 +198,10 @@ export var useApplePay = function (_a) {
234
198
  if (debug) {
235
199
  console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(window.location.hostname));
236
200
  }
237
- return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id || profileData.merchant.id }), event.validationURL, window.location.hostname, (isWebViewIntegration ? applePayPaymentMethodOptions === null || applePayPaymentMethodOptions === void 0 ? void 0 : applePayPaymentMethodOptions.identifier : merchant.identifier || merchant.id) ||
238
- profileData.merchant.id)];
201
+ if (!merchantValidationRequestData) {
202
+ throw new Error('Merchant Validation Request Data is not prepared!');
203
+ }
204
+ return [4, appService.appleSession(__assign(__assign({}, merchantValidationRequestData), { validationUrl: event.validationURL }))];
239
205
  case 2:
240
206
  merchantSession = _a.sent();
241
207
  if (debug)
@@ -270,7 +236,7 @@ export var useApplePay = function (_a) {
270
236
  _b = scope;
271
237
  switch (_b) {
272
238
  case Scope.APPLE_PAY_TOKEN: return [3, 2];
273
- case Scope.TAP_TOKEN: return [3, 4];
239
+ case Scope.TOKEN: return [3, 4];
274
240
  case Scope.AUTHORIZE: return [3, 7];
275
241
  case Scope.CHARGE: return [3, 7];
276
242
  }
@@ -407,14 +373,21 @@ export var useApplePay = function (_a) {
407
373
  var handleClick = useCallback(function () {
408
374
  var _a, _b;
409
375
  if (isIframeIntegration) {
410
- (_a = buttonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(buttonProps, __assign(__assign({}, applePayRequestConfiguration), { applePayRequestData: applePayRequestData }));
376
+ (_a = buttonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(buttonProps, __assign(__assign({}, applePayRequestConfiguration), { merchantValidationRequestData: merchantValidationRequestData, applePayRequestData: applePayRequestData }));
411
377
  return;
412
378
  }
413
379
  onApplePayButtonClicked();
414
380
  (_b = buttonProps.onClick) === null || _b === void 0 ? void 0 : _b.call(buttonProps);
415
- }, [applePayRequestConfiguration, applePayRequestData, buttonProps, isIframeIntegration, onApplePayButtonClicked]);
381
+ }, [
382
+ applePayRequestConfiguration,
383
+ applePayRequestData,
384
+ buttonProps,
385
+ isIframeIntegration,
386
+ onApplePayButtonClicked,
387
+ merchantValidationRequestData
388
+ ]);
416
389
  useEffect(function () {
417
- initialize(metaData);
390
+ initialize();
418
391
  }, []);
419
392
  useEffect(function () {
420
393
  setIsRounded(error || success || loading);
@@ -439,7 +412,6 @@ export var useApplePay = function (_a) {
439
412
  applePayRequestConfiguration: applePayRequestConfiguration,
440
413
  mappedProps: mappedProps,
441
414
  theme: theme,
442
- initialLoading: initialLoading,
443
415
  isRounded: isRounded,
444
416
  success: success,
445
417
  error: error,
@@ -1,4 +1,5 @@
1
- import { MetaData, ApplePayButtonProps, Scope } from '../@types';
1
+ import { MetaData, ApplePayButtonProps, ProfileData } from '../@types';
2
+ import { Scope } from '@tap-payments/acceptance-sdk';
2
3
  interface ApplePayRequestData {
3
4
  isIframeIntegration: boolean;
4
5
  onError?: (error: any) => void;
@@ -6,8 +7,8 @@ interface ApplePayRequestData {
6
7
  setLoading?: (loading: boolean) => void;
7
8
  setSuccess?: (success: boolean) => void;
8
9
  setError?: (error: boolean) => void;
9
- scope: (typeof Scope)[keyof typeof Scope];
10
- profileData?: Pick<MetaData, 'merchant' | 'payment_options'>;
10
+ scope: Scope;
11
+ profileData?: ProfileData;
11
12
  merchant: Pick<MetaData['merchant'], 'id'>;
12
13
  order: ApplePayButtonProps['order'];
13
14
  customer: ApplePayButtonProps['customer'];
@@ -47,7 +47,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
47
  };
48
48
  import * as React from 'react';
49
49
  import appService from '../api';
50
- import { Scope, CHARGE_CODE } from '../@types';
50
+ import { CHARGE_CODE } from '../@types';
51
+ import { Scope } from '@tap-payments/acceptance-sdk';
51
52
  var EVENT_NAME = 'TAP_BUTTON::APPLE_PAY_ON_PAYMENT_AUTHORIZED';
52
53
  export var useMerchantApplePay = function (_a) {
53
54
  var isIframeIntegration = _a.isIframeIntegration, onError = _a.onError, onSuccess = _a.onSuccess, setLoading = _a.setLoading, setError = _a.setError, setSuccess = _a.setSuccess, scope = _a.scope, profileData = _a.profileData, order = _a.order, customer = _a.customer, transaction = _a.transaction, operator = _a.operator, redirect = _a.redirect, post = _a.post;
@@ -69,7 +70,7 @@ export var useMerchantApplePay = function (_a) {
69
70
  _d = scope;
70
71
  switch (_d) {
71
72
  case Scope.APPLE_PAY_TOKEN: return [3, 2];
72
- case Scope.TAP_TOKEN: return [3, 3];
73
+ case Scope.TOKEN: return [3, 3];
73
74
  case Scope.AUTHORIZE: return [3, 5];
74
75
  case Scope.CHARGE: return [3, 5];
75
76
  }
package/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
+ import { Edges, Locale, Scope, ThemeMode } from '@tap-payments/acceptance-sdk';
1
2
  import { ApplePayButtonProps, ApplePayButton, ApplePayRequestData } from './features/ApplePayButton';
2
- import { ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities } from './@types/enums';
3
+ import { SupportedNetworks, ButtonType, MerchantCapabilities } from './@types/enums';
3
4
  export type { ApplePayButtonProps, ApplePayRequestData };
4
5
  export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities };
package/build/index.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { Edges, Locale, Scope, ThemeMode } from '@tap-payments/acceptance-sdk';
1
2
  import { ApplePayButton, renderApplePayButton } from './features/ApplePayButton';
2
- import { ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities } from './@types/enums';
3
+ import { SupportedNetworks, ButtonType, MerchantCapabilities } from './@types/enums';
3
4
  export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Locale, ButtonType, Edges, MerchantCapabilities };
4
5
  window['TapSDKs'] = {
5
6
  renderApplePayButton: renderApplePayButton,
@@ -1,14 +1,14 @@
1
- import { Acceptance, ApplePayButtonProps, ApplePayRequestData, MetaData, PaymentMethod } from '../@types';
1
+ import { Acceptance, ApplePayButtonProps, ApplePayRequestData, ProfileData } from '../@types';
2
2
  export declare const validateSupportedNetworks: (supportedNetworksOptions: Acceptance['supportedSchemes'], merchantSupportedNetworks?: Acceptance['supportedSchemes']) => Acceptance['supportedSchemes'];
3
- export declare const getApplePayPaymentMethod: (paymentMethods: Array<PaymentMethod>) => PaymentMethod;
3
+ export declare const getApplePayPaymentMethod: (paymentMethods: ProfileData['payment_options']['payment_methods']) => import("@tap-payments/acceptance-sdk").PaymentMethod;
4
4
  export declare const getApplePayRequest: ({ order, customer, supportedNetworks, merchantCapabilities, countryCode, name }: Pick<ApplePayButtonProps, "order" | "customer"> & {
5
5
  supportedNetworks: Acceptance['supportedSchemes'];
6
6
  merchantCapabilities: ApplePayRequestData['merchantCapabilities'];
7
7
  countryCode: string;
8
8
  name: string;
9
9
  }) => ApplePayRequestData;
10
- export declare const prepareApplePayRequest: ({ payment_options, merchant, order, customer, acceptance }: Pick<MetaData, 'merchant' | 'payment_options'> & Pick<ApplePayButtonProps, 'order' | 'customer' | 'acceptance'>) => {
10
+ export declare const prepareApplePayRequest: ({ payment_options, merchant, order, customer, acceptance }: ProfileData & Pick<ApplePayButtonProps, 'order' | 'customer' | 'acceptance'>) => {
11
11
  applePaySessionRequest: ApplePayRequestData;
12
- paymentMethod: PaymentMethod;
12
+ paymentMethod: import("@tap-payments/acceptance-sdk").PaymentMethod;
13
13
  };
14
14
  export declare const shallRenderApplePay: () => boolean;
@@ -1,4 +1,3 @@
1
- export * from './html';
2
1
  export * from './theme';
3
2
  export * from './config';
4
3
  export * from './defaultValues';
@@ -1,4 +1,3 @@
1
- export * from './html';
2
1
  export * from './theme';
3
2
  export * from './config';
4
3
  export * from './defaultValues';
@@ -1,6 +1,7 @@
1
1
  import { TapThemeResponse } from '../@types';
2
- import { ColorStyle, FullThemeMode, Locale, ThemeMode } from '../@types/enums';
2
+ import { FullThemeMode } from '../@types/enums';
3
3
  import { ApplePayButtonProps } from '..';
4
+ import { ColorStyle, Locale, ThemeMode } from '@tap-payments/acceptance-sdk';
4
5
  export declare const mappingInterface: (interfaceParam?: ApplePayButtonProps['interface']) => ApplePayButtonProps['interface'];
5
6
  export declare const getDefaultThemeMode: (themeMode?: ThemeMode) => ThemeMode;
6
7
  export declare const getDefaultLocale: (locale?: Locale) => Locale;
@@ -9,7 +9,8 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { ColorStyle, Edges, FullThemeMode, Locale, ThemeMode } from '../@types/enums';
12
+ import { FullThemeMode } from '../@types/enums';
13
+ import { ColorStyle, Edges, Locale, ThemeMode } from '@tap-payments/acceptance-sdk';
13
14
  export var mappingInterface = function (interfaceParam) {
14
15
  return __assign(__assign({ edges: Edges.CURVED, colorStyle: ColorStyle.COLORED, loader: true }, interfaceParam), { locale: getDefaultLocale(interfaceParam === null || interfaceParam === void 0 ? void 0 : interfaceParam.locale), theme: getDefaultThemeMode(interfaceParam === null || interfaceParam === void 0 ? void 0 : interfaceParam.theme) });
15
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "0.0.85-development",
3
+ "version": "0.0.87-development",
4
4
  "description": "Apple Pay Button React Component",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "license": "ISC",
31
31
  "dependencies": {
32
- "@tap-payments/acceptance-sdk": "^0.0.46",
32
+ "@tap-payments/acceptance-sdk": "0.0.58",
33
33
  "@tap-payments/browser-info": "^1.0.2",
34
34
  "@tap-payments/web-error-handing": "^1.0.1",
35
35
  "axios": "^1.2.2",
@@ -1 +0,0 @@
1
- export declare const findOrCreateElementAndInject: (id: string) => HTMLElement;
@@ -1,9 +0,0 @@
1
- export var findOrCreateElementAndInject = function (id) {
2
- var findElement = document.getElementById(id);
3
- if (findElement)
4
- return findElement;
5
- var element = document.createElement('div');
6
- element.setAttribute('id', id);
7
- document.body.appendChild(element);
8
- return element;
9
- };