@tap-payments/apple-pay-button 0.0.52-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 }: 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 {};
@@ -49,33 +49,29 @@ import { useEffect, useState } from 'react';
49
49
  import appService from '../api/app.service';
50
50
  import { ApplePayVersion, Scope } from '../constants';
51
51
  import { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api/httpClient';
52
- import { getApplePayPaymentMethod, getApplePayRequest, validateSupportedNetworks } from '../utils/config';
53
- import { getMerchantCapabilities } from '../utils/defaultValues';
52
+ import { prepareApplePayRequest } from '../utils/config';
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;
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
- var prepareApplePayRequest = function (_a) {
62
- var payment_options = _a.payment_options, merchant = _a.merchant;
63
- var paymentMethod = getApplePayPaymentMethod(payment_options.payment_methods || []);
64
- if (debug)
65
- console.log('payment method: ', paymentMethod);
66
- var supportedNetworks = validateSupportedNetworks(paymentMethod.supported_card_brands, acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedSchemes);
67
- var request = getApplePayRequest({
68
- countryCode: merchant.country_code,
69
- order: order,
70
- customer: customer,
71
- supportedNetworks: supportedNetworks,
72
- merchantCapabilities: getMerchantCapabilities(acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedFundSource),
73
- name: merchant.name
74
- });
75
- if (debug)
76
- console.log('apple pay request data: ', request);
77
- setApplePayRequestData(request);
78
- };
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
+ });
79
75
  var initialize = function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
80
76
  var merchantProfile, payment_options, headers_1, data, err_1;
81
77
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
@@ -95,7 +91,7 @@ export var useApplePay = function (_a) {
95
91
  return [2];
96
92
  }
97
93
  if (!headers) return [3, 3];
98
- return [4, appService.setHttpHeaders(__assign(__assign({}, headers), { pk: operator.publicKey }))];
94
+ return [4, appService.setHttpHeaders(__assign(__assign({}, headers), { authorization: operator.publicKey }))];
99
95
  case 2:
100
96
  _m.sent();
101
97
  return [3, 5];
@@ -142,7 +138,7 @@ export var useApplePay = function (_a) {
142
138
  if (debug)
143
139
  console.log('merchant configuration: ', data);
144
140
  setProfile(data);
145
- prepareApplePayRequest(data);
141
+ setApplePayRequestData(prepareApplePayRequest(__assign(__assign({}, data), { order: order, acceptance: acceptance, customer: customer })));
146
142
  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);
147
143
  setApplePayRequestConfiguration({
148
144
  BASE_URL: appService.getBaseUrl(),
@@ -237,47 +233,39 @@ export var useApplePay = function (_a) {
237
233
  console.info('onpaymentauthorized event', event);
238
234
  _b.label = 1;
239
235
  case 1:
240
- _b.trys.push([1, 9, 10, 11]);
236
+ _b.trys.push([1, 7, 8, 9]);
241
237
  _a = scope;
242
238
  switch (_a) {
243
239
  case Scope.APPLE_PAY_TOKEN: return [3, 2];
244
240
  case Scope.TAP_TOKEN: return [3, 3];
245
- case Scope.CHARGE: return [3, 5];
246
- case Scope.AUTHORIZE: return [3, 6];
247
241
  }
248
- return [3, 7];
242
+ return [3, 5];
249
243
  case 2:
250
244
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(event.payment.token.paymentData);
251
245
  session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
252
- return [3, 8];
246
+ return [3, 6];
253
247
  case 3: return [4, appService.tapTokenization(event.payment.token.paymentData)];
254
248
  case 4:
255
249
  data = _b.sent();
256
250
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
257
251
  session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
258
- return [3, 8];
252
+ return [3, 6];
259
253
  case 5:
260
- session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
261
- return [3, 8];
262
- case 6:
263
- session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
264
- return [3, 8];
265
- case 7:
266
254
  console.error('We only support AppleToken and TapToken for now');
267
255
  console.info('Completing payment with status: STATUS_FAILURE');
268
256
  session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
269
- _b.label = 8;
270
- case 8: return [3, 11];
271
- case 9:
257
+ _b.label = 6;
258
+ case 6: return [3, 9];
259
+ case 7:
272
260
  error_2 = _b.sent();
273
261
  if (debug)
274
262
  console.error('error in onpaymentauthorized', error_2);
275
263
  session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
276
264
  throw error_2;
277
- case 10:
265
+ case 8:
278
266
  setLoading(false);
279
267
  return [7];
280
- case 11: return [2];
268
+ case 9: return [2];
281
269
  }
282
270
  });
283
271
  }); };
@@ -300,7 +288,7 @@ export var useApplePay = function (_a) {
300
288
  return [2];
301
289
  }
302
290
  if (e.message) {
303
- onError([{ description: e.message, code: '400' }]);
291
+ onError([{ message: e.message, code: '400' }]);
304
292
  return [2];
305
293
  }
306
294
  onError(e);
@@ -308,8 +296,6 @@ export var useApplePay = function (_a) {
308
296
  return [2];
309
297
  });
310
298
  }); };
311
- if (debug)
312
- console.log('useApplePay return hooks', { loading: loading, disabled: disabled, applePayRequestData: applePayRequestData, applePayRequestConfiguration: applePayRequestConfiguration });
313
299
  return {
314
300
  loading: loading,
315
301
  onApplePayButtonClicked: onApplePayButtonClicked,
@@ -0,0 +1,18 @@
1
+ import { Scope } from '../constants';
2
+ import { MetaData, ApplePayButtonProps } from '../@types';
3
+ interface ApplePayRequestData {
4
+ isIframeIntegration: boolean;
5
+ onError?: (error: any) => void;
6
+ onSuccess?: (data: Record<string, any>) => void;
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'];
16
+ }
17
+ export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, scope, profileData, order, customer, transaction, operator, redirect, post }: ApplePayRequestData) => void;
18
+ export {};
@@ -0,0 +1,161 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import * as React from 'react';
38
+ import { Scope } from '../constants';
39
+ import appService from '../api/app.service';
40
+ var EVENT_NAME = 'TAP_BUTTON::APPLE_PAY_ON_PAYMENT_AUTHORIZED';
41
+ export var useMerchantApplePay = function (_a) {
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
+ var onMessageReceived = function (_a) {
44
+ var message = _a.data;
45
+ return __awaiter(void 0, void 0, void 0, function () {
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
+ case 0:
51
+ _b = message !== null && message !== void 0 ? message : {}, event = _b.event, data = _b.data;
52
+ if (!data || event !== EVENT_NAME)
53
+ return [2];
54
+ _w.label = 1;
55
+ case 1:
56
+ _w.trys.push([1, 13, , 14]);
57
+ _c = scope;
58
+ switch (_c) {
59
+ case Scope.APPLE_PAY_TOKEN: return [3, 2];
60
+ case Scope.TAP_TOKEN: return [3, 3];
61
+ case Scope.AUTHORIZE: return [3, 5];
62
+ case Scope.CHARGE: return [3, 5];
63
+ }
64
+ return [3, 11];
65
+ case 2:
66
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
67
+ return [3, 12];
68
+ case 3: return [4, appService.tapTokenization(data)];
69
+ case 4:
70
+ response = _w.sent();
71
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
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)];
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:
128
+ console.error("We only support: ".concat(Object.values(Scope).join(', '), " for now"));
129
+ onError === null || onError === void 0 ? void 0 : onError({ message: "We only support: ".concat(Object.values(Scope).join(', '), " for now"), code: '400' });
130
+ return [3, 12];
131
+ case 12: return [3, 14];
132
+ case 13:
133
+ e_1 = _w.sent();
134
+ if (!onError)
135
+ return [2];
136
+ if (e_1.errors) {
137
+ onError(e_1.errors);
138
+ return [2];
139
+ }
140
+ if ((_v = e_1.response) === null || _v === void 0 ? void 0 : _v.data.errors) {
141
+ onError(e_1.response.data.errors);
142
+ return [2];
143
+ }
144
+ if (e_1.message) {
145
+ onError([{ message: e_1.message, code: '400' }]);
146
+ return [2];
147
+ }
148
+ onError(e_1);
149
+ return [3, 14];
150
+ case 14: return [2];
151
+ }
152
+ });
153
+ });
154
+ };
155
+ React.useEffect(function () {
156
+ if (!isIframeIntegration)
157
+ return;
158
+ window.addEventListener('message', onMessageReceived);
159
+ return function () { return window.removeEventListener('message', onMessageReceived); };
160
+ }, [isIframeIntegration]);
161
+ };
@@ -1 +1 @@
1
- export declare function useScript(src: string, async?: boolean): "loading" | "ready" | "idle" | "error";
1
+ export declare function useScript(src: string, async?: boolean): "error" | "loading" | "ready" | "idle";
@@ -1,4 +1,4 @@
1
- import { Acceptance, ApplePayButtonProps, ApplePayRequestData, PaymentMethod } from '../@types';
1
+ import { Acceptance, ApplePayButtonProps, ApplePayRequestData, MetaData, PaymentMethod } from '../@types';
2
2
  export declare const validateSupportedNetworks: (supportedNetworksOptions: Acceptance['supportedSchemes'], merchantSupportedNetworks?: Acceptance['supportedSchemes']) => Acceptance['supportedSchemes'];
3
3
  export declare const getApplePayRequest: ({ order, customer, supportedNetworks, merchantCapabilities, countryCode, name }: Pick<ApplePayButtonProps, "order" | "customer"> & {
4
4
  supportedNetworks: Acceptance['supportedSchemes'];
@@ -9,3 +9,4 @@ export declare const getApplePayRequest: ({ order, customer, supportedNetworks,
9
9
  export declare const getApplePayPaymentMethod: (paymentMethods: Array<PaymentMethod>) => PaymentMethod;
10
10
  export declare const rsaSetup: (key: string) => (string: string) => string;
11
11
  export declare function generateApplicationHeader(obj: Record<string, string | any>): string;
12
+ export declare const prepareApplePayRequest: ({ payment_options, merchant, order, customer, acceptance }: Pick<MetaData, 'merchant' | 'payment_options'> & Pick<ApplePayButtonProps, 'order' | 'customer' | 'acceptance'>) => ApplePayRequestData;
@@ -1,4 +1,5 @@
1
1
  import { JSEncrypt } from 'jsencrypt';
2
+ import { getMerchantCapabilities } from './defaultValues';
2
3
  export var validateSupportedNetworks = function (supportedNetworksOptions, merchantSupportedNetworks) {
3
4
  var toLowerCase = function (item) { return item.toLowerCase(); };
4
5
  if (!supportedNetworksOptions)
@@ -62,3 +63,17 @@ export function generateApplicationHeader(obj) {
62
63
  .map(function (key) { return "".concat(key, "=").concat(obj[key]); })
63
64
  .join('|');
64
65
  }
66
+ export var prepareApplePayRequest = function (_a) {
67
+ var payment_options = _a.payment_options, merchant = _a.merchant, order = _a.order, customer = _a.customer, acceptance = _a.acceptance;
68
+ var paymentMethod = getApplePayPaymentMethod(payment_options.payment_methods || []);
69
+ var supportedNetworks = validateSupportedNetworks(paymentMethod.supported_card_brands, acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedSchemes);
70
+ var request = getApplePayRequest({
71
+ countryCode: merchant.country_code,
72
+ order: order,
73
+ customer: customer,
74
+ supportedNetworks: supportedNetworks,
75
+ merchantCapabilities: getMerchantCapabilities(acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedFundSource),
76
+ name: merchant.name
77
+ });
78
+ return request;
79
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "0.0.52-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",