@fat-zebra/sdk 1.0.5 → 1.2.1

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 (172) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +162 -0
  3. package/dist/applepay/applepay.d.ts +20 -0
  4. package/dist/applepay/applepay.js +93 -0
  5. package/dist/applepay/clients/apple-pay-client.d.ts +24 -0
  6. package/dist/applepay/clients/apple-pay-client.js +29 -0
  7. package/dist/applepay/clients/paynow-client.d.ts +17 -0
  8. package/dist/applepay/clients/paynow-client.js +55 -0
  9. package/dist/applepay/index.d.ts +1 -0
  10. package/dist/applepay/index.js +1 -0
  11. package/dist/env.d.ts +5 -0
  12. package/dist/env.development.d.ts +5 -0
  13. package/dist/env.development.js +5 -0
  14. package/dist/env.js +5 -0
  15. package/dist/hpp/hpp.d.ts +61 -0
  16. package/dist/hpp/hpp.js +186 -0
  17. package/dist/hpp/index.d.ts +2 -0
  18. package/dist/hpp/index.js +1 -0
  19. package/dist/index.d.ts +5 -2
  20. package/dist/index.js +6 -2
  21. package/dist/local/fatzebra.js +17728 -0
  22. package/dist/local/fatzebra.js.map +1 -0
  23. package/dist/local/index.html +247 -0
  24. package/dist/main.d.ts +38 -0
  25. package/dist/main.js +148 -0
  26. package/dist/paypal/paypal-button.d.ts +31 -0
  27. package/dist/paypal/paypal-button.js +199 -0
  28. package/dist/paypal/paypal-checkout.d.ts +21 -0
  29. package/dist/paypal/paypal-checkout.js +100 -0
  30. package/dist/paypal/types.d.ts +188 -0
  31. package/dist/paypal/types.js +5 -0
  32. package/dist/paypal/validation.d.ts +4 -0
  33. package/dist/paypal/validation.js +65 -0
  34. package/dist/react/VerifyCard.d.ts +2 -4
  35. package/dist/react/VerifyCard.js +3 -3
  36. package/dist/react/url.d.ts +3 -18
  37. package/dist/react/url.js +3 -29
  38. package/dist/react/useFatZebra.d.ts +2 -3
  39. package/dist/react/useFatZebra.js +7 -7
  40. package/dist/sca/cardinal.d.ts +1 -1
  41. package/dist/sca/cardinal.js +1 -1
  42. package/dist/sca/index.d.ts +8 -5
  43. package/dist/sca/index.js +26 -85
  44. package/dist/sca/sca.d.ts +42 -0
  45. package/dist/sca/sca.js +273 -0
  46. package/dist/sca/scenarios/index.d.ts +3 -2
  47. package/dist/sca/types.d.ts +1 -1
  48. package/dist/sca/types.js +1 -1
  49. package/dist/shared/api-gateway-client.d.ts +7 -0
  50. package/dist/shared/api-gateway-client.js +35 -1
  51. package/dist/shared/env.d.ts +5 -0
  52. package/dist/shared/env.development.d.ts +5 -0
  53. package/dist/shared/env.development.js +5 -0
  54. package/dist/shared/env.js +5 -0
  55. package/dist/shared/event-manager.d.ts +1 -1
  56. package/dist/shared/event-manager.js +0 -1
  57. package/dist/shared/post-message-client.d.ts +1 -1
  58. package/dist/shared/post-message-client.js +1 -1
  59. package/dist/shared/types.d.ts +40 -33
  60. package/dist/shared/types.js +7 -1
  61. package/dist/src/applepay/applepay.js +198 -0
  62. package/dist/src/applepay/applepay.js.map +1 -0
  63. package/dist/src/applepay/clients/apple-pay-client.js +66 -0
  64. package/dist/src/applepay/clients/apple-pay-client.js.map +1 -0
  65. package/dist/src/applepay/clients/paynow-client.js +96 -0
  66. package/dist/src/applepay/clients/paynow-client.js.map +1 -0
  67. package/dist/src/applepay/index.js +6 -0
  68. package/dist/src/applepay/index.js.map +1 -0
  69. package/dist/src/hpp/hpp.js +230 -0
  70. package/dist/src/hpp/hpp.js.map +1 -0
  71. package/dist/src/hpp/hpp.test.js +135 -0
  72. package/dist/src/hpp/hpp.test.js.map +1 -0
  73. package/dist/src/hpp/index.js +6 -0
  74. package/dist/src/hpp/index.js.map +1 -0
  75. package/dist/src/index.js +7 -0
  76. package/dist/src/index.js.map +1 -0
  77. package/dist/src/main.js +225 -0
  78. package/dist/src/main.js.map +1 -0
  79. package/dist/src/main.test.js +236 -0
  80. package/dist/src/main.test.js.map +1 -0
  81. package/dist/src/paypal/paypal-button.js +311 -0
  82. package/dist/src/paypal/paypal-button.js.map +1 -0
  83. package/dist/src/paypal/paypal-button.test.js +41 -0
  84. package/dist/src/paypal/paypal-button.test.js.map +1 -0
  85. package/dist/src/paypal/paypal-checkout.js +111 -0
  86. package/dist/src/paypal/paypal-checkout.js.map +1 -0
  87. package/dist/src/paypal/paypal-checkout.test.js +167 -0
  88. package/dist/src/paypal/paypal-checkout.test.js.map +1 -0
  89. package/dist/src/paypal/types.js +9 -0
  90. package/dist/src/paypal/types.js.map +1 -0
  91. package/dist/src/paypal/validation.js +73 -0
  92. package/dist/src/paypal/validation.js.map +1 -0
  93. package/dist/src/sca/__tests__/eci-mappings.test.js +31 -0
  94. package/dist/src/sca/__tests__/eci-mappings.test.js.map +1 -0
  95. package/dist/src/sca/__tests__/index.test.js +558 -0
  96. package/dist/src/sca/__tests__/index.test.js.map +1 -0
  97. package/dist/src/sca/cardinal.js +110 -0
  98. package/dist/src/sca/cardinal.js.map +1 -0
  99. package/dist/src/sca/eci-mappings.js +63 -0
  100. package/dist/src/sca/eci-mappings.js.map +1 -0
  101. package/dist/src/sca/eci-mappings.test.js +31 -0
  102. package/dist/src/sca/eci-mappings.test.js.map +1 -0
  103. package/dist/src/sca/index.js +388 -0
  104. package/dist/src/sca/index.js.map +1 -0
  105. package/dist/src/sca/index.test.js +558 -0
  106. package/dist/src/sca/index.test.js.map +1 -0
  107. package/dist/src/sca/scenarios/enrollment.js +150 -0
  108. package/dist/src/sca/scenarios/enrollment.js.map +1 -0
  109. package/dist/src/sca/scenarios/index.js +8 -0
  110. package/dist/src/sca/scenarios/index.js.map +1 -0
  111. package/dist/src/sca/scenarios/validation.js +128 -0
  112. package/dist/src/sca/scenarios/validation.js.map +1 -0
  113. package/dist/src/sca/types.js +57 -0
  114. package/dist/src/sca/types.js.map +1 -0
  115. package/dist/src/shared/api-gateway-client.js +150 -0
  116. package/dist/src/shared/api-gateway-client.js.map +1 -0
  117. package/dist/src/shared/bridge-client.js +24 -0
  118. package/dist/src/shared/bridge-client.js.map +1 -0
  119. package/dist/src/shared/constants.js +19 -0
  120. package/dist/src/shared/constants.js.map +1 -0
  121. package/dist/src/shared/event-manager.js +15 -0
  122. package/dist/src/shared/event-manager.js.map +1 -0
  123. package/dist/src/shared/post-message-client.js +107 -0
  124. package/dist/src/shared/post-message-client.js.map +1 -0
  125. package/dist/src/shared/post-message-client.test.js +58 -0
  126. package/dist/src/shared/post-message-client.test.js.map +1 -0
  127. package/dist/src/shared/types.js +47 -0
  128. package/dist/src/shared/types.js.map +1 -0
  129. package/dist/src/shared/types.test.js +55 -0
  130. package/dist/src/shared/types.test.js.map +1 -0
  131. package/dist/src/shared/util.js +96 -0
  132. package/dist/src/shared/util.js.map +1 -0
  133. package/dist/src/shared/util.test.js +148 -0
  134. package/dist/src/shared/util.test.js.map +1 -0
  135. package/dist/src/validation/index.js +10 -0
  136. package/dist/src/validation/index.js.map +1 -0
  137. package/dist/src/validation/validation-helper.js +10 -0
  138. package/dist/src/validation/validation-helper.js.map +1 -0
  139. package/dist/src/validation/validation-helper.test.js +34 -0
  140. package/dist/src/validation/validation-helper.test.js.map +1 -0
  141. package/dist/src/validation/validators/hpp-load-params-validator.js +17 -0
  142. package/dist/src/validation/validators/hpp-load-params-validator.js.map +1 -0
  143. package/dist/src/validation/validators/hpp-load-params-validator.test.js +56 -0
  144. package/dist/src/validation/validators/hpp-load-params-validator.test.js.map +1 -0
  145. package/dist/src/validation/validators/verify-card-params-validator.js +18 -0
  146. package/dist/src/validation/validators/verify-card-params-validator.js.map +1 -0
  147. package/dist/tests/helpers/api-gateway-mock.js +36 -0
  148. package/dist/tests/helpers/api-gateway-mock.js.map +1 -0
  149. package/dist/validation/index.d.ts +3 -0
  150. package/dist/validation/index.js +3 -0
  151. package/dist/validation/schemas/customer.json +38 -0
  152. package/dist/validation/schemas/hpp-load-params.json +40 -0
  153. package/dist/validation/schemas/hpp-options.json +48 -0
  154. package/dist/validation/schemas/payment-intent.json +48 -0
  155. package/dist/validation/schemas/payment-method.json +83 -0
  156. package/dist/validation/schemas/verify-card-options.json +15 -0
  157. package/dist/validation/schemas/verify-card-params.json +24 -0
  158. package/dist/validation/validation-helper.d.ts +3 -0
  159. package/dist/validation/validation-helper.js +6 -0
  160. package/dist/validation/validators/hpp-load-params-validator.d.ts +3 -0
  161. package/dist/validation/validators/hpp-load-params-validator.js +14 -0
  162. package/dist/validation/validators/verify-card-params-validator.d.ts +3 -0
  163. package/dist/validation/validators/verify-card-params-validator.js +16 -0
  164. package/docker-compose.yml +16 -0
  165. package/package.json +44 -13
  166. package/tsconfig.json +8 -18
  167. package/tsconfig.package.json +25 -0
  168. package/fat-zebra-sdk-1.0.2.tgz +0 -0
  169. package/fatzebra-sdk-1.0.0.tgz +0 -0
  170. package/index.js +0 -0
  171. package/jest.config.js +0 -16
  172. package/yarn-error.log +0 -2374
@@ -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
+ };
@@ -2,9 +2,7 @@ import React from "react";
2
2
  import * as FatZebra from "../shared/types";
3
3
  type FrameProps = {
4
4
  handlers: FatZebra.Handlers;
5
- username: string;
6
- accessToken: string;
7
- config: FatZebra.VerificationConfig;
5
+ config: FatZebra.PaymentConfig;
8
6
  };
9
- declare const Frame: ({ username, handlers, config }: FrameProps) => React.JSX.Element;
7
+ declare const Frame: ({ handlers, config }: FrameProps) => React.JSX.Element;
10
8
  export default Frame;
@@ -1,15 +1,15 @@
1
1
  import React from "react";
2
2
  import useFatZebra from "./useFatZebra";
3
- const Frame = ({ username, handlers, config }) => {
3
+ import * as env from "../shared/env";
4
+ const Frame = ({ handlers, config }) => {
4
5
  const bridgeRef = React.useRef(null);
5
6
  const { url } = useFatZebra({
6
- username: username,
7
7
  config,
8
8
  handlers: handlers,
9
9
  bridge: bridgeRef,
10
10
  });
11
11
  return (React.createElement("div", null,
12
12
  React.createElement("iframe", { src: url, width: "100%", height: "700px", title: "verification-form" }),
13
- React.createElement("iframe", { title: "bridge-form", src: "http://paynow.test:3004/sdk/bridge", width: "100%", height: "700px", ref: bridgeRef })));
13
+ React.createElement("iframe", { title: "bridge-form", src: env.bridgeUrl, width: "100%", height: "700px", ref: bridgeRef })));
14
14
  };
15
15
  export default Frame;
@@ -1,3 +1,4 @@
1
+ import { OptionalUrlValues } from '../shared/types';
1
2
  type RequiredURLValues = {
2
3
  merchant: string;
3
4
  hash: string;
@@ -5,22 +6,6 @@ type RequiredURLValues = {
5
6
  amount: number;
6
7
  currency: string;
7
8
  };
8
- type VerificationURLValues = OptionalURLValues & {
9
- merchant: string;
10
- timestamp: string;
11
- verification: string;
12
- };
13
- type OptionalURLValues = Partial<{
14
- hide_card_holder: string;
15
- return_path: string;
16
- card_types: Array<string>;
17
- surcharge_enabled: string;
18
- sca_enabled: boolean;
19
- css: string;
20
- css_signature: string;
21
- tokenize_only: boolean;
22
- }>;
23
- type UrlValues = RequiredURLValues & OptionalURLValues;
9
+ type UrlValues = RequiredURLValues & OptionalUrlValues;
24
10
  declare const generatePaymentURL: (values: UrlValues) => string;
25
- declare const generateVerificationURL: (values: VerificationURLValues) => string;
26
- export { generatePaymentURL, generateVerificationURL };
11
+ export { generatePaymentURL };
package/dist/react/url.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { parseTemplate } from 'url-template';
2
+ import * as env from "../shared/env";
2
3
  const generatePaymentURL = (values) => {
3
4
  const queryParts = [
4
5
  "tokenize_only",
@@ -12,7 +13,7 @@ const generatePaymentURL = (values) => {
12
13
  "surcharge_enabled",
13
14
  "sca_enabled",
14
15
  ];
15
- const urlTemplate = parseTemplate(`http://paynow.test:3004/sdk/v3/{merchant}/{reference}/{currency}/{amount}/{verification}{?${queryParts.join(",")}}`);
16
+ const urlTemplate = parseTemplate(`${env.payNowUrl}/sdk/v3/{merchant}/{reference}/{currency}/{amount}/{verification}{?${queryParts.join(",")}}`);
16
17
  const url = urlTemplate.expand({
17
18
  merchant: values.merchant,
18
19
  reference: values.reference,
@@ -28,31 +29,4 @@ const generatePaymentURL = (values) => {
28
29
  });
29
30
  return url;
30
31
  };
31
- const generateVerificationURL = (values) => {
32
- const queryParts = [
33
- "tokenize_only",
34
- "css",
35
- "css_signature",
36
- "iframe",
37
- "postmessage",
38
- "hide_card_holder",
39
- "return_path",
40
- "card_types",
41
- "surcharge_enabled",
42
- "sca_enabled",
43
- ];
44
- const urlTemplate = parseTemplate(`http://paynow.test:3004/sdk/v3/{merchant}/verification/{timestamp}/{verification}{?${queryParts.join(",")}}`);
45
- const url = urlTemplate.expand({
46
- merchant: values.merchant,
47
- timestamp: values.timestamp,
48
- verification: values.verification,
49
- sca_enabled: values.sca_enabled,
50
- css: values.css,
51
- css_signature: values.css_signature,
52
- iframe: true,
53
- postmessage: true,
54
- tokenize_only: values.tokenize_only,
55
- });
56
- return url;
57
- };
58
- export { generatePaymentURL, generateVerificationURL };
32
+ export { generatePaymentURL };
@@ -1,12 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import * as FatZebra from "../shared/types";
3
3
  type UseFatZebraProps = {
4
- username: string;
5
4
  handlers: FatZebra.Handlers;
6
- config: FatZebra.VerificationConfig;
5
+ config: FatZebra.PaymentConfig;
7
6
  bridge: React.MutableRefObject<HTMLIFrameElement>;
8
7
  };
9
- declare const useFatZebra: ({ username, config, handlers, bridge }: UseFatZebraProps) => {
8
+ declare const useFatZebra: ({ config, handlers, bridge }: UseFatZebraProps) => {
10
9
  url: string;
11
10
  };
12
11
  export default useFatZebra;
@@ -3,11 +3,13 @@ import * as FatZebra from "../shared/types";
3
3
  import { generatePaymentURL } from "./url";
4
4
  import Sca from "../sca";
5
5
  import GatewayClient from "../shared/api-gateway-client";
6
- const useFatZebra = ({ username, config, handlers, bridge }) => {
7
- const { options, accessToken, paymentIntent, verification } = config;
6
+ const useFatZebra = ({ config, handlers, bridge }) => {
7
+ const { options, accessToken, paymentIntent, username } = config;
8
8
  const sca = useMemo(() => {
9
9
  const gatewayClient = new GatewayClient({ accessToken, username });
10
- return new Sca({ gatewayClient });
10
+ const successCallback = handlers[FatZebra.PublicEvent.SCA_SUCCESS];
11
+ const failureCallback = handlers[FatZebra.PublicEvent.SCA_ERROR];
12
+ return new Sca({ gatewayClient, successCallback, failureCallback });
11
13
  }, [config, username]);
12
14
  const emit = (event, data) => {
13
15
  const handler = handlers[event];
@@ -60,9 +62,7 @@ const useFatZebra = ({ username, config, handlers, bridge }) => {
60
62
  },
61
63
  });
62
64
  }
63
- if (options.tokenizeOnly)
64
- return;
65
- if (options.enableSca) {
65
+ if (options.sca_enabled) {
66
66
  sca.run({ paymentIntent, bin: data.bin, cardToken: data.token });
67
67
  }
68
68
  };
@@ -101,7 +101,7 @@ const useFatZebra = ({ username, config, handlers, bridge }) => {
101
101
  };
102
102
  }, []);
103
103
  const payment = paymentIntent.payment;
104
- const url = generatePaymentURL(Object.assign(Object.assign({}, options), { merchant: username, reference: payment.reference, amount: payment.amount, currency: payment.currency, hash: verification }));
104
+ const url = generatePaymentURL(Object.assign({ merchant: username, reference: payment.reference, amount: payment.amount, currency: payment.currency, hash: paymentIntent.verification }, options));
105
105
  return { url };
106
106
  };
107
107
  export default useFatZebra;
@@ -25,5 +25,5 @@ export default class CardinalManager {
25
25
  processBin(bin: string): Promise<any>;
26
26
  continue(acsUrl: string, pareq: string, transactionId: string): void;
27
27
  }
28
- export { CardinalManager };
28
+ export { CardinalManager, };
29
29
  export type { PaymentValidatedDTO };
@@ -67,4 +67,4 @@ export default class CardinalManager {
67
67
  });
68
68
  }
69
69
  }
70
- export { CardinalManager };
70
+ export { CardinalManager, };
@@ -1,5 +1,5 @@
1
1
  import * as t from './types';
2
- import { Customer, CustomerSnakeCase, PaymentIntent } from '../shared/types';
2
+ import { Customer, CustomerSnakeCase, PaymentIntent, PublicEvent } from '../shared/types';
3
3
  import { CardinalManager } from './cardinal';
4
4
  import GatewayClient from '../shared/api-gateway-client';
5
5
  export interface ScaRunProps {
@@ -11,10 +11,11 @@ export interface ScaRunProps {
11
11
  }
12
12
  export interface ScaConfig {
13
13
  gatewayClient: GatewayClient;
14
+ successCallback?: (event: PublicEvent.SCA_SUCCESS, detail: any) => void;
15
+ failureCallback?: (event: PublicEvent.SCA_ERROR, detail: any) => void;
14
16
  }
15
17
  declare class Sca {
16
18
  private _cardinal;
17
- private _eventEmitTarget;
18
19
  private enrollmentResult;
19
20
  private paymentIntent;
20
21
  private bin;
@@ -23,12 +24,14 @@ declare class Sca {
23
24
  private challengeWindowSize;
24
25
  private sessionId;
25
26
  private gatewayClient;
26
- constructor({ gatewayClient }: ScaConfig);
27
+ private successCallback;
28
+ private failureCallback;
29
+ constructor({ gatewayClient, successCallback, failureCallback }: ScaConfig);
27
30
  loadScript(): void;
28
31
  get cardinal(): CardinalManager;
29
32
  set cardinal(cardinal: CardinalManager);
30
- get eventEmitTarget(): HTMLDivElement | Window;
31
- set eventEmitTarget(target: HTMLDivElement | Window);
33
+ reportFailure(message: string): void;
34
+ reportSuccess(message: string, data: any): void;
32
35
  run(config: ScaRunProps): Promise<void>;
33
36
  createCardinalJWT(): Promise<string>;
34
37
  check3DSEnrollment(): Promise<void>;