@tap-payments/apple-pay-button 0.0.53-development → 0.0.54-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.
@@ -132,6 +132,7 @@ export interface PaymentOptionsResponse {
132
132
  country: string;
133
133
  currency: string;
134
134
  payment_methods: PaymentMethod[];
135
+ [other: string]: any;
135
136
  }
136
137
  export interface MetaData {
137
138
  merchant: MerchantResponse;
@@ -182,7 +183,7 @@ export interface ChargeRequestBody {
182
183
  currency: string;
183
184
  selected_amount?: string;
184
185
  selected_currency?: string;
185
- product: 'Google-Pay-Button';
186
+ product: string;
186
187
  threeDSecure?: boolean;
187
188
  save_card: boolean;
188
189
  fee: number;
@@ -223,6 +224,8 @@ export interface ChargeRequestBody {
223
224
  transaction?: string;
224
225
  };
225
226
  description?: string;
227
+ }
228
+ export interface AuthorizeRequestBody extends ChargeRequestBody {
226
229
  auto?: {
227
230
  type: string;
228
231
  time: number;
@@ -1,4 +1,4 @@
1
- import { MerchantResponse, ApplePayButtonProps, CheckoutProfileRequest } from '../@types';
1
+ import { MerchantResponse, ApplePayButtonProps, CheckoutProfileRequest, ChargeRequestBody, AuthorizeRequestBody } from '../@types';
2
2
  import BaseService from './base';
3
3
  declare class APPService extends BaseService {
4
4
  private baseUrl;
@@ -20,6 +20,8 @@ declare class APPService extends BaseService {
20
20
  }>;
21
21
  appleSession(merchant: Pick<MerchantResponse, 'name' | 'id'>, validationURL: string, merchantRegisteredDomain: string): Promise<any>;
22
22
  tapTokenization(applePaymentData: Record<string, string>): Promise<any>;
23
+ createCharge(request: ChargeRequestBody): Promise<any>;
24
+ createAuthorize(request: AuthorizeRequestBody): Promise<any>;
23
25
  }
24
26
  declare const appService: APPService;
25
27
  export default appService;
@@ -268,6 +268,46 @@ var APPService = (function (_super) {
268
268
  });
269
269
  }
270
270
  });
271
+ Object.defineProperty(APPService.prototype, "createCharge", {
272
+ enumerable: false,
273
+ configurable: true,
274
+ writable: true,
275
+ value: function (request) {
276
+ return __awaiter(this, void 0, void 0, function () {
277
+ var data;
278
+ return __generator(this, function (_a) {
279
+ switch (_a.label) {
280
+ case 0: return [4, this.post(this.baseUrl + '/charge', request)];
281
+ case 1:
282
+ data = (_a.sent()).data;
283
+ if (data.errors)
284
+ throw data;
285
+ return [2, data];
286
+ }
287
+ });
288
+ });
289
+ }
290
+ });
291
+ Object.defineProperty(APPService.prototype, "createAuthorize", {
292
+ enumerable: false,
293
+ configurable: true,
294
+ writable: true,
295
+ value: function (request) {
296
+ return __awaiter(this, void 0, void 0, function () {
297
+ var data;
298
+ return __generator(this, function (_a) {
299
+ switch (_a.label) {
300
+ case 0: return [4, this.post(this.baseUrl + '/authorize', request)];
301
+ case 1:
302
+ data = (_a.sent()).data;
303
+ if (data.errors)
304
+ throw data;
305
+ return [2, data];
306
+ }
307
+ });
308
+ });
309
+ }
310
+ });
271
311
  return APPService;
272
312
  }(BaseService));
273
313
  var appService = new APPService();
@@ -7,5 +7,5 @@ interface UseApplePayReturnProps {
7
7
  applePayRequestData?: ApplePayRequestData;
8
8
  applePayRequestConfiguration?: Omit<ApplePayDataToLunchSDKFromMerchantSide, 'applePayRequestData'>;
9
9
  }
10
- export declare const useApplePay: ({ environment, interface: interfaceObj, merchant, customer, acceptance, scope, debug, onError, onSuccess, onCancel, onReady, metaData, headers, operator, order, onOrderCreated, integration }: UseApplePayProps) => UseApplePayReturnProps;
10
+ export declare const useApplePay: ({ environment, interface: interfaceObj, merchant, customer, acceptance, scope, debug, onError, onSuccess, onCancel, onReady, metaData, headers, operator, order, onOrderCreated, integration, transaction, post, redirect }: UseApplePayProps) => UseApplePayReturnProps;
11
11
  export {};
@@ -52,13 +52,26 @@ import { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api/httpClient'
52
52
  import { prepareApplePayRequest } from '../utils/config';
53
53
  import { useMerchantApplePay } from './useMerchantApplePay';
54
54
  export var useApplePay = function (_a) {
55
- var environment = _a.environment, interfaceObj = _a.interface, merchant = _a.merchant, customer = _a.customer, acceptance = _a.acceptance, scope = _a.scope, debug = _a.debug, onError = _a.onError, onSuccess = _a.onSuccess, onCancel = _a.onCancel, onReady = _a.onReady, metaData = _a.metaData, headers = _a.headers, operator = _a.operator, order = _a.order, onOrderCreated = _a.onOrderCreated, integration = _a.integration;
55
+ var environment = _a.environment, interfaceObj = _a.interface, merchant = _a.merchant, customer = _a.customer, acceptance = _a.acceptance, scope = _a.scope, debug = _a.debug, onError = _a.onError, onSuccess = _a.onSuccess, onCancel = _a.onCancel, onReady = _a.onReady, metaData = _a.metaData, headers = _a.headers, operator = _a.operator, order = _a.order, onOrderCreated = _a.onOrderCreated, integration = _a.integration, transaction = _a.transaction, post = _a.post, redirect = _a.redirect;
56
56
  var _b = useState(false), loading = _b[0], setLoading = _b[1];
57
57
  var _c = useState(), profileData = _c[0], setProfile = _c[1];
58
58
  var _d = useState(false), disabled = _d[0], setDisabled = _d[1];
59
59
  var _e = useState(), applePayRequestData = _e[0], setApplePayRequestData = _e[1];
60
60
  var _f = useState(), applePayRequestConfiguration = _f[0], setApplePayRequestConfiguration = _f[1];
61
- useMerchantApplePay({ isIframeIntegration: integration === 'iframe', onError: onError, onSuccess: onSuccess, scope: scope });
61
+ useMerchantApplePay({
62
+ isIframeIntegration: integration === 'iframe',
63
+ onError: onError,
64
+ onSuccess: onSuccess,
65
+ scope: scope,
66
+ profileData: profileData,
67
+ merchant: merchant,
68
+ order: order,
69
+ customer: customer,
70
+ transaction: transaction,
71
+ operator: operator,
72
+ post: post,
73
+ redirect: redirect
74
+ });
62
75
  var initialize = function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
63
76
  var merchantProfile, payment_options, headers_1, data, err_1;
64
77
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
@@ -78,7 +91,7 @@ export var useApplePay = function (_a) {
78
91
  return [2];
79
92
  }
80
93
  if (!headers) return [3, 3];
81
- return [4, appService.setHttpHeaders(__assign(__assign({}, headers), { pk: operator.publicKey }))];
94
+ return [4, appService.setHttpHeaders(__assign(__assign({}, headers), { authorization: operator.publicKey }))];
82
95
  case 2:
83
96
  _m.sent();
84
97
  return [3, 5];
@@ -1,9 +1,18 @@
1
1
  import { Scope } from '../constants';
2
+ import { MetaData, ApplePayButtonProps } from '../@types';
2
3
  interface ApplePayRequestData {
3
4
  isIframeIntegration: boolean;
4
5
  onError?: (error: any) => void;
5
6
  onSuccess?: (data: Record<string, any>) => void;
6
7
  scope: typeof Scope[keyof typeof Scope];
8
+ profileData?: Pick<MetaData, 'merchant' | 'payment_options'>;
9
+ merchant: Pick<MetaData['merchant'], 'id'>;
10
+ order: ApplePayButtonProps['order'];
11
+ customer: ApplePayButtonProps['customer'];
12
+ transaction: ApplePayButtonProps['transaction'];
13
+ operator: ApplePayButtonProps['operator'];
14
+ redirect?: ApplePayButtonProps['redirect'];
15
+ post?: ApplePayButtonProps['post'];
7
16
  }
8
- export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, scope }: ApplePayRequestData) => void;
17
+ export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, scope, profileData, order, customer, transaction, operator, redirect, post }: ApplePayRequestData) => void;
9
18
  export {};
@@ -39,53 +39,105 @@ import { Scope } from '../constants';
39
39
  import appService from '../api/app.service';
40
40
  var EVENT_NAME = 'TAP_BUTTON::APPLE_PAY_ON_PAYMENT_AUTHORIZED';
41
41
  export var useMerchantApplePay = function (_a) {
42
- var isIframeIntegration = _a.isIframeIntegration, onError = _a.onError, onSuccess = _a.onSuccess, scope = _a.scope;
42
+ var isIframeIntegration = _a.isIframeIntegration, onError = _a.onError, onSuccess = _a.onSuccess, scope = _a.scope, profileData = _a.profileData, order = _a.order, customer = _a.customer, transaction = _a.transaction, operator = _a.operator, redirect = _a.redirect, post = _a.post;
43
43
  var onMessageReceived = function (_a) {
44
44
  var message = _a.data;
45
45
  return __awaiter(void 0, void 0, void 0, function () {
46
- var _b, event, data, _c, response, e_1;
47
- var _d;
48
- return __generator(this, function (_e) {
49
- switch (_e.label) {
46
+ var _b, event, data, _c, response, tokenId, supportCurrency, transactionRequest, transactionResponse, _d, e_1;
47
+ var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
48
+ return __generator(this, function (_w) {
49
+ switch (_w.label) {
50
50
  case 0:
51
51
  _b = message !== null && message !== void 0 ? message : {}, event = _b.event, data = _b.data;
52
52
  if (!data || event !== EVENT_NAME)
53
53
  return [2];
54
- _e.label = 1;
54
+ _w.label = 1;
55
55
  case 1:
56
- _e.trys.push([1, 9, , 10]);
56
+ _w.trys.push([1, 13, , 14]);
57
57
  _c = scope;
58
58
  switch (_c) {
59
59
  case Scope.APPLE_PAY_TOKEN: return [3, 2];
60
60
  case Scope.TAP_TOKEN: return [3, 3];
61
61
  case Scope.AUTHORIZE: return [3, 5];
62
- case Scope.CHARGE: return [3, 6];
62
+ case Scope.CHARGE: return [3, 5];
63
63
  }
64
- return [3, 7];
64
+ return [3, 11];
65
65
  case 2:
66
66
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
67
- return [3, 8];
67
+ return [3, 12];
68
68
  case 3: return [4, appService.tapTokenization(data)];
69
69
  case 4:
70
- response = _e.sent();
70
+ response = _w.sent();
71
71
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
72
- return [3, 8];
73
- case 5: return [3, 8];
74
- case 6: return [3, 8];
72
+ return [3, 12];
73
+ case 5: return [4, appService.tapTokenization(data)];
74
+ case 6:
75
+ tokenId = (_w.sent()).id;
76
+ supportCurrency = ((_f = (_e = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _e === void 0 ? void 0 : _e.supported_currencies) !== null && _f !== void 0 ? _f : [])[0];
77
+ transactionRequest = {
78
+ auto: (_g = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _g === void 0 ? void 0 : _g.auto,
79
+ amount: order.amount,
80
+ currency: order.currency,
81
+ selected_amount: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.amount,
82
+ selected_currency: supportCurrency === null || supportCurrency === void 0 ? void 0 : supportCurrency.currency,
83
+ customer: (customer === null || customer === void 0 ? void 0 : customer.id)
84
+ ? { id: customer === null || customer === void 0 ? void 0 : customer.id }
85
+ : {
86
+ email: (_h = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _h === void 0 ? void 0 : _h.email,
87
+ first_name: ((_j = customer === null || customer === void 0 ? void 0 : customer.name) === null || _j === void 0 ? void 0 : _j.length) ? customer.name[0].first : '',
88
+ last_name: ((_k = customer === null || customer === void 0 ? void 0 : customer.name) === null || _k === void 0 ? void 0 : _k.length) ? customer.name[0].last : '',
89
+ phone: {
90
+ country_code: (_o = (_m = (_l = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _l === void 0 ? void 0 : _l.phone) === null || _m === void 0 ? void 0 : _m.countryCode) !== null && _o !== void 0 ? _o : '',
91
+ number: (_r = (_q = (_p = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _p === void 0 ? void 0 : _p.phone) === null || _q === void 0 ? void 0 : _q.number) !== null && _r !== void 0 ? _r : ''
92
+ }
93
+ },
94
+ fee: 0,
95
+ merchant: {
96
+ id: (_t = (_s = profileData === null || profileData === void 0 ? void 0 : profileData.merchant) === null || _s === void 0 ? void 0 : _s.id) !== null && _t !== void 0 ? _t : ''
97
+ },
98
+ order: (_u = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _u === void 0 ? void 0 : _u.order,
99
+ product: 'Apple-Pay-Button',
100
+ save_card: false,
101
+ source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
102
+ threeDSecure: transaction === null || transaction === void 0 ? void 0 : transaction.authentication,
103
+ hashstring: operator.hashstring,
104
+ redirect: redirect,
105
+ metadata: transaction === null || transaction === void 0 ? void 0 : transaction.metadata,
106
+ post: post,
107
+ payment_agreement: transaction === null || transaction === void 0 ? void 0 : transaction.paymentAgreement,
108
+ destinations: transaction === null || transaction === void 0 ? void 0 : transaction.destinations,
109
+ reference: {
110
+ order: order === null || order === void 0 ? void 0 : order.reference,
111
+ transaction: transaction === null || transaction === void 0 ? void 0 : transaction.reference
112
+ }
113
+ };
114
+ if (!(scope === Scope.AUTHORIZE)) return [3, 8];
115
+ return [4, appService.createAuthorize(transactionRequest)];
75
116
  case 7:
117
+ _d = _w.sent();
118
+ return [3, 10];
119
+ case 8: return [4, appService.createCharge(transactionRequest)];
120
+ case 9:
121
+ _d = _w.sent();
122
+ _w.label = 10;
123
+ case 10:
124
+ transactionResponse = _d;
125
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionResponse);
126
+ return [3, 12];
127
+ case 11:
76
128
  console.error("We only support: ".concat(Object.values(Scope).join(', '), " for now"));
77
129
  onError === null || onError === void 0 ? void 0 : onError({ message: "We only support: ".concat(Object.values(Scope).join(', '), " for now"), code: '400' });
78
- return [3, 8];
79
- case 8: return [3, 10];
80
- case 9:
81
- e_1 = _e.sent();
130
+ return [3, 12];
131
+ case 12: return [3, 14];
132
+ case 13:
133
+ e_1 = _w.sent();
82
134
  if (!onError)
83
135
  return [2];
84
136
  if (e_1.errors) {
85
137
  onError(e_1.errors);
86
138
  return [2];
87
139
  }
88
- if ((_d = e_1.response) === null || _d === void 0 ? void 0 : _d.data.errors) {
140
+ if ((_v = e_1.response) === null || _v === void 0 ? void 0 : _v.data.errors) {
89
141
  onError(e_1.response.data.errors);
90
142
  return [2];
91
143
  }
@@ -94,8 +146,8 @@ export var useMerchantApplePay = function (_a) {
94
146
  return [2];
95
147
  }
96
148
  onError(e_1);
97
- return [3, 10];
98
- case 10: return [2];
149
+ return [3, 14];
150
+ case 14: return [2];
99
151
  }
100
152
  });
101
153
  });
@@ -105,5 +157,5 @@ export var useMerchantApplePay = function (_a) {
105
157
  return;
106
158
  window.addEventListener('message', onMessageReceived);
107
159
  return function () { return window.removeEventListener('message', onMessageReceived); };
108
- }, []);
160
+ }, [isIframeIntegration]);
109
161
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "0.0.53-development",
3
+ "version": "0.0.54-development",
4
4
  "description": "Apple Pay Button React Component",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",