@tap-payments/apple-pay-button 0.0.37-development → 0.0.38-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.
- package/build/@types/index.d.ts +113 -13
- package/build/api/app.service.d.ts +1 -0
- package/build/api/app.service.js +13 -0
- package/build/constants/index.d.ts +16 -3
- package/build/constants/index.js +17 -4
- package/build/features/ApplePayButton/ApplePayButton.js +9 -4
- package/build/hooks/index.d.ts +0 -1
- package/build/hooks/index.js +0 -1
- package/build/hooks/useApplePay.d.ts +3 -2
- package/build/hooks/useApplePay.js +113 -83
- package/build/hooks/useScript.d.ts +1 -1
- package/build/index.d.ts +1 -3
- package/build/index.js +2 -7
- package/build/utils/config.d.ts +3 -5
- package/build/utils/config.js +15 -23
- package/build/utils/defaultValues.d.ts +52 -13
- package/build/utils/defaultValues.js +9 -8
- package/package.json +1 -1
- package/build/hooks/useApplePayFromMerchantSide.d.ts +0 -11
- package/build/hooks/useApplePayFromMerchantSide.js +0 -177
package/build/@types/index.d.ts
CHANGED
|
@@ -38,32 +38,71 @@ export interface Customer {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
export interface Acceptance {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
supportedSchemes?: Array<typeof SupportedNetworks[keyof typeof SupportedNetworks]>;
|
|
42
|
+
supportedFundSource?: string[];
|
|
43
|
+
supportedPaymentAuthentications?: string[];
|
|
44
44
|
}
|
|
45
45
|
export interface ApplePayButtonProps {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
operator: {
|
|
47
|
+
publicKey: string;
|
|
48
|
+
hashstring?: string;
|
|
49
|
+
};
|
|
49
50
|
merchant: {
|
|
50
51
|
id: string;
|
|
51
|
-
domain: string;
|
|
52
52
|
};
|
|
53
|
+
scope: typeof Scope[keyof typeof Scope];
|
|
54
|
+
environment: typeof Environment[keyof typeof Environment];
|
|
53
55
|
interface?: Interface;
|
|
54
56
|
customer?: Customer;
|
|
55
|
-
acceptance
|
|
56
|
-
transaction
|
|
57
|
-
|
|
57
|
+
acceptance?: Acceptance;
|
|
58
|
+
transaction?: {
|
|
59
|
+
authentication?: boolean;
|
|
60
|
+
authorize?: {
|
|
61
|
+
auto: {
|
|
62
|
+
type: string;
|
|
63
|
+
time: number;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
metadata?: Record<string, string>;
|
|
67
|
+
reference?: string;
|
|
68
|
+
paymentAgreement?: {
|
|
69
|
+
id: string;
|
|
70
|
+
contract?: {
|
|
71
|
+
id: string;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
destinations?: Record<string, any>;
|
|
75
|
+
};
|
|
76
|
+
invoice?: {
|
|
77
|
+
id: string;
|
|
78
|
+
};
|
|
79
|
+
order: {
|
|
80
|
+
amount: number;
|
|
58
81
|
currency: string;
|
|
82
|
+
id?: string;
|
|
83
|
+
description?: string;
|
|
84
|
+
metadata?: Record<string, string>;
|
|
85
|
+
reference?: string;
|
|
86
|
+
};
|
|
87
|
+
post?: {
|
|
88
|
+
url: string;
|
|
89
|
+
};
|
|
90
|
+
redirect?: {
|
|
91
|
+
url: string;
|
|
59
92
|
};
|
|
93
|
+
onOrderCreated?: (orderId: string) => void;
|
|
60
94
|
onCancel?: () => void;
|
|
61
95
|
onError?: (error: any) => void;
|
|
62
|
-
onSuccess?: (data: Record<string, any>) =>
|
|
63
|
-
onClick?: () => void;
|
|
96
|
+
onSuccess?: (data: Record<string, any>) => void;
|
|
97
|
+
onClick?: (data?: ApplePayRequestData) => void;
|
|
64
98
|
onReady?: () => void;
|
|
65
99
|
metaData?: MetaData;
|
|
66
100
|
debug?: boolean;
|
|
101
|
+
integration?: 'merchant' | 'tap';
|
|
102
|
+
headers?: {
|
|
103
|
+
mdn: string;
|
|
104
|
+
application: string;
|
|
105
|
+
};
|
|
67
106
|
}
|
|
68
107
|
export interface MerchantResponse {
|
|
69
108
|
id: string;
|
|
@@ -92,12 +131,18 @@ export interface MetaData {
|
|
|
92
131
|
headers: Record<string, string>;
|
|
93
132
|
}
|
|
94
133
|
export interface CheckoutProfileRequest {
|
|
134
|
+
supported_payment_methods: string[];
|
|
135
|
+
supported_currencies: string[];
|
|
136
|
+
transaction_mode: string;
|
|
95
137
|
currency: string;
|
|
96
138
|
merchant_id: string;
|
|
97
139
|
total_amount: number;
|
|
98
140
|
order: {
|
|
141
|
+
id?: string;
|
|
99
142
|
amount: number;
|
|
100
143
|
currency: string;
|
|
144
|
+
description?: string;
|
|
145
|
+
metadata?: Record<string, string>;
|
|
101
146
|
customer?: {
|
|
102
147
|
id?: string;
|
|
103
148
|
email?: string;
|
|
@@ -113,10 +158,65 @@ export interface CheckoutProfileRequest {
|
|
|
113
158
|
amount: number;
|
|
114
159
|
currency: string;
|
|
115
160
|
name: string;
|
|
116
|
-
|
|
161
|
+
description: string;
|
|
117
162
|
}[];
|
|
118
163
|
merchant: {
|
|
119
164
|
id: string;
|
|
120
165
|
};
|
|
121
166
|
};
|
|
122
167
|
}
|
|
168
|
+
export interface ChargeRequestBody {
|
|
169
|
+
source: {
|
|
170
|
+
id: string;
|
|
171
|
+
};
|
|
172
|
+
ipaddress?: string;
|
|
173
|
+
amount: number;
|
|
174
|
+
currency: string;
|
|
175
|
+
selected_amount?: string;
|
|
176
|
+
selected_currency?: string;
|
|
177
|
+
product: 'Google-Pay-Button';
|
|
178
|
+
threeDSecure?: boolean;
|
|
179
|
+
save_card: boolean;
|
|
180
|
+
fee: number;
|
|
181
|
+
customer: {
|
|
182
|
+
id?: string;
|
|
183
|
+
first_name?: string;
|
|
184
|
+
middle_name?: string;
|
|
185
|
+
last_name?: string;
|
|
186
|
+
email?: string;
|
|
187
|
+
phone?: {
|
|
188
|
+
country_code: string;
|
|
189
|
+
number: string;
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
hashstring?: string;
|
|
193
|
+
metadata?: Record<string, string>;
|
|
194
|
+
post?: {
|
|
195
|
+
url: string;
|
|
196
|
+
};
|
|
197
|
+
redirect?: {
|
|
198
|
+
url: string;
|
|
199
|
+
};
|
|
200
|
+
merchant?: {
|
|
201
|
+
id: string;
|
|
202
|
+
};
|
|
203
|
+
order?: {
|
|
204
|
+
id: string;
|
|
205
|
+
};
|
|
206
|
+
payment_agreement?: {
|
|
207
|
+
id: string;
|
|
208
|
+
contract?: {
|
|
209
|
+
id: string;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
destinations?: Record<string, any>;
|
|
213
|
+
reference?: {
|
|
214
|
+
order?: string;
|
|
215
|
+
transaction?: string;
|
|
216
|
+
};
|
|
217
|
+
description?: string;
|
|
218
|
+
auto?: {
|
|
219
|
+
type: string;
|
|
220
|
+
time: number;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
@@ -7,6 +7,7 @@ declare class APPService extends BaseService {
|
|
|
7
7
|
setEnv(env: ApplePayButtonProps['environment']): void;
|
|
8
8
|
setBaseUrl(): void;
|
|
9
9
|
getHeaderPublicKey(): "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8AX++RtxPZFtns4XzXFlDIxPBh0umN4qRXZaKDIlb6a3MknaB7psJWmf2l+e4Cfh9b5tey/+rZqpQ065eXTZfGCAuBLt+fYLQBhLfjRpk8S6hlIzc1Kdjg65uqzMwcTd0p7I4KLwHk1I0oXzuEu53fU1LSZhWp4Mnd6wjVgXAsQIDAQAB\n-----END PUBLIC KEY-----" | "" | "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----" | "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi9W5jyTvA4Iwv3V5sfNQ7VdSz\n7WqwBbnWFbIUL/GjaaE93mvDv4zbgRSznHaHQPH6pxrMhMh0tV58njkvjHvQ/tvg\npwM8SemNPKEEAPl69tnMvCrJRPh2dWL3OHY8yCW4c38Hyx4fy56Zd5cdoVWfCReu\njCsvASLGz+cfRrj2swIDAQAB\n-----END PUBLIC KEY-----";
|
|
10
|
+
setHttpHeaders(headers: Record<string, string>): Promise<void>;
|
|
10
11
|
setBrowserHeaders({ locale, pk, domain }: {
|
|
11
12
|
locale: string;
|
|
12
13
|
pk: string;
|
package/build/api/app.service.js
CHANGED
|
@@ -140,6 +140,19 @@ var APPService = (function (_super) {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
|
+
Object.defineProperty(APPService.prototype, "setHttpHeaders", {
|
|
144
|
+
enumerable: false,
|
|
145
|
+
configurable: true,
|
|
146
|
+
writable: true,
|
|
147
|
+
value: function (headers) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
return __generator(this, function (_a) {
|
|
150
|
+
setAxiosGlobalHeaders(headers);
|
|
151
|
+
return [2];
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
});
|
|
143
156
|
Object.defineProperty(APPService.prototype, "setBrowserHeaders", {
|
|
144
157
|
enumerable: false,
|
|
145
158
|
configurable: true,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const Scope: {
|
|
2
|
-
readonly
|
|
3
|
-
readonly
|
|
2
|
+
readonly CHARGE: "charge";
|
|
3
|
+
readonly AUTHORIZE: "authorize";
|
|
4
|
+
readonly TAP_TOKEN: "taptoken";
|
|
5
|
+
readonly APPLE_PAY_TOKEN: "applepaytoken";
|
|
4
6
|
};
|
|
5
7
|
export declare const ButtonStyle: {
|
|
6
8
|
readonly Black: "black";
|
|
@@ -10,7 +12,17 @@ export declare const ButtonStyle: {
|
|
|
10
12
|
export declare const Locale: {
|
|
11
13
|
readonly EN: "en";
|
|
12
14
|
readonly AR: "ar";
|
|
13
|
-
readonly
|
|
15
|
+
readonly DYNAMIC: "dynamic";
|
|
16
|
+
};
|
|
17
|
+
export declare const ColorStyle: {
|
|
18
|
+
readonly COLORED: "colored";
|
|
19
|
+
readonly MONOCHROME: "monochrome";
|
|
20
|
+
};
|
|
21
|
+
export declare const FullThemeMode: {
|
|
22
|
+
readonly DARK: "dark";
|
|
23
|
+
readonly LIGHT: "light";
|
|
24
|
+
readonly LIGHT_MONO: "light_mono";
|
|
25
|
+
readonly DARK_COLORED: "dark_colored";
|
|
14
26
|
};
|
|
15
27
|
export declare const ButtonType: {
|
|
16
28
|
readonly BOOK: "book";
|
|
@@ -23,6 +35,7 @@ export declare const ButtonType: {
|
|
|
23
35
|
export declare const ThemeMode: {
|
|
24
36
|
readonly DARK: "dark";
|
|
25
37
|
readonly LIGHT: "light";
|
|
38
|
+
readonly DYNAMIC: "dynamic";
|
|
26
39
|
};
|
|
27
40
|
export declare const Edges: {
|
|
28
41
|
readonly STRAIGHT: "straight";
|
package/build/constants/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export var Scope = {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
CHARGE: 'charge',
|
|
3
|
+
AUTHORIZE: 'authorize',
|
|
4
|
+
TAP_TOKEN: 'taptoken',
|
|
5
|
+
APPLE_PAY_TOKEN: 'applepaytoken'
|
|
4
6
|
};
|
|
5
7
|
export var ButtonStyle = {
|
|
6
8
|
Black: 'black',
|
|
@@ -10,7 +12,17 @@ export var ButtonStyle = {
|
|
|
10
12
|
export var Locale = {
|
|
11
13
|
EN: 'en',
|
|
12
14
|
AR: 'ar',
|
|
13
|
-
|
|
15
|
+
DYNAMIC: 'dynamic'
|
|
16
|
+
};
|
|
17
|
+
export var ColorStyle = {
|
|
18
|
+
COLORED: 'colored',
|
|
19
|
+
MONOCHROME: 'monochrome'
|
|
20
|
+
};
|
|
21
|
+
export var FullThemeMode = {
|
|
22
|
+
DARK: 'dark',
|
|
23
|
+
LIGHT: 'light',
|
|
24
|
+
LIGHT_MONO: 'light_mono',
|
|
25
|
+
DARK_COLORED: 'dark_colored'
|
|
14
26
|
};
|
|
15
27
|
export var ButtonType = {
|
|
16
28
|
BOOK: 'book',
|
|
@@ -22,7 +34,8 @@ export var ButtonType = {
|
|
|
22
34
|
};
|
|
23
35
|
export var ThemeMode = {
|
|
24
36
|
DARK: 'dark',
|
|
25
|
-
LIGHT: 'light'
|
|
37
|
+
LIGHT: 'light',
|
|
38
|
+
DYNAMIC: 'dynamic'
|
|
26
39
|
};
|
|
27
40
|
export var Edges = {
|
|
28
41
|
STRAIGHT: 'straight',
|
|
@@ -14,12 +14,13 @@ import * as React from 'react';
|
|
|
14
14
|
import { createRoot } from 'react-dom/client';
|
|
15
15
|
import { findOrCreateElementAndInject } from '../../utils';
|
|
16
16
|
import { useApplePay } from '../../hooks/useApplePay';
|
|
17
|
-
import './ApplePayButton.css';
|
|
18
17
|
import { getDefaultValues } from '../../utils/defaultValues';
|
|
19
18
|
import { ButtonStyle, Edges, ThemeMode } from '../../constants';
|
|
19
|
+
import './ApplePayButton.css';
|
|
20
20
|
var ApplePay = React.memo(function (props) {
|
|
21
21
|
var mappedProps = getDefaultValues(props);
|
|
22
|
-
var _a = useApplePay(mappedProps), loading = _a.loading, onApplePayButtonClicked = _a.onApplePayButtonClicked, disabled = _a.disabled;
|
|
22
|
+
var _a = useApplePay(mappedProps), loading = _a.loading, onApplePayButtonClicked = _a.onApplePayButtonClicked, disabled = _a.disabled, applePayRequestData = _a.applePayRequestData;
|
|
23
|
+
var isMerchantIntegration = props.integration === 'merchant';
|
|
23
24
|
React.useEffect(function () {
|
|
24
25
|
if (props.debug) {
|
|
25
26
|
console.log('ApplePayButtonProps', props);
|
|
@@ -30,9 +31,13 @@ var ApplePay = React.memo(function (props) {
|
|
|
30
31
|
ApplePayButtonStyle: mappedProps.interface.theme === ThemeMode.DARK ? ButtonStyle.Black : ButtonStyle.White,
|
|
31
32
|
borderRadius: mappedProps.interface.edges === Edges.STRAIGHT ? '0' : '10px'
|
|
32
33
|
}, onClick: function () {
|
|
33
|
-
var _a;
|
|
34
|
+
var _a, _b;
|
|
35
|
+
if (isMerchantIntegration) {
|
|
36
|
+
(_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, applePayRequestData);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
34
39
|
onApplePayButtonClicked();
|
|
35
|
-
(
|
|
40
|
+
(_b = props.onClick) === null || _b === void 0 ? void 0 : _b.call(props);
|
|
36
41
|
}, lang: mappedProps.interface.locale, disabled: loading || disabled }));
|
|
37
42
|
});
|
|
38
43
|
export function ApplePayButton(props) {
|
package/build/hooks/index.d.ts
CHANGED
package/build/hooks/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ApplePayButtonProps } from '../@types';
|
|
1
|
+
import { ApplePayButtonProps, ApplePayRequestData } from '../@types';
|
|
2
2
|
declare type UseApplePayProps = Omit<ApplePayButtonProps, 'buttonStyle'>;
|
|
3
3
|
interface UseApplePayReturnProps {
|
|
4
4
|
loading: boolean;
|
|
5
5
|
onApplePayButtonClicked: () => Promise<void>;
|
|
6
6
|
disabled: boolean;
|
|
7
|
+
applePayRequestData?: ApplePayRequestData;
|
|
7
8
|
}
|
|
8
|
-
export declare const useApplePay: ({
|
|
9
|
+
export declare const useApplePay: ({ environment, interface: interfaceObj, merchant, customer, acceptance, scope, debug, onError, onSuccess, onCancel, onReady, metaData, headers, operator, order, onOrderCreated }: UseApplePayProps) => UseApplePayReturnProps;
|
|
9
10
|
export {};
|
|
@@ -47,90 +47,116 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
};
|
|
48
48
|
import { useCallback, useEffect, useState } from 'react';
|
|
49
49
|
import appService from '../api/app.service';
|
|
50
|
-
import { ApplePayVersion } from '../constants';
|
|
50
|
+
import { ApplePayVersion, Scope } from '../constants';
|
|
51
51
|
import { setAxiosGlobalHeaders } from '../api/httpClient';
|
|
52
|
-
import { getApplePayPaymentMethod, getApplePayRequest,
|
|
53
|
-
import {
|
|
52
|
+
import { getApplePayPaymentMethod, getApplePayRequest, validateSupportedNetworks } from '../utils/config';
|
|
53
|
+
import { getMerchantCapabilities } from '../utils/defaultValues';
|
|
54
54
|
export var useApplePay = function (_a) {
|
|
55
|
-
var
|
|
55
|
+
var environment = _a.environment, interfaceObj = _a.interface, merchant = _a.merchant, customer = _a.customer, acceptance = _a.acceptance, scope = _a.scope, debug = _a.debug, onError = _a.onError, onSuccess = _a.onSuccess, onCancel = _a.onCancel, onReady = _a.onReady, metaData = _a.metaData, headers = _a.headers, operator = _a.operator, order = _a.order, onOrderCreated = _a.onOrderCreated;
|
|
56
56
|
var _b = useState(false), loading = _b[0], setLoading = _b[1];
|
|
57
|
-
var _c = useState(
|
|
57
|
+
var _c = useState(), profileData = _c[0], setProfile = _c[1];
|
|
58
58
|
var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
|
|
59
|
+
var _e = useState(), applePayRequestData = _e[0], setApplePayRequestData = _e[1];
|
|
60
|
+
var prepareApplePayRequest = function (_a) {
|
|
61
|
+
var payment_options = _a.payment_options, merchant = _a.merchant;
|
|
62
|
+
var paymentMethod = getApplePayPaymentMethod(payment_options.payment_methods || []);
|
|
63
|
+
var supportedNetworks = validateSupportedNetworks(paymentMethod.supported_card_brands, acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedSchemes);
|
|
64
|
+
var request = getApplePayRequest({
|
|
65
|
+
countryCode: merchant.country_code,
|
|
66
|
+
order: order,
|
|
67
|
+
customer: customer,
|
|
68
|
+
supportedNetworks: supportedNetworks,
|
|
69
|
+
merchantCapabilities: getMerchantCapabilities(acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedFundSource),
|
|
70
|
+
name: merchant.name
|
|
71
|
+
});
|
|
72
|
+
setApplePayRequestData(request);
|
|
73
|
+
};
|
|
59
74
|
var initialize = useCallback(function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
-
var merchantProfile, payment_options,
|
|
61
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
62
|
-
return __generator(this, function (
|
|
63
|
-
switch (
|
|
75
|
+
var merchantProfile, payment_options, headers_1, data, err_1;
|
|
76
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
77
|
+
return __generator(this, function (_m) {
|
|
78
|
+
switch (_m.label) {
|
|
64
79
|
case 0:
|
|
65
80
|
setLoading(true);
|
|
66
81
|
appService.setEnv(environment);
|
|
67
82
|
appService.setBaseUrl();
|
|
68
|
-
|
|
83
|
+
_m.label = 1;
|
|
69
84
|
case 1:
|
|
70
|
-
|
|
85
|
+
_m.trys.push([1, 7, 8, 9]);
|
|
71
86
|
if (metaData) {
|
|
72
|
-
merchantProfile = metaData.merchant, payment_options = metaData.payment_options,
|
|
73
|
-
setAxiosGlobalHeaders(__assign({},
|
|
87
|
+
merchantProfile = metaData.merchant, payment_options = metaData.payment_options, headers_1 = metaData.headers;
|
|
88
|
+
setAxiosGlobalHeaders(__assign({}, headers_1));
|
|
74
89
|
setProfile({ merchant: merchantProfile, payment_options: payment_options });
|
|
75
90
|
return [2];
|
|
76
91
|
}
|
|
77
|
-
return [
|
|
78
|
-
|
|
79
|
-
domain: merchant.domain,
|
|
80
|
-
pk: publicKey
|
|
81
|
-
})];
|
|
92
|
+
if (!headers) return [3, 3];
|
|
93
|
+
return [4, appService.setHttpHeaders(__assign(__assign({}, headers), { pk: operator.publicKey }))];
|
|
82
94
|
case 2:
|
|
83
|
-
|
|
84
|
-
return [
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
_m.sent();
|
|
96
|
+
return [3, 5];
|
|
97
|
+
case 3: return [4, appService.setBrowserHeaders({
|
|
98
|
+
locale: interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale,
|
|
99
|
+
domain: window.location.origin,
|
|
100
|
+
pk: operator.publicKey
|
|
101
|
+
})];
|
|
102
|
+
case 4:
|
|
103
|
+
_m.sent();
|
|
104
|
+
_m.label = 5;
|
|
105
|
+
case 5: return [4, appService.checkoutProfile({
|
|
106
|
+
supported_payment_methods: ['APPLE_PAY'],
|
|
107
|
+
supported_currencies: [order.currency],
|
|
108
|
+
transaction_mode: scope.toLowerCase() === Scope.AUTHORIZE ? 'AUTHORIZE_CAPTURE' : 'PURCHASE',
|
|
109
|
+
currency: order.currency,
|
|
110
|
+
merchant_id: merchant === null || merchant === void 0 ? void 0 : merchant.id,
|
|
111
|
+
total_amount: Number(order.amount),
|
|
112
|
+
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 && {
|
|
113
|
+
customer: {
|
|
114
|
+
id: customer === null || customer === void 0 ? void 0 : customer.id,
|
|
115
|
+
email: (_a = customer.contact) === null || _a === void 0 ? void 0 : _a.email,
|
|
116
|
+
first_name: ((_b = customer.name) === null || _b === void 0 ? void 0 : _b.length) ? customer.name[0].first : '',
|
|
117
|
+
last_name: ((_c = customer.name) === null || _c === void 0 ? void 0 : _c.length) ? customer.name[0].last : '',
|
|
118
|
+
phone: {
|
|
119
|
+
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 : '',
|
|
120
|
+
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 : ''
|
|
98
121
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
122
|
+
}
|
|
123
|
+
})), { merchant: {
|
|
124
|
+
id: merchant === null || merchant === void 0 ? void 0 : merchant.id
|
|
125
|
+
}, items: [
|
|
126
|
+
{
|
|
127
|
+
amount: Number(order.amount),
|
|
128
|
+
currency: order.currency,
|
|
129
|
+
name: "apple pay sdk button order item",
|
|
130
|
+
quantity: 1,
|
|
131
|
+
description: "apple pay sdk button order item description"
|
|
132
|
+
}
|
|
133
|
+
] })
|
|
134
|
+
})];
|
|
135
|
+
case 6:
|
|
136
|
+
data = _m.sent();
|
|
113
137
|
if (debug)
|
|
114
138
|
console.log('merchant configuration: ', data);
|
|
115
139
|
setProfile(data);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
140
|
+
prepareApplePayRequest(data);
|
|
141
|
+
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);
|
|
142
|
+
return [3, 9];
|
|
143
|
+
case 7:
|
|
144
|
+
err_1 = _m.sent();
|
|
145
|
+
onError === null || onError === void 0 ? void 0 : onError(err_1.errors || err_1);
|
|
146
|
+
return [3, 9];
|
|
147
|
+
case 8:
|
|
122
148
|
setLoading(false);
|
|
123
|
-
onReady
|
|
149
|
+
onReady === null || onReady === void 0 ? void 0 : onReady();
|
|
124
150
|
return [7];
|
|
125
|
-
case
|
|
151
|
+
case 9: return [2];
|
|
126
152
|
}
|
|
127
153
|
});
|
|
128
|
-
}); }, [environment, interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale, merchant
|
|
154
|
+
}); }, [environment, interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale, order, customer, merchant, scope, debug, onError, onReady, onOrderCreated]);
|
|
129
155
|
useEffect(function () {
|
|
130
156
|
initialize(metaData);
|
|
131
157
|
}, [initialize, metaData]);
|
|
132
158
|
var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
133
|
-
var ApplePaySession,
|
|
159
|
+
var ApplePaySession, session_1;
|
|
134
160
|
var _a;
|
|
135
161
|
return __generator(this, function (_b) {
|
|
136
162
|
ApplePaySession = window.ApplePaySession;
|
|
@@ -141,25 +167,19 @@ export var useApplePay = function (_a) {
|
|
|
141
167
|
}
|
|
142
168
|
if (!profileData) {
|
|
143
169
|
setDisabled(true);
|
|
144
|
-
console.error('The profile data is not available, please check
|
|
170
|
+
console.error('The profile data is not available, please check the network and try again');
|
|
171
|
+
return [2];
|
|
172
|
+
}
|
|
173
|
+
if (!applePayRequestData) {
|
|
174
|
+
setDisabled(true);
|
|
175
|
+
console.error("We can't find the apple pay request data, please the network and try again");
|
|
145
176
|
return [2];
|
|
146
177
|
}
|
|
147
178
|
try {
|
|
148
|
-
paymentMethod = getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
|
|
149
|
-
currency = validateCurrency(transaction.currency, paymentMethod.supported_currencies);
|
|
150
|
-
cardBrands = validateSupportedNetworks(paymentMethod.supported_card_brands, acceptance.supportedBrands);
|
|
151
|
-
request = getApplePayRequest({
|
|
152
|
-
countryCode: profileData.merchant.country_code,
|
|
153
|
-
transaction: __assign(__assign({}, transaction), { currency: currency }),
|
|
154
|
-
customer: customer,
|
|
155
|
-
supportedNetworks: cardBrands,
|
|
156
|
-
merchantCapabilities: getMerchantCapaplities(acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedCards),
|
|
157
|
-
name: profileData.merchant.name
|
|
158
|
-
});
|
|
159
179
|
if (debug) {
|
|
160
|
-
console.info("Creating ApplePaySession with version: ".concat(ApplePayVersion, " and request: ").concat(JSON.stringify(
|
|
180
|
+
console.info("Creating ApplePaySession with version: ".concat(ApplePayVersion, " and request: ").concat(JSON.stringify(applePayRequestData)));
|
|
161
181
|
}
|
|
162
|
-
session_1 = new ApplePaySession(ApplePayVersion,
|
|
182
|
+
session_1 = new ApplePaySession(ApplePayVersion, applePayRequestData);
|
|
163
183
|
session_1.onvalidatemerchant = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
164
184
|
var merchantSession, error_1;
|
|
165
185
|
return __generator(this, function (_a) {
|
|
@@ -174,9 +194,9 @@ export var useApplePay = function (_a) {
|
|
|
174
194
|
case 1:
|
|
175
195
|
_a.trys.push([1, 3, , 4]);
|
|
176
196
|
if (debug) {
|
|
177
|
-
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(
|
|
197
|
+
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(window.location.origin));
|
|
178
198
|
}
|
|
179
|
-
return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id }), event.validationURL,
|
|
199
|
+
return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id }), event.validationURL, window.location.origin)];
|
|
180
200
|
case 2:
|
|
181
201
|
merchantSession = _a.sent();
|
|
182
202
|
if (debug)
|
|
@@ -209,21 +229,26 @@ export var useApplePay = function (_a) {
|
|
|
209
229
|
_b.trys.push([1, 9, 10, 11]);
|
|
210
230
|
_a = scope;
|
|
211
231
|
switch (_a) {
|
|
212
|
-
case
|
|
213
|
-
case
|
|
232
|
+
case Scope.APPLE_PAY_TOKEN: return [3, 2];
|
|
233
|
+
case Scope.TAP_TOKEN: return [3, 3];
|
|
234
|
+
case Scope.CHARGE: return [3, 5];
|
|
235
|
+
case Scope.AUTHORIZE: return [3, 6];
|
|
214
236
|
}
|
|
215
237
|
return [3, 7];
|
|
216
|
-
case 2:
|
|
217
|
-
|
|
218
|
-
_b.sent();
|
|
238
|
+
case 2:
|
|
239
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(event.payment.token.paymentData);
|
|
219
240
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
220
241
|
return [3, 8];
|
|
221
|
-
case
|
|
222
|
-
case
|
|
242
|
+
case 3: return [4, appService.tapTokenization(event.payment.token.paymentData)];
|
|
243
|
+
case 4:
|
|
223
244
|
data = _b.sent();
|
|
224
|
-
|
|
245
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
246
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
247
|
+
return [3, 8];
|
|
248
|
+
case 5:
|
|
249
|
+
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
250
|
+
return [3, 8];
|
|
225
251
|
case 6:
|
|
226
|
-
_b.sent();
|
|
227
252
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
228
253
|
return [3, 8];
|
|
229
254
|
case 7:
|
|
@@ -272,5 +297,10 @@ export var useApplePay = function (_a) {
|
|
|
272
297
|
return [2];
|
|
273
298
|
});
|
|
274
299
|
}); };
|
|
275
|
-
return {
|
|
300
|
+
return {
|
|
301
|
+
loading: loading,
|
|
302
|
+
onApplePayButtonClicked: onApplePayButtonClicked,
|
|
303
|
+
disabled: !profileData || disabled || !applePayRequestData,
|
|
304
|
+
applePayRequestData: applePayRequestData
|
|
305
|
+
};
|
|
276
306
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useScript(src: string, async?: boolean): "
|
|
1
|
+
export declare function useScript(src: string, async?: boolean): "loading" | "ready" | "idle" | "error";
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { ApplePayGetFromMerchantEvents } from './hooks/useApplePayFromMerchantSide';
|
|
2
1
|
import { ApplePayButtonProps, ApplePayButton } from './features/ApplePayButton';
|
|
3
|
-
import { ApplePayPostFromMerchantEvents, useApplePayFromMerchantSide } from './hooks/useApplePayFromMerchantSide';
|
|
4
2
|
import { ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities } from './constants';
|
|
5
3
|
export type { ApplePayButtonProps };
|
|
6
|
-
export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities
|
|
4
|
+
export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities };
|
package/build/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { ApplePayGetFromMerchantEvents } from './hooks/useApplePayFromMerchantSide';
|
|
2
1
|
import { ApplePayButton, renderApplePayButton } from './features/ApplePayButton';
|
|
3
|
-
import { ApplePayPostFromMerchantEvents, useApplePayFromMerchantSide } from './hooks/useApplePayFromMerchantSide';
|
|
4
2
|
import { ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities } from './constants';
|
|
5
|
-
export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities
|
|
3
|
+
export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities };
|
|
6
4
|
window['TapSDKs'] = {
|
|
7
5
|
renderApplePayButton: renderApplePayButton,
|
|
8
6
|
Scope: Scope,
|
|
@@ -12,8 +10,5 @@ window['TapSDKs'] = {
|
|
|
12
10
|
ButtonType: ButtonType,
|
|
13
11
|
ThemeMode: ThemeMode,
|
|
14
12
|
Edges: Edges,
|
|
15
|
-
MerchantCapabilities: MerchantCapabilities
|
|
16
|
-
ApplePayPostFromMerchantEvents: ApplePayPostFromMerchantEvents,
|
|
17
|
-
useApplePayFromMerchantSide: useApplePayFromMerchantSide,
|
|
18
|
-
ApplePayGetFromMerchantEvents: ApplePayGetFromMerchantEvents
|
|
13
|
+
MerchantCapabilities: MerchantCapabilities
|
|
19
14
|
};
|
package/build/utils/config.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Acceptance, ApplePayButtonProps, ApplePayRequestData, PaymentMethod } from '../@types';
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
|
|
5
|
-
export declare const getApplePayRequest: ({ transaction, customer, supportedNetworks, merchantCapabilities, countryCode, name }: Pick<ApplePayButtonProps, "transaction" | "customer"> & {
|
|
6
|
-
supportedNetworks: Acceptance['supportedBrands'];
|
|
2
|
+
export declare const validateSupportedNetworks: (supportedNetworksOptions: Acceptance['supportedSchemes'], merchantSupportedNetworks?: Acceptance['supportedSchemes']) => Acceptance['supportedSchemes'];
|
|
3
|
+
export declare const getApplePayRequest: ({ order, customer, supportedNetworks, merchantCapabilities, countryCode, name }: Pick<ApplePayButtonProps, "order" | "customer"> & {
|
|
4
|
+
supportedNetworks: Acceptance['supportedSchemes'];
|
|
7
5
|
merchantCapabilities: ApplePayRequestData['merchantCapabilities'];
|
|
8
6
|
countryCode: string;
|
|
9
7
|
name: string;
|
package/build/utils/config.js
CHANGED
|
@@ -1,34 +1,26 @@
|
|
|
1
1
|
import { JSEncrypt } from 'jsencrypt';
|
|
2
|
-
export var validateSupportedNetworks = function (
|
|
2
|
+
export var validateSupportedNetworks = function (supportedNetworksOptions, merchantSupportedNetworks) {
|
|
3
3
|
var toLowerCase = function (item) { return item.toLowerCase(); };
|
|
4
|
-
if (!
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
return
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var isSupported = supportedNetworksConfig.some(function (item) { return item.toLowerCase() === network.toLowerCase(); });
|
|
13
|
-
if (!isSupported) {
|
|
14
|
-
throw new Error("The supported network ".concat(network, " is not supported"));
|
|
15
|
-
}
|
|
4
|
+
if (!supportedNetworksOptions)
|
|
5
|
+
throw new Error("There is no supported networks available in your acceptance object");
|
|
6
|
+
if (!merchantSupportedNetworks)
|
|
7
|
+
return supportedNetworksOptions.map(toLowerCase);
|
|
8
|
+
if (merchantSupportedNetworks.length === 0)
|
|
9
|
+
return supportedNetworksOptions.map(toLowerCase);
|
|
10
|
+
var supportedNetworks = supportedNetworksOptions.filter(function (item) {
|
|
11
|
+
return merchantSupportedNetworks.find(function (network) { return network.toLowerCase() === item.toLowerCase(); });
|
|
16
12
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export var validateCurrency = function (currency, currencies) {
|
|
20
|
-
var isSupported = currencies.some(function (item) { return item.toLowerCase() === currency.toLowerCase(); });
|
|
21
|
-
if (!isSupported) {
|
|
22
|
-
throw new Error("The currency \"".concat(currency, "\" is not supported, you have to use one of these currencies: ").concat(currencies));
|
|
13
|
+
if (supportedNetworks.length === 0) {
|
|
14
|
+
throw new Error("It seems that there is no supported networks available in based on your acceptance object");
|
|
23
15
|
}
|
|
24
|
-
return
|
|
16
|
+
return supportedNetworks.map(toLowerCase);
|
|
25
17
|
};
|
|
26
18
|
export var getApplePayRequest = function (_a) {
|
|
27
19
|
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
28
|
-
var
|
|
20
|
+
var order = _a.order, customer = _a.customer, supportedNetworks = _a.supportedNetworks, merchantCapabilities = _a.merchantCapabilities, countryCode = _a.countryCode, name = _a.name;
|
|
29
21
|
return {
|
|
30
22
|
countryCode: countryCode,
|
|
31
|
-
currencyCode:
|
|
23
|
+
currencyCode: order.currency,
|
|
32
24
|
merchantCapabilities: merchantCapabilities,
|
|
33
25
|
supportedNetworks: supportedNetworks,
|
|
34
26
|
billingContact: customer && {
|
|
@@ -38,7 +30,7 @@ export var getApplePayRequest = function (_a) {
|
|
|
38
30
|
familyName: ((_j = customer.name) === null || _j === void 0 ? void 0 : _j.length) ? (_k = customer.name[0]) === null || _k === void 0 ? void 0 : _k.last : ''
|
|
39
31
|
},
|
|
40
32
|
total: {
|
|
41
|
-
amount: Number(
|
|
33
|
+
amount: Number(order.amount.toFixed(2)),
|
|
42
34
|
label: name
|
|
43
35
|
}
|
|
44
36
|
};
|
|
@@ -1,30 +1,69 @@
|
|
|
1
|
-
import { ApplePayButtonProps } from '../@types';
|
|
1
|
+
import { ApplePayRequestData, ApplePayButtonProps } from '../@types';
|
|
2
2
|
export declare const getDefaultValues: (mainObject: ApplePayButtonProps) => {
|
|
3
3
|
interface: {
|
|
4
|
-
locale?: "en" | "ar" | "
|
|
5
|
-
theme?: "dark" | "light" | undefined;
|
|
4
|
+
locale?: "en" | "ar" | "dynamic" | undefined;
|
|
5
|
+
theme?: "dynamic" | "dark" | "light" | undefined;
|
|
6
6
|
edges?: "straight" | "curved" | undefined;
|
|
7
7
|
type?: "book" | "buy" | "check-out" | "pay" | "plain" | "subscribe" | undefined;
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
operator: {
|
|
10
|
+
publicKey: string;
|
|
11
|
+
hashstring?: string | undefined;
|
|
12
|
+
};
|
|
12
13
|
merchant: {
|
|
13
14
|
id: string;
|
|
14
|
-
domain: string;
|
|
15
15
|
};
|
|
16
|
+
scope: "charge" | "authorize" | "taptoken" | "applepaytoken";
|
|
17
|
+
environment: "production" | "sandbox" | "beta" | "development" | "staging";
|
|
16
18
|
customer?: import("../@types").Customer | undefined;
|
|
17
|
-
acceptance
|
|
18
|
-
transaction
|
|
19
|
-
|
|
19
|
+
acceptance?: import("../@types").Acceptance | undefined;
|
|
20
|
+
transaction?: {
|
|
21
|
+
authentication?: boolean | undefined;
|
|
22
|
+
authorize?: {
|
|
23
|
+
auto: {
|
|
24
|
+
type: string;
|
|
25
|
+
time: number;
|
|
26
|
+
};
|
|
27
|
+
} | undefined;
|
|
28
|
+
metadata?: Record<string, string> | undefined;
|
|
29
|
+
reference?: string | undefined;
|
|
30
|
+
paymentAgreement?: {
|
|
31
|
+
id: string;
|
|
32
|
+
contract?: {
|
|
33
|
+
id: string;
|
|
34
|
+
} | undefined;
|
|
35
|
+
} | undefined;
|
|
36
|
+
destinations?: Record<string, any> | undefined;
|
|
37
|
+
} | undefined;
|
|
38
|
+
invoice?: {
|
|
39
|
+
id: string;
|
|
40
|
+
} | undefined;
|
|
41
|
+
order: {
|
|
42
|
+
amount: number;
|
|
20
43
|
currency: string;
|
|
44
|
+
id?: string | undefined;
|
|
45
|
+
description?: string | undefined;
|
|
46
|
+
metadata?: Record<string, string> | undefined;
|
|
47
|
+
reference?: string | undefined;
|
|
21
48
|
};
|
|
49
|
+
post?: {
|
|
50
|
+
url: string;
|
|
51
|
+
} | undefined;
|
|
52
|
+
redirect?: {
|
|
53
|
+
url: string;
|
|
54
|
+
} | undefined;
|
|
55
|
+
onOrderCreated?: ((orderId: string) => void) | undefined;
|
|
22
56
|
onCancel?: (() => void) | undefined;
|
|
23
57
|
onError?: ((error: any) => void) | undefined;
|
|
24
|
-
onSuccess?: ((data: Record<string, any>) =>
|
|
25
|
-
onClick?: (() => void) | undefined;
|
|
58
|
+
onSuccess?: ((data: Record<string, any>) => void) | undefined;
|
|
59
|
+
onClick?: ((data?: ApplePayRequestData | undefined) => void) | undefined;
|
|
26
60
|
onReady?: (() => void) | undefined;
|
|
27
61
|
metaData?: import("../@types").MetaData | undefined;
|
|
28
62
|
debug?: boolean | undefined;
|
|
63
|
+
integration?: "merchant" | "tap" | undefined;
|
|
64
|
+
headers?: {
|
|
65
|
+
mdn: string;
|
|
66
|
+
application: string;
|
|
67
|
+
} | undefined;
|
|
29
68
|
};
|
|
30
|
-
export declare const
|
|
69
|
+
export declare const getMerchantCapabilities: (supportedCards?: Array<string>) => ("supports3DS" | "supportsCredit" | "supportsDebit")[];
|
|
@@ -30,19 +30,20 @@ export var getDefaultValues = function (mainObject) {
|
|
|
30
30
|
};
|
|
31
31
|
return __assign(__assign({}, mainObject), { interface: __assign(__assign({}, defaultInterface), mainObject.interface) });
|
|
32
32
|
};
|
|
33
|
-
export var
|
|
34
|
-
var
|
|
33
|
+
export var getMerchantCapabilities = function (supportedCards) {
|
|
34
|
+
var merchantCapabilities = [MerchantCapabilities.Supports3DS];
|
|
35
35
|
if (!supportedCards) {
|
|
36
|
-
|
|
36
|
+
merchantCapabilities = __spreadArray(__spreadArray([], merchantCapabilities, true), [
|
|
37
37
|
MerchantCapabilities.SupportsCredit,
|
|
38
38
|
MerchantCapabilities.SupportsDebit
|
|
39
39
|
], false);
|
|
40
|
+
return merchantCapabilities;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
if (supportedCards.includes('CREDIT')) {
|
|
43
|
+
merchantCapabilities.push(MerchantCapabilities.SupportsCredit);
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
if (supportedCards.includes('DEBIT')) {
|
|
46
|
+
merchantCapabilities.push(MerchantCapabilities.SupportsDebit);
|
|
46
47
|
}
|
|
47
|
-
return
|
|
48
|
+
return merchantCapabilities;
|
|
48
49
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare enum ApplePayGetFromMerchantEvents {
|
|
2
|
-
APPLE_PAY_CLICKED = "APPLE_PAY_CLICKED"
|
|
3
|
-
}
|
|
4
|
-
export declare enum ApplePayPostFromMerchantEvents {
|
|
5
|
-
APPLE_PAY_BUTTON_READY = "APPLE_PAY_BUTTON_READY",
|
|
6
|
-
APPLE_PAY_BUTTON_SUCCESS = "APPLE_PAY_BUTTON_SUCCESS",
|
|
7
|
-
APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS = "APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS",
|
|
8
|
-
APPLE_PAY_BUTTON_ERROR = "APPLE_PAY_BUTTON_ERROR",
|
|
9
|
-
APPLE_PAY_BUTTON_CANCELLED = "APPLE_PAY_BUTTON_CANCELLED"
|
|
10
|
-
}
|
|
11
|
-
export declare const useApplePayFromMerchantSide: (frameId: string) => void;
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (_) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
import { useCallback, useEffect } from 'react';
|
|
49
|
-
import appService from '../api/app.service';
|
|
50
|
-
import { setAxiosGlobalHeaders } from '../api/httpClient';
|
|
51
|
-
export var ApplePayGetFromMerchantEvents;
|
|
52
|
-
(function (ApplePayGetFromMerchantEvents) {
|
|
53
|
-
ApplePayGetFromMerchantEvents["APPLE_PAY_CLICKED"] = "APPLE_PAY_CLICKED";
|
|
54
|
-
})(ApplePayGetFromMerchantEvents || (ApplePayGetFromMerchantEvents = {}));
|
|
55
|
-
export var ApplePayPostFromMerchantEvents;
|
|
56
|
-
(function (ApplePayPostFromMerchantEvents) {
|
|
57
|
-
ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_READY"] = "APPLE_PAY_BUTTON_READY";
|
|
58
|
-
ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_SUCCESS"] = "APPLE_PAY_BUTTON_SUCCESS";
|
|
59
|
-
ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS"] = "APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS";
|
|
60
|
-
ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_ERROR"] = "APPLE_PAY_BUTTON_ERROR";
|
|
61
|
-
ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_CANCELLED"] = "APPLE_PAY_BUTTON_CANCELLED";
|
|
62
|
-
})(ApplePayPostFromMerchantEvents || (ApplePayPostFromMerchantEvents = {}));
|
|
63
|
-
var usePostEventsToIframe = function (frameId) {
|
|
64
|
-
var send = function (event, data) {
|
|
65
|
-
var _a;
|
|
66
|
-
var frame = document.getElementById(frameId);
|
|
67
|
-
if (!frame)
|
|
68
|
-
return;
|
|
69
|
-
(_a = frame.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage({ event: event, data: data }, frame.src);
|
|
70
|
-
};
|
|
71
|
-
return {
|
|
72
|
-
send: send
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
export var useApplePayFromMerchantSide = function (frameId) {
|
|
76
|
-
var send = usePostEventsToIframe(frameId).send;
|
|
77
|
-
var onApplePayButtonClicked = function (applePaymentOptionsMetaData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
78
|
-
var ApplePaySession, _a, merchant, supportedNetworks, transaction, billingContact, merchantCapabilities, debug, applePaySDKVersion, headers, merchantRegisteredDomain, environment, request, session;
|
|
79
|
-
return __generator(this, function (_b) {
|
|
80
|
-
send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_READY, {});
|
|
81
|
-
ApplePaySession = window.ApplePaySession;
|
|
82
|
-
if (!ApplePaySession) {
|
|
83
|
-
console.error('ApplePaySession is not available, please check if you are using Safari browser');
|
|
84
|
-
return [2];
|
|
85
|
-
}
|
|
86
|
-
if (!applePaymentOptionsMetaData) {
|
|
87
|
-
console.error('Make sure you have passed prerequisites options for Apple Pay');
|
|
88
|
-
return [2];
|
|
89
|
-
}
|
|
90
|
-
_a = __assign(__assign({}, applePaymentOptionsMetaData), { merchantRegisteredDomain: window.location.hostname }), merchant = _a.merchant, supportedNetworks = _a.supportedNetworks, transaction = _a.transaction, billingContact = _a.billingContact, merchantCapabilities = _a.merchantCapabilities, debug = _a.debug, applePaySDKVersion = _a.applePaySDKVersion, headers = _a.headers, merchantRegisteredDomain = _a.merchantRegisteredDomain, environment = _a.environment;
|
|
91
|
-
if (debug)
|
|
92
|
-
console.log('apple payment options metadata', applePaymentOptionsMetaData);
|
|
93
|
-
appService.setEnv(environment);
|
|
94
|
-
appService.setBaseUrl();
|
|
95
|
-
request = {
|
|
96
|
-
countryCode: merchant.country_code,
|
|
97
|
-
currencyCode: transaction.currency,
|
|
98
|
-
merchantCapabilities: merchantCapabilities,
|
|
99
|
-
supportedNetworks: supportedNetworks,
|
|
100
|
-
billingContact: billingContact && {
|
|
101
|
-
phoneNumber: billingContact.phoneNumber,
|
|
102
|
-
emailAddress: billingContact.emailAddress,
|
|
103
|
-
givenName: billingContact.givenName,
|
|
104
|
-
familyName: billingContact.familyName
|
|
105
|
-
},
|
|
106
|
-
total: {
|
|
107
|
-
amount: Number(transaction.amount),
|
|
108
|
-
label: merchant.name
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
if (debug) {
|
|
112
|
-
console.info("Creating ApplePaySession with version: ".concat(applePaySDKVersion, " and request: ").concat(JSON.stringify(request)));
|
|
113
|
-
}
|
|
114
|
-
session = new ApplePaySession(applePaySDKVersion, request);
|
|
115
|
-
session.onvalidatemerchant = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
116
|
-
var data, error_1;
|
|
117
|
-
var _a;
|
|
118
|
-
return __generator(this, function (_b) {
|
|
119
|
-
switch (_b.label) {
|
|
120
|
-
case 0:
|
|
121
|
-
if (debug) {
|
|
122
|
-
console.info('Creating merchant session and validating merchant session');
|
|
123
|
-
console.info('onvalidatemerchant event', event);
|
|
124
|
-
}
|
|
125
|
-
_b.label = 1;
|
|
126
|
-
case 1:
|
|
127
|
-
_b.trys.push([1, 3, , 4]);
|
|
128
|
-
setAxiosGlobalHeaders(headers);
|
|
129
|
-
return [4, appService.appleSession(__assign({}, merchant), event.validationURL, merchantRegisteredDomain)];
|
|
130
|
-
case 2:
|
|
131
|
-
data = _b.sent();
|
|
132
|
-
if (debug)
|
|
133
|
-
console.info('merchant session created', data);
|
|
134
|
-
session.completeMerchantValidation(data);
|
|
135
|
-
send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS, data);
|
|
136
|
-
return [3, 4];
|
|
137
|
-
case 3:
|
|
138
|
-
error_1 = _b.sent();
|
|
139
|
-
if (debug)
|
|
140
|
-
console.error('error in onvalidatemerchant', error_1);
|
|
141
|
-
session.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
142
|
-
send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_ERROR, ((_a = error_1.response) === null || _a === void 0 ? void 0 : _a.data) || error_1.message);
|
|
143
|
-
return [3, 4];
|
|
144
|
-
case 4: return [2];
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}); };
|
|
148
|
-
session.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
149
|
-
return __generator(this, function (_a) {
|
|
150
|
-
if (debug)
|
|
151
|
-
console.info('onpaymentauthorized event', event);
|
|
152
|
-
send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_SUCCESS, event.payment.token.paymentData);
|
|
153
|
-
session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
154
|
-
return [2];
|
|
155
|
-
});
|
|
156
|
-
}); };
|
|
157
|
-
session.oncancel = function (event) {
|
|
158
|
-
console.info('oncancel event', event);
|
|
159
|
-
send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_CANCELLED, event);
|
|
160
|
-
};
|
|
161
|
-
session.begin();
|
|
162
|
-
return [2];
|
|
163
|
-
});
|
|
164
|
-
}); };
|
|
165
|
-
var onMessage = useCallback(function (message) {
|
|
166
|
-
var _a = message.data, event = _a.event, data = _a.data;
|
|
167
|
-
if (event === ApplePayGetFromMerchantEvents.APPLE_PAY_CLICKED) {
|
|
168
|
-
onApplePayButtonClicked(data);
|
|
169
|
-
}
|
|
170
|
-
}, []);
|
|
171
|
-
useEffect(function () {
|
|
172
|
-
window.addEventListener('message', onMessage);
|
|
173
|
-
return function () {
|
|
174
|
-
window.removeEventListener('message', onMessage);
|
|
175
|
-
};
|
|
176
|
-
}, []);
|
|
177
|
-
};
|