@tap-payments/apple-pay-button 0.0.27-test → 0.0.28-test
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/README.md +133 -106
- package/build/@types/index.d.ts +40 -29
- package/build/api/httpClient.d.ts +1 -1
- package/build/api/httpClient.js +1 -1
- package/build/constants/index.d.ts +9 -1
- package/build/constants/index.js +9 -1
- package/build/features/ApplePayButton/ApplePayButton.js +13 -38
- package/build/hooks/useApplePay.d.ts +1 -1
- package/build/hooks/useApplePay.js +26 -22
- package/build/index.d.ts +2 -2
- package/build/index.js +6 -4
- package/build/utils/config.d.ts +4 -3
- package/build/utils/config.js +7 -6
- package/build/utils/defaultValues.d.ts +29 -0
- package/build/utils/defaultValues.js +23 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,12 +26,13 @@ yarn add @tap-payments/apple-pay-button
|
|
|
26
26
|
import React from 'react'
|
|
27
27
|
import {
|
|
28
28
|
ApplePayButton,
|
|
29
|
-
|
|
29
|
+
ThemeMode,
|
|
30
30
|
SupportedNetworks,
|
|
31
31
|
Scope,
|
|
32
32
|
Environment,
|
|
33
|
+
Locale,
|
|
33
34
|
ButtonType,
|
|
34
|
-
|
|
35
|
+
Edges
|
|
35
36
|
} from '@tap-payments/apple-pay-button'
|
|
36
37
|
|
|
37
38
|
const App = () => {
|
|
@@ -39,17 +40,15 @@ const App = () => {
|
|
|
39
40
|
<ApplePayButton
|
|
40
41
|
// required (The public Key provided by Tap)
|
|
41
42
|
publicKey={'pk_test_xxxxxxxxxxxxxxxzh'}
|
|
42
|
-
// optional (The environment of the SDK and it can be one of these
|
|
43
|
+
// optional (The environment of the SDK and it can be one of these environments)
|
|
43
44
|
environment={Environment.Development}
|
|
44
45
|
// optional (to enable the debug mode)
|
|
45
46
|
debug
|
|
46
|
-
// required (The merchant identifier provided by Tap)
|
|
47
|
-
merchantIdentifier='merchant.tap.applepay.test'
|
|
48
47
|
// required
|
|
49
48
|
merchant={{
|
|
50
49
|
// required (The merchant domain name)
|
|
51
50
|
domain: 'example.com',
|
|
52
|
-
//
|
|
51
|
+
// required (The merchant identifier provided by Tap)
|
|
53
52
|
id: '1xxxxx8'
|
|
54
53
|
}}
|
|
55
54
|
// required
|
|
@@ -62,39 +61,54 @@ const App = () => {
|
|
|
62
61
|
// optional (The scope of the SDK and it can be one of these scopes:
|
|
63
62
|
// [TapToken,AppleToken], by default it is TapToken)
|
|
64
63
|
scope={Scope.TapToken}
|
|
65
|
-
// optional
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// optional (The locale of the Apple Pay button and it can be one of these locales)
|
|
73
|
-
locale={Locale.EN}
|
|
74
|
-
// optional (The type of the Apple Pay button and it can be one of these types)
|
|
75
|
-
type={ButtonType.PLAIN}
|
|
64
|
+
// optional
|
|
65
|
+
acceptance={{
|
|
66
|
+
// optional (The supported networks for the Apple Pay button and it
|
|
67
|
+
// can be one of these networks: [Mada,Visa,MasterCard], by default
|
|
68
|
+
// we bring all the supported networks from tap merchant configuration)
|
|
69
|
+
supportedBrands: [SupportedNetworks.Mada, SupportedNetworks.Visa, SupportedNetworks.MasterCard]
|
|
70
|
+
}}
|
|
76
71
|
// optional (The billing contact information)
|
|
77
|
-
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
72
|
+
customer={{
|
|
73
|
+
//"OPTIONAL : Customer ID",
|
|
74
|
+
id: 'cus_xxx',
|
|
75
|
+
name: [
|
|
76
|
+
{
|
|
77
|
+
//"REQUIRED : en or ar",
|
|
78
|
+
lang: Locale.EN,
|
|
79
|
+
// "OPTIONAL : First name of the customer.",
|
|
80
|
+
first: 'test',
|
|
81
|
+
//"OPTIONAL : Last name of the customer.",
|
|
82
|
+
last: 'tester',
|
|
83
|
+
// "OPTIONAL : Middle name of the customer.",
|
|
84
|
+
middle: 'test'
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
// Defines the contact details for the customer & to be used in creating the billing contact info in Apple pay request
|
|
88
|
+
contact: {
|
|
89
|
+
//"OPTIONAL : The customer's email",
|
|
90
|
+
email: 'test@gmail.com',
|
|
91
|
+
//"OPTIONAL : The customer's phone number"
|
|
92
|
+
phone: {
|
|
93
|
+
//"OPTIONAL : The customer's country code",
|
|
94
|
+
countryCode: '+20',
|
|
95
|
+
//"OPTIONAL : The customer's phone number
|
|
96
|
+
number: '10XXXXXX56'
|
|
97
|
+
}
|
|
96
98
|
}
|
|
97
99
|
}}
|
|
100
|
+
//optional (for styling button)
|
|
101
|
+
interface={{
|
|
102
|
+
// optional (The locale of the Apple Pay button and it can be one of these locales:[EN,AR])
|
|
103
|
+
locale: Locale.EN,
|
|
104
|
+
// optional (The theme of the Apple Pay button and it can be one of
|
|
105
|
+
// these values : [light,Dark], by default it is detected from user device )
|
|
106
|
+
theme: ThemeMode.DARK,
|
|
107
|
+
// optional (The type of the Apple Pay )
|
|
108
|
+
type: ButtonType.BUY,
|
|
109
|
+
// optional (The border of the Apple Pay button and it can be one of these values:[curved,straight])
|
|
110
|
+
edges: Edges.CURVED
|
|
111
|
+
}}
|
|
98
112
|
// optional (A callback function that will be called when you cancel
|
|
99
113
|
// the payment process)
|
|
100
114
|
onCancel={() => console.log('cancelled')}
|
|
@@ -106,6 +120,14 @@ const App = () => {
|
|
|
106
120
|
// do your stuff here...
|
|
107
121
|
console.log(token)
|
|
108
122
|
}}
|
|
123
|
+
// optional (A callback function that will be called when you button is clickable)
|
|
124
|
+
onReady={() => {
|
|
125
|
+
console.log('Ready')
|
|
126
|
+
}}
|
|
127
|
+
// optional (A callback function that will be called when the button clicked)
|
|
128
|
+
onClick={() => {
|
|
129
|
+
console.log('Clicked')
|
|
130
|
+
}}
|
|
109
131
|
/>
|
|
110
132
|
)
|
|
111
133
|
}
|
|
@@ -124,62 +146,63 @@ const App = () => {
|
|
|
124
146
|
<link rel="stylesheet" href="https://apple-pay-button.b-cdn.net/build-0.0.21-test/main.css" />
|
|
125
147
|
<script src="https://apple-pay-button.b-cdn.net/build-0.0.21-test/main.js"></script>
|
|
126
148
|
</head>
|
|
149
|
+
|
|
127
150
|
<body>
|
|
128
151
|
<div id="apple-pay-button"></div>
|
|
129
152
|
<script type="text/javascript">
|
|
130
153
|
const { renderApplePayButton, ButtonStyle, Scope, SupportedNetworks, Locale, ButtonType } = window.TapSDKs
|
|
131
154
|
renderApplePayButton(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
155
|
+
{
|
|
156
|
+
publicKey: 'pk_test_7xxxxxxxxx',
|
|
157
|
+
environment: Environment.Sandbox,
|
|
158
|
+
scope: Scope.TapToken,
|
|
159
|
+
merchant: {
|
|
160
|
+
domain: 'tp-txxxxxxxx',
|
|
161
|
+
id: 'merchant_xxxxxxxxxx"
|
|
162
|
+
},
|
|
163
|
+
transaction: {
|
|
164
|
+
currency: 'SAR',
|
|
165
|
+
amount: '3'
|
|
166
|
+
},
|
|
167
|
+
acceptance: {
|
|
168
|
+
supportedBrands: [SupportedNetworks.Mada, SupportedNetworks.Visa, SupportedNetworks.MasterCard]
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
customer: {
|
|
172
|
+
name: [{
|
|
173
|
+
locale: 'en'
|
|
174
|
+
first: 'test',
|
|
175
|
+
last: 'tester',
|
|
176
|
+
middle: 'test'
|
|
177
|
+
}],
|
|
178
|
+
contact: {
|
|
179
|
+
email: 'test@gmail.com',
|
|
180
|
+
phone:{
|
|
181
|
+
number: '10XXXXXX56',
|
|
182
|
+
countryCode: '+20',
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
interface: {
|
|
187
|
+
locale: Locale.EN,
|
|
188
|
+
theme: ThemeMode.DARK,
|
|
189
|
+
type: ButtonType.BUY,
|
|
190
|
+
edges: Edges.CURVED
|
|
191
|
+
},
|
|
192
|
+
onCancel: async () => {
|
|
193
|
+
console.log('onCancel')
|
|
194
|
+
},
|
|
195
|
+
onError: async (error) => {
|
|
196
|
+
console.log('onError', error)
|
|
197
|
+
},
|
|
198
|
+
onSuccess: async (data) => {
|
|
199
|
+
console.log('onSuccess', data)
|
|
200
|
+
},
|
|
201
|
+
onReady: async () => {
|
|
202
|
+
console.log('onReady')
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
'apple-pay-button'
|
|
183
206
|
)
|
|
184
207
|
</script>
|
|
185
208
|
</body>
|
|
@@ -188,22 +211,26 @@ const App = () => {
|
|
|
188
211
|
|
|
189
212
|
## Configurations
|
|
190
213
|
|
|
191
|
-
| Name
|
|
192
|
-
|
|
|
193
|
-
| publicKey
|
|
194
|
-
| environment
|
|
195
|
-
| debug
|
|
196
|
-
|
|
|
197
|
-
| merchant.
|
|
198
|
-
|
|
|
199
|
-
| transaction.
|
|
200
|
-
|
|
|
201
|
-
|
|
|
202
|
-
|
|
|
203
|
-
|
|
|
204
|
-
|
|
|
205
|
-
|
|
|
206
|
-
|
|
|
207
|
-
|
|
|
208
|
-
|
|
|
209
|
-
|
|
|
214
|
+
| Name | Type | R/O | Description |
|
|
215
|
+
| -------------------------------------------- | ------------ | ---------- | -------------------------------------------------------------------------------- |
|
|
216
|
+
| publicKey | `string` | `required` | The public Key provided by Tap |
|
|
217
|
+
| environment | `enum` | `optional` | The environment of the SDK and it can be one of these environments `Environment` |
|
|
218
|
+
| debug | `boolean` | `optional` | To enable the debug mode |
|
|
219
|
+
| merchant.id | `string` | `required` | The merchant identifier provided by Tap |
|
|
220
|
+
| merchant.domain | `string` | `required` | The merchant domain name |
|
|
221
|
+
| transaction.amount | `string` | `required` | The amount to be charged |
|
|
222
|
+
| transaction.currency | `string` | `required` | The currency of the amount |
|
|
223
|
+
| scope | `enum` | `optional` | The scope of the SDK |
|
|
224
|
+
| acceptance.supportedBrands | `array` | `optional` | The supported networks for the Apple Pay button |
|
|
225
|
+
| acceptance.supportedCards | `array` | `optional` | The supported cards for the Apple Pay button |
|
|
226
|
+
| acceptance.supportedCardsWithAuthentications | `array` | `optional` | The supported cards with authentications for the Apple Pay button |
|
|
227
|
+
| interface.theme | `enum` | `optional` | The theme of the Apple Pay button |
|
|
228
|
+
| interface.locale | `Locale` | `optional` | The locale of the Apple Pay button |
|
|
229
|
+
| interface.type | `ButtonType` | `optional` | The type of the Apple Pay button |
|
|
230
|
+
| interface.edges | `ButtonType` | `optional` | The border of the Apple Pay button |
|
|
231
|
+
| customer | `object` | `optional` | The Customer details information |
|
|
232
|
+
| onCancel | `function` | `optional` | A callback function that will be called when you cancel the process |
|
|
233
|
+
| onError | `function` | `optional` | A callback function that will be called when you have an error |
|
|
234
|
+
| onSuccess | `function` | `optional` | A async function that will be called after creating the token successfully |
|
|
235
|
+
| onClick | `function` | `optional` | A callback function that will be called when the button clicked |
|
|
236
|
+
| onReady | `function` | `optional` | A callback function that will be called when you button is clickable |
|
package/build/@types/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Scope,
|
|
1
|
+
import { Scope, MerchantCapabilities, SupportedNetworks, ButtonType, Locale, Environment, ThemeMode, Edges } from '../constants';
|
|
2
2
|
export interface ApplePayRequestData {
|
|
3
3
|
countryCode: string;
|
|
4
4
|
currencyCode: string;
|
|
5
5
|
merchantCapabilities: Array<typeof MerchantCapabilities[keyof typeof MerchantCapabilities]>;
|
|
6
6
|
supportedNetworks: Array<typeof SupportedNetworks[keyof typeof SupportedNetworks]>;
|
|
7
7
|
billingContact?: {
|
|
8
|
-
phoneNumber
|
|
9
|
-
emailAddress
|
|
8
|
+
phoneNumber?: string;
|
|
9
|
+
emailAddress?: string;
|
|
10
10
|
givenName: string;
|
|
11
11
|
familyName: string;
|
|
12
12
|
};
|
|
@@ -15,31 +15,44 @@ export interface ApplePayRequestData {
|
|
|
15
15
|
amount: number;
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
export interface Interface {
|
|
19
|
+
locale?: typeof Locale[keyof typeof Locale];
|
|
20
|
+
theme?: typeof ThemeMode[keyof typeof ThemeMode];
|
|
21
|
+
edges?: typeof Edges[keyof typeof Edges];
|
|
22
|
+
type?: typeof ButtonType[keyof typeof ButtonType];
|
|
23
|
+
}
|
|
24
|
+
export interface Customer {
|
|
25
|
+
id?: string;
|
|
26
|
+
name?: {
|
|
27
|
+
lang: typeof Locale[keyof typeof Locale];
|
|
28
|
+
first: string;
|
|
29
|
+
last: string;
|
|
30
|
+
middle?: string;
|
|
31
|
+
}[];
|
|
32
|
+
contact?: {
|
|
33
|
+
email?: string;
|
|
34
|
+
phone?: {
|
|
35
|
+
countryCode: string;
|
|
36
|
+
number: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface Acceptance {
|
|
41
|
+
supportedBrands?: Array<typeof SupportedNetworks[keyof typeof SupportedNetworks]>;
|
|
42
|
+
supportedCards?: Array<string>;
|
|
43
|
+
supportedCardsWithAuthentications?: Array<string>;
|
|
44
|
+
}
|
|
18
45
|
export interface ApplePayButtonProps {
|
|
46
|
+
scope?: typeof Scope[keyof typeof Scope];
|
|
19
47
|
publicKey: string;
|
|
20
48
|
environment: typeof Environment[keyof typeof Environment];
|
|
21
|
-
merchantIdentifier: string;
|
|
22
49
|
merchant: {
|
|
23
|
-
id
|
|
50
|
+
id: string;
|
|
24
51
|
domain: string;
|
|
25
52
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
billingContact?: {
|
|
30
|
-
name: {
|
|
31
|
-
first: string;
|
|
32
|
-
middle?: string;
|
|
33
|
-
last: string;
|
|
34
|
-
};
|
|
35
|
-
email: {
|
|
36
|
-
address: string;
|
|
37
|
-
};
|
|
38
|
-
phone: {
|
|
39
|
-
code: string;
|
|
40
|
-
number: string;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
53
|
+
interface?: Interface;
|
|
54
|
+
customer?: Customer;
|
|
55
|
+
acceptance: Acceptance;
|
|
43
56
|
transaction: {
|
|
44
57
|
amount: string;
|
|
45
58
|
currency: string;
|
|
@@ -50,8 +63,6 @@ export interface ApplePayButtonProps {
|
|
|
50
63
|
onClick?: () => void;
|
|
51
64
|
onReady?: () => void;
|
|
52
65
|
metaData?: MetaData;
|
|
53
|
-
type?: typeof ButtonType[keyof typeof ButtonType];
|
|
54
|
-
locale?: typeof Locale[keyof typeof Locale];
|
|
55
66
|
debug?: boolean;
|
|
56
67
|
}
|
|
57
68
|
export interface MerchantResponse {
|
|
@@ -88,11 +99,11 @@ export interface CheckoutProfileRequest {
|
|
|
88
99
|
amount: number;
|
|
89
100
|
currency: string;
|
|
90
101
|
customer?: {
|
|
91
|
-
id
|
|
92
|
-
email
|
|
93
|
-
first_name
|
|
94
|
-
last_name
|
|
95
|
-
phone
|
|
102
|
+
id?: string;
|
|
103
|
+
email?: string;
|
|
104
|
+
first_name?: string;
|
|
105
|
+
last_name?: string;
|
|
106
|
+
phone?: {
|
|
96
107
|
country_code: string;
|
|
97
108
|
number: string;
|
|
98
109
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const MW_BASE_LIVE_URL = "https://mw-sdk.tap.company/v2/checkout";
|
|
2
|
-
export declare const MW_BASE_STAGING_URL = "https://mw-sdk.
|
|
2
|
+
export declare const MW_BASE_STAGING_URL = "https://mw-sdk.staging.tap.company/v2/checkout";
|
|
3
3
|
export declare const MW_BASE_DEV_URL = "https://mw-sdk.dev.tap.company/v2/checkout";
|
|
4
4
|
export declare const MW_BASE_BETA_URL = "https://mw-sdk.beta.tap.company/v2/checkout";
|
|
5
5
|
export declare const MW_BASE_SANDBOX_URL = "https://mw-sdk.sandbox.tap.company/v2/checkout";
|
package/build/api/httpClient.js
CHANGED
|
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
};
|
|
12
12
|
import axios from 'axios';
|
|
13
13
|
export var MW_BASE_LIVE_URL = 'https://mw-sdk.tap.company/v2/checkout';
|
|
14
|
-
export var MW_BASE_STAGING_URL = 'https://mw-sdk.
|
|
14
|
+
export var MW_BASE_STAGING_URL = 'https://mw-sdk.staging.tap.company/v2/checkout';
|
|
15
15
|
export var MW_BASE_DEV_URL = 'https://mw-sdk.dev.tap.company/v2/checkout';
|
|
16
16
|
export var MW_BASE_BETA_URL = 'https://mw-sdk.beta.tap.company/v2/checkout';
|
|
17
17
|
export var MW_BASE_SANDBOX_URL = 'https://mw-sdk.sandbox.tap.company/v2/checkout';
|
|
@@ -20,6 +20,14 @@ export declare const ButtonType: {
|
|
|
20
20
|
readonly PLAIN: "plain";
|
|
21
21
|
readonly SUBSCRIBE: "subscribe";
|
|
22
22
|
};
|
|
23
|
+
export declare const ThemeMode: {
|
|
24
|
+
readonly DARK: "dark";
|
|
25
|
+
readonly LIGHT: "light";
|
|
26
|
+
};
|
|
27
|
+
export declare const Edges: {
|
|
28
|
+
readonly STRAIGHT: "straight";
|
|
29
|
+
readonly CURVED: "curved";
|
|
30
|
+
};
|
|
23
31
|
export declare const MerchantCapabilities: {
|
|
24
32
|
readonly Supports3DS: "supports3DS";
|
|
25
33
|
readonly SupportsCredit: "supportsCredit";
|
|
@@ -36,7 +44,7 @@ export declare const SupportedNetworks: {
|
|
|
36
44
|
readonly Jcb: "jcb";
|
|
37
45
|
readonly Maestro: "maestro";
|
|
38
46
|
};
|
|
39
|
-
export declare const ApplePayVersion =
|
|
47
|
+
export declare const ApplePayVersion = 5;
|
|
40
48
|
export declare const Environment: {
|
|
41
49
|
readonly Production: "production";
|
|
42
50
|
readonly Sandbox: "sandbox";
|
package/build/constants/index.js
CHANGED
|
@@ -20,6 +20,14 @@ export var ButtonType = {
|
|
|
20
20
|
PLAIN: 'plain',
|
|
21
21
|
SUBSCRIBE: 'subscribe'
|
|
22
22
|
};
|
|
23
|
+
export var ThemeMode = {
|
|
24
|
+
DARK: 'dark',
|
|
25
|
+
LIGHT: 'light'
|
|
26
|
+
};
|
|
27
|
+
export var Edges = {
|
|
28
|
+
STRAIGHT: 'straight',
|
|
29
|
+
CURVED: 'curved'
|
|
30
|
+
};
|
|
23
31
|
export var MerchantCapabilities = {
|
|
24
32
|
Supports3DS: 'supports3DS',
|
|
25
33
|
SupportsCredit: 'supportsCredit',
|
|
@@ -36,7 +44,7 @@ export var SupportedNetworks = {
|
|
|
36
44
|
Jcb: 'jcb',
|
|
37
45
|
Maestro: 'maestro'
|
|
38
46
|
};
|
|
39
|
-
export var ApplePayVersion =
|
|
47
|
+
export var ApplePayVersion = 5;
|
|
40
48
|
export var Environment = {
|
|
41
49
|
Production: 'production',
|
|
42
50
|
Sandbox: 'sandbox',
|
|
@@ -14,51 +14,26 @@ 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 { ButtonStyle, ButtonType, Locale, Scope } from '../../constants';
|
|
18
17
|
import './ApplePayButton.css';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
transaction: transaction,
|
|
25
|
-
billingContact: billingContact,
|
|
26
|
-
supportedNetworks: supportedNetworks,
|
|
27
|
-
onError: onError,
|
|
28
|
-
onSuccess: onSuccess,
|
|
29
|
-
onCancel: onCancel,
|
|
30
|
-
scope: scope,
|
|
31
|
-
metaData: metaData,
|
|
32
|
-
debug: debug,
|
|
33
|
-
merchantIdentifier: merchantIdentifier,
|
|
34
|
-
environment: environment,
|
|
35
|
-
locale: locale,
|
|
36
|
-
onReady: onReady
|
|
37
|
-
}), loading = _f.loading, onApplePayButtonClicked = _f.onApplePayButtonClicked, disabled = _f.disabled;
|
|
18
|
+
import { getDefaultValues } from '../../utils/defaultValues';
|
|
19
|
+
import { ButtonStyle, Edges, ThemeMode } from '../../constants';
|
|
20
|
+
var ApplePay = React.memo(function (props) {
|
|
21
|
+
var mappedProps = getDefaultValues(props);
|
|
22
|
+
var _a = useApplePay(mappedProps), loading = _a.loading, onApplePayButtonClicked = _a.onApplePayButtonClicked, disabled = _a.disabled;
|
|
38
23
|
React.useEffect(function () {
|
|
39
|
-
if (debug) {
|
|
40
|
-
console.log('ApplePayButtonProps',
|
|
41
|
-
publicKey: publicKey,
|
|
42
|
-
merchant: merchant,
|
|
43
|
-
transaction: transaction,
|
|
44
|
-
billingContact: billingContact,
|
|
45
|
-
supportedNetworks: supportedNetworks,
|
|
46
|
-
metaData: metaData,
|
|
47
|
-
scope: scope,
|
|
48
|
-
buttonStyle: buttonStyle,
|
|
49
|
-
type: type,
|
|
50
|
-
locale: locale,
|
|
51
|
-
debug: debug
|
|
52
|
-
});
|
|
24
|
+
if (props.debug) {
|
|
25
|
+
console.log('ApplePayButtonProps', props);
|
|
53
26
|
}
|
|
54
27
|
}, []);
|
|
55
28
|
return (_jsx("button", { className: 'button-applepay-tap', style: {
|
|
56
|
-
ApplePayButtonType: type,
|
|
57
|
-
ApplePayButtonStyle:
|
|
29
|
+
ApplePayButtonType: mappedProps.interface.type,
|
|
30
|
+
ApplePayButtonStyle: mappedProps.interface.theme === ThemeMode.DARK ? ButtonStyle.Black : ButtonStyle.White,
|
|
31
|
+
borderRadius: mappedProps.interface.edges === Edges.STRAIGHT ? '0' : '10px'
|
|
58
32
|
}, onClick: function () {
|
|
33
|
+
var _a;
|
|
59
34
|
onApplePayButtonClicked();
|
|
60
|
-
onClick === null ||
|
|
61
|
-
}, lang: locale, disabled: loading || disabled }));
|
|
35
|
+
(_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
36
|
+
}, lang: mappedProps.interface.locale, disabled: loading || disabled }));
|
|
62
37
|
});
|
|
63
38
|
export function ApplePayButton(props) {
|
|
64
39
|
return _jsx(ApplePay, __assign({}, props));
|
|
@@ -5,5 +5,5 @@ interface UseApplePayReturnProps {
|
|
|
5
5
|
onApplePayButtonClicked: () => Promise<void>;
|
|
6
6
|
disabled: boolean;
|
|
7
7
|
}
|
|
8
|
-
export declare const useApplePay: ({ publicKey, merchant, transaction,
|
|
8
|
+
export declare const useApplePay: ({ publicKey, merchant, transaction, interface: interfaceObj, customer, onCancel, onError, onSuccess, scope, acceptance, metaData, debug, environment, onReady }: UseApplePayProps) => UseApplePayReturnProps;
|
|
9
9
|
export {};
|
|
@@ -51,48 +51,52 @@ import { ApplePayVersion } from '../constants';
|
|
|
51
51
|
import { setAxiosGlobalHeaders } from '../api/httpClient';
|
|
52
52
|
import { getApplePayPaymentMethod, getApplePayRequest, validateCurrency, validateSupportedNetworks } from '../utils/config';
|
|
53
53
|
export var useApplePay = function (_a) {
|
|
54
|
-
var publicKey = _a.publicKey, merchant = _a.merchant, transaction = _a.transaction,
|
|
54
|
+
var publicKey = _a.publicKey, merchant = _a.merchant, transaction = _a.transaction, interfaceObj = _a.interface, customer = _a.customer, onCancel = _a.onCancel, onError = _a.onError, onSuccess = _a.onSuccess, scope = _a.scope, acceptance = _a.acceptance, metaData = _a.metaData, debug = _a.debug, environment = _a.environment, onReady = _a.onReady;
|
|
55
55
|
var _b = useState(false), loading = _b[0], setLoading = _b[1];
|
|
56
56
|
var _c = useState(null), profileData = _c[0], setProfile = _c[1];
|
|
57
57
|
var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
|
|
58
58
|
var initialize = useCallback(function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
59
|
var merchantProfile, payment_options, headers, data, err_1;
|
|
60
|
-
var _a, _b;
|
|
61
|
-
return __generator(this, function (
|
|
62
|
-
switch (
|
|
60
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
61
|
+
return __generator(this, function (_h) {
|
|
62
|
+
switch (_h.label) {
|
|
63
63
|
case 0:
|
|
64
64
|
setLoading(true);
|
|
65
65
|
appService.setEnv(environment);
|
|
66
66
|
appService.setBaseUrl();
|
|
67
|
-
|
|
67
|
+
_h.label = 1;
|
|
68
68
|
case 1:
|
|
69
|
-
|
|
69
|
+
_h.trys.push([1, 4, 5, 6]);
|
|
70
70
|
if (metaData) {
|
|
71
71
|
merchantProfile = metaData.merchant, payment_options = metaData.payment_options, headers = metaData.headers;
|
|
72
72
|
setAxiosGlobalHeaders(__assign({}, headers));
|
|
73
73
|
setProfile({ merchant: merchantProfile, payment_options: payment_options });
|
|
74
74
|
return [2];
|
|
75
75
|
}
|
|
76
|
-
return [4, appService.setBrowserHeaders({
|
|
76
|
+
return [4, appService.setBrowserHeaders({
|
|
77
|
+
locale: interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale,
|
|
78
|
+
domain: merchant.domain,
|
|
79
|
+
pk: publicKey
|
|
80
|
+
})];
|
|
77
81
|
case 2:
|
|
78
|
-
|
|
82
|
+
_h.sent();
|
|
79
83
|
return [4, appService.checkoutProfile({
|
|
80
84
|
currency: transaction.currency,
|
|
81
|
-
merchant_id:
|
|
85
|
+
merchant_id: merchant.id,
|
|
82
86
|
total_amount: Number(transaction.amount),
|
|
83
|
-
order: __assign(__assign({ amount: Number(transaction.amount), currency: transaction.currency }, (
|
|
87
|
+
order: __assign(__assign({ amount: Number(transaction.amount), currency: transaction.currency }, (customer && {
|
|
84
88
|
customer: {
|
|
85
89
|
id: '',
|
|
86
|
-
email:
|
|
87
|
-
first_name:
|
|
88
|
-
last_name:
|
|
90
|
+
email: (_a = customer.contact) === null || _a === void 0 ? void 0 : _a.email,
|
|
91
|
+
first_name: ((_b = customer.name) === null || _b === void 0 ? void 0 : _b.length) ? customer.name[0].first : '',
|
|
92
|
+
last_name: ((_c = customer.name) === null || _c === void 0 ? void 0 : _c.length) ? customer.name[0].last : '',
|
|
89
93
|
phone: {
|
|
90
|
-
country_code:
|
|
91
|
-
number:
|
|
94
|
+
country_code: ((_e = (_d = customer.contact) === null || _d === void 0 ? void 0 : _d.phone) === null || _e === void 0 ? void 0 : _e.countryCode) || '',
|
|
95
|
+
number: ((_g = (_f = customer.contact) === null || _f === void 0 ? void 0 : _f.phone) === null || _g === void 0 ? void 0 : _g.number) || ''
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
})), { merchant: {
|
|
95
|
-
id:
|
|
99
|
+
id: merchant.id
|
|
96
100
|
}, items: [
|
|
97
101
|
{
|
|
98
102
|
amount: Number(transaction.amount),
|
|
@@ -104,13 +108,13 @@ export var useApplePay = function (_a) {
|
|
|
104
108
|
] })
|
|
105
109
|
})];
|
|
106
110
|
case 3:
|
|
107
|
-
data =
|
|
111
|
+
data = _h.sent();
|
|
108
112
|
if (debug)
|
|
109
113
|
console.log('merchant configuration: ', data);
|
|
110
114
|
setProfile(data);
|
|
111
115
|
return [3, 6];
|
|
112
116
|
case 4:
|
|
113
|
-
err_1 =
|
|
117
|
+
err_1 = _h.sent();
|
|
114
118
|
onError && onError(err_1.errors || err_1);
|
|
115
119
|
return [3, 6];
|
|
116
120
|
case 5:
|
|
@@ -120,7 +124,7 @@ export var useApplePay = function (_a) {
|
|
|
120
124
|
case 6: return [2];
|
|
121
125
|
}
|
|
122
126
|
});
|
|
123
|
-
}); }, [environment, locale, merchant.domain, publicKey, debug, onError]);
|
|
127
|
+
}); }, [environment, interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale, merchant.domain, publicKey, debug, onError]);
|
|
124
128
|
useEffect(function () {
|
|
125
129
|
initialize(metaData);
|
|
126
130
|
}, [initialize, metaData]);
|
|
@@ -142,11 +146,11 @@ export var useApplePay = function (_a) {
|
|
|
142
146
|
try {
|
|
143
147
|
paymentMethod = getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
|
|
144
148
|
currency = validateCurrency(transaction.currency, paymentMethod.supported_currencies);
|
|
145
|
-
cardBrands = validateSupportedNetworks(paymentMethod.supported_card_brands,
|
|
149
|
+
cardBrands = validateSupportedNetworks(paymentMethod.supported_card_brands, acceptance.supportedBrands);
|
|
146
150
|
request = getApplePayRequest({
|
|
147
151
|
countryCode: profileData.merchant.country_code,
|
|
148
152
|
transaction: __assign(__assign({}, transaction), { currency: currency }),
|
|
149
|
-
|
|
153
|
+
customer: customer,
|
|
150
154
|
supportedNetworks: cardBrands,
|
|
151
155
|
name: profileData.merchant.name
|
|
152
156
|
});
|
|
@@ -170,7 +174,7 @@ export var useApplePay = function (_a) {
|
|
|
170
174
|
if (debug) {
|
|
171
175
|
console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(merchant.domain));
|
|
172
176
|
}
|
|
173
|
-
return [4, appService.appleSession(profileData.merchant, event.validationURL, merchant.domain,
|
|
177
|
+
return [4, appService.appleSession(__assign(__assign({}, profileData.merchant), { id: merchant.id }), event.validationURL, merchant.domain, merchant.id)];
|
|
174
178
|
case 2:
|
|
175
179
|
merchantSession = _a.sent();
|
|
176
180
|
if (debug)
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ApplePayButtonProps, ApplePayButton } from './features/ApplePayButton';
|
|
2
|
-
import {
|
|
2
|
+
import { ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities } from './constants';
|
|
3
3
|
export type { ApplePayButtonProps };
|
|
4
|
-
export { ApplePayButton,
|
|
4
|
+
export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities };
|
package/build/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ApplePayButton, renderApplePayButton } from './features/ApplePayButton';
|
|
2
|
-
import {
|
|
3
|
-
export { ApplePayButton,
|
|
2
|
+
import { ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities } from './constants';
|
|
3
|
+
export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities };
|
|
4
4
|
window['TapSDKs'] = {
|
|
5
5
|
renderApplePayButton: renderApplePayButton,
|
|
6
|
-
ButtonStyle: ButtonStyle,
|
|
7
6
|
Scope: Scope,
|
|
8
7
|
SupportedNetworks: SupportedNetworks,
|
|
9
8
|
Environment: Environment,
|
|
10
9
|
Locale: Locale,
|
|
11
|
-
ButtonType: ButtonType
|
|
10
|
+
ButtonType: ButtonType,
|
|
11
|
+
ThemeMode: ThemeMode,
|
|
12
|
+
Edges: Edges,
|
|
13
|
+
MerchantCapabilities: MerchantCapabilities
|
|
12
14
|
};
|
package/build/utils/config.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ApplePayButtonProps, ApplePayRequestData, PaymentMethod } from '../@types';
|
|
1
|
+
import { Acceptance, ApplePayButtonProps, ApplePayRequestData, PaymentMethod } from '../@types';
|
|
2
2
|
import { SupportedNetworks } from '../constants';
|
|
3
|
-
export declare const validateSupportedNetworks: (supportedNetworksConfig: Array<(typeof SupportedNetworks)[keyof typeof SupportedNetworks]>, supportedNetworks:
|
|
3
|
+
export declare const validateSupportedNetworks: (supportedNetworksConfig: Array<(typeof SupportedNetworks)[keyof typeof SupportedNetworks]>, supportedNetworks: Acceptance['supportedBrands']) => ("amex" | "mada" | "masterCard" | "visa" | "chinaUnionPay" | "discover" | "electron" | "jcb" | "maestro")[];
|
|
4
4
|
export declare const validateCurrency: (currency: string, currencies: string[]) => string;
|
|
5
|
-
export declare const getApplePayRequest: ({ transaction,
|
|
5
|
+
export declare const getApplePayRequest: ({ transaction, customer, supportedNetworks, countryCode, name }: Pick<ApplePayButtonProps, "transaction" | "customer"> & {
|
|
6
|
+
supportedNetworks: Acceptance['supportedBrands'];
|
|
6
7
|
countryCode: string;
|
|
7
8
|
name: string;
|
|
8
9
|
}) => ApplePayRequestData;
|
package/build/utils/config.js
CHANGED
|
@@ -25,17 +25,18 @@ export var validateCurrency = function (currency, currencies) {
|
|
|
25
25
|
return currency;
|
|
26
26
|
};
|
|
27
27
|
export var getApplePayRequest = function (_a) {
|
|
28
|
-
var
|
|
28
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
29
|
+
var transaction = _a.transaction, customer = _a.customer, supportedNetworks = _a.supportedNetworks, countryCode = _a.countryCode, name = _a.name;
|
|
29
30
|
return {
|
|
30
31
|
countryCode: countryCode,
|
|
31
32
|
currencyCode: transaction.currency,
|
|
32
33
|
merchantCapabilities: [MerchantCapabilities.Supports3DS],
|
|
33
34
|
supportedNetworks: supportedNetworks,
|
|
34
|
-
billingContact:
|
|
35
|
-
phoneNumber:
|
|
36
|
-
emailAddress:
|
|
37
|
-
givenName:
|
|
38
|
-
familyName:
|
|
35
|
+
billingContact: customer && {
|
|
36
|
+
phoneNumber: ((_c = (_b = customer.contact) === null || _b === void 0 ? void 0 : _b.phone) === null || _c === void 0 ? void 0 : _c.countryCode) || '' + ((_e = (_d = customer.contact) === null || _d === void 0 ? void 0 : _d.phone) === null || _e === void 0 ? void 0 : _e.number),
|
|
37
|
+
emailAddress: (_f = customer.contact) === null || _f === void 0 ? void 0 : _f.email,
|
|
38
|
+
givenName: ((_g = customer.name) === null || _g === void 0 ? void 0 : _g.length) ? (_h = customer.name[0]) === null || _h === void 0 ? void 0 : _h.first : '',
|
|
39
|
+
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
40
|
},
|
|
40
41
|
total: {
|
|
41
42
|
amount: Number(transaction.amount),
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ApplePayButtonProps } from '..';
|
|
2
|
+
export declare const getDefaultValues: (mainObject: ApplePayButtonProps) => {
|
|
3
|
+
interface: {
|
|
4
|
+
locale?: "en" | "ar" | "fr" | undefined;
|
|
5
|
+
theme?: "dark" | "light" | undefined;
|
|
6
|
+
edges?: "straight" | "curved" | undefined;
|
|
7
|
+
type?: "book" | "buy" | "check-out" | "pay" | "plain" | "subscribe" | undefined;
|
|
8
|
+
};
|
|
9
|
+
scope?: "AppleToken" | "TapToken" | undefined;
|
|
10
|
+
publicKey: string;
|
|
11
|
+
environment: "production" | "sandbox" | "beta" | "development" | "staging";
|
|
12
|
+
merchant: {
|
|
13
|
+
id: string;
|
|
14
|
+
domain: string;
|
|
15
|
+
};
|
|
16
|
+
customer?: import("../@types").Customer | undefined;
|
|
17
|
+
acceptance: import("../@types").Acceptance;
|
|
18
|
+
transaction: {
|
|
19
|
+
amount: string;
|
|
20
|
+
currency: string;
|
|
21
|
+
};
|
|
22
|
+
onCancel?: (() => void) | undefined;
|
|
23
|
+
onError?: ((error: any) => void) | undefined;
|
|
24
|
+
onSuccess?: ((data: Record<string, any>) => Promise<void>) | undefined;
|
|
25
|
+
onClick?: (() => void) | undefined;
|
|
26
|
+
onReady?: (() => void) | undefined;
|
|
27
|
+
metaData?: import("../@types").MetaData | undefined;
|
|
28
|
+
debug?: boolean | undefined;
|
|
29
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
import { ThemeMode, Locale, ButtonType, Edges } from '../constants';
|
|
13
|
+
export var getDefaultValues = function (mainObject) {
|
|
14
|
+
var userThemeMode = window.matchMedia('(prefers-color-scheme: light)').matches ? ThemeMode.LIGHT : ThemeMode.DARK;
|
|
15
|
+
var userLang = navigator.language.toLowerCase().includes(Locale.AR) ? Locale.AR : Locale.EN;
|
|
16
|
+
var defaultInterface = {
|
|
17
|
+
locale: userLang,
|
|
18
|
+
theme: userThemeMode,
|
|
19
|
+
type: ButtonType.PLAIN,
|
|
20
|
+
edges: Edges.CURVED
|
|
21
|
+
};
|
|
22
|
+
return __assign(__assign({}, mainObject), { interface: __assign(__assign({}, defaultInterface), mainObject.interface) });
|
|
23
|
+
};
|