@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
package/dist/main.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Customer, PaymentIntent, PaymentMethod, PublicEvent } from './shared/types';
2
2
  import { HppLoadParams } from './hpp';
3
3
  import { ChallengeWindowSize } from './sca/types';
4
- import { ApplePayParams } from './applepay/types';
5
4
  import { HppClickToPayParams } from './click_to_pay/types';
6
5
  export interface FZConfig {
7
6
  username: string;
@@ -32,7 +31,6 @@ export default class FatZebra {
32
31
  cardDidTokenize(headless: HTMLIFrameElement, callback: (data: any) => void): void;
33
32
  verifyCard(params: VerifyCardParams): Promise<void>;
34
33
  renderPaymentsPage(params: HppLoadParams): void;
35
- renderApplePayButton(params: ApplePayParams): void;
36
34
  renderClickToPay(params: HppClickToPayParams): void;
37
35
  checkout(): void;
38
36
  on(event: PublicEvent, callback: (e: any) => void): void;
package/dist/main.js CHANGED
@@ -11,14 +11,12 @@ import Sca from './sca';
11
11
  import { PostMessageClient, } from './shared/post-message-client';
12
12
  import { BridgeEvent, PaymentMethodType, PublicEvent, } from './shared/types';
13
13
  import { LocalStorageAccessTokenKey } from './shared/constants';
14
- import { emit, off, on, onOnce } from './shared/event-manager';
14
+ import { emit, on, off, onOnce } from './shared/event-manager';
15
15
  import * as bridge from './shared/bridge-client';
16
- import { toHumanizedErrors, validateClickToPayLoadParams, validateHppLoadParams, validateVerifyCardParams, } from './validation';
16
+ import { validateHppLoadParams, validateVerifyCardParams, toHumanizedErrors, validateClickToPayLoadParams, } from './validation';
17
17
  import GatewayClient from './shared/api-gateway-client';
18
18
  import { Hpp } from './hpp';
19
19
  import ClickToPay from './click_to_pay';
20
- import { validateApplePayLoadParams } from "./validation/validators/apple-pay-load-params-button-validator";
21
- import { ApplePay } from "./applepay";
22
20
  export default class FatZebra {
23
21
  constructor(config) {
24
22
  this.fzConfig = config;
@@ -122,26 +120,6 @@ export default class FatZebra {
122
120
  });
123
121
  window.HPP.load(params);
124
122
  }
125
- renderApplePayButton(params) {
126
- const valid = validateApplePayLoadParams(params);
127
- if (!valid) {
128
- emit(PublicEvent.VALIDATION_ERROR, {
129
- errors: toHumanizedErrors(validateApplePayLoadParams.errors),
130
- data: null
131
- });
132
- return;
133
- }
134
- window.ApplePayButton = new ApplePay({
135
- environment: params.environment,
136
- paymentIntent: params.paymentIntent,
137
- username: this.fzConfig.username
138
- });
139
- window.ApplePayButton.load({
140
- containerId: params.containerId,
141
- paymentIntent: params.paymentIntent,
142
- options: params.options
143
- });
144
- }
145
123
  renderClickToPay(params) {
146
124
  const valid = validateClickToPayLoadParams(params);
147
125
  if (!valid) {
@@ -0,0 +1,31 @@
1
+ import { PayPalPaymentMethod } from './types';
2
+ import { PaymentIntent } from '../shared/types';
3
+ interface PayPal {
4
+ render(containerId: string): void;
5
+ }
6
+ interface PayPalButtonStyle {
7
+ [key: string]: any;
8
+ }
9
+ export default class PayPalButton {
10
+ private validationErrorRaised;
11
+ private _paypalButtons;
12
+ private paymentMethod;
13
+ private paymentIntent;
14
+ private buttonStyle;
15
+ private billingAgreement;
16
+ private client;
17
+ private actions;
18
+ constructor(paymentMethod?: PayPalPaymentMethod, paymentIntent?: PaymentIntent, billingAgreement?: boolean, buttonStyle?: PayPalButtonStyle);
19
+ get paypalButtons(): any;
20
+ get paypalActions(): any;
21
+ render(containerId: string): void;
22
+ getContainer(containerId: string): any;
23
+ private createButton;
24
+ private createOrder;
25
+ private approveOrder;
26
+ private createBillingAgreement;
27
+ private approveBillingAgreement;
28
+ private formatError;
29
+ }
30
+ export { PayPalButton };
31
+ export type { PayPal, PayPalButtonStyle, };
@@ -0,0 +1,199 @@
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
+ import { emit } from '../shared/event-manager';
11
+ import { PayPalIntent } from './types';
12
+ import GatewayClient from '../shared/api-gateway-client';
13
+ import { PublicEvent } from '../shared/types';
14
+ import * as util from '../shared/util';
15
+ import { LocalStorageAccessTokenKey } from '../shared/constants';
16
+ const defaultStyle = {
17
+ layout: 'horizontal',
18
+ color: 'gold',
19
+ shape: 'pill',
20
+ label: 'paypal',
21
+ };
22
+ export default class PayPalButton {
23
+ constructor(paymentMethod, paymentIntent, billingAgreement, buttonStyle) {
24
+ this.paymentMethod = paymentMethod;
25
+ this.paymentIntent = paymentIntent;
26
+ this.billingAgreement = billingAgreement;
27
+ this.buttonStyle = buttonStyle;
28
+ this.client = new GatewayClient({ accessToken: window.localStorage.getItem(LocalStorageAccessTokenKey),
29
+ username: window.MerchantUsername,
30
+ });
31
+ this.createButton();
32
+ }
33
+ get paypalButtons() {
34
+ return this._paypalButtons;
35
+ }
36
+ get paypalActions() {
37
+ return this.actions;
38
+ }
39
+ render(containerId) {
40
+ let container = this.getContainer(containerId);
41
+ if (typeof (container) != 'undefined' && container != null) {
42
+ this._paypalButtons.render('#' + container.id);
43
+ }
44
+ else {
45
+ emit(PublicEvent.PAYPAL_ERROR, {
46
+ errors: [`Container with id #${containerId} does not exist.`],
47
+ data: null
48
+ });
49
+ }
50
+ }
51
+ getContainer(containerId) {
52
+ return document.getElementById(containerId);
53
+ }
54
+ createButton() {
55
+ let button = ({});
56
+ button.style = (this.buttonStyle ? this.buttonStyle : defaultStyle);
57
+ if (this.billingAgreement === true) {
58
+ button.createBillingAgreement = () => __awaiter(this, void 0, void 0, function* () {
59
+ return this.createBillingAgreement();
60
+ });
61
+ button.onApprove = (data, actions) => __awaiter(this, void 0, void 0, function* () {
62
+ emit(PublicEvent.PAYPAL_PROCESSESING, { data: {}, message: 'The request is being processed.' });
63
+ return this.approveBillingAgreement(data);
64
+ });
65
+ button.onCancel = (data, actions) => {
66
+ emit(PublicEvent.PAYPAL_CANCEL, { data: { id: data.orderID }, message: 'PayPal Billing Agreement cancelled.' });
67
+ };
68
+ }
69
+ else {
70
+ button.createOrder = () => __awaiter(this, void 0, void 0, function* () {
71
+ return this.createOrder();
72
+ });
73
+ button.onApprove = (data, actions) => __awaiter(this, void 0, void 0, function* () {
74
+ emit(PublicEvent.PAYPAL_PROCESSESING, { data: {}, message: 'The request is being processed.' });
75
+ return this.approveOrder(data);
76
+ });
77
+ button.onCancel = (data, actions) => {
78
+ emit(PublicEvent.PAYPAL_CANCEL, { data: { id: data.orderID }, message: 'PayPal Order cancelled.' });
79
+ };
80
+ }
81
+ button.onError = (error) => {
82
+ // This flag is used to prevent emitting general error from PayPal
83
+ // if an error has already been raised and emitted.
84
+ if (this.validationErrorRaised === false) {
85
+ emit(PublicEvent.PAYPAL_ERROR, {
86
+ errors: ['PayPal Checkout failed.'],
87
+ data: null
88
+ });
89
+ }
90
+ };
91
+ this._paypalButtons = window.paypal.Buttons(button);
92
+ }
93
+ createOrder() {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ try {
96
+ this.validationErrorRaised = false;
97
+ let payload = util.toObjectWithSnakeCaseKeys(this.paymentMethod);
98
+ payload.payment_intent = this.paymentIntent;
99
+ const response = (yield this.client.createPayPalOrder({
100
+ order: payload
101
+ })).data;
102
+ return response.id;
103
+ }
104
+ catch (error) {
105
+ this.validationErrorRaised = true;
106
+ emit(PublicEvent.PAYPAL_ERROR, {
107
+ errors: this.formatError(error),
108
+ data: null
109
+ });
110
+ return null;
111
+ }
112
+ });
113
+ }
114
+ approveOrder(data) {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ try {
117
+ this.validationErrorRaised = false;
118
+ let response = undefined;
119
+ if (this.paymentMethod.intent.toUpperCase() === PayPalIntent.CAPTURE) {
120
+ response = (yield this.client.capturePayPalOrder({
121
+ id: data.orderID
122
+ })).data;
123
+ }
124
+ else if (this.paymentMethod.intent.toUpperCase() === PayPalIntent.AUTHORIZE) {
125
+ response = (yield this.client.authorizePayPalOrder({
126
+ id: data.orderID
127
+ })).data;
128
+ }
129
+ emit(PublicEvent.PAYPAL_SUCCESS, {
130
+ data: util.toObjectWithCamelCaseKeys(response),
131
+ message: 'PayPal order approved.'
132
+ });
133
+ return;
134
+ }
135
+ catch (error) {
136
+ this.validationErrorRaised = true;
137
+ emit(PublicEvent.PAYPAL_ERROR, {
138
+ errors: this.formatError(error),
139
+ data: null
140
+ });
141
+ return;
142
+ }
143
+ });
144
+ }
145
+ createBillingAgreement() {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ try {
148
+ this.validationErrorRaised = false;
149
+ let payload = util.toObjectWithSnakeCaseKeys(this.paymentMethod);
150
+ delete payload.billing_agreement;
151
+ let response = (yield this.client.createPayPalBillingAgreement({
152
+ billing: payload
153
+ })).data;
154
+ return response.token_id;
155
+ }
156
+ catch (error) {
157
+ this.validationErrorRaised = true;
158
+ emit(PublicEvent.PAYPAL_ERROR, {
159
+ errors: this.formatError(error),
160
+ data: null
161
+ });
162
+ return;
163
+ }
164
+ });
165
+ }
166
+ approveBillingAgreement(data) {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ try {
169
+ this.validationErrorRaised = false;
170
+ let response = (yield this.client.approvePayPalBillingAgreement({
171
+ id: data.billingToken
172
+ })).data;
173
+ emit(PublicEvent.PAYPAL_SUCCESS, {
174
+ data: util.toObjectWithCamelCaseKeys(response),
175
+ message: 'PayPal Billing Agreement created.'
176
+ });
177
+ return;
178
+ }
179
+ catch (error) {
180
+ this.validationErrorRaised = true;
181
+ emit(PublicEvent.PAYPAL_ERROR, {
182
+ errors: this.formatError(error),
183
+ data: null
184
+ });
185
+ return;
186
+ }
187
+ });
188
+ }
189
+ formatError(error) {
190
+ var _a, _b;
191
+ var message = [(_b = (_a = error === null || error === void 0 ? void 0 : error.request) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.errors].flat();
192
+ if (typeof message[0] === 'undefined')
193
+ message = [error === null || error === void 0 ? void 0 : error.message].flat();
194
+ if (typeof message[0] === 'undefined')
195
+ message = ['Unknown error'];
196
+ return message;
197
+ }
198
+ }
199
+ export { PayPalButton };
@@ -0,0 +1,21 @@
1
+ import { PayPalButton } from './paypal-button';
2
+ import { PayPalConfig } from './types';
3
+ export default class PayPalCheckout {
4
+ private paypalButton;
5
+ private validationErrors;
6
+ private intent;
7
+ private currency;
8
+ private payment;
9
+ private billingAgreement;
10
+ private containerId;
11
+ private buttonStyle;
12
+ constructor(config: PayPalConfig);
13
+ get paypal(): PayPalButton;
14
+ set paypal(paypal: PayPalButton);
15
+ load(): Promise<any>;
16
+ render(): void;
17
+ private validatePayPalSetup;
18
+ private validatePayPalRequest;
19
+ private errors;
20
+ }
21
+ export { PayPalCheckout };
@@ -0,0 +1,100 @@
1
+ // This is the implementation of PayPal Checkout
2
+ //
3
+ // https://developer.paypal.com/docs/checkout/
4
+ import { emit } from '../shared/event-manager';
5
+ import { PaymentMethodType, PublicEvent } from '../shared/types';
6
+ import { PayPalButton, } from './paypal-button';
7
+ import { validatePayPalSetup, validatePayPalRequest, } from './validation';
8
+ export default class PayPalCheckout {
9
+ constructor(config) {
10
+ var _a, _b, _c, _d, _e;
11
+ if (!this.validatePayPalSetup(config)) {
12
+ emit(PublicEvent.PAYPAL_ERROR, {
13
+ errors: this.errors(),
14
+ data: null
15
+ });
16
+ return;
17
+ }
18
+ this.billingAgreement = (((_b = (_a = config === null || config === void 0 ? void 0 : config.payment) === null || _a === void 0 ? void 0 : _a.paymentMethod) === null || _b === void 0 ? void 0 : _b.type) === PaymentMethodType.PAYPAL_BILLING);
19
+ this.payment = config === null || config === void 0 ? void 0 : config.payment;
20
+ this.intent = (_e = (_d = (_c = config === null || config === void 0 ? void 0 : config.payment) === null || _c === void 0 ? void 0 : _c.paymentMethod) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.intent;
21
+ this.currency = config === null || config === void 0 ? void 0 : config.currency;
22
+ this.containerId = config === null || config === void 0 ? void 0 : config.containerId;
23
+ this.buttonStyle = config === null || config === void 0 ? void 0 : config.style;
24
+ if (!this.validatePayPalRequest()) {
25
+ emit(PublicEvent.PAYPAL_ERROR, {
26
+ errors: this.errors(),
27
+ data: null
28
+ });
29
+ return;
30
+ }
31
+ }
32
+ get paypal() {
33
+ return this.paypalButton;
34
+ }
35
+ set paypal(paypal) {
36
+ this.paypalButton = paypal;
37
+ }
38
+ load() {
39
+ if (this.errors()) {
40
+ return;
41
+ }
42
+ if (this.intent && !this.billingAgreement) {
43
+ let data = this.payment.paymentMethod.data;
44
+ data.intent = this.intent.toUpperCase();
45
+ }
46
+ let self = this;
47
+ return new Promise((resolve, reject) => {
48
+ const script = document.createElement('script');
49
+ script.type = 'text/javascript';
50
+ let source = process.env.PAYPAL_SDK_URL + '&client-id=' + process.env.PAYPAL_CLIENT_ID + '&debug=' + process.env.PAYPAL_DEBUG;
51
+ if (this.currency)
52
+ source += '&currency=' + this.currency;
53
+ if (this.intent && !this.billingAgreement)
54
+ source += '&intent=' + this.intent;
55
+ if (this.billingAgreement === true)
56
+ source += '&vault=true';
57
+ script.setAttribute('data-partner-attribution-id', process.env.PAYPAL_PARTNER_ID);
58
+ script.src = source;
59
+ script.async = true;
60
+ document.body.appendChild(script);
61
+ script.onload = () => {
62
+ self.paypalButton = new PayPalButton(self.payment.paymentMethod.data, self.payment.paymentIntent, self.billingAgreement, self.buttonStyle);
63
+ resolve(null);
64
+ };
65
+ script.onerror = () => {
66
+ reject(['Loading PayPal failed']);
67
+ };
68
+ });
69
+ }
70
+ render() {
71
+ if (this.errors()) {
72
+ return;
73
+ }
74
+ this.paypalButton.render(this.containerId);
75
+ }
76
+ validatePayPalSetup(config) {
77
+ const validations = validatePayPalSetup(config);
78
+ this.validationErrors = null;
79
+ if (!validations.valid) {
80
+ this.validationErrors = validations.errors;
81
+ return false;
82
+ }
83
+ return true;
84
+ }
85
+ validatePayPalRequest() {
86
+ const validations = validatePayPalRequest(this.payment, this.billingAgreement);
87
+ this.validationErrors = null;
88
+ if (!validations.valid) {
89
+ this.validationErrors = validations.errors;
90
+ return false;
91
+ }
92
+ return true;
93
+ }
94
+ errors() {
95
+ if (this.validationErrors !== null)
96
+ return this.validationErrors;
97
+ return null;
98
+ }
99
+ }
100
+ export { PayPalCheckout };
@@ -0,0 +1,188 @@
1
+ import { PaymentMethod, PaymentIntent } from '../shared/types';
2
+ export interface PayPalConfig {
3
+ currency: string;
4
+ payment: PayPalOrderParams;
5
+ containerId: string;
6
+ style?: {
7
+ [key: string]: any;
8
+ };
9
+ }
10
+ export interface PayPalOrderParams {
11
+ paymentIntent?: PaymentIntent;
12
+ paymentMethod: PaymentMethod;
13
+ }
14
+ export declare enum PayPalIntent {
15
+ CAPTURE = "CAPTURE",
16
+ AUTHORIZE = "AUTHORIZE"
17
+ }
18
+ export type PayPalPaymentMethod = PayPalOrderRequest | PayPalBillingAgreementRequest;
19
+ /***************** PayPal Order Object ******************/
20
+ export interface PayPalOrderRequest {
21
+ intent: 'capture' | 'authorize';
22
+ options?: {
23
+ brandName?: string;
24
+ landingPage?: string;
25
+ payeePreferredPayment?: string;
26
+ shippingPreference?: string;
27
+ };
28
+ purchases: Purchases[];
29
+ }
30
+ interface Purchases {
31
+ description?: string;
32
+ softDescriptor?: string;
33
+ amount: Amount;
34
+ items?: Item[];
35
+ shippingAddress: {
36
+ name?: string;
37
+ method?: string;
38
+ address: Address;
39
+ };
40
+ payee?: {
41
+ emailAddress: string;
42
+ merchantId: string;
43
+ };
44
+ }
45
+ interface Amount {
46
+ itemTotal?: number;
47
+ shipping?: number;
48
+ handling?: number;
49
+ taxTotal?: number;
50
+ shippingDiscount?: number;
51
+ insurance?: number;
52
+ discount?: number;
53
+ }
54
+ interface Address {
55
+ firstName?: string;
56
+ lastName?: string;
57
+ address_1?: string;
58
+ address_2?: string;
59
+ city?: string;
60
+ state?: string;
61
+ postcode?: string;
62
+ country: string;
63
+ }
64
+ interface Item {
65
+ name: string;
66
+ description?: string;
67
+ sku?: string;
68
+ unitAmount: number;
69
+ tax?: number;
70
+ qty: string;
71
+ category?: string;
72
+ }
73
+ export interface CreatePayPalOrderRequest {
74
+ order: PayPalOrderRequest;
75
+ }
76
+ export interface PayPalOrderResponse {
77
+ id: string;
78
+ intent: PayPalIntent;
79
+ }
80
+ /***************** PayPal Capture Object ******************/
81
+ export interface CapturePayPalOrderRequest {
82
+ id: string;
83
+ }
84
+ export interface CapturePayPalOrderResponse {
85
+ id: string;
86
+ intent: string;
87
+ reference: string;
88
+ paypal_reference: string;
89
+ invoice_id: string;
90
+ amount: number;
91
+ decimal_amount: number;
92
+ captured_amount: number;
93
+ captured: boolean;
94
+ successful: boolean;
95
+ status: string;
96
+ message: string;
97
+ currency: string;
98
+ transaction_id: string;
99
+ transaction_date: Date;
100
+ response_code: string;
101
+ paypal_fee: number;
102
+ seller_receivable_net_amount: number;
103
+ note_to_payer: string;
104
+ is_final_capture: boolean;
105
+ refunded_amount: number;
106
+ balance_available_for_refund: number;
107
+ balance_available_for_capture: number;
108
+ authorization: string;
109
+ order: string;
110
+ }
111
+ /***************** PayPal Authorize Object ******************/
112
+ export interface AuthorizePayPalOrderRequest {
113
+ id: string;
114
+ }
115
+ export interface AuthorizePayPalOrderResponse {
116
+ id: string;
117
+ intent: string;
118
+ reference: string;
119
+ paypal_reference: string;
120
+ invoice_id: string;
121
+ amount: number;
122
+ decimal_amount: number;
123
+ captured_amount: number;
124
+ captured: boolean;
125
+ successful: boolean;
126
+ status: string;
127
+ message: string;
128
+ currency: string;
129
+ transaction_id: string;
130
+ transaction_date: Date;
131
+ response_code: string;
132
+ refunded_amount: number;
133
+ balance_available_for_capture: number;
134
+ order: string;
135
+ }
136
+ /***************** PayPal Billing Agreement Object ******************/
137
+ export interface PayPalBillingAgreementRequest {
138
+ name?: string;
139
+ description?: string;
140
+ shippingAddress: BillingAddress;
141
+ merchantCustomData?: string;
142
+ }
143
+ export interface CreatePayPalBillingAgreementRequest {
144
+ billing: PayPalBillingAgreementRequest;
145
+ }
146
+ interface BillingAddress {
147
+ firstName?: string;
148
+ lastName?: string;
149
+ address_1: string;
150
+ address_2?: string;
151
+ city: string;
152
+ state: string;
153
+ postcode: string;
154
+ country: string;
155
+ }
156
+ export interface PayPalBillingAgreementResponse {
157
+ token_id: string;
158
+ }
159
+ export interface ApprovePayPalBillingAgreementRequest {
160
+ id: string;
161
+ }
162
+ export interface ApprovePayPalBillingAgreementResponse {
163
+ token: string;
164
+ name?: string;
165
+ description?: string;
166
+ state: string;
167
+ payer?: {
168
+ payer_info: {
169
+ email: string;
170
+ first_name: string;
171
+ last_name: string;
172
+ payer_id: string;
173
+ };
174
+ };
175
+ shipping_address?: {
176
+ first_name?: string;
177
+ last_name?: string;
178
+ address_1: string;
179
+ address_2?: string;
180
+ city: string;
181
+ state: string;
182
+ postcode: string;
183
+ country: string;
184
+ };
185
+ merchant_custom_data?: string;
186
+ created_at: Date;
187
+ }
188
+ export {};
@@ -0,0 +1,5 @@
1
+ export var PayPalIntent;
2
+ (function (PayPalIntent) {
3
+ PayPalIntent["CAPTURE"] = "CAPTURE";
4
+ PayPalIntent["AUTHORIZE"] = "AUTHORIZE";
5
+ })(PayPalIntent || (PayPalIntent = {}));
@@ -0,0 +1,4 @@
1
+ import { PayPalConfig, PayPalOrderParams } from './types';
2
+ import { ValidationResult } from '../shared/types';
3
+ export declare const validatePayPalSetup: (props: PayPalConfig) => ValidationResult;
4
+ export declare const validatePayPalRequest: (props: PayPalOrderParams, billing?: boolean) => ValidationResult;
@@ -0,0 +1,65 @@
1
+ import { PayPalIntent } from './types';
2
+ const PaypalConfigRequiredProps = ['currency', 'containerId', 'payment'];
3
+ const PaypalOrderRequiredProps = ['intent', 'purchases'];
4
+ const PaypalBillingRequiredProps = ['shippingAddress'];
5
+ export const validatePayPalSetup = (props) => {
6
+ let errors = [];
7
+ const keys = Object.keys(props);
8
+ for (let requiredProp of PaypalConfigRequiredProps) {
9
+ // @ts-ignore
10
+ if (!keys.includes(requiredProp) || props[requiredProp] === undefined) {
11
+ errors.push(`${requiredProp} is missing.`);
12
+ }
13
+ }
14
+ return {
15
+ valid: errors.length == 0,
16
+ errors
17
+ };
18
+ };
19
+ export const validatePayPalRequest = (props, billing) => {
20
+ let errors = [];
21
+ const keys = Object.keys(props);
22
+ if (!keys.includes('paymentMethod')) {
23
+ errors.push(`paymentMethod is missing.`);
24
+ }
25
+ if (!keys.includes('paymentIntent') && !billing) {
26
+ errors.push(`paymentIntent is missing.`);
27
+ }
28
+ if (props.paymentMethod) {
29
+ const orderKeys = Object.keys(props.paymentMethod.data);
30
+ if (orderKeys.includes('intent')) {
31
+ const intent = props.paymentMethod.data.intent.toLowerCase();
32
+ const intents = Object.values(PayPalIntent).map(v => v.toLowerCase());
33
+ if (!intents.includes(intent)) {
34
+ errors.push(`intent is invalid, must be one of [${intents.join(', ')}].`);
35
+ }
36
+ }
37
+ if (!props.paymentMethod.type) {
38
+ errors.push(`paymentMethod.type is missing.`);
39
+ }
40
+ }
41
+ if (errors.length > 0) {
42
+ return {
43
+ valid: errors.length == 0,
44
+ errors
45
+ };
46
+ }
47
+ const paymentMethod = props.paymentMethod.data;
48
+ const providedKeys = Object.keys(paymentMethod);
49
+ let requiredProps;
50
+ if (billing === true) {
51
+ requiredProps = PaypalBillingRequiredProps;
52
+ }
53
+ else {
54
+ requiredProps = PaypalOrderRequiredProps;
55
+ }
56
+ for (let requiredProp of requiredProps) {
57
+ if (!providedKeys.includes(requiredProp)) {
58
+ errors.push(`${requiredProp} is missing.`);
59
+ }
60
+ }
61
+ return {
62
+ valid: errors.length == 0,
63
+ errors
64
+ };
65
+ };
@@ -1,5 +1,4 @@
1
1
  import VerifyCard from "./VerifyCard";
2
2
  import VerifyExistingCard from "./VerifyExistingCard";
3
3
  import submitForm from "./submitForm";
4
- import ApplePayButton from "./ApplePayButton";
5
- export { VerifyCard, VerifyExistingCard, submitForm, ApplePayButton };
4
+ export { VerifyCard, VerifyExistingCard, submitForm };