@tap-payments/apple-pay-button 0.0.68-development → 1.0.0-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.
Files changed (51) hide show
  1. package/README.md +30 -30
  2. package/build/@types/ApplePaySession.d.ts +67 -0
  3. package/build/@types/index.d.ts +118 -6
  4. package/build/@types/index.js +1 -6
  5. package/build/api/app.service.d.ts +23 -0
  6. package/build/{api.js → api/app.service.js} +93 -84
  7. package/build/api/base.d.ts +9 -0
  8. package/build/api/base.js +45 -0
  9. package/build/api/httpClient.d.ts +8 -0
  10. package/build/api/httpClient.js +33 -0
  11. package/build/constants/index.d.ts +58 -2
  12. package/build/constants/index.js +58 -2
  13. package/build/features/ApplePayButton/ApplePayButton.css +21 -0
  14. package/build/features/ApplePayButton/ApplePayButton.d.ts +5 -3
  15. package/build/features/ApplePayButton/ApplePayButton.js +25 -9
  16. package/build/features/ApplePayButton/index.d.ts +3 -3
  17. package/build/features/ApplePayButton/index.js +2 -2
  18. package/build/hooks/index.d.ts +1 -1
  19. package/build/hooks/index.js +1 -1
  20. package/build/hooks/useApplePay.d.ts +7 -85
  21. package/build/hooks/useApplePay.js +178 -262
  22. package/build/hooks/useGetEvents.d.ts +4 -0
  23. package/build/hooks/useGetEvents.js +15 -0
  24. package/build/hooks/useScript.d.ts +1 -0
  25. package/build/hooks/useScript.js +39 -0
  26. package/build/index.d.ts +4 -4
  27. package/build/index.js +7 -5
  28. package/build/utils/config.d.ts +9 -7
  29. package/build/utils/config.js +52 -41
  30. package/build/utils/defaultValues.d.ts +32 -2
  31. package/build/utils/defaultValues.js +31 -10
  32. package/build/utils/index.d.ts +0 -3
  33. package/build/utils/index.js +0 -3
  34. package/package.json +11 -16
  35. package/build/@types/ApplePayButtonProps.d.ts +0 -128
  36. package/build/@types/charge.d.ts +0 -57
  37. package/build/@types/charge.js +0 -1
  38. package/build/@types/checkoutProfile.d.ts +0 -194
  39. package/build/@types/checkoutProfile.js +0 -1
  40. package/build/@types/enums.d.ts +0 -65
  41. package/build/@types/enums.js +0 -76
  42. package/build/@types/tapLocalisation.d.ts +0 -193
  43. package/build/@types/tapLocalisation.js +0 -1
  44. package/build/@types/tapTheme.d.ts +0 -842
  45. package/build/@types/tapTheme.js +0 -1
  46. package/build/api.d.ts +0 -34
  47. package/build/hooks/useMerchantApplePay.d.ts +0 -20
  48. package/build/hooks/useMerchantApplePay.js +0 -176
  49. package/build/utils/theme.d.ts +0 -12
  50. package/build/utils/theme.js +0 -61
  51. /package/build/@types/{ApplePayButtonProps.js → ApplePaySession.js} +0 -0
package/README.md CHANGED
@@ -141,22 +141,22 @@ const App = () => {
141
141
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
142
142
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
143
143
  <title>apple pay button</title>
144
- <link rel="stylesheet" href="https://tap-sdks.b-cdn.net/apple-pay/build-0.0.36-test/main.css" />
145
- <script src="https://tap-sdks.b-cdn.net/apple-pay/build-0.0.36-test/main.js"></script>
144
+ <link rel="stylesheet" href="https://tap-sdks.b-cdn.net/apple-pay/build-1.0.19/main.css" />
145
+ <script src="https://tap-sdks.b-cdn.net/apple-pay/build-1.0.19/main.js"></script>
146
146
  </head>
147
147
 
148
148
  <body>
149
149
  <div id="apple-pay-button"></div>
150
150
  <script type="text/javascript">
151
- const { renderApplePayButton, ThemeMode, SupportedNetworks, Scope, Environment, Locale, ButtonType, Edges } =
152
- window.TapSDKs
153
- renderApplePayButton(
151
+ const { render, ThemeMode, SupportedNetworks, Scope, Environment, Locale, ButtonType, Edges } =
152
+ window.TapApplepaySDK
153
+ render(
154
154
  {
155
155
  publicKey: 'pk_test_7xxxxxxxxx',
156
- environment: Environment.Sandbox,
156
+ environment: Environment.Development,
157
157
  scope: Scope.TapToken,
158
158
  merchant: {
159
- domain: 'tp-txxxxxxxx',
159
+ domain: window.location.hostname,
160
160
  id: 'merchant_xxxxxxxxxx'
161
161
  },
162
162
  transaction: {
@@ -215,26 +215,26 @@ const App = () => {
215
215
 
216
216
  ## Configurations
217
217
 
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` |
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 |
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 |
@@ -0,0 +1,67 @@
1
+ import { MerchantCapabilities, SupportedNetworks } from '../constants';
2
+ export declare type RequiredShippingContactField = 'postalAddress' | 'name' | 'phoneticName' | 'phone' | 'email';
3
+ export declare type ApplePayPaymentMethodType = 'debit' | 'credit' | 'prepaid' | 'store';
4
+ export interface ApplePayShippingMethod {
5
+ label: string;
6
+ detail: string;
7
+ amount: string;
8
+ identifier: string;
9
+ }
10
+ export interface ApplePayPaymentContact {
11
+ phoneNumber?: string;
12
+ emailAddress?: string;
13
+ givenName?: string;
14
+ familyName?: string;
15
+ phoneticGivenName?: string;
16
+ phoneticFamilyName?: string;
17
+ addressLines?: string[];
18
+ subLocality?: string;
19
+ locality?: string;
20
+ postalCode?: string;
21
+ subAdministrativeArea?: string;
22
+ administrativeArea?: string;
23
+ country?: string;
24
+ countryCode?: string;
25
+ }
26
+ export interface ApplePayPaymentMethod {
27
+ displayName?: string;
28
+ network?: string;
29
+ type?: ApplePayPaymentMethodType;
30
+ billingContact?: ApplePayPaymentContact;
31
+ }
32
+ export interface ApplePayLineItem {
33
+ type?: 'final' | 'pending';
34
+ label?: string;
35
+ amount?: string;
36
+ paymentTiming?: 'immediate' | 'recurring' | 'deferred' | 'automaticReload';
37
+ recurringPaymentStartDate?: Date;
38
+ recurringPaymentIntervalUnit?: 'year' | 'month' | 'day' | 'hour' | 'minute';
39
+ recurringPaymentIntervalCount?: number;
40
+ recurringPaymentEndDate?: Date;
41
+ deferredPaymentDate?: Date;
42
+ automaticReloadPaymentThresholdAmount?: string;
43
+ }
44
+ export interface ApplePayUpdateData {
45
+ newTotal: ApplePayLineItem;
46
+ newLineItems?: ApplePayLineItem[];
47
+ }
48
+ export interface ApplePayRequestData {
49
+ countryCode: string;
50
+ currencyCode: string;
51
+ merchantCapabilities: Array<typeof MerchantCapabilities[keyof typeof MerchantCapabilities]>;
52
+ supportedNetworks: Array<typeof SupportedNetworks[keyof typeof SupportedNetworks]>;
53
+ billingContact?: {
54
+ phoneNumber?: string;
55
+ emailAddress?: string;
56
+ givenName: string;
57
+ familyName: string;
58
+ };
59
+ total: {
60
+ label: string;
61
+ amount: number;
62
+ };
63
+ requiredShippingContactFields?: Array<RequiredShippingContactField>;
64
+ supportsCouponCode?: boolean;
65
+ couponCode?: string;
66
+ shippingMethods?: ApplePayShippingMethod[];
67
+ }
@@ -1,6 +1,118 @@
1
- export * from './charge';
2
- export * from './checkoutProfile';
3
- export * from './ApplePayButtonProps';
4
- export * from './enums';
5
- export * from './tapLocalisation';
6
- export * from './tapTheme';
1
+ import { Scope, SupportedNetworks, ButtonType, Locale, Environment, ThemeMode, Edges } from '../constants';
2
+ import { ApplePayPaymentContact, ApplePayPaymentMethod, ApplePayShippingMethod, ApplePayUpdateData, RequiredShippingContactField } from './ApplePaySession';
3
+ export * from './ApplePaySession';
4
+ export interface Interface {
5
+ locale?: typeof Locale[keyof typeof Locale];
6
+ theme?: typeof ThemeMode[keyof typeof ThemeMode];
7
+ edges?: typeof Edges[keyof typeof Edges];
8
+ type?: typeof ButtonType[keyof typeof ButtonType];
9
+ }
10
+ export interface Customer {
11
+ id?: string;
12
+ name?: {
13
+ lang: typeof Locale[keyof typeof Locale];
14
+ first: string;
15
+ last: string;
16
+ middle?: string;
17
+ }[];
18
+ contact?: {
19
+ email?: string;
20
+ phone?: {
21
+ countryCode: string;
22
+ number: string;
23
+ };
24
+ };
25
+ requiredShippingContactFields?: Array<RequiredShippingContactField>;
26
+ }
27
+ export interface Acceptance {
28
+ supportedBrands?: Array<typeof SupportedNetworks[keyof typeof SupportedNetworks]>;
29
+ supportedCards?: Array<string>;
30
+ supportedCardsWithAuthentications?: Array<string>;
31
+ supportsCouponCode?: boolean;
32
+ }
33
+ export interface Transaction {
34
+ amount: string;
35
+ currency: string;
36
+ couponCode?: string;
37
+ shipping?: ApplePayShippingMethod[];
38
+ }
39
+ export interface ApplePayButtonProps {
40
+ scope?: typeof Scope[keyof typeof Scope];
41
+ publicKey: string;
42
+ environment: typeof Environment[keyof typeof Environment];
43
+ merchant: {
44
+ id: string;
45
+ domain: string;
46
+ identifier?: string;
47
+ };
48
+ interface?: Interface;
49
+ customer?: Customer;
50
+ acceptance: Acceptance;
51
+ transaction: Transaction;
52
+ onCancel?: () => void;
53
+ onError?: (error: any) => void;
54
+ onSuccess?: (data: Record<string, any>) => Promise<void>;
55
+ onClick?: () => void;
56
+ onReady?: () => void;
57
+ onMerchantValidation?: (status: 'initiated' | 'completed' | 'error') => void;
58
+ onShippingContactSelected?: (shippingContact: ApplePayPaymentContact) => Promise<ApplePayUpdateData> | void;
59
+ onPaymentMethodSelected?: (paymentMethod: ApplePayPaymentMethod) => Promise<ApplePayUpdateData> | void;
60
+ onCouponChanged?: (couponCode: string) => Promise<ApplePayUpdateData> | void;
61
+ metaData?: MetaData;
62
+ debug?: boolean;
63
+ }
64
+ export interface MerchantResponse {
65
+ id: string;
66
+ name: string;
67
+ country_code: string;
68
+ session_token: string;
69
+ [other: string]: string;
70
+ }
71
+ export interface PaymentMethod {
72
+ id: string;
73
+ image: string;
74
+ name: string;
75
+ payment_type: string;
76
+ supported_card_brands: Array<typeof SupportedNetworks[keyof typeof SupportedNetworks]>;
77
+ supported_currencies: string[];
78
+ }
79
+ export interface PaymentOptionsResponse {
80
+ id: string;
81
+ country: string;
82
+ currency: string;
83
+ payment_methods: PaymentMethod[];
84
+ }
85
+ export interface MetaData {
86
+ merchant: MerchantResponse;
87
+ payment_options: PaymentOptionsResponse;
88
+ headers: Record<string, string>;
89
+ }
90
+ export interface CheckoutProfileRequest {
91
+ currency: string;
92
+ merchant_id: string;
93
+ total_amount: number;
94
+ order: {
95
+ amount: number;
96
+ currency: string;
97
+ customer?: {
98
+ id?: string;
99
+ email?: string;
100
+ first_name?: string;
101
+ last_name?: string;
102
+ phone?: {
103
+ country_code: string;
104
+ number: string;
105
+ };
106
+ };
107
+ items: {
108
+ quantity: number;
109
+ amount: number;
110
+ currency: string;
111
+ name: string;
112
+ requiresShipping: string;
113
+ }[];
114
+ merchant: {
115
+ id: string;
116
+ };
117
+ };
118
+ }
@@ -1,6 +1 @@
1
- export * from './charge';
2
- export * from './checkoutProfile';
3
- export * from './ApplePayButtonProps';
4
- export * from './enums';
5
- export * from './tapLocalisation';
6
- export * from './tapTheme';
1
+ export * from './ApplePaySession';
@@ -0,0 +1,23 @@
1
+ import { MerchantResponse, ApplePayButtonProps, CheckoutProfileRequest } from '../@types';
2
+ import BaseService from './base';
3
+ declare class APPService extends BaseService {
4
+ private baseUrl;
5
+ private env;
6
+ constructor();
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-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi9W5jyTvA4Iwv3V5sfNQ7VdSz\n7WqwBbnWFbIUL/GjaaE93mvDv4zbgRSznHaHQPH6pxrMhMh0tV58njkvjHvQ/tvg\npwM8SemNPKEEAPl69tnMvCrJRPh2dWL3OHY8yCW4c38Hyx4fy56Zd5cdoVWfCReu\njCsvASLGz+cfRrj2swIDAQAB\n-----END PUBLIC KEY-----" | "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----";
10
+ setBrowserHeaders({ locale, pk, domain }: {
11
+ locale: string;
12
+ pk: string;
13
+ domain: string;
14
+ }): Promise<void>;
15
+ checkoutProfile(request: CheckoutProfileRequest): 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>;
21
+ }
22
+ declare const appService: APPService;
23
+ export default appService;
@@ -1,14 +1,18 @@
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;
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
9
7
  };
10
- return __assign.apply(this, arguments);
11
- };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
12
16
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
17
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
18
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -56,39 +60,84 @@ var __rest = (this && this.__rest) || function (s, e) {
56
60
  }
57
61
  return t;
58
62
  };
63
+ import BaseService from './base';
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';
59
65
  import BrowserInfo from '@tap-payments/browser-info';
60
- import { MW_BASE_URL, RSA_MW_PUBLIC_KEY } from './constants';
61
- import axios from 'axios';
62
- import { generateApplicationHeader, rsaSetup } from '@tap-payments/acceptance-sdk';
63
- var axiosInstance = axios.create({
64
- baseURL: MW_BASE_URL,
65
- headers: {
66
- 'Content-Type': 'application/json'
67
- }
68
- });
69
- export var setAxiosGlobalHeaders = function (headers) {
70
- Object.entries(headers).forEach(function (_a) {
71
- var key = _a[0], value = _a[1];
72
- axiosInstance.defaults.headers.common[key] = value;
73
- });
74
- };
75
- export var getAxiosGlobalHeaders = function () {
76
- return __assign({}, axiosInstance.defaults.headers.common);
77
- };
78
- var APPService = (function () {
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';
68
+ var APPService = (function (_super) {
69
+ __extends(APPService, _super);
79
70
  function APPService() {
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;
80
87
  }
81
- Object.defineProperty(APPService.prototype, "setHttpHeaders", {
88
+ Object.defineProperty(APPService.prototype, "setEnv", {
82
89
  enumerable: false,
83
90
  configurable: true,
84
91
  writable: true,
85
- value: function (headers) {
86
- return __awaiter(this, void 0, void 0, function () {
87
- return __generator(this, function (_a) {
88
- setAxiosGlobalHeaders(headers);
89
- return [2];
90
- });
91
- });
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
+ }
92
141
  }
93
142
  });
94
143
  Object.defineProperty(APPService.prototype, "setBrowserHeaders", {
@@ -102,7 +151,7 @@ var APPService = (function () {
102
151
  return __generator(this, function (_b) {
103
152
  switch (_b.label) {
104
153
  case 0:
105
- encryptString = rsaSetup(RSA_MW_PUBLIC_KEY);
154
+ encryptString = rsaSetup(this.getHeaderPublicKey());
106
155
  return [4, new BrowserInfo.BrowserInfo({
107
156
  app: { name: '@tap-payments/apple-pay-button', language: locale },
108
157
  credentials: { mdn: domain, pk: pk },
@@ -132,7 +181,7 @@ var APPService = (function () {
132
181
  var data, merchant, payment_options, session;
133
182
  return __generator(this, function (_a) {
134
183
  switch (_a.label) {
135
- case 0: return [4, axiosInstance.post('/checkoutprofile', request)];
184
+ case 0: return [4, this.post(this.baseUrl + '/checkoutprofile', request)];
136
185
  case 1:
137
186
  data = (_a.sent()).data;
138
187
  if (data.errors)
@@ -149,7 +198,7 @@ var APPService = (function () {
149
198
  enumerable: false,
150
199
  configurable: true,
151
200
  writable: true,
152
- value: function (merchant, validationURL, merchantRegisteredDomain) {
201
+ value: function (merchant, validationURL, merchantRegisteredDomain, merchantIdentifier) {
153
202
  return __awaiter(this, void 0, void 0, function () {
154
203
  var body, data;
155
204
  return __generator(this, function (_a) {
@@ -158,11 +207,11 @@ var APPService = (function () {
158
207
  body = {
159
208
  validationUrl: validationURL,
160
209
  origin: merchantRegisteredDomain,
161
- merchantIdentifier: merchant.id,
210
+ merchantIdentifier: merchantIdentifier,
162
211
  merchantId: merchant.id,
163
212
  merchantName: merchant.name
164
213
  };
165
- return [4, axiosInstance.post('/validatemerchant', body)];
214
+ return [4, this.post(this.baseUrl + '/validatemerchant', body)];
166
215
  case 1:
167
216
  data = (_a.sent()).data;
168
217
  if (data.errors)
@@ -187,47 +236,7 @@ var APPService = (function () {
187
236
  type: 'applepay',
188
237
  token_data: applePaymentData
189
238
  };
190
- return [4, axiosInstance.post('/token', body)];
191
- case 1:
192
- data = (_a.sent()).data;
193
- if (data.errors)
194
- throw data;
195
- return [2, data];
196
- }
197
- });
198
- });
199
- }
200
- });
201
- Object.defineProperty(APPService.prototype, "createCharge", {
202
- enumerable: false,
203
- configurable: true,
204
- writable: true,
205
- value: function (request) {
206
- return __awaiter(this, void 0, void 0, function () {
207
- var data;
208
- return __generator(this, function (_a) {
209
- switch (_a.label) {
210
- case 0: return [4, axiosInstance.post('/charge', request)];
211
- case 1:
212
- data = (_a.sent()).data;
213
- if (data.errors)
214
- throw data;
215
- return [2, data];
216
- }
217
- });
218
- });
219
- }
220
- });
221
- Object.defineProperty(APPService.prototype, "createAuthorize", {
222
- enumerable: false,
223
- configurable: true,
224
- writable: true,
225
- value: function (request) {
226
- return __awaiter(this, void 0, void 0, function () {
227
- var data;
228
- return __generator(this, function (_a) {
229
- switch (_a.label) {
230
- case 0: return [4, axiosInstance.post('/authorize', request)];
239
+ return [4, this.post(this.baseUrl + '/token', body)];
231
240
  case 1:
232
241
  data = (_a.sent()).data;
233
242
  if (data.errors)
@@ -239,6 +248,6 @@ var APPService = (function () {
239
248
  }
240
249
  });
241
250
  return APPService;
242
- }());
251
+ }(BaseService));
243
252
  var appService = new APPService();
244
253
  export default appService;
@@ -0,0 +1,9 @@
1
+ import { AxiosInstance, AxiosRequestConfig } from 'axios';
2
+ export default class BaseService {
3
+ httpClient: AxiosInstance;
4
+ constructor(httpClient: AxiosInstance);
5
+ get(url: string, config?: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
6
+ post(url: string, data?: any, config?: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
7
+ put(url: string, data?: any, config?: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
8
+ delete(url: string, config?: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
9
+ }
@@ -0,0 +1,45 @@
1
+ var BaseService = (function () {
2
+ function BaseService(httpClient) {
3
+ Object.defineProperty(this, "httpClient", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: void 0
8
+ });
9
+ this.httpClient = httpClient;
10
+ }
11
+ Object.defineProperty(BaseService.prototype, "get", {
12
+ enumerable: false,
13
+ configurable: true,
14
+ writable: true,
15
+ value: function (url, config) {
16
+ return this.httpClient.get(url, config);
17
+ }
18
+ });
19
+ Object.defineProperty(BaseService.prototype, "post", {
20
+ enumerable: false,
21
+ configurable: true,
22
+ writable: true,
23
+ value: function (url, data, config) {
24
+ return this.httpClient.post(url, data, config);
25
+ }
26
+ });
27
+ Object.defineProperty(BaseService.prototype, "put", {
28
+ enumerable: false,
29
+ configurable: true,
30
+ writable: true,
31
+ value: function (url, data, config) {
32
+ return this.httpClient.put(url, data, config);
33
+ }
34
+ });
35
+ Object.defineProperty(BaseService.prototype, "delete", {
36
+ enumerable: false,
37
+ configurable: true,
38
+ writable: true,
39
+ value: function (url, config) {
40
+ return this.httpClient.delete(url, config);
41
+ }
42
+ });
43
+ return BaseService;
44
+ }());
45
+ export default BaseService;
@@ -0,0 +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.staging.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.beta.tap.company/v2/checkout";
5
+ export declare const MW_BASE_SANDBOX_URL = "https://mw-sdk.sandbox.tap.company/v2/checkout";
6
+ declare const httpClient: import("axios").AxiosInstance;
7
+ export declare const setAxiosGlobalHeaders: (headers: Record<string, string>) => void;
8
+ export default httpClient;
@@ -0,0 +1,33 @@
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 axios from 'axios';
13
+ export var MW_BASE_LIVE_URL = 'https://mw-sdk.tap.company/v2/checkout';
14
+ export var MW_BASE_STAGING_URL = 'https://mw-sdk.staging.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.beta.tap.company/v2/checkout';
17
+ export var MW_BASE_SANDBOX_URL = 'https://mw-sdk.sandbox.tap.company/v2/checkout';
18
+ var httpClient = axios.create({
19
+ headers: {
20
+ 'Content-Type': 'application/json',
21
+ Accept: 'application/json'
22
+ }
23
+ });
24
+ httpClient.interceptors.request.use(function (config) {
25
+ return config;
26
+ });
27
+ httpClient.interceptors.response.use(function (response) {
28
+ return response;
29
+ });
30
+ export var setAxiosGlobalHeaders = function (headers) {
31
+ httpClient.defaults.headers.common = __assign(__assign({}, httpClient.defaults.headers.common), headers);
32
+ };
33
+ export default httpClient;