@fat-zebra/sdk 1.0.6 → 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 (169) 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 +1 -2
  36. package/dist/react/url.d.ts +2 -11
  37. package/dist/react/useFatZebra.d.ts +2 -3
  38. package/dist/react/useFatZebra.js +7 -7
  39. package/dist/sca/cardinal.d.ts +1 -1
  40. package/dist/sca/cardinal.js +1 -1
  41. package/dist/sca/index.d.ts +8 -5
  42. package/dist/sca/index.js +26 -87
  43. package/dist/sca/sca.d.ts +42 -0
  44. package/dist/sca/sca.js +273 -0
  45. package/dist/sca/scenarios/index.d.ts +3 -2
  46. package/dist/sca/types.d.ts +1 -1
  47. package/dist/sca/types.js +1 -1
  48. package/dist/shared/api-gateway-client.d.ts +7 -0
  49. package/dist/shared/api-gateway-client.js +37 -3
  50. package/dist/shared/env.d.ts +1 -1
  51. package/dist/shared/env.development.d.ts +5 -0
  52. package/dist/shared/env.development.js +5 -0
  53. package/dist/shared/env.js +1 -1
  54. package/dist/shared/event-manager.d.ts +1 -1
  55. package/dist/shared/event-manager.js +0 -1
  56. package/dist/shared/post-message-client.d.ts +1 -1
  57. package/dist/shared/post-message-client.js +2 -3
  58. package/dist/shared/types.d.ts +40 -33
  59. package/dist/shared/types.js +7 -1
  60. package/dist/src/applepay/applepay.js +198 -0
  61. package/dist/src/applepay/applepay.js.map +1 -0
  62. package/dist/src/applepay/clients/apple-pay-client.js +66 -0
  63. package/dist/src/applepay/clients/apple-pay-client.js.map +1 -0
  64. package/dist/src/applepay/clients/paynow-client.js +96 -0
  65. package/dist/src/applepay/clients/paynow-client.js.map +1 -0
  66. package/dist/src/applepay/index.js +6 -0
  67. package/dist/src/applepay/index.js.map +1 -0
  68. package/dist/src/hpp/hpp.js +230 -0
  69. package/dist/src/hpp/hpp.js.map +1 -0
  70. package/dist/src/hpp/hpp.test.js +135 -0
  71. package/dist/src/hpp/hpp.test.js.map +1 -0
  72. package/dist/src/hpp/index.js +6 -0
  73. package/dist/src/hpp/index.js.map +1 -0
  74. package/dist/src/index.js +7 -0
  75. package/dist/src/index.js.map +1 -0
  76. package/dist/src/main.js +225 -0
  77. package/dist/src/main.js.map +1 -0
  78. package/dist/src/main.test.js +236 -0
  79. package/dist/src/main.test.js.map +1 -0
  80. package/dist/src/paypal/paypal-button.js +311 -0
  81. package/dist/src/paypal/paypal-button.js.map +1 -0
  82. package/dist/src/paypal/paypal-button.test.js +41 -0
  83. package/dist/src/paypal/paypal-button.test.js.map +1 -0
  84. package/dist/src/paypal/paypal-checkout.js +111 -0
  85. package/dist/src/paypal/paypal-checkout.js.map +1 -0
  86. package/dist/src/paypal/paypal-checkout.test.js +167 -0
  87. package/dist/src/paypal/paypal-checkout.test.js.map +1 -0
  88. package/dist/src/paypal/types.js +9 -0
  89. package/dist/src/paypal/types.js.map +1 -0
  90. package/dist/src/paypal/validation.js +73 -0
  91. package/dist/src/paypal/validation.js.map +1 -0
  92. package/dist/src/sca/__tests__/eci-mappings.test.js +31 -0
  93. package/dist/src/sca/__tests__/eci-mappings.test.js.map +1 -0
  94. package/dist/src/sca/__tests__/index.test.js +558 -0
  95. package/dist/src/sca/__tests__/index.test.js.map +1 -0
  96. package/dist/src/sca/cardinal.js +110 -0
  97. package/dist/src/sca/cardinal.js.map +1 -0
  98. package/dist/src/sca/eci-mappings.js +63 -0
  99. package/dist/src/sca/eci-mappings.js.map +1 -0
  100. package/dist/src/sca/eci-mappings.test.js +31 -0
  101. package/dist/src/sca/eci-mappings.test.js.map +1 -0
  102. package/dist/src/sca/index.js +388 -0
  103. package/dist/src/sca/index.js.map +1 -0
  104. package/dist/src/sca/index.test.js +558 -0
  105. package/dist/src/sca/index.test.js.map +1 -0
  106. package/dist/src/sca/scenarios/enrollment.js +150 -0
  107. package/dist/src/sca/scenarios/enrollment.js.map +1 -0
  108. package/dist/src/sca/scenarios/index.js +8 -0
  109. package/dist/src/sca/scenarios/index.js.map +1 -0
  110. package/dist/src/sca/scenarios/validation.js +128 -0
  111. package/dist/src/sca/scenarios/validation.js.map +1 -0
  112. package/dist/src/sca/types.js +57 -0
  113. package/dist/src/sca/types.js.map +1 -0
  114. package/dist/src/shared/api-gateway-client.js +150 -0
  115. package/dist/src/shared/api-gateway-client.js.map +1 -0
  116. package/dist/src/shared/bridge-client.js +24 -0
  117. package/dist/src/shared/bridge-client.js.map +1 -0
  118. package/dist/src/shared/constants.js +19 -0
  119. package/dist/src/shared/constants.js.map +1 -0
  120. package/dist/src/shared/event-manager.js +15 -0
  121. package/dist/src/shared/event-manager.js.map +1 -0
  122. package/dist/src/shared/post-message-client.js +107 -0
  123. package/dist/src/shared/post-message-client.js.map +1 -0
  124. package/dist/src/shared/post-message-client.test.js +58 -0
  125. package/dist/src/shared/post-message-client.test.js.map +1 -0
  126. package/dist/src/shared/types.js +47 -0
  127. package/dist/src/shared/types.js.map +1 -0
  128. package/dist/src/shared/types.test.js +55 -0
  129. package/dist/src/shared/types.test.js.map +1 -0
  130. package/dist/src/shared/util.js +96 -0
  131. package/dist/src/shared/util.js.map +1 -0
  132. package/dist/src/shared/util.test.js +148 -0
  133. package/dist/src/shared/util.test.js.map +1 -0
  134. package/dist/src/validation/index.js +10 -0
  135. package/dist/src/validation/index.js.map +1 -0
  136. package/dist/src/validation/validation-helper.js +10 -0
  137. package/dist/src/validation/validation-helper.js.map +1 -0
  138. package/dist/src/validation/validation-helper.test.js +34 -0
  139. package/dist/src/validation/validation-helper.test.js.map +1 -0
  140. package/dist/src/validation/validators/hpp-load-params-validator.js +17 -0
  141. package/dist/src/validation/validators/hpp-load-params-validator.js.map +1 -0
  142. package/dist/src/validation/validators/hpp-load-params-validator.test.js +56 -0
  143. package/dist/src/validation/validators/hpp-load-params-validator.test.js.map +1 -0
  144. package/dist/src/validation/validators/verify-card-params-validator.js +18 -0
  145. package/dist/src/validation/validators/verify-card-params-validator.js.map +1 -0
  146. package/dist/tests/helpers/api-gateway-mock.js +36 -0
  147. package/dist/tests/helpers/api-gateway-mock.js.map +1 -0
  148. package/dist/validation/index.d.ts +3 -0
  149. package/dist/validation/index.js +3 -0
  150. package/dist/validation/schemas/customer.json +38 -0
  151. package/dist/validation/schemas/hpp-load-params.json +40 -0
  152. package/dist/validation/schemas/hpp-options.json +48 -0
  153. package/dist/validation/schemas/payment-intent.json +48 -0
  154. package/dist/validation/schemas/payment-method.json +83 -0
  155. package/dist/validation/schemas/verify-card-options.json +15 -0
  156. package/dist/validation/schemas/verify-card-params.json +24 -0
  157. package/dist/validation/validation-helper.d.ts +3 -0
  158. package/dist/validation/validation-helper.js +6 -0
  159. package/dist/validation/validators/hpp-load-params-validator.d.ts +3 -0
  160. package/dist/validation/validators/hpp-load-params-validator.js +14 -0
  161. package/dist/validation/validators/verify-card-params-validator.d.ts +3 -0
  162. package/dist/validation/validators/verify-card-params-validator.js +16 -0
  163. package/docker-compose.yml +16 -0
  164. package/package.json +44 -15
  165. package/tsconfig.json +8 -18
  166. package/tsconfig.package.json +25 -0
  167. package/index.js +0 -0
  168. package/jest.config.js +0 -16
  169. package/yarn-error.log +0 -2374
package/dist/sca/index.js CHANGED
@@ -13,30 +13,22 @@ import { PublicEvent, } from '../shared/types';
13
13
  import { CardinalManager, } from './cardinal';
14
14
  import { emit, } from '../shared/event-manager';
15
15
  import { toFzSli } from './eci-mappings';
16
- import * as env from "../shared/env";
17
16
  class Sca {
18
- constructor({ gatewayClient }) {
19
- this._eventEmitTarget = window;
17
+ constructor({ gatewayClient, successCallback, failureCallback }) {
20
18
  this.sessionId = null;
21
19
  this.gatewayClient = gatewayClient;
22
- this.loadScript();
20
+ this.successCallback = successCallback || emit;
21
+ this.failureCallback = failureCallback || emit;
23
22
  }
24
23
  loadScript() {
25
- if (!document.getElementById("songbird-script")) {
26
- console.log(env);
27
- const script = document.createElement('script');
28
- script.type = 'text/javascript';
29
- script.id = "songbird-script";
30
- script.src = env.songbirdUrl;
31
- script.async = true;
32
- script.onload = () => {
33
- this._cardinal = new CardinalManager();
34
- };
35
- document.body.appendChild(script);
36
- }
37
- else {
24
+ const script = document.createElement('script');
25
+ script.type = 'text/javascript';
26
+ script.src = process.env.SONGBIRD_URL;
27
+ script.async = true;
28
+ script.onload = () => {
38
29
  this._cardinal = new CardinalManager();
39
- }
30
+ };
31
+ document.body.appendChild(script);
40
32
  }
41
33
  get cardinal() {
42
34
  return this._cardinal;
@@ -44,12 +36,13 @@ class Sca {
44
36
  set cardinal(cardinal) {
45
37
  this._cardinal = cardinal;
46
38
  }
47
- get eventEmitTarget() {
48
- return this._eventEmitTarget;
39
+ reportFailure(message) {
40
+ this.failureCallback(PublicEvent.SCA_ERROR, { errors: [message] });
41
+ console.log(message);
49
42
  }
50
- // Specify the DOM element to which the SCA results are outputted.
51
- set eventEmitTarget(target) {
52
- this._eventEmitTarget = target;
43
+ reportSuccess(message, data) {
44
+ this.successCallback(PublicEvent.SCA_SUCCESS, { data, message });
45
+ console.log(message);
53
46
  }
54
47
  run(config) {
55
48
  return __awaiter(this, void 0, void 0, function* () {
@@ -65,12 +58,7 @@ class Sca {
65
58
  cardinalJwt = yield this.createCardinalJWT();
66
59
  }
67
60
  catch (error) {
68
- const message = 'FatZebra.3DS: JWT creation failed.';
69
- emit(PublicEvent.SCA_ERROR, {
70
- errors: [message],
71
- data: null
72
- });
73
- console.log(message);
61
+ this.reportFailure('FatZebra.3DS: JWT creation failed.');
74
62
  return;
75
63
  }
76
64
  // Init cardinal
@@ -81,24 +69,14 @@ class Sca {
81
69
  // Register handler. Called after OTP is entered on challenge prompt.
82
70
  this._cardinal.onPaymentValidated((data, error) => __awaiter(this, void 0, void 0, function* () {
83
71
  if (typeof error == 'string') {
84
- const message = `FatZebra.3DS: Validation failed. ${error}.`;
85
- emit(PublicEvent.SCA_ERROR, {
86
- errors: [message],
87
- data: null,
88
- });
89
- console.log(message);
72
+ this.reportFailure(`FatZebra.3DS: Validation failed. ${error}.`);
90
73
  return;
91
74
  }
92
75
  const decodeSCASessionResponse = (yield this.gatewayClient.decodeSCASession({
93
76
  token: data.jwt
94
77
  })).data;
95
78
  if (data.processorTransactionId !== decodeSCASessionResponse.processor_transaction_id) {
96
- const message = 'FatZebra.3DS: Validation failed. Invalid process transaction id.';
97
- emit(PublicEvent.SCA_ERROR, {
98
- errors: [message],
99
- data: null
100
- });
101
- console.log(message);
79
+ this.reportFailure("FatZebra.3DS: Validation failed. Invalid process transaction id.");
102
80
  }
103
81
  let validateSCAResponse;
104
82
  try {
@@ -113,33 +91,16 @@ class Sca {
113
91
  validateSCAResponse = (yield this.gatewayClient.validateSCA(requestParams)).data;
114
92
  }
115
93
  catch (errorResponse) {
116
- const message = 'FatZebra.3DS: Validation failed. Server error.';
117
- emit(PublicEvent.SCA_ERROR, {
118
- errors: [message],
119
- data: null,
120
- });
121
- console.log(message);
94
+ this.reportFailure('FatZebra.3DS: Validation failed. Server error.');
122
95
  return;
123
96
  }
124
97
  const threedsData = threedsResponseData(validateSCAResponse);
125
98
  const scenario = getValidationResult(validateSCAResponse);
126
99
  if (scenario.outcome.success) {
127
- const message = `FatZebra.3DS: 3DS success - ${scenario.description}.`;
128
- emit(PublicEvent.SCA_SUCCESS, {
129
- message,
130
- data: threedsData,
131
- });
132
- console.log(message);
100
+ this.reportSuccess(`FatZebra.3DS: 3DS success - ${scenario.description}.`, threedsData);
133
101
  }
134
102
  else {
135
- const message = `FatZebra.3DS: 3DS error - ${scenario.description}`;
136
- emit(PublicEvent.SCA_ERROR, {
137
- errors: [message],
138
- data: {
139
- errorCode: scenario.outcome.errorCode
140
- },
141
- });
142
- console.log(message);
103
+ this.reportFailure(`FatZebra.3DS: 3DS error - ${scenario.description} - ${scenario.outcome.errorCode}`);
143
104
  }
144
105
  }));
145
106
  }
@@ -148,24 +109,14 @@ class Sca {
148
109
  yield this._cardinal.processBin(this.bin);
149
110
  }
150
111
  catch (err) {
151
- const message = 'FatZebra.3DS: BIN verification failed.';
152
- emit(PublicEvent.SCA_ERROR, {
153
- errors: [message],
154
- data: null
155
- });
156
- console.log(message);
112
+ this.reportFailure('FatZebra.3DS: BIN verification failed.');
157
113
  return;
158
114
  }
159
115
  try {
160
116
  yield this.check3DSEnrollment();
161
117
  }
162
118
  catch (err) {
163
- const message = 'FatZebra.3DS: Enrollment failed. Server error.';
164
- emit(PublicEvent.SCA_ERROR, {
165
- errors: [message],
166
- data: null
167
- });
168
- console.log(message);
119
+ this.reportFailure('FatZebra.3DS: Enrollment failed. Server error.');
169
120
  return;
170
121
  }
171
122
  this.handleEnrollmentResult(this.enrollmentResult);
@@ -228,22 +179,10 @@ class Sca {
228
179
  return;
229
180
  }
230
181
  if (scenario.outcome.success) {
231
- const message = `FatZebra.3DS: 3DS success - ${scenario.description}.`;
232
- emit(PublicEvent.SCA_SUCCESS, {
233
- message,
234
- data: threedsData,
235
- });
236
- console.log(message);
182
+ this.reportSuccess(`FatZebra.3DS: 3DS success - ${scenario.description}.`, threedsData);
237
183
  }
238
184
  else {
239
- const message = `FatZebra.3DS: 3DS error - ${scenario.description}`;
240
- emit(PublicEvent.SCA_ERROR, {
241
- errors: [message],
242
- data: {
243
- errorCode: scenario.outcome.errorCode
244
- },
245
- });
246
- console.log(message);
185
+ this.reportFailure(`FatZebra.3DS: 3DS error - ${scenario.description} - ${scenario.outcome.errorCode}`);
247
186
  }
248
187
  }
249
188
  }
@@ -0,0 +1,42 @@
1
+ import * as t from './types';
2
+ import { Customer, CustomerSnakeCase, PaymentIntent } from '../shared/types';
3
+ import { CardinalManager } from './cardinal';
4
+ interface ScaConfig {
5
+ cardToken: string;
6
+ customer?: Customer;
7
+ paymentIntent: PaymentIntent;
8
+ bin: string;
9
+ challengeWindowSize?: t.ChallengeWindowSize;
10
+ }
11
+ interface ThreedsData {
12
+ cavv: string;
13
+ par: string;
14
+ sli: string;
15
+ xid: string;
16
+ ver: string;
17
+ directoryServerTxnId: string;
18
+ threedsVersion: string;
19
+ }
20
+ declare class Sca {
21
+ private _cardinal;
22
+ private _eventEmitTarget;
23
+ private enrollmentResult;
24
+ private paymentIntent;
25
+ private bin;
26
+ private cardToken;
27
+ private customer;
28
+ private challengeWindowSize;
29
+ private sessionId;
30
+ constructor();
31
+ loadScript(): void;
32
+ get cardinal(): CardinalManager;
33
+ set cardinal(cardinal: CardinalManager);
34
+ get eventEmitTarget(): HTMLDivElement | Window;
35
+ set eventEmitTarget(target: HTMLDivElement | Window);
36
+ run(config: ScaConfig): Promise<void>;
37
+ createCardinalJWT(): Promise<string>;
38
+ check3DSEnrollment(): Promise<void>;
39
+ customerProperties(customer: Customer): CustomerSnakeCase;
40
+ handleEnrollmentResult(enrollSCAResponse: t.EnrollSCAResponse): void;
41
+ }
42
+ export { Sca, ThreedsData, ScaConfig };
@@ -0,0 +1,273 @@
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 { createSCASession, decodeSCASession, enrolSCA, validateSCA, } from '../shared/api-gateway-client';
11
+ import * as t from './types';
12
+ import { enrollmentScenarios, validationScenarios, } from './scenarios';
13
+ import { PublicEvent, } from '../shared/types';
14
+ import { CardinalManager, } from './cardinal';
15
+ import { emit, } from '../shared/event-manager';
16
+ import { toFzSli } from './eci-mappings';
17
+ class Sca {
18
+ constructor() {
19
+ this._eventEmitTarget = window;
20
+ this.sessionId = null;
21
+ }
22
+ loadScript() {
23
+ const script = document.createElement('script');
24
+ script.type = 'text/javascript';
25
+ script.src = process.env.SONGBIRD_URL;
26
+ script.async = true;
27
+ script.onload = () => {
28
+ this._cardinal = new CardinalManager();
29
+ };
30
+ document.body.appendChild(script);
31
+ }
32
+ get cardinal() {
33
+ return this._cardinal;
34
+ }
35
+ set cardinal(cardinal) {
36
+ this._cardinal = cardinal;
37
+ }
38
+ get eventEmitTarget() {
39
+ return this._eventEmitTarget;
40
+ }
41
+ // Specify the DOM element to which the SCA results are outputted.
42
+ set eventEmitTarget(target) {
43
+ this._eventEmitTarget = target;
44
+ }
45
+ run(config) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ // Persist states until next 3DS run.
48
+ this.paymentIntent = config.paymentIntent;
49
+ this.bin = config.bin;
50
+ this.cardToken = config.cardToken;
51
+ this.customer = config.customer;
52
+ this.challengeWindowSize = config.challengeWindowSize || t.ChallengeWindowSize.SIZE_FULL_PAGE;
53
+ let cardinalJwt;
54
+ // Generate Cardinal JWT
55
+ try {
56
+ cardinalJwt = yield this.createCardinalJWT();
57
+ }
58
+ catch (error) {
59
+ const message = 'FatZebra.3DS: JWT creation failed.';
60
+ emit(PublicEvent.SCA_ERROR, {
61
+ errors: [message],
62
+ data: null
63
+ });
64
+ console.log(message);
65
+ return;
66
+ }
67
+ // Init cardinal
68
+ this._cardinal.setup(cardinalJwt);
69
+ if (!this.sessionId) {
70
+ const paymentsSetupCompleteResponse = yield this._cardinal.onPaymentSetupComplete();
71
+ this.sessionId = paymentsSetupCompleteResponse.sessionId;
72
+ // Register handler. Called after OTP is entered on challenge prompt.
73
+ this._cardinal.onPaymentValidated((data, error) => __awaiter(this, void 0, void 0, function* () {
74
+ if (typeof error == 'string') {
75
+ const message = `FatZebra.3DS: Validation failed. ${error}.`;
76
+ emit(PublicEvent.SCA_ERROR, {
77
+ errors: [message],
78
+ data: null,
79
+ });
80
+ console.log(message);
81
+ return;
82
+ }
83
+ const decodeSCASessionResponse = (yield decodeSCASession({
84
+ token: data.jwt
85
+ })).data;
86
+ if (data.processorTransactionId !== decodeSCASessionResponse.processor_transaction_id) {
87
+ const message = 'FatZebra.3DS: Validation failed. Invalid process transaction id.';
88
+ emit(PublicEvent.SCA_ERROR, {
89
+ errors: [message],
90
+ data: null
91
+ });
92
+ console.log(message);
93
+ }
94
+ let validateSCAResponse;
95
+ try {
96
+ const requestParams = {
97
+ amount: this.paymentIntent.payment.amount,
98
+ authentication_transaction_id: this.enrollmentResult.authentication_transaction_id,
99
+ card_token: this.cardToken,
100
+ currency: this.paymentIntent.payment.currency,
101
+ pareq: this.enrollmentResult.pareq,
102
+ reference: this.paymentIntent.payment.reference,
103
+ };
104
+ validateSCAResponse = (yield validateSCA(requestParams)).data;
105
+ }
106
+ catch (errorResponse) {
107
+ const message = 'FatZebra.3DS: Validation failed. Server error.';
108
+ emit(PublicEvent.SCA_ERROR, {
109
+ errors: [message],
110
+ data: null,
111
+ });
112
+ console.log(message);
113
+ return;
114
+ }
115
+ const threedsData = threedsResponseData(validateSCAResponse);
116
+ const scenario = getValidationResult(validateSCAResponse);
117
+ if (scenario.outcome.success) {
118
+ const message = `FatZebra.3DS: 3DS success - ${scenario.description}.`;
119
+ emit(PublicEvent.SCA_SUCCESS, {
120
+ message,
121
+ data: threedsData,
122
+ });
123
+ console.log(message);
124
+ }
125
+ else {
126
+ const message = `FatZebra.3DS: 3DS error - ${scenario.description}`;
127
+ emit(PublicEvent.SCA_ERROR, {
128
+ errors: [message],
129
+ data: {
130
+ errorCode: scenario.outcome.errorCode
131
+ },
132
+ });
133
+ console.log(message);
134
+ }
135
+ }));
136
+ }
137
+ // Cardinal processs BIN using directory server. This determines the 3DS version used.
138
+ try {
139
+ yield this._cardinal.processBin(this.bin);
140
+ }
141
+ catch (err) {
142
+ const message = 'FatZebra.3DS: BIN verification failed.';
143
+ emit(PublicEvent.SCA_ERROR, {
144
+ errors: [message],
145
+ data: null
146
+ });
147
+ console.log(message);
148
+ return;
149
+ }
150
+ try {
151
+ yield this.check3DSEnrollment();
152
+ }
153
+ catch (err) {
154
+ const message = 'FatZebra.3DS: Enrollment failed. Server error.';
155
+ emit(PublicEvent.SCA_ERROR, {
156
+ errors: [message],
157
+ data: null
158
+ });
159
+ console.log(message);
160
+ return;
161
+ }
162
+ this.handleEnrollmentResult(this.enrollmentResult);
163
+ });
164
+ }
165
+ createCardinalJWT() {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const { payment } = this.paymentIntent;
168
+ const response = (yield createSCASession({
169
+ amount: payment.amount,
170
+ currency: payment.currency,
171
+ hide_card_holder: payment.hide_card_holder,
172
+ })).data;
173
+ return response.jwt;
174
+ });
175
+ }
176
+ check3DSEnrollment() {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ // Persist enrollResult state in memory for handlePaymentValidation handler
179
+ this.enrollmentResult = (yield enrolSCA({
180
+ amount: this.paymentIntent.payment.amount,
181
+ card_token: this.cardToken,
182
+ currency: this.paymentIntent.payment.currency,
183
+ reference: this.paymentIntent.payment.reference,
184
+ verification: this.paymentIntent.verification,
185
+ session_id: this.sessionId,
186
+ challenge_window_size: this.challengeWindowSize,
187
+ hide_card_holder: this.paymentIntent.payment.hide_card_holder,
188
+ customer: this.customerProperties(this.customer),
189
+ })).data;
190
+ });
191
+ }
192
+ customerProperties(customer) {
193
+ let properties = {};
194
+ if (!customer)
195
+ return properties;
196
+ if (customer.firstName)
197
+ properties.first_name = customer.firstName;
198
+ if (customer.lastName)
199
+ properties.last_name = customer.lastName;
200
+ if (customer.email)
201
+ properties.email = customer.email;
202
+ if (customer.address)
203
+ properties.address = customer.address;
204
+ if (customer.city)
205
+ properties.city = customer.city;
206
+ if (customer.state)
207
+ properties.state = customer.state;
208
+ if (customer.postcode)
209
+ properties.postcode = customer.postcode;
210
+ if (customer.country)
211
+ properties.country = customer.country;
212
+ return properties;
213
+ }
214
+ handleEnrollmentResult(enrollSCAResponse) {
215
+ const threedsData = threedsResponseData(enrollSCAResponse);
216
+ const scenario = getEnrollmentResult(enrollSCAResponse);
217
+ if (scenario.outcome.authenticationType === 'challenge') {
218
+ this._cardinal.continue(enrollSCAResponse.acs_url, enrollSCAResponse.pareq, enrollSCAResponse.authentication_transaction_id);
219
+ return;
220
+ }
221
+ if (scenario.outcome.success) {
222
+ const message = `FatZebra.3DS: 3DS success - ${scenario.description}.`;
223
+ emit(PublicEvent.SCA_SUCCESS, {
224
+ message,
225
+ data: threedsData,
226
+ });
227
+ console.log(message);
228
+ }
229
+ else {
230
+ const message = `FatZebra.3DS: 3DS error - ${scenario.description}`;
231
+ emit(PublicEvent.SCA_ERROR, {
232
+ errors: [message],
233
+ data: {
234
+ errorCode: scenario.outcome.errorCode
235
+ },
236
+ });
237
+ console.log(message);
238
+ }
239
+ }
240
+ }
241
+ const threedsResponseData = (response) => {
242
+ return {
243
+ // CAVV: Visa & Amex only
244
+ // AAV: Mastercard only, known as UCAF
245
+ cavv: response.cavv || response.aav,
246
+ par: response.pares,
247
+ sli: toFzSli(response.eci),
248
+ xid: response.xid,
249
+ ver: response.enrolled,
250
+ directoryServerTxnId: response.directory_server_txn_id,
251
+ threedsVersion: response.version,
252
+ };
253
+ };
254
+ const getEnrollmentResult = (enrollment) => {
255
+ return enrollmentScenarios.find((item) => {
256
+ return item.reasonCode === enrollment.reason_code &&
257
+ item.veresEnrolled === enrollment.enrolled &&
258
+ item.pares === enrollment.pares &&
259
+ item.threedsVersion === getMajor3dsVersion(enrollment.version);
260
+ });
261
+ };
262
+ const getValidationResult = (validation) => {
263
+ return validationScenarios.find((item) => {
264
+ return item.reasonCode === validation.reason_code &&
265
+ item.pares === validation.pares &&
266
+ item.threedsVersion === getMajor3dsVersion(validation.version);
267
+ });
268
+ };
269
+ // 3DS versioning follows SEMVER format. The first charactor is the major version number.
270
+ const getMajor3dsVersion = (original) => {
271
+ return original[0];
272
+ };
273
+ export { Sca };
@@ -1,4 +1,5 @@
1
1
  export { enrollmentScenarios } from './enrollment';
2
- export type { EnrollmentScenario } from './enrollment';
3
2
  export { validationScenarios } from './validation';
4
- export type { ValidationScenario } from './validation';
3
+ import type { EnrollmentScenario } from './enrollment';
4
+ import type { ValidationScenario } from './validation';
5
+ export type { EnrollmentScenario, ValidationScenario };
@@ -155,5 +155,5 @@ interface GetCardRequest {
155
155
  interface GetCardResponse {
156
156
  bin: string;
157
157
  }
158
- export { ScaErrorCode, ChallengeWindowSize, CommerceIndicator, VEResEnrolled, PARes };
158
+ export { ScaErrorCode, ChallengeWindowSize, CommerceIndicator, VEResEnrolled, PARes, };
159
159
  export type { CreateSCASessionRequest, CreateSCASessionResponse, EnrollSCARequest, EnrollSCAResponse, ValidateSCARequest, ValidateSCAResponse, DecodeSCASessionRequest, DecodeSCASessionResponse, GetCardRequest, GetCardResponse, ThreedsData };
package/dist/sca/types.js CHANGED
@@ -51,4 +51,4 @@ var PARes;
51
51
  PARes["NOT_COMPLETED"] = "U";
52
52
  PARes["SUCCESS"] = "Y";
53
53
  })(PARes || (PARes = {}));
54
- export { ScaErrorCode, ChallengeWindowSize, CommerceIndicator, VEResEnrolled, PARes };
54
+ export { ScaErrorCode, ChallengeWindowSize, CommerceIndicator, VEResEnrolled, PARes, };
@@ -1,5 +1,6 @@
1
1
  import { AxiosResponse, AxiosInstance } from "axios";
2
2
  import * as sca from "../sca/types";
3
+ import * as paypal from "../paypal/types";
3
4
  export type GatewayClientProps = {
4
5
  accessToken: string;
5
6
  username: string;
@@ -13,5 +14,11 @@ declare class GatewayClient {
13
14
  enrolSCA(data: sca.EnrollSCARequest): Promise<AxiosResponse>;
14
15
  validateSCA(data: sca.ValidateSCARequest): Promise<AxiosResponse>;
15
16
  getCard(data: sca.GetCardRequest): Promise<AxiosResponse>;
17
+ /**************** PayPal /****************/
18
+ createPayPalOrder(data: paypal.CreatePayPalOrderRequest): Promise<AxiosResponse>;
19
+ capturePayPalOrder(data: paypal.CapturePayPalOrderRequest): Promise<AxiosResponse>;
20
+ authorizePayPalOrder(data: paypal.AuthorizePayPalOrderRequest): Promise<AxiosResponse>;
21
+ createPayPalBillingAgreement(data: paypal.CreatePayPalBillingAgreementRequest): Promise<AxiosResponse>;
22
+ approvePayPalBillingAgreement(data: paypal.ApprovePayPalBillingAgreementRequest): Promise<AxiosResponse>;
16
23
  }
17
24
  export default GatewayClient;
@@ -7,10 +7,10 @@ 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 { RequestHeaderSdkVersion, RequestHeaderMerchantUsername, RequestTimeout, } from "./constants";
10
+ import { RequestHeaderSdkVersion, RequestHeaderMerchantUsername, RequestTimeout, LongRequestTimeout, } from "./constants";
11
11
  import axios from "axios";
12
12
  import { getSdkVersionNumber } from "./util";
13
- import * as env from "../shared/env";
13
+ const baseUrl = process.env.API_GATEWAY_URL;
14
14
  class GatewayClient {
15
15
  constructor({ accessToken, username }) {
16
16
  const headers = {};
@@ -18,7 +18,7 @@ class GatewayClient {
18
18
  headers[RequestHeaderSdkVersion] = getSdkVersionNumber();
19
19
  headers[RequestHeaderMerchantUsername] = username;
20
20
  this.client = axios.create({
21
- baseURL: env.apiUrl,
21
+ baseURL: baseUrl,
22
22
  timeout: RequestTimeout,
23
23
  headers,
24
24
  responseType: "json",
@@ -57,5 +57,39 @@ class GatewayClient {
57
57
  return this.client.get(`/credit_cards/${data.card_token}`);
58
58
  });
59
59
  }
60
+ /**************** PayPal /****************/
61
+ createPayPalOrder(data) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ return this.client.post("/paypal/orders", data, {
64
+ timeout: LongRequestTimeout,
65
+ });
66
+ });
67
+ }
68
+ capturePayPalOrder(data) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ return this.client.post(`/paypal/orders/${data.id}/capture`, null, {
71
+ timeout: LongRequestTimeout,
72
+ });
73
+ });
74
+ }
75
+ authorizePayPalOrder(data) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ return this.client.post(`/paypal/orders/${data.id}/authorize`, null, {
78
+ timeout: LongRequestTimeout,
79
+ });
80
+ });
81
+ }
82
+ createPayPalBillingAgreement(data) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ return this.client.post("/paypal/billing_agreements", data, {
85
+ timeout: LongRequestTimeout,
86
+ });
87
+ });
88
+ }
89
+ approvePayPalBillingAgreement(data) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ return this.client.post(`/paypal/billing_agreements/${data.id}/approve`, null, { timeout: LongRequestTimeout });
92
+ });
93
+ }
60
94
  }
61
95
  export default GatewayClient;
@@ -1,5 +1,5 @@
1
1
  declare const bridgeUrl = "http://paynow.test";
2
2
  declare const apiUrl = "http://api.test:3002/sdk";
3
- declare const payNowUrl = "http://paynow.test";
3
+ declare const payNowUrl = "http://paynow.test:3004";
4
4
  declare const songbirdUrl = "https://songbirdstag.cardinalcommerce.com/edge/v1/songbird.js";
5
5
  export { bridgeUrl, apiUrl, payNowUrl, songbirdUrl };
@@ -0,0 +1,5 @@
1
+ declare const bridgeUrl = "http://paynow.test";
2
+ declare const apiUrl = "http://api.test:3002/sdk";
3
+ declare const payNowUrl = "http://paynow.test:3004";
4
+ declare const songbirdUrl = "https://songbirdstag.cardinalcommerce.com/edge/v1/songbird.js";
5
+ export { bridgeUrl, apiUrl, payNowUrl, songbirdUrl };
@@ -0,0 +1,5 @@
1
+ const bridgeUrl = "http://paynow.test";
2
+ const apiUrl = "http://api.test:3002/sdk";
3
+ const payNowUrl = "http://paynow.test:3004";
4
+ const songbirdUrl = "https://songbirdstag.cardinalcommerce.com/edge/v1/songbird.js";
5
+ export { bridgeUrl, apiUrl, payNowUrl, songbirdUrl };
@@ -1,5 +1,5 @@
1
1
  const bridgeUrl = "http://paynow.test";
2
2
  const apiUrl = "http://api.test:3002/sdk";
3
- const payNowUrl = "http://paynow.test";
3
+ const payNowUrl = "http://paynow.test:3004";
4
4
  const songbirdUrl = "https://songbirdstag.cardinalcommerce.com/edge/v1/songbird.js";
5
5
  export { bridgeUrl, apiUrl, payNowUrl, songbirdUrl };
@@ -26,4 +26,4 @@ interface ErrorEventDetail {
26
26
  declare const emit: (event: PublicEvent, data: SuccessEventDetail | ErrorEventDetail, target?: HTMLElement | Window) => void;
27
27
  declare const on: (event: PublicEvent, callback: (e: any) => void, target?: HTMLElement | Window) => void;
28
28
  export { emit, on };
29
- export type { EventData };
29
+ export type { EventData, SuccessEventDetail, ErrorEventDetail };
@@ -1,4 +1,3 @@
1
- // TODO: CustomEvent requires polyfill for IE.
2
1
  const emit = (event, data, target = window) => {
3
2
  target.dispatchEvent(new CustomEvent(event, { detail: data }));
4
3
  };
@@ -44,5 +44,5 @@ declare class PostMessageClient {
44
44
  setEventListenersLegacy(handlers: EventHandlers): void;
45
45
  send(message: PostMessage | PostMessageLegacy): void;
46
46
  }
47
- export { PostMessageClient };
47
+ export { PostMessageClient, };
48
48
  export type { CreateCardTokenPostMessageData, CreatePurchasePostMessageData, PostMessage, PostMessageLegacy, PostMessageClientConfig };