@tap-payments/apple-pay-button 1.0.10 → 1.0.12

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