@tap-payments/apple-pay-button 0.0.36-test → 0.0.37-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.
@@ -16,7 +16,7 @@ declare class APPService extends BaseService {
16
16
  merchant: any;
17
17
  payment_options: any;
18
18
  }>;
19
- appleSession(merchant: MerchantResponse, validationURL: string, merchantRegisteredDomain: string): Promise<any>;
19
+ appleSession(merchant: Pick<MerchantResponse, 'name' | 'id'>, validationURL: string, merchantRegisteredDomain: string): Promise<any>;
20
20
  tapTokenization(applePaymentData: Record<string, string>): Promise<any>;
21
21
  }
22
22
  declare const appService: APPService;
@@ -1 +1,3 @@
1
1
  export * from './useScript';
2
+ export * from './useApplePay';
3
+ export * from './useApplePayFromMerchantSide';
@@ -1 +1,3 @@
1
1
  export * from './useScript';
2
+ export * from './useApplePay';
3
+ export * from './useApplePayFromMerchantSide';
@@ -0,0 +1,11 @@
1
+ export declare enum ApplePayGetFromMerchantEvents {
2
+ APPLE_PAY_CLICKED = "APPLE_PAY_CLICKED"
3
+ }
4
+ export declare enum ApplePayPostFromMerchantEvents {
5
+ APPLE_PAY_BUTTON_READY = "APPLE_PAY_BUTTON_READY",
6
+ APPLE_PAY_BUTTON_SUCCESS = "APPLE_PAY_BUTTON_SUCCESS",
7
+ APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS = "APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS",
8
+ APPLE_PAY_BUTTON_ERROR = "APPLE_PAY_BUTTON_ERROR",
9
+ APPLE_PAY_BUTTON_CANCELLED = "APPLE_PAY_BUTTON_CANCELLED"
10
+ }
11
+ export declare const useApplePayFromMerchantSide: (frameId: string) => void;
@@ -0,0 +1,177 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (_) try {
28
+ 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;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import { useCallback, useEffect } from 'react';
49
+ import appService from '../api/app.service';
50
+ import { setAxiosGlobalHeaders } from '../api/httpClient';
51
+ export var ApplePayGetFromMerchantEvents;
52
+ (function (ApplePayGetFromMerchantEvents) {
53
+ ApplePayGetFromMerchantEvents["APPLE_PAY_CLICKED"] = "APPLE_PAY_CLICKED";
54
+ })(ApplePayGetFromMerchantEvents || (ApplePayGetFromMerchantEvents = {}));
55
+ export var ApplePayPostFromMerchantEvents;
56
+ (function (ApplePayPostFromMerchantEvents) {
57
+ ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_READY"] = "APPLE_PAY_BUTTON_READY";
58
+ ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_SUCCESS"] = "APPLE_PAY_BUTTON_SUCCESS";
59
+ ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS"] = "APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS";
60
+ ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_ERROR"] = "APPLE_PAY_BUTTON_ERROR";
61
+ ApplePayPostFromMerchantEvents["APPLE_PAY_BUTTON_CANCELLED"] = "APPLE_PAY_BUTTON_CANCELLED";
62
+ })(ApplePayPostFromMerchantEvents || (ApplePayPostFromMerchantEvents = {}));
63
+ var usePostEventsToIframe = function (frameId) {
64
+ var send = function (event, data) {
65
+ var _a;
66
+ var frame = document.getElementById(frameId);
67
+ if (!frame)
68
+ return;
69
+ (_a = frame.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage({ event: event, data: data }, frame.src);
70
+ };
71
+ return {
72
+ send: send
73
+ };
74
+ };
75
+ export var useApplePayFromMerchantSide = function (frameId) {
76
+ var send = usePostEventsToIframe(frameId).send;
77
+ var onApplePayButtonClicked = function (applePaymentOptionsMetaData) { return __awaiter(void 0, void 0, void 0, function () {
78
+ var ApplePaySession, _a, merchant, supportedNetworks, transaction, billingContact, merchantCapabilities, debug, applePaySDKVersion, headers, merchantRegisteredDomain, environment, request, session;
79
+ return __generator(this, function (_b) {
80
+ send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_READY, {});
81
+ ApplePaySession = window.ApplePaySession;
82
+ if (!ApplePaySession) {
83
+ console.error('ApplePaySession is not available, please check if you are using Safari browser');
84
+ return [2];
85
+ }
86
+ if (!applePaymentOptionsMetaData) {
87
+ console.error('Make sure you have passed prerequisites options for Apple Pay');
88
+ return [2];
89
+ }
90
+ _a = __assign(__assign({}, applePaymentOptionsMetaData), { merchantRegisteredDomain: window.location.hostname }), merchant = _a.merchant, supportedNetworks = _a.supportedNetworks, transaction = _a.transaction, billingContact = _a.billingContact, merchantCapabilities = _a.merchantCapabilities, debug = _a.debug, applePaySDKVersion = _a.applePaySDKVersion, headers = _a.headers, merchantRegisteredDomain = _a.merchantRegisteredDomain, environment = _a.environment;
91
+ if (debug)
92
+ console.log('apple payment options metadata', applePaymentOptionsMetaData);
93
+ appService.setEnv(environment);
94
+ appService.setBaseUrl();
95
+ request = {
96
+ countryCode: merchant.country_code,
97
+ currencyCode: transaction.currency,
98
+ merchantCapabilities: merchantCapabilities,
99
+ supportedNetworks: supportedNetworks,
100
+ billingContact: billingContact && {
101
+ phoneNumber: billingContact.phoneNumber,
102
+ emailAddress: billingContact.emailAddress,
103
+ givenName: billingContact.givenName,
104
+ familyName: billingContact.familyName
105
+ },
106
+ total: {
107
+ amount: Number(transaction.amount),
108
+ label: merchant.name
109
+ }
110
+ };
111
+ if (debug) {
112
+ console.info("Creating ApplePaySession with version: ".concat(applePaySDKVersion, " and request: ").concat(JSON.stringify(request)));
113
+ }
114
+ session = new ApplePaySession(applePaySDKVersion, request);
115
+ session.onvalidatemerchant = function (event) { return __awaiter(void 0, void 0, void 0, function () {
116
+ var data, error_1;
117
+ var _a;
118
+ return __generator(this, function (_b) {
119
+ switch (_b.label) {
120
+ case 0:
121
+ if (debug) {
122
+ console.info('Creating merchant session and validating merchant session');
123
+ console.info('onvalidatemerchant event', event);
124
+ }
125
+ _b.label = 1;
126
+ case 1:
127
+ _b.trys.push([1, 3, , 4]);
128
+ setAxiosGlobalHeaders(headers);
129
+ return [4, appService.appleSession(__assign({}, merchant), event.validationURL, merchantRegisteredDomain)];
130
+ case 2:
131
+ data = _b.sent();
132
+ if (debug)
133
+ console.info('merchant session created', data);
134
+ session.completeMerchantValidation(data);
135
+ send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_MERCHANT_VALIDATION_SUCCESS, data);
136
+ return [3, 4];
137
+ case 3:
138
+ error_1 = _b.sent();
139
+ if (debug)
140
+ console.error('error in onvalidatemerchant', error_1);
141
+ session.completePayment({ status: ApplePaySession.STATUS_FAILURE });
142
+ send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_ERROR, ((_a = error_1.response) === null || _a === void 0 ? void 0 : _a.data) || error_1.message);
143
+ return [3, 4];
144
+ case 4: return [2];
145
+ }
146
+ });
147
+ }); };
148
+ session.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
149
+ return __generator(this, function (_a) {
150
+ if (debug)
151
+ console.info('onpaymentauthorized event', event);
152
+ send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_SUCCESS, event.payment.token.paymentData);
153
+ session.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
154
+ return [2];
155
+ });
156
+ }); };
157
+ session.oncancel = function (event) {
158
+ console.info('oncancel event', event);
159
+ send(ApplePayPostFromMerchantEvents.APPLE_PAY_BUTTON_CANCELLED, event);
160
+ };
161
+ session.begin();
162
+ return [2];
163
+ });
164
+ }); };
165
+ var onMessage = useCallback(function (message) {
166
+ var _a = message.data, event = _a.event, data = _a.data;
167
+ if (event === ApplePayGetFromMerchantEvents.APPLE_PAY_CLICKED) {
168
+ onApplePayButtonClicked(data);
169
+ }
170
+ }, []);
171
+ useEffect(function () {
172
+ window.addEventListener('message', onMessage);
173
+ return function () {
174
+ window.removeEventListener('message', onMessage);
175
+ };
176
+ }, []);
177
+ };
@@ -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";
package/build/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ import { ApplePayGetFromMerchantEvents } from './hooks/useApplePayFromMerchantSide';
1
2
  import { ApplePayButtonProps, ApplePayButton } from './features/ApplePayButton';
3
+ import { ApplePayPostFromMerchantEvents, useApplePayFromMerchantSide } from './hooks/useApplePayFromMerchantSide';
2
4
  import { ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities } from './constants';
3
5
  export type { ApplePayButtonProps };
4
- export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities };
6
+ export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities, ApplePayPostFromMerchantEvents, useApplePayFromMerchantSide, ApplePayGetFromMerchantEvents };
package/build/index.js CHANGED
@@ -1,6 +1,8 @@
1
+ import { ApplePayGetFromMerchantEvents } from './hooks/useApplePayFromMerchantSide';
1
2
  import { ApplePayButton, renderApplePayButton } from './features/ApplePayButton';
3
+ import { ApplePayPostFromMerchantEvents, useApplePayFromMerchantSide } from './hooks/useApplePayFromMerchantSide';
2
4
  import { ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities } from './constants';
3
- export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities };
5
+ export { ApplePayButton, ThemeMode, Scope, SupportedNetworks, Environment, Locale, ButtonType, Edges, MerchantCapabilities, ApplePayPostFromMerchantEvents, useApplePayFromMerchantSide, ApplePayGetFromMerchantEvents };
4
6
  window['TapSDKs'] = {
5
7
  renderApplePayButton: renderApplePayButton,
6
8
  Scope: Scope,
@@ -10,5 +12,8 @@ window['TapSDKs'] = {
10
12
  ButtonType: ButtonType,
11
13
  ThemeMode: ThemeMode,
12
14
  Edges: Edges,
13
- MerchantCapabilities: MerchantCapabilities
15
+ MerchantCapabilities: MerchantCapabilities,
16
+ ApplePayPostFromMerchantEvents: ApplePayPostFromMerchantEvents,
17
+ useApplePayFromMerchantSide: useApplePayFromMerchantSide,
18
+ ApplePayGetFromMerchantEvents: ApplePayGetFromMerchantEvents
14
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/apple-pay-button",
3
- "version": "0.0.36-test",
3
+ "version": "0.0.37-development",
4
4
  "description": "Apple Pay Button React Component",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.js",
@@ -20,7 +20,7 @@
20
20
  "copy:files": "copyfiles -u 1 src/**/*.css build/",
21
21
  "tsc:alias": "tsc-alias -p tsconfig.json",
22
22
  "ts:build": "rm -rf build && tsc && yarn tsc:alias && yarn copy:files",
23
- "push": "npm publish --access public --tag test"
23
+ "push": "npm publish --access public --tag development"
24
24
  },
25
25
  "keywords": [],
26
26
  "author": {