@tap-payments/apple-pay-button 0.0.16-test → 0.0.18-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.
@@ -1,4 +1,4 @@
1
- import { Scope, ButtonStyle, MerchantCapabilities, SupportedNetworks, ButtonType, Locale } from '../constants';
1
+ import { Scope, ButtonStyle, MerchantCapabilities, SupportedNetworks, ButtonType, Locale, Environment } from '../constants';
2
2
  export interface ApplePayRequestData {
3
3
  countryCode: string;
4
4
  currencyCode: string;
@@ -17,6 +17,8 @@ export interface ApplePayRequestData {
17
17
  }
18
18
  export interface ApplePayButtonProps {
19
19
  publicKey: string;
20
+ environment: typeof Environment[keyof typeof Environment];
21
+ merchantIdentifier: string;
20
22
  merchant: {
21
23
  id?: string;
22
24
  domain: string;
@@ -46,7 +48,8 @@ export interface ApplePayButtonProps {
46
48
  onError?: (error: any) => void;
47
49
  onSuccess?: (data: Record<string, any>) => Promise<void>;
48
50
  onClick?: () => void;
49
- metaData?: ProfileResponse;
51
+ onReady?: () => void;
52
+ metaData?: MetaData;
50
53
  type?: typeof ButtonType[keyof typeof ButtonType];
51
54
  locale?: typeof Locale[keyof typeof Locale];
52
55
  debug?: boolean;
@@ -72,7 +75,8 @@ export interface PaymentOptionsResponse {
72
75
  currency: string;
73
76
  payment_methods: PaymentMethod[];
74
77
  }
75
- export interface ProfileResponse {
78
+ export interface MetaData {
76
79
  merchant: MerchantResponse;
77
80
  payment_options: PaymentOptionsResponse;
81
+ headers: Record<string, string>;
78
82
  }
@@ -1,11 +1,23 @@
1
- import { MerchantResponse, ApplePayRequestData, ProfileResponse } from '../@types';
1
+ import { MerchantResponse, ApplePayButtonProps } from '../@types';
2
2
  import BaseService from './base';
3
3
  declare class APPService extends BaseService {
4
+ private baseUrl;
5
+ private env;
4
6
  constructor();
5
- init(publicKey: string, merchantId?: string): Promise<ProfileResponse>;
6
- appleSession(merchant: MerchantResponse, validationURL: string, merchantRegisteredDomain: string): Promise<any>;
7
- tapTokenization(applePaymentData: Record<string, string>, merchant: MerchantResponse): Promise<any>;
8
- createCharge(publicKey: string, merchant: MerchantResponse, request: ApplePayRequestData, cardToken: string): Promise<import("axios").AxiosResponse<any, any>>;
7
+ setEnv(env: ApplePayButtonProps['environment']): void;
8
+ setBaseUrl(): void;
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
+ setBrowserHeaders({ locale, pk, domain }: {
11
+ locale: string;
12
+ pk: string;
13
+ domain: string;
14
+ }): Promise<void>;
15
+ checkoutProfile(merchantId?: string): Promise<{
16
+ merchant: any;
17
+ payment_options: any;
18
+ }>;
19
+ appleSession(merchant: MerchantResponse, validationURL: string, merchantRegisteredDomain: string, merchantIdentifier: string): Promise<any>;
20
+ tapTokenization(applePaymentData: Record<string, string>): Promise<any>;
9
21
  }
10
22
  declare const appService: APPService;
11
23
  export default appService;
@@ -49,36 +49,146 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
49
49
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
50
  }
51
51
  };
52
+ var __rest = (this && this.__rest) || function (s, e) {
53
+ var t = {};
54
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
55
+ t[p] = s[p];
56
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
57
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
58
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
59
+ t[p[i]] = s[p[i]];
60
+ }
61
+ return t;
62
+ };
52
63
  import BaseService from './base';
53
- import httpClient from './httpClient';
64
+ import httpClient, { setAxiosGlobalHeaders, MW_BASE_BETA_URL, MW_BASE_DEV_URL, MW_BASE_LIVE_URL, MW_BASE_STAGING_URL, MW_BASE_SANDBOX_URL } from './httpClient';
65
+ import BrowserInfo from '@tap-payments/browser-info';
66
+ import { generateApplicationHeader, rsaSetup } from '../utils/config';
67
+ import { RSA_BETA_MW_PUBLIC_KEY, RSA_DEV_MW_PUBLIC_KEY, RSA_PRODUCTION_MW_PUBLIC_KEY, RSA_SANDBOX_MW_PUBLIC_KEY, RSA_STAGING_MW_PUBLIC_KEY } from '../constants';
54
68
  var APPService = (function (_super) {
55
69
  __extends(APPService, _super);
56
70
  function APPService() {
57
- return _super.call(this, httpClient) || this;
71
+ var _this = _super.call(this, httpClient) || this;
72
+ Object.defineProperty(_this, "baseUrl", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: void 0
77
+ });
78
+ Object.defineProperty(_this, "env", {
79
+ enumerable: true,
80
+ configurable: true,
81
+ writable: true,
82
+ value: void 0
83
+ });
84
+ _this.baseUrl = MW_BASE_LIVE_URL;
85
+ _this.env = 'production';
86
+ return _this;
58
87
  }
59
- Object.defineProperty(APPService.prototype, "init", {
88
+ Object.defineProperty(APPService.prototype, "setEnv", {
89
+ enumerable: false,
90
+ configurable: true,
91
+ writable: true,
92
+ value: function (env) {
93
+ this.env = env;
94
+ }
95
+ });
96
+ Object.defineProperty(APPService.prototype, "setBaseUrl", {
97
+ enumerable: false,
98
+ configurable: true,
99
+ writable: true,
100
+ value: function () {
101
+ if (!this.env)
102
+ throw new Error('Environment is not set');
103
+ switch (this.env) {
104
+ case 'staging':
105
+ this.baseUrl = MW_BASE_STAGING_URL;
106
+ break;
107
+ case 'beta':
108
+ this.baseUrl = MW_BASE_BETA_URL;
109
+ break;
110
+ case 'development':
111
+ this.baseUrl = MW_BASE_DEV_URL;
112
+ break;
113
+ case 'sandbox':
114
+ this.baseUrl = MW_BASE_SANDBOX_URL;
115
+ break;
116
+ default:
117
+ this.baseUrl = MW_BASE_LIVE_URL;
118
+ break;
119
+ }
120
+ }
121
+ });
122
+ Object.defineProperty(APPService.prototype, "getHeaderPublicKey", {
123
+ enumerable: false,
124
+ configurable: true,
125
+ writable: true,
126
+ value: function () {
127
+ if (!this.env)
128
+ throw new Error('Environment is not set');
129
+ switch (this.env) {
130
+ case 'staging':
131
+ return RSA_STAGING_MW_PUBLIC_KEY;
132
+ case 'beta':
133
+ return RSA_BETA_MW_PUBLIC_KEY;
134
+ case 'development':
135
+ return RSA_DEV_MW_PUBLIC_KEY;
136
+ case 'sandbox':
137
+ return RSA_SANDBOX_MW_PUBLIC_KEY;
138
+ default:
139
+ return RSA_PRODUCTION_MW_PUBLIC_KEY;
140
+ }
141
+ }
142
+ });
143
+ Object.defineProperty(APPService.prototype, "setBrowserHeaders", {
60
144
  enumerable: false,
61
145
  configurable: true,
62
146
  writable: true,
63
- value: function (publicKey, merchantId) {
147
+ value: function (_a) {
148
+ var locale = _a.locale, pk = _a.pk, domain = _a.domain;
64
149
  return __awaiter(this, void 0, void 0, function () {
65
- var body, data;
150
+ var encryptString, encryptedHeaders, mdn, authorization, rest, application;
151
+ return __generator(this, function (_b) {
152
+ switch (_b.label) {
153
+ case 0:
154
+ encryptString = rsaSetup(this.getHeaderPublicKey());
155
+ return [4, new BrowserInfo.BrowserInfo({
156
+ app: { name: '@tap-payments/apple-pay-button', language: locale },
157
+ credentials: { mdn: domain, pk: pk },
158
+ encrypt: function (_key, value) { return encryptString(value); }
159
+ }).get()];
160
+ case 1:
161
+ encryptedHeaders = _b.sent();
162
+ mdn = encryptedHeaders.mdn, authorization = encryptedHeaders.authorization, rest = __rest(encryptedHeaders, ["mdn", "authorization"]);
163
+ application = generateApplicationHeader(rest);
164
+ setAxiosGlobalHeaders({
165
+ authorization: pk,
166
+ mdn: mdn,
167
+ application: application
168
+ });
169
+ return [2];
170
+ }
171
+ });
172
+ });
173
+ }
174
+ });
175
+ Object.defineProperty(APPService.prototype, "checkoutProfile", {
176
+ enumerable: false,
177
+ configurable: true,
178
+ writable: true,
179
+ value: function (merchantId) {
180
+ return __awaiter(this, void 0, void 0, function () {
181
+ var data, merchant, payment_options, session;
66
182
  return __generator(this, function (_a) {
67
183
  switch (_a.label) {
68
- case 0:
69
- body = {
70
- headers: { authorization: "Bearer ".concat(publicKey) },
71
- reqBody: { public_key: publicKey, merchant_id: merchantId }
72
- };
73
- return [4, this.post('/init', body)];
184
+ case 0: return [4, this.post(this.baseUrl + '/checkoutprofile', { merchant_id: merchantId !== null && merchantId !== void 0 ? merchantId : '' })];
74
185
  case 1:
75
186
  data = (_a.sent()).data;
76
187
  if (data.errors)
77
188
  throw data;
78
- return [2, {
79
- merchant: data.merchant,
80
- payment_options: data.payment_options
81
- }];
189
+ merchant = data.merchant, payment_options = data.payment_options, session = data.session;
190
+ setAxiosGlobalHeaders({ session: session });
191
+ return [2, { merchant: merchant, payment_options: payment_options }];
82
192
  }
83
193
  });
84
194
  });
@@ -88,7 +198,7 @@ var APPService = (function (_super) {
88
198
  enumerable: false,
89
199
  configurable: true,
90
200
  writable: true,
91
- value: function (merchant, validationURL, merchantRegisteredDomain) {
201
+ value: function (merchant, validationURL, merchantRegisteredDomain, merchantIdentifier) {
92
202
  return __awaiter(this, void 0, void 0, function () {
93
203
  var body, data;
94
204
  return __generator(this, function (_a) {
@@ -97,12 +207,11 @@ var APPService = (function (_super) {
97
207
  body = {
98
208
  validationUrl: validationURL,
99
209
  origin: merchantRegisteredDomain,
100
- merchantIdentifier: 'merchant.tap.gosell',
210
+ merchantIdentifier: merchantIdentifier,
101
211
  merchantId: merchant.id,
102
- merchantName: merchant.name,
103
- session_token: merchant.session_token
212
+ merchantName: merchant.name
104
213
  };
105
- return [4, this.post('/session', body)];
214
+ return [4, this.post(this.baseUrl + '/validatemerchant', body)];
106
215
  case 1:
107
216
  data = (_a.sent()).data;
108
217
  if (data.errors)
@@ -117,24 +226,17 @@ var APPService = (function (_super) {
117
226
  enumerable: false,
118
227
  configurable: true,
119
228
  writable: true,
120
- value: function (applePaymentData, merchant) {
229
+ value: function (applePaymentData) {
121
230
  return __awaiter(this, void 0, void 0, function () {
122
231
  var body, data;
123
232
  return __generator(this, function (_a) {
124
233
  switch (_a.label) {
125
234
  case 0:
126
235
  body = {
127
- method: 'POST',
128
- path: '/v2/token',
129
- headers: {
130
- session_token: merchant.session_token
131
- },
132
- reqBody: {
133
- type: 'applepay',
134
- token_data: applePaymentData
135
- }
236
+ type: 'applepay',
237
+ token_data: applePaymentData
136
238
  };
137
- return [4, this.post('/api', body)];
239
+ return [4, this.post(this.baseUrl + '/token', body)];
138
240
  case 1:
139
241
  data = (_a.sent()).data;
140
242
  if (data.errors)
@@ -145,72 +247,6 @@ var APPService = (function (_super) {
145
247
  });
146
248
  }
147
249
  });
148
- Object.defineProperty(APPService.prototype, "createCharge", {
149
- enumerable: false,
150
- configurable: true,
151
- writable: true,
152
- value: function (publicKey, merchant, request, cardToken) {
153
- var body = {
154
- method: 'POST',
155
- path: '/v2/charge',
156
- headers: {
157
- session_token: merchant.session_token
158
- },
159
- reqBody: {
160
- id: null,
161
- amount: request.total.amount,
162
- currency: request.currencyCode,
163
- public_key: publicKey,
164
- product: 'GOSELL',
165
- threeDSecure: true,
166
- save_card: false,
167
- fee: 0,
168
- statement_descriptor: 'Sample',
169
- description: 'Test Description',
170
- metadata: {},
171
- reference: {
172
- transaction: 'txn_0001',
173
- order: 'ord_0001'
174
- },
175
- receipt: {
176
- email: false,
177
- sms: true
178
- },
179
- customer: {
180
- id: null,
181
- first_name: 'Hala',
182
- middle_name: null,
183
- last_name: 'Q.',
184
- email: 'email@email.com',
185
- phone: {
186
- country_code: '965',
187
- number: '00000000'
188
- }
189
- },
190
- source: {
191
- id: cardToken
192
- },
193
- hashstring: null,
194
- post: {
195
- url: null
196
- },
197
- redirect: {
198
- url: 'https://jslib.gosell.io/demo?token=63cce645332aa501e6cf768f&mode=popup'
199
- },
200
- ipaddress: null,
201
- selected_currency: request.currencyCode,
202
- selected_amount: request.total.amount,
203
- merchant: {
204
- id: merchant.id
205
- },
206
- order: {
207
- id: 'ord_06CO2023731xt7V22SC0X487'
208
- }
209
- }
210
- };
211
- return this.post('/api', body);
212
- }
213
- });
214
250
  return APPService;
215
251
  }(BaseService));
216
252
  var appService = new APPService();
@@ -1,2 +1,8 @@
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.staing.tap.company/v2/checkout";
3
+ export declare const MW_BASE_DEV_URL = "https://mw-sdk.dev.tap.company/v2/checkout";
4
+ export declare const MW_BASE_BETA_URL = "https://mw-sdk.dev.tap.company/v2/checkout";
5
+ export declare const MW_BASE_SANDBOX_URL = "https://mw-sdk.sandbox.tap.company/v2/checkout";
1
6
  declare const httpClient: import("axios").AxiosInstance;
7
+ export declare const setAxiosGlobalHeaders: (headers: Record<string, string>) => void;
2
8
  export default httpClient;
@@ -1,7 +1,21 @@
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
+ };
1
12
  import axios from 'axios';
2
- var MW_BASE_URL = 'https://checkout.payments.tap.company/api';
13
+ export var MW_BASE_LIVE_URL = 'https://mw-sdk.tap.company/v2/checkout';
14
+ export var MW_BASE_STAGING_URL = 'https://mw-sdk.staing.tap.company/v2/checkout';
15
+ export var MW_BASE_DEV_URL = 'https://mw-sdk.dev.tap.company/v2/checkout';
16
+ export var MW_BASE_BETA_URL = 'https://mw-sdk.dev.tap.company/v2/checkout';
17
+ export var MW_BASE_SANDBOX_URL = 'https://mw-sdk.sandbox.tap.company/v2/checkout';
3
18
  var httpClient = axios.create({
4
- baseURL: MW_BASE_URL,
5
19
  headers: {
6
20
  'Content-Type': 'application/json',
7
21
  Accept: 'application/json'
@@ -13,4 +27,7 @@ httpClient.interceptors.request.use(function (config) {
13
27
  httpClient.interceptors.response.use(function (response) {
14
28
  return response;
15
29
  });
30
+ export var setAxiosGlobalHeaders = function (headers) {
31
+ httpClient.defaults.headers.common = __assign(__assign({}, httpClient.defaults.headers.common), headers);
32
+ };
16
33
  export default httpClient;
@@ -37,3 +37,15 @@ export declare const SupportedNetworks: {
37
37
  readonly Maestro: "maestro";
38
38
  };
39
39
  export declare const ApplePayVersion = 5;
40
+ export declare const Environment: {
41
+ readonly Production: "production";
42
+ readonly Sandbox: "sandbox";
43
+ readonly Beta: "beta";
44
+ readonly Development: "development";
45
+ readonly Staging: "staging";
46
+ };
47
+ export declare const RSA_DEV_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8AX++RtxPZFtns4XzXFlDIxPBh0umN4qRXZaKDIlb6a3MknaB7psJWmf2l+e4Cfh9b5tey/+rZqpQ065eXTZfGCAuBLt+fYLQBhLfjRpk8S6hlIzc1Kdjg65uqzMwcTd0p7I4KLwHk1I0oXzuEu53fU1LSZhWp4Mnd6wjVgXAsQIDAQAB\n-----END PUBLIC KEY-----";
48
+ export declare const RSA_SANDBOX_MW_PUBLIC_KEY = "";
49
+ export declare const RSA_PRODUCTION_MW_PUBLIC_KEY = "";
50
+ export declare const RSA_BETA_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
51
+ export declare const RSA_STAGING_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi9W5jyTvA4Iwv3V5sfNQ7VdSz\n7WqwBbnWFbIUL/GjaaE93mvDv4zbgRSznHaHQPH6pxrMhMh0tV58njkvjHvQ/tvg\npwM8SemNPKEEAPl69tnMvCrJRPh2dWL3OHY8yCW4c38Hyx4fy56Zd5cdoVWfCReu\njCsvASLGz+cfRrj2swIDAQAB\n-----END PUBLIC KEY-----";
@@ -37,3 +37,15 @@ export var SupportedNetworks = {
37
37
  Maestro: 'maestro'
38
38
  };
39
39
  export var ApplePayVersion = 5;
40
+ export var Environment = {
41
+ Production: 'production',
42
+ Sandbox: 'sandbox',
43
+ Beta: 'beta',
44
+ Development: 'development',
45
+ Staging: 'staging'
46
+ };
47
+ export var RSA_DEV_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8AX++RtxPZFtns4XzXFlDIxPBh0umN4qRXZaKDIlb6a3MknaB7psJWmf2l+e4Cfh9b5tey/+rZqpQ065eXTZfGCAuBLt+fYLQBhLfjRpk8S6hlIzc1Kdjg65uqzMwcTd0p7I4KLwHk1I0oXzuEu53fU1LSZhWp4Mnd6wjVgXAsQIDAQAB\n-----END PUBLIC KEY-----";
48
+ export var RSA_SANDBOX_MW_PUBLIC_KEY = "";
49
+ export var RSA_PRODUCTION_MW_PUBLIC_KEY = "";
50
+ export var RSA_BETA_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
51
+ export var RSA_STAGING_MW_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi9W5jyTvA4Iwv3V5sfNQ7VdSz\n7WqwBbnWFbIUL/GjaaE93mvDv4zbgRSznHaHQPH6pxrMhMh0tV58njkvjHvQ/tvg\npwM8SemNPKEEAPl69tnMvCrJRPh2dWL3OHY8yCW4c38Hyx4fy56Zd5cdoVWfCReu\njCsvASLGz+cfRrj2swIDAQAB\n-----END PUBLIC KEY-----";
@@ -1,4 +1,3 @@
1
-
2
1
  .button-applepay-tap {
3
2
  -webkit-appearance: -apple-pay-button;
4
3
  display: block;
@@ -20,4 +19,3 @@
20
19
  -apple-pay-button-style: white;
21
20
  border: solid 1px gray;
22
21
  }
23
-
@@ -17,7 +17,7 @@ import { useApplePay } from '../../hooks/useApplePay';
17
17
  import { ButtonStyle, ButtonType, Locale, Scope } from '../../constants';
18
18
  import './ApplePayButton.css';
19
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;
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, merchantIdentifier = _a.merchantIdentifier, environment = _a.environment, onReady = _a.onReady;
21
21
  var _f = useApplePay({
22
22
  publicKey: publicKey,
23
23
  merchant: merchant,
@@ -29,7 +29,11 @@ var ApplePay = React.memo(function (_a) {
29
29
  onCancel: onCancel,
30
30
  scope: scope,
31
31
  metaData: metaData,
32
- debug: debug
32
+ debug: debug,
33
+ merchantIdentifier: merchantIdentifier,
34
+ environment: environment,
35
+ locale: locale,
36
+ onReady: onReady
33
37
  }), loading = _f.loading, onApplePayButtonClicked = _f.onApplePayButtonClicked, disabled = _f.disabled;
34
38
  React.useEffect(function () {
35
39
  if (debug) {
@@ -48,7 +52,7 @@ var ApplePay = React.memo(function (_a) {
48
52
  });
49
53
  }
50
54
  }, []);
51
- return (_jsx("button", { className: "button-applepay-tap", style: {
55
+ return (_jsx("button", { className: 'button-applepay-tap', style: {
52
56
  '-apple-pay-button-type': type,
53
57
  '-apple-pay-button-style': buttonStyle
54
58
  }, onClick: function () {
@@ -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 }: UseApplePayProps) => UseApplePayReturnProps;
8
+ export declare const useApplePay: ({ publicKey, merchant, transaction, billingContact, onCancel, onError, onSuccess, scope, supportedNetworks, metaData, debug, merchantIdentifier, environment, locale, onReady }: UseApplePayProps) => UseApplePayReturnProps;
9
9
  export {};
@@ -48,36 +48,55 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
48
48
  import { useCallback, useEffect, useState } from 'react';
49
49
  import appService from '../api/app.service';
50
50
  import { ApplePayVersion } from '../constants';
51
+ import { setAxiosGlobalHeaders } from '../api/httpClient';
51
52
  import { getApplePayPaymentMethod, getApplePayRequest, validateCurrency, validateSupportedNetworks } from '../utils/config';
52
53
  export var useApplePay = function (_a) {
53
- 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;
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, merchantIdentifier = _a.merchantIdentifier, environment = _a.environment, locale = _a.locale, onReady = _a.onReady;
54
55
  var _b = useState(false), loading = _b[0], setLoading = _b[1];
55
56
  var _c = useState(null), profileData = _c[0], setProfile = _c[1];
56
57
  var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
57
- var getMerchantData = useCallback(function () {
58
- setLoading(true);
59
- appService
60
- .init(publicKey, merchant.id)
61
- .then(function (data) {
62
- if (debug)
63
- console.log('Merchant response: ', data);
64
- setProfile(data);
65
- })
66
- .catch(function (error) {
67
- onError && onError(error.errors || error);
68
- })
69
- .finally(function () {
70
- setLoading(false);
58
+ var initialize = useCallback(function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
59
+ var merchantProfile, payment_options, headers, data, err_1;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0:
63
+ setLoading(true);
64
+ appService.setEnv(environment);
65
+ appService.setBaseUrl();
66
+ _a.label = 1;
67
+ case 1:
68
+ _a.trys.push([1, 4, 5, 6]);
69
+ if (metaData) {
70
+ merchantProfile = metaData.merchant, payment_options = metaData.payment_options, headers = metaData.headers;
71
+ setAxiosGlobalHeaders(__assign({}, headers));
72
+ setProfile({ merchant: merchantProfile, payment_options: payment_options });
73
+ return [2];
74
+ }
75
+ return [4, appService.setBrowserHeaders({ locale: locale, domain: merchant.domain, pk: publicKey })];
76
+ case 2:
77
+ _a.sent();
78
+ return [4, appService.checkoutProfile()];
79
+ case 3:
80
+ data = _a.sent();
81
+ if (debug)
82
+ console.log('merchant configuration: ', data);
83
+ setProfile(data);
84
+ return [3, 6];
85
+ case 4:
86
+ err_1 = _a.sent();
87
+ onError && onError(err_1.errors || err_1);
88
+ return [3, 6];
89
+ case 5:
90
+ setLoading(false);
91
+ onReady && onReady();
92
+ return [7];
93
+ case 6: return [2];
94
+ }
71
95
  });
72
- }, [merchant, onError, publicKey]);
96
+ }); }, [environment, locale, merchant.domain, publicKey, debug, onError]);
73
97
  useEffect(function () {
74
- if (metaData) {
75
- setProfile(metaData);
76
- }
77
- else {
78
- getMerchantData();
79
- }
80
- }, [getMerchantData, metaData]);
98
+ initialize(metaData);
99
+ }, [initialize, metaData]);
81
100
  var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
82
101
  var ApplePaySession, paymentMethod, currency, cardBrands, request, session_1;
83
102
  var _a;
@@ -124,9 +143,9 @@ export var useApplePay = function (_a) {
124
143
  if (debug) {
125
144
  console.info("creating merchant session for merchantData: ".concat(JSON.stringify(profileData.merchant), " and validationURL: ").concat(event.validationURL, " and merchant.domain: ").concat(merchant.domain));
126
145
  }
127
- return [4, appService.appleSession(profileData.merchant, event.validationURL, merchant.domain)];
146
+ return [4, appService.appleSession(profileData.merchant, event.validationURL, merchant.domain, merchantIdentifier)];
128
147
  case 2:
129
- merchantSession = (_a.sent()).body;
148
+ merchantSession = _a.sent();
130
149
  if (debug)
131
150
  console.info('merchantSession', merchantSession);
132
151
  session_1.completeMerchantValidation(merchantSession);
@@ -154,7 +173,7 @@ export var useApplePay = function (_a) {
154
173
  console.info('onpaymentauthorized event', event);
155
174
  _b.label = 1;
156
175
  case 1:
157
- _b.trys.push([1, 9, , 10]);
176
+ _b.trys.push([1, 9, 10, 11]);
158
177
  _a = scope;
159
178
  switch (_a) {
160
179
  case 'AppleToken': return [3, 2];
@@ -166,7 +185,7 @@ export var useApplePay = function (_a) {
166
185
  _b.sent();
167
186
  session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
168
187
  return [3, 8];
169
- case 4: return [4, appService.tapTokenization(event.payment.token.paymentData, profileData.merchant)];
188
+ case 4: return [4, appService.tapTokenization(event.payment.token.paymentData)];
170
189
  case 5:
171
190
  data = _b.sent();
172
191
  return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data))];
@@ -179,7 +198,7 @@ export var useApplePay = function (_a) {
179
198
  console.info('Completing payment with status: STATUS_FAILURE');
180
199
  session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
181
200
  _b.label = 8;
182
- case 8: return [3, 10];
201
+ case 8: return [3, 11];
183
202
  case 9:
184
203
  error_2 = _b.sent();
185
204
  if (debug)
@@ -188,7 +207,8 @@ export var useApplePay = function (_a) {
188
207
  throw error_2;
189
208
  case 10:
190
209
  setLoading(false);
191
- return [2];
210
+ return [7];
211
+ case 11: return [2];
192
212
  }
193
213
  });
194
214
  }); };
package/build/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { ApplePayButtonProps, ApplePayButton } from './features/ApplePayButton';
2
- import { ButtonStyle, Scope, SupportedNetworks } from './constants';
2
+ import { ButtonStyle, Scope, SupportedNetworks, Environment } from './constants';
3
3
  export type { ApplePayButtonProps };
4
- export { ApplePayButton, ButtonStyle, Scope, SupportedNetworks };
4
+ export { ApplePayButton, ButtonStyle, Scope, SupportedNetworks, Environment };
package/build/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { ApplePayButton, renderApplePayButton } from './features/ApplePayButton';
2
- import { ButtonStyle, Scope, SupportedNetworks } from './constants';
3
- export { ApplePayButton, ButtonStyle, Scope, SupportedNetworks };
2
+ import { ButtonStyle, Scope, SupportedNetworks, Environment } from './constants';
3
+ export { ApplePayButton, ButtonStyle, Scope, SupportedNetworks, Environment };
4
4
  window['TapSDKs'] = {
5
5
  renderApplePayButton: renderApplePayButton,
6
6
  ButtonStyle: ButtonStyle,
7
7
  Scope: Scope,
8
- SupportedNetworks: SupportedNetworks
8
+ SupportedNetworks: SupportedNetworks,
9
+ Environment: Environment
9
10
  };
@@ -7,3 +7,5 @@ export declare const getApplePayRequest: ({ transaction, billingContact, support
7
7
  name: string;
8
8
  }) => ApplePayRequestData;
9
9
  export declare const getApplePayPaymentMethod: (paymentMethods: Array<PaymentMethod>) => PaymentMethod;
10
+ export declare const rsaSetup: (key: string) => (string: string) => string;
11
+ export declare function generateApplicationHeader(obj: Record<string, string | any>): string;
@@ -1,4 +1,5 @@
1
1
  import { MerchantCapabilities } from '../constants';
2
+ import { JSEncrypt } from 'jsencrypt';
2
3
  export var validateSupportedNetworks = function (supportedNetworksConfig, supportedNetworks) {
3
4
  var toLowerCase = function (item) { return item.toLowerCase(); };
4
5
  if (!supportedNetworks)
@@ -52,3 +53,20 @@ export var getApplePayPaymentMethod = function (paymentMethods) {
52
53
  }
53
54
  return paymentMethod;
54
55
  };
56
+ export var rsaSetup = function (key) {
57
+ var rsa = new JSEncrypt();
58
+ rsa.setPublicKey(key);
59
+ return function (string) {
60
+ if (typeof string !== 'string')
61
+ throw new Error('string should be from type string');
62
+ var encrypted = rsa.encrypt(string);
63
+ if (!encrypted)
64
+ throw new Error('encryption data reached max allowed length');
65
+ return encrypted;
66
+ };
67
+ };
68
+ export function generateApplicationHeader(obj) {
69
+ return Object.keys(obj)
70
+ .map(function (key) { return "".concat(key, "=").concat(obj[key]); })
71
+ .join('|');
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "0.0.16-test",
3
+ "version": "0.0.18-test",
4
4
  "description": "Apple Pay Button React Component",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",
@@ -72,7 +72,9 @@
72
72
  "webpack-merge": "^5.8.0"
73
73
  },
74
74
  "dependencies": {
75
+ "@tap-payments/browser-info": "^1.0.2",
75
76
  "axios": "^1.2.2",
77
+ "jsencrypt": "^3.3.2",
76
78
  "react": ">=17.0.2",
77
79
  "react-dom": ">=17.0.2"
78
80
  },