@tap-payments/apple-pay-button 0.0.39-development → 0.0.41-development

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,14 @@ export interface ApplePayRequestData {
15
15
  amount: number;
16
16
  };
17
17
  }
18
+ export interface ApplePayDataToLunchSDKFromMerchantSide {
19
+ headers: Record<string, any>;
20
+ BASE_URL: string;
21
+ merchant: Record<string, string>;
22
+ applePayRequestData: ApplePayRequestData;
23
+ debug?: boolean;
24
+ applePaySDKVersion?: number;
25
+ }
18
26
  export interface Interface {
19
27
  locale?: typeof Locale[keyof typeof Locale];
20
28
  theme?: typeof ThemeMode[keyof typeof ThemeMode];
@@ -94,7 +102,7 @@ export interface ApplePayButtonProps {
94
102
  onCancel?: () => void;
95
103
  onError?: (error: any) => void;
96
104
  onSuccess?: (data: Record<string, any>) => void;
97
- onClick?: (data?: ApplePayRequestData) => void;
105
+ onClick?: (data?: ApplePayDataToLunchSDKFromMerchantSide) => void;
98
106
  onReady?: () => void;
99
107
  metaData?: MetaData;
100
108
  debug?: boolean;
@@ -7,6 +7,7 @@ declare class APPService extends BaseService {
7
7
  setEnv(env: ApplePayButtonProps['environment']): void;
8
8
  setBaseUrl(): void;
9
9
  getHeaderPublicKey(): "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8AX++RtxPZFtns4XzXFlDIxPBh0umN4qRXZaKDIlb6a3MknaB7psJWmf2l+e4Cfh9b5tey/+rZqpQ065eXTZfGCAuBLt+fYLQBhLfjRpk8S6hlIzc1Kdjg65uqzMwcTd0p7I4KLwHk1I0oXzuEu53fU1LSZhWp4Mnd6wjVgXAsQIDAQAB\n-----END PUBLIC KEY-----" | "" | "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hSRms7Ir1HmzdZxGXFYgmpi3\nez7VBFje0f8wwrxYS9oVoBtN4iAt0DOs3DbeuqtueI31wtpFVUMGg8W7R0SbtkZd\nGzszQNqt/wyqxpDC9q+97XdXwkWQFA72s76ud7eMXQlsWKsvgwhY+Ywzt0KlpNC3\nHj+N6UWFOYK98Xi+sQIDAQAB\n-----END PUBLIC KEY-----" | "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCi9W5jyTvA4Iwv3V5sfNQ7VdSz\n7WqwBbnWFbIUL/GjaaE93mvDv4zbgRSznHaHQPH6pxrMhMh0tV58njkvjHvQ/tvg\npwM8SemNPKEEAPl69tnMvCrJRPh2dWL3OHY8yCW4c38Hyx4fy56Zd5cdoVWfCReu\njCsvASLGz+cfRrj2swIDAQAB\n-----END PUBLIC KEY-----";
10
+ getBaseUrl(): string;
10
11
  setHttpHeaders(headers: Record<string, string>): Promise<void>;
11
12
  setBrowserHeaders({ locale, pk, domain }: {
12
13
  locale: string;
@@ -16,6 +17,9 @@ declare class APPService extends BaseService {
16
17
  checkoutProfile(request: CheckoutProfileRequest): Promise<{
17
18
  merchant: any;
18
19
  payment_options: any;
20
+ headers: import("axios").AxiosResponseHeaders | Partial<Record<string, string> & {
21
+ "set-cookie"?: string[] | undefined;
22
+ }>;
19
23
  }>;
20
24
  appleSession(merchant: Pick<MerchantResponse, 'name' | 'id'>, validationURL: string, merchantRegisteredDomain: string): Promise<any>;
21
25
  tapTokenization(applePaymentData: Record<string, string>): Promise<any>;
@@ -140,6 +140,14 @@ var APPService = (function (_super) {
140
140
  }
141
141
  }
142
142
  });
143
+ Object.defineProperty(APPService.prototype, "getBaseUrl", {
144
+ enumerable: false,
145
+ configurable: true,
146
+ writable: true,
147
+ value: function () {
148
+ return this.baseUrl;
149
+ }
150
+ });
143
151
  Object.defineProperty(APPService.prototype, "setHttpHeaders", {
144
152
  enumerable: false,
145
153
  configurable: true,
@@ -191,17 +199,17 @@ var APPService = (function (_super) {
191
199
  writable: true,
192
200
  value: function (request) {
193
201
  return __awaiter(this, void 0, void 0, function () {
194
- var data, merchant, payment_options, session;
195
- return __generator(this, function (_a) {
196
- switch (_a.label) {
202
+ var _a, data, headers, merchant, payment_options, session;
203
+ return __generator(this, function (_b) {
204
+ switch (_b.label) {
197
205
  case 0: return [4, this.post(this.baseUrl + '/checkoutprofile', request)];
198
206
  case 1:
199
- data = (_a.sent()).data;
207
+ _a = _b.sent(), data = _a.data, headers = _a.headers;
200
208
  if (data.errors)
201
209
  throw data;
202
210
  merchant = data.merchant, payment_options = data.payment_options, session = data.session;
203
211
  setAxiosGlobalHeaders({ session: session });
204
- return [2, { merchant: merchant, payment_options: payment_options }];
212
+ return [2, { merchant: merchant, payment_options: payment_options, headers: headers }];
205
213
  }
206
214
  });
207
215
  });
@@ -19,7 +19,7 @@ import { ButtonStyle, Edges, ThemeMode } from '../../constants';
19
19
  import './ApplePayButton.css';
20
20
  var ApplePay = React.memo(function (props) {
21
21
  var mappedProps = getDefaultValues(props);
22
- var _a = useApplePay(mappedProps), loading = _a.loading, onApplePayButtonClicked = _a.onApplePayButtonClicked, disabled = _a.disabled, applePayRequestData = _a.applePayRequestData;
22
+ var _a = useApplePay(mappedProps), loading = _a.loading, onApplePayButtonClicked = _a.onApplePayButtonClicked, disabled = _a.disabled, applePayRequestData = _a.applePayRequestData, applePayRequestConfiguration = _a.applePayRequestConfiguration;
23
23
  var isMerchantIntegration = props.integration === 'merchant';
24
24
  React.useEffect(function () {
25
25
  if (props.debug) {
@@ -33,7 +33,7 @@ var ApplePay = React.memo(function (props) {
33
33
  }, onClick: function () {
34
34
  var _a, _b;
35
35
  if (isMerchantIntegration) {
36
- (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, applePayRequestData);
36
+ (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, __assign(__assign({}, applePayRequestConfiguration), { applePayRequestData: applePayRequestData }));
37
37
  return;
38
38
  }
39
39
  onApplePayButtonClicked();
@@ -1,10 +1,11 @@
1
- import { ApplePayButtonProps, ApplePayRequestData } from '../@types';
1
+ import { ApplePayButtonProps, ApplePayDataToLunchSDKFromMerchantSide, ApplePayRequestData } from '../@types';
2
2
  declare type UseApplePayProps = Omit<ApplePayButtonProps, 'buttonStyle'>;
3
3
  interface UseApplePayReturnProps {
4
4
  loading: boolean;
5
5
  onApplePayButtonClicked: () => Promise<void>;
6
6
  disabled: boolean;
7
7
  applePayRequestData?: ApplePayRequestData;
8
+ applePayRequestConfiguration?: Omit<ApplePayDataToLunchSDKFromMerchantSide, 'applePayRequestData'>;
8
9
  }
9
10
  export declare const useApplePay: ({ environment, interface: interfaceObj, merchant, customer, acceptance, scope, debug, onError, onSuccess, onCancel, onReady, metaData, headers, operator, order, onOrderCreated }: UseApplePayProps) => UseApplePayReturnProps;
10
11
  export {};
@@ -45,6 +45,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
+ var __rest = (this && this.__rest) || function (s, e) {
49
+ var t = {};
50
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
+ t[p] = s[p];
52
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
+ t[p[i]] = s[p[i]];
56
+ }
57
+ return t;
58
+ };
48
59
  import { useCallback, useEffect, useState } from 'react';
49
60
  import appService from '../api/app.service';
50
61
  import { ApplePayVersion, Scope } from '../constants';
@@ -57,6 +68,7 @@ export var useApplePay = function (_a) {
57
68
  var _c = useState(), profileData = _c[0], setProfile = _c[1];
58
69
  var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
59
70
  var _e = useState(), applePayRequestData = _e[0], setApplePayRequestData = _e[1];
71
+ var _f = useState(), applePayRequestConfiguration = _f[0], setApplePayRequestConfiguration = _f[1];
60
72
  var prepareApplePayRequest = function (_a) {
61
73
  var payment_options = _a.payment_options, merchant = _a.merchant;
62
74
  var paymentMethod = getApplePayPaymentMethod(payment_options.payment_methods || []);
@@ -72,17 +84,18 @@ export var useApplePay = function (_a) {
72
84
  setApplePayRequestData(request);
73
85
  };
74
86
  var initialize = useCallback(function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
75
- var merchantProfile, payment_options, headers_1, data, err_1;
76
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
77
- return __generator(this, function (_m) {
78
- switch (_m.label) {
87
+ var merchantProfile, payment_options, headers_1, _a, httpHeaders, data, err_1;
88
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
89
+ return __generator(this, function (_o) {
90
+ switch (_o.label) {
79
91
  case 0:
92
+ console.log('environment, interfaceObj?.locale, order, customer, merchant, scope', environment, interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale, order, customer, merchant, scope);
80
93
  setLoading(true);
81
94
  appService.setEnv(environment);
82
95
  appService.setBaseUrl();
83
- _m.label = 1;
96
+ _o.label = 1;
84
97
  case 1:
85
- _m.trys.push([1, 7, 8, 9]);
98
+ _o.trys.push([1, 7, 8, 9]);
86
99
  if (metaData) {
87
100
  merchantProfile = metaData.merchant, payment_options = metaData.payment_options, headers_1 = metaData.headers;
88
101
  setAxiosGlobalHeaders(__assign({}, headers_1));
@@ -92,7 +105,7 @@ export var useApplePay = function (_a) {
92
105
  if (!headers) return [3, 3];
93
106
  return [4, appService.setHttpHeaders(__assign(__assign({}, headers), { pk: operator.publicKey }))];
94
107
  case 2:
95
- _m.sent();
108
+ _o.sent();
96
109
  return [3, 5];
97
110
  case 3: return [4, appService.setBrowserHeaders({
98
111
  locale: interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale,
@@ -100,8 +113,8 @@ export var useApplePay = function (_a) {
100
113
  pk: operator.publicKey
101
114
  })];
102
115
  case 4:
103
- _m.sent();
104
- _m.label = 5;
116
+ _o.sent();
117
+ _o.label = 5;
105
118
  case 5: return [4, appService.checkoutProfile({
106
119
  supported_payment_methods: ['APPLE_PAY'],
107
120
  supported_currencies: [order.currency],
@@ -112,12 +125,12 @@ export var useApplePay = function (_a) {
112
125
  order: __assign(__assign({ id: order === null || order === void 0 ? void 0 : order.id, amount: Number(order.amount), currency: order.currency, description: order === null || order === void 0 ? void 0 : order.description, metadata: order === null || order === void 0 ? void 0 : order.metadata }, (customer && {
113
126
  customer: {
114
127
  id: customer === null || customer === void 0 ? void 0 : customer.id,
115
- email: (_a = customer.contact) === null || _a === void 0 ? void 0 : _a.email,
116
- first_name: ((_b = customer.name) === null || _b === void 0 ? void 0 : _b.length) ? customer.name[0].first : '',
117
- last_name: ((_c = customer.name) === null || _c === void 0 ? void 0 : _c.length) ? customer.name[0].last : '',
128
+ email: (_b = customer.contact) === null || _b === void 0 ? void 0 : _b.email,
129
+ first_name: ((_c = customer.name) === null || _c === void 0 ? void 0 : _c.length) ? customer.name[0].first : '',
130
+ last_name: ((_d = customer.name) === null || _d === void 0 ? void 0 : _d.length) ? customer.name[0].last : '',
118
131
  phone: {
119
- country_code: (_f = (_e = (_d = customer.contact) === null || _d === void 0 ? void 0 : _d.phone) === null || _e === void 0 ? void 0 : _e.countryCode) !== null && _f !== void 0 ? _f : '',
120
- number: (_j = (_h = (_g = customer.contact) === null || _g === void 0 ? void 0 : _g.phone) === null || _h === void 0 ? void 0 : _h.number) !== null && _j !== void 0 ? _j : ''
132
+ country_code: (_g = (_f = (_e = customer.contact) === null || _e === void 0 ? void 0 : _e.phone) === null || _f === void 0 ? void 0 : _f.countryCode) !== null && _g !== void 0 ? _g : '',
133
+ number: (_k = (_j = (_h = customer.contact) === null || _h === void 0 ? void 0 : _h.phone) === null || _j === void 0 ? void 0 : _j.number) !== null && _k !== void 0 ? _k : ''
121
134
  }
122
135
  }
123
136
  })), { merchant: {
@@ -133,15 +146,20 @@ export var useApplePay = function (_a) {
133
146
  ] })
134
147
  })];
135
148
  case 6:
136
- data = _m.sent();
149
+ _a = _o.sent(), httpHeaders = _a.headers, data = __rest(_a, ["headers"]);
137
150
  if (debug)
138
151
  console.log('merchant configuration: ', data);
139
152
  setProfile(data);
140
153
  prepareApplePayRequest(data);
141
- onOrderCreated === null || onOrderCreated === void 0 ? void 0 : onOrderCreated((_l = (_k = data.payment_options) === null || _k === void 0 ? void 0 : _k.order) === null || _l === void 0 ? void 0 : _l.id);
154
+ onOrderCreated === null || onOrderCreated === void 0 ? void 0 : onOrderCreated((_m = (_l = data.payment_options) === null || _l === void 0 ? void 0 : _l.order) === null || _m === void 0 ? void 0 : _m.id);
155
+ setApplePayRequestConfiguration({
156
+ BASE_URL: appService.getBaseUrl(),
157
+ headers: httpHeaders,
158
+ merchant: data.merchant
159
+ });
142
160
  return [3, 9];
143
161
  case 7:
144
- err_1 = _m.sent();
162
+ err_1 = _o.sent();
145
163
  onError === null || onError === void 0 ? void 0 : onError(err_1.errors || err_1);
146
164
  return [3, 9];
147
165
  case 8:
@@ -151,7 +169,7 @@ export var useApplePay = function (_a) {
151
169
  case 9: return [2];
152
170
  }
153
171
  });
154
- }); }, [environment, interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale, order, customer, merchant, scope, debug, onError, onReady, onOrderCreated]);
172
+ }); }, [environment, interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.locale, order, customer, merchant, scope]);
155
173
  useEffect(function () {
156
174
  initialize(metaData);
157
175
  }, [initialize, metaData]);
@@ -301,6 +319,7 @@ export var useApplePay = function (_a) {
301
319
  loading: loading,
302
320
  onApplePayButtonClicked: onApplePayButtonClicked,
303
321
  disabled: !profileData || disabled || !applePayRequestData,
304
- applePayRequestData: applePayRequestData
322
+ applePayRequestData: applePayRequestData,
323
+ applePayRequestConfiguration: applePayRequestConfiguration
305
324
  };
306
325
  };
@@ -1,4 +1,4 @@
1
- import { ApplePayRequestData, ApplePayButtonProps } from '../@types';
1
+ import { ApplePayButtonProps } from '../@types';
2
2
  export declare const getDefaultValues: (mainObject: ApplePayButtonProps) => {
3
3
  interface: {
4
4
  locale?: "en" | "ar" | "dynamic" | undefined;
@@ -56,7 +56,7 @@ export declare const getDefaultValues: (mainObject: ApplePayButtonProps) => {
56
56
  onCancel?: (() => void) | undefined;
57
57
  onError?: ((error: any) => void) | undefined;
58
58
  onSuccess?: ((data: Record<string, any>) => void) | undefined;
59
- onClick?: ((data?: ApplePayRequestData | undefined) => void) | undefined;
59
+ onClick?: ((data?: import("../@types").ApplePayDataToLunchSDKFromMerchantSide | undefined) => void) | undefined;
60
60
  onReady?: (() => void) | undefined;
61
61
  metaData?: import("../@types").MetaData | undefined;
62
62
  debug?: boolean | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "0.0.39-development",
3
+ "version": "0.0.41-development",
4
4
  "description": "Apple Pay Button React Component",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",