@fat-zebra/sdk 1.5.5-beta.0 → 1.5.5

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 (97) hide show
  1. package/dist/applepay/applepay.d.ts +7 -22
  2. package/dist/applepay/applepay.js +21 -89
  3. package/dist/applepay/clients/apple-pay-client.d.ts +5 -9
  4. package/dist/applepay/clients/apple-pay-client.js +3 -9
  5. package/dist/applepay/clients/paynow-client.d.ts +2 -4
  6. package/dist/applepay/clients/paynow-client.js +7 -2
  7. package/dist/click_to_pay/index.js +0 -12
  8. package/dist/click_to_pay/types.d.ts +2 -11
  9. package/dist/local/fatzebra.js.map +1 -1
  10. package/dist/main.d.ts +0 -2
  11. package/dist/main.js +2 -24
  12. package/dist/paypal/paypal-button.d.ts +31 -0
  13. package/dist/paypal/paypal-button.js +199 -0
  14. package/dist/paypal/paypal-checkout.d.ts +21 -0
  15. package/dist/paypal/paypal-checkout.js +100 -0
  16. package/dist/paypal/types.d.ts +188 -0
  17. package/dist/paypal/types.js +5 -0
  18. package/dist/paypal/validation.d.ts +4 -0
  19. package/dist/paypal/validation.js +65 -0
  20. package/dist/react/index.d.ts +1 -2
  21. package/dist/react/index.js +1 -2
  22. package/dist/react/{applePayUrl.d.ts → url.d.ts} +2 -2
  23. package/dist/react/url.js +33 -0
  24. package/dist/react/useFatZebra.js +57 -8
  25. package/dist/shared/env.development.d.ts +3 -3
  26. package/dist/shared/env.development.js +3 -3
  27. package/dist/shared/envs/local.d.ts +3 -3
  28. package/dist/shared/envs/local.js +3 -3
  29. package/dist/shared/post-message-client.d.ts +0 -2
  30. package/dist/shared/post-message-client.js +1 -1
  31. package/dist/shared/types.d.ts +2 -14
  32. package/dist/shared/types.js +0 -2
  33. package/dist/src/paypal/paypal-button.js +311 -0
  34. package/dist/src/paypal/paypal-button.js.map +1 -0
  35. package/dist/src/paypal/paypal-button.test.js +41 -0
  36. package/dist/src/paypal/paypal-button.test.js.map +1 -0
  37. package/dist/src/paypal/paypal-checkout.js +111 -0
  38. package/dist/src/paypal/paypal-checkout.js.map +1 -0
  39. package/dist/src/paypal/paypal-checkout.test.js +167 -0
  40. package/dist/src/paypal/paypal-checkout.test.js.map +1 -0
  41. package/dist/src/paypal/types.js +9 -0
  42. package/dist/src/paypal/types.js.map +1 -0
  43. package/dist/src/paypal/validation.js +73 -0
  44. package/dist/src/paypal/validation.js.map +1 -0
  45. package/dist/src/react/{applePayUrl.js → url.js} +21 -7
  46. package/dist/src/react/url.js.map +1 -0
  47. package/dist/src/react/url.test.js +88 -0
  48. package/dist/src/react/url.test.js.map +1 -0
  49. package/dist/src/react/useFatZebra.js +56 -7
  50. package/dist/src/react/useFatZebra.js.map +1 -1
  51. package/dist/validation/schemas/click-to-pay/options.json +3 -30
  52. package/dist/version.d.ts +1 -1
  53. package/dist/version.js +1 -1
  54. package/package.json +2 -2
  55. package/.idea/fatzebra-js.iml +0 -12
  56. package/.idea/modules.xml +0 -8
  57. package/.idea/vcs.xml +0 -6
  58. package/dist/applepay/applepaymanager.d.ts +0 -28
  59. package/dist/applepay/applepaymanager.js +0 -115
  60. package/dist/applepay/types.d.ts +0 -15
  61. package/dist/applepay/types.js +0 -1
  62. package/dist/fatzebra.css +0 -91
  63. package/dist/local/fatzebra.js +0 -19565
  64. package/dist/production/fatzebra.css +0 -91
  65. package/dist/production/fatzebra.js +0 -2
  66. package/dist/react/ApplePay.d.ts +0 -9
  67. package/dist/react/ApplePay.js +0 -11
  68. package/dist/react/ApplePayButton.d.ts +0 -8
  69. package/dist/react/ApplePayButton.js +0 -18
  70. package/dist/react/applePayUrl.js +0 -19
  71. package/dist/react/useMessage.d.ts +0 -10
  72. package/dist/react/useMessage.js +0 -70
  73. package/dist/sandbox/fatzebra.css +0 -91
  74. package/dist/sandbox/fatzebra.js +0 -2
  75. package/dist/sandbox/fatzebra.js.LICENSE.txt +0 -1
  76. package/dist/src/applepay/applepaymanager.js +0 -279
  77. package/dist/src/applepay/applepaymanager.js.map +0 -1
  78. package/dist/src/react/ApplePayButton.js +0 -56
  79. package/dist/src/react/ApplePayButton.js.map +0 -1
  80. package/dist/src/react/applePayUrl.js.map +0 -1
  81. package/dist/src/react/applePayUrl.test.js +0 -57
  82. package/dist/src/react/applePayUrl.test.js.map +0 -1
  83. package/dist/src/react/useMessage.js +0 -140
  84. package/dist/src/react/useMessage.js.map +0 -1
  85. package/dist/src/react/useMessage.test.js +0 -222
  86. package/dist/src/react/useMessage.test.js.map +0 -1
  87. package/dist/src/validation/validators/apple-pay-load-params-button-validator.js +0 -19
  88. package/dist/src/validation/validators/apple-pay-load-params-button-validator.js.map +0 -1
  89. package/dist/staging/fatzebra.css +0 -91
  90. package/dist/staging/fatzebra.js +0 -19565
  91. package/dist/staging/fatzebra.js.map +0 -1
  92. package/dist/staging/index.html +0 -247
  93. package/dist/validation/schemas/applepay/load-params.json +0 -31
  94. package/dist/validation/schemas/applepay/options.json +0 -42
  95. package/dist/validation/schemas/applepay/payment-intent.json +0 -42
  96. package/dist/validation/validators/apple-pay-load-params-button-validator.d.ts +0 -3
  97. package/dist/validation/validators/apple-pay-load-params-button-validator.js +0 -12
@@ -1,35 +1,20 @@
1
1
  import { PaymentRequest } from './clients/apple-pay-client';
2
2
  import * as payNow from './clients/paynow-client';
3
- import { OptionalUrlValues, PaymentIntent } from "../shared/types";
4
- import { Environment } from "../shared/env";
5
- interface ApplePayLoadParams {
6
- containerId: string;
7
- paymentIntent: PaymentIntent;
8
- options?: OptionalUrlValues;
9
- }
3
+ import { PostMessage } from '../shared/post-message-client';
10
4
  export declare class ApplePay {
5
+ private merchantId;
11
6
  private canMakePayments;
12
7
  private iframe;
13
8
  private applePaySession;
14
9
  private postMessageClient;
15
- private fzPayNowDomain;
16
- private domain_name;
17
- private username;
18
- private environment;
19
- private paymentIntent;
20
10
  constructor(config: {
21
- environment: Environment;
22
- paymentIntent: PaymentIntent;
23
- username: string;
11
+ iframe: HTMLIFrameElement;
24
12
  });
25
- load(config: ApplePayLoadParams): void;
26
- getPayNowUrl(options?: OptionalUrlValues): string;
27
- initialize(): Promise<void>;
28
- checkApplePayEligibility(): void;
29
- notifyApplePayEligibility(): void;
30
- registerEventListener(): Promise<void>;
13
+ checkApplePayEligibilty(): void;
14
+ notifyApplePayEligibiity(): void;
15
+ registerEventListener(): void;
31
16
  purchase(request: PaymentRequest): Promise<void>;
32
17
  extractApplePaymentRequestParams(payload: any): PaymentRequest;
33
18
  extractPayNowPaymentAttributes(payload: any): payNow.PaymentAttributes;
19
+ sendMessage(payload: PostMessage): void;
34
20
  }
35
- export {};
@@ -7,75 +7,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { createSession, getEligibility, } from './clients/apple-pay-client';
10
+ import { createSession, getEligibilty, } from './clients/apple-pay-client';
11
11
  import * as payNow from './clients/paynow-client';
12
12
  import { PostMessageClient } from '../shared/post-message-client';
13
- import * as FatZebra from "../shared/types";
14
- import env from "../shared/env";
15
- import { emit } from "../shared/event-manager";
16
13
  const channel = 'applepay';
17
- const merchantSessionPath = '/v2/apple_pay/auth';
18
- const purchaseTokenPath = '/v2/apple_pay/token';
14
+ const fzPayNowDomain = process.env.PAYNOW_BASE_URL;
19
15
  export class ApplePay {
20
16
  constructor(config) {
21
- this.paymentIntent = config.paymentIntent;
22
- this.environment = config.environment;
23
- this.fzPayNowDomain = env[this.environment].payNowUrl;
24
- this.username = config.username;
25
- }
26
- load(config) {
27
- var _a, _b;
28
- this.domain_name = (_b = (_a = config === null || config === void 0 ? void 0 : config.options) === null || _a === void 0 ? void 0 : _a.domain_name) !== null && _b !== void 0 ? _b : window.location.hostname;
29
- this.iframe = document.createElement('iframe');
30
- document.getElementById(config.containerId).appendChild(this.iframe);
31
- const applePayUrl = this.getPayNowUrl(config.options);
32
- this.iframe.setAttribute("src", applePayUrl);
33
- this.iframe.setAttribute("height", '100%');
34
- this.iframe.setAttribute("width", '100%');
17
+ this.iframe = config.iframe;
35
18
  this.postMessageClient = new PostMessageClient({
36
- channel,
37
- target: this.iframe,
38
- environment: this.environment,
39
- });
40
- this.iframe.onload = () => __awaiter(this, void 0, void 0, function* () {
41
- yield this.initialize();
42
- });
43
- }
44
- getPayNowUrl(options) {
45
- const { payment, verification } = this.paymentIntent;
46
- const base = [
47
- this.fzPayNowDomain,
48
- 'sdk',
49
- 'apple_pay',
50
- this.username,
51
- payment.reference,
52
- payment.currency,
53
- payment.amount,
54
- verification
55
- ].join('/');
56
- const query = new URLSearchParams();
57
- if (options === null || options === void 0 ? void 0 : options.allowed_card_networks) {
58
- query.append('allowed_card_networks', options.allowed_card_networks.toString());
59
- }
60
- if (options === null || options === void 0 ? void 0 : options.allowed_card_types) {
61
- query.append('allowed_card_types', options.allowed_card_types.toString());
62
- }
63
- query.append('domain_name', this.domain_name);
64
- return `${base}?${query.toString()}`;
65
- }
66
- initialize() {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- yield this.registerEventListener();
69
- this.checkApplePayEligibility();
70
- this.notifyApplePayEligibility();
19
+ channel: 'applepay',
20
+ target: this.iframe
71
21
  });
22
+ this.registerEventListener();
23
+ this.checkApplePayEligibilty();
24
+ this.notifyApplePayEligibiity();
72
25
  }
73
- checkApplePayEligibility() {
74
- if (getEligibility()) {
26
+ checkApplePayEligibilty() {
27
+ if (getEligibilty()) {
75
28
  this.canMakePayments = true;
76
29
  }
77
30
  }
78
- notifyApplePayEligibility() {
31
+ notifyApplePayEligibiity() {
79
32
  const message = {
80
33
  channel,
81
34
  subject: 'eligibility',
@@ -86,13 +39,10 @@ export class ApplePay {
86
39
  this.postMessageClient.send(message);
87
40
  }
88
41
  registerEventListener() {
89
- return new Promise((resolve, _) => {
90
- this.postMessageClient.setEventListeners({
91
- 'paymentrequest': (data) => __awaiter(this, void 0, void 0, function* () {
92
- yield this.purchase(data);
93
- })
94
- });
95
- resolve();
42
+ this.postMessageClient.setEventListeners({
43
+ 'paymentrequest': (data) => __awaiter(this, void 0, void 0, function* () {
44
+ yield this.purchase(data);
45
+ })
96
46
  });
97
47
  }
98
48
  purchase(request) {
@@ -103,44 +53,23 @@ export class ApplePay {
103
53
  this.applePaySession.onvalidatemerchant = (event) => __awaiter(this, void 0, void 0, function* () {
104
54
  let merchantSession;
105
55
  try {
106
- merchantSession = yield payNow.getMerchantSession(event.validationURL, Object.assign(Object.assign({}, payNowPaymentAttributes), { merchant: this.username, domain_name: this.domain_name, display_name: this.username }), `${this.fzPayNowDomain}${merchantSessionPath}`);
56
+ merchantSession = yield payNow.getMerchantSession(event.validationURL, payNowPaymentAttributes);
107
57
  }
108
58
  catch (e) {
109
- const payload = {
110
- data: 'Payment failed. Unable to establish session',
111
- errors: e,
112
- };
113
- emit(FatZebra.PublicEvent.PAYMENT_ERROR, payload);
59
+ console.log('Unable to establish new merchant session');
114
60
  return;
115
61
  }
116
62
  this.applePaySession.completeMerchantValidation(merchantSession);
117
63
  });
118
64
  this.applePaySession.onpaymentauthorized = (event) => __awaiter(this, void 0, void 0, function* () {
119
65
  try {
120
- const result = yield payNow.authorizePayment(Object.assign(Object.assign({}, payNowPaymentAttributes), { merchant: this.username, token: event.payment.token, domain_name: this.domain_name }), `${this.fzPayNowDomain}${purchaseTokenPath}`);
66
+ yield payNow.authorizePayment(Object.assign(Object.assign({}, payNowPaymentAttributes), event.payment.token));
121
67
  this.applePaySession.completePayment(window.ApplePaySession.STATUS_SUCCESS);
122
- const payload = {
123
- message: 'Payment successful.',
124
- data: result,
125
- };
126
- emit(FatZebra.PublicEvent.PAYMENT_SUCCESS, payload);
127
68
  }
128
69
  catch (e) {
129
70
  this.applePaySession.completePayment(window.ApplePaySession.STATUS_FAILURE);
130
- const payload = {
131
- data: 'Payment failed.',
132
- errors: ['Payment declined']
133
- };
134
- emit(FatZebra.PublicEvent.PAYMENT_ERROR, payload);
135
71
  }
136
72
  });
137
- this.applePaySession.oncancel = () => __awaiter(this, void 0, void 0, function* () {
138
- const payload = {
139
- data: 'Payment failed.',
140
- errors: ['User cancelled payment.'],
141
- };
142
- emit(FatZebra.PublicEvent.PAYMENT_ERROR, payload);
143
- });
144
73
  this.applePaySession.begin();
145
74
  });
146
75
  }
@@ -158,4 +87,7 @@ export class ApplePay {
158
87
  const { paymentAttributes } = payload;
159
88
  return paymentAttributes;
160
89
  }
90
+ sendMessage(payload) {
91
+ this.iframe.contentWindow.postMessage(payload, fzPayNowDomain);
92
+ }
161
93
  }
@@ -1,11 +1,7 @@
1
1
  declare enum SupportedNetwork {
2
2
  Amex = "amex",
3
- ChinaUnionPay = "chinaUnionPay",
4
- Discover = "discover",
5
- JCB = "jcb",
6
- Maestro = "maestro",
7
- MasterCard = "masterCard",
8
- Visa = "visa"
3
+ Visa = "visa",
4
+ MasterCard = "masterCard"
9
5
  }
10
6
  declare enum MerchantCapability {
11
7
  Supports3DS = "supports3DS",
@@ -19,10 +15,10 @@ interface PaymentRequest {
19
15
  merchantCapabilities: MerchantCapability[];
20
16
  supportedNetworks: SupportedNetwork[];
21
17
  total: {
22
- label: string;
18
+ lable: string;
23
19
  amount: string;
24
20
  };
25
21
  }
26
- declare const getEligibility: () => boolean;
22
+ declare const getEligibilty: () => boolean;
27
23
  declare const createSession: (payload: PaymentRequest) => Promise<any>;
28
- export { createSession, type PaymentRequest, getEligibility, MerchantCapability, SupportedNetwork, };
24
+ export { createSession, type PaymentRequest, getEligibilty, MerchantCapability, SupportedNetwork, };
@@ -7,17 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- // valid schemes
11
- // https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymentrequest/1916122-supportednetworks
12
10
  var SupportedNetwork;
13
11
  (function (SupportedNetwork) {
14
12
  SupportedNetwork["Amex"] = "amex";
15
- SupportedNetwork["ChinaUnionPay"] = "chinaUnionPay";
16
- SupportedNetwork["Discover"] = "discover";
17
- SupportedNetwork["JCB"] = "jcb";
18
- SupportedNetwork["Maestro"] = "maestro";
19
- SupportedNetwork["MasterCard"] = "masterCard";
20
13
  SupportedNetwork["Visa"] = "visa";
14
+ SupportedNetwork["MasterCard"] = "masterCard";
21
15
  })(SupportedNetwork || (SupportedNetwork = {}));
22
16
  var MerchantCapability;
23
17
  (function (MerchantCapability) {
@@ -26,10 +20,10 @@ var MerchantCapability;
26
20
  MerchantCapability["SupportsDebit"] = "supportsDebit";
27
21
  MerchantCapability["SupportsEMV"] = "supportsEMV";
28
22
  })(MerchantCapability || (MerchantCapability = {}));
29
- const getEligibility = () => {
23
+ const getEligibilty = () => {
30
24
  return window.ApplePaySession && window.ApplePaySession.canMakePayments();
31
25
  };
32
26
  const createSession = (payload) => __awaiter(void 0, void 0, void 0, function* () {
33
27
  return yield new window.ApplePaySession(2, payload);
34
28
  });
35
- export { createSession, getEligibility, MerchantCapability, SupportedNetwork, };
29
+ export { createSession, getEligibilty, MerchantCapability, SupportedNetwork, };
@@ -8,12 +8,10 @@ export interface PaymentAttributes {
8
8
  merchant_id?: string;
9
9
  recurring: boolean;
10
10
  send_email?: string;
11
- display_name?: string;
12
- domain_name?: string;
13
11
  }
14
12
  export interface AuthorizePaymentRequestPayload extends PaymentAttributes {
15
13
  token: string;
16
14
  }
17
15
  export declare const objectToQueryString: (obj: any) => string;
18
- export declare const getMerchantSession: (validationUrl: string, paymentAttributes: PaymentAttributes, baseUrl: string) => Promise<any>;
19
- export declare const authorizePayment: (payload: AuthorizePaymentRequestPayload, url: string) => Promise<any>;
16
+ export declare const getMerchantSession: (validationUrl: string, paymentAttributes: PaymentAttributes) => Promise<any>;
17
+ export declare const authorizePayment: (payload: AuthorizePaymentRequestPayload) => Promise<any>;
@@ -7,6 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ const paynowDomain = process.env.PAYNOW_BASE_URL;
11
+ const merchantSessionPath = process.env.PAYNOW_APPLEPAY_AUTH_PATH;
12
+ const purchaseTokenPath = process.env.PAYNOW_APPLEPAY_TOKEN_PATH;
10
13
  export const objectToQueryString = (obj) => {
11
14
  let queryString = [];
12
15
  for (const key of Object.keys(obj)) {
@@ -14,7 +17,8 @@ export const objectToQueryString = (obj) => {
14
17
  }
15
18
  return queryString.join("&");
16
19
  };
17
- export const getMerchantSession = (validationUrl, paymentAttributes, baseUrl) => __awaiter(void 0, void 0, void 0, function* () {
20
+ export const getMerchantSession = (validationUrl, paymentAttributes) => __awaiter(void 0, void 0, void 0, function* () {
21
+ const baseUrl = `${paynowDomain}${merchantSessionPath}`;
18
22
  const queryString = `url=${validationUrl}&${objectToQueryString(paymentAttributes)}`;
19
23
  return new Promise((resolve, reject) => {
20
24
  const request = new XMLHttpRequest();
@@ -31,7 +35,8 @@ export const getMerchantSession = (validationUrl, paymentAttributes, baseUrl) =>
31
35
  request.send();
32
36
  });
33
37
  });
34
- export const authorizePayment = (payload, url) => __awaiter(void 0, void 0, void 0, function* () {
38
+ export const authorizePayment = (payload) => __awaiter(void 0, void 0, void 0, function* () {
39
+ const url = `${paynowDomain}${purchaseTokenPath}`;
35
40
  return new Promise((resolve, reject) => {
36
41
  const request = new XMLHttpRequest();
37
42
  request.onload = () => {
@@ -81,18 +81,6 @@ class ClickToPay {
81
81
  data
82
82
  });
83
83
  };
84
- handlers[PublicEvent.CLICK_TO_PAY_RESIZE] = (data) => {
85
- emit(PublicEvent.CLICK_TO_PAY_RESIZE, {
86
- message: 'Container resized.',
87
- data
88
- });
89
- };
90
- handlers[PublicEvent.CLICK_TO_PAY_DCF_LOADED] = (data) => {
91
- emit(PublicEvent.CLICK_TO_PAY_DCF_LOADED, {
92
- message: 'Digital checkout form loaded.',
93
- data
94
- });
95
- };
96
84
  this.postMessageClient.setEventListeners(handlers);
97
85
  }
98
86
  purchase() {
@@ -1,18 +1,9 @@
1
1
  import { PaymentIntent } from "../shared/types";
2
2
  interface ClickToPayOptions {
3
- auth?: boolean;
4
- cardListButtonText?: string;
5
- css?: string;
6
- cssSignature?: string;
7
- displayName?: string;
8
3
  hideConfirmButton?: boolean;
9
- hideManualEntryLink?: boolean;
10
- returnPath?: string;
11
- returnTarget?: string;
12
- saveCard?: boolean;
13
- sharedData?: string;
14
- submitPaymentButtonText?: string;
15
4
  tokenizeOnly?: boolean;
5
+ css?: string;
6
+ cssSignature?: string;
16
7
  }
17
8
  interface HppClickToPayParams {
18
9
  containerId: string;