@paydock/client-sdk 1.112.0 → 1.112.5-beta

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 (132) hide show
  1. package/README.md +805 -22
  2. package/bundles/index.cjs +1559 -229
  3. package/bundles/index.cjs.d.ts +2503 -2052
  4. package/bundles/index.mjs +1551 -226
  5. package/bundles/index.mjs.d.ts +2503 -2052
  6. package/bundles/types/api/api-base.d.ts.map +1 -1
  7. package/bundles/types/api/api-charge-internal.d.ts +1 -0
  8. package/bundles/types/api/api-charge-internal.d.ts.map +1 -1
  9. package/bundles/types/api/api-checkout-internal.d.ts +2 -0
  10. package/bundles/types/api/api-checkout-internal.d.ts.map +1 -1
  11. package/bundles/types/checkout/checkout.d.ts.map +1 -1
  12. package/bundles/types/checkout/helpers/instruction-module.d.ts +1 -1
  13. package/bundles/types/checkout/helpers/instruction-module.d.ts.map +1 -1
  14. package/bundles/types/checkout/helpers/resource-helper.d.ts +4 -3
  15. package/bundles/types/checkout/helpers/resource-helper.d.ts.map +1 -1
  16. package/bundles/types/checkout/helpers/session-helper.d.ts +3 -0
  17. package/bundles/types/checkout/helpers/session-helper.d.ts.map +1 -1
  18. package/bundles/types/checkout/instructions/v1/instruction.afterpay_checkout_form.show.d.ts.map +1 -1
  19. package/bundles/types/checkout/instructions/v1/instruction.apple_pay_form.show.d.ts.map +1 -1
  20. package/bundles/types/checkout/instructions/v1/instruction.canvas_3ds.show.d.ts.map +1 -1
  21. package/bundles/types/checkout/instructions/v1/instruction.card_form.show.d.ts.map +1 -1
  22. package/bundles/types/checkout/instructions/v1/instruction.generic.show_message.d.ts.map +1 -1
  23. package/bundles/types/checkout/instructions/v1/instruction.google_pay_form.show.d.ts.map +1 -1
  24. package/bundles/types/checkout/instructions/v1/instruction.payment_methods.show.d.ts.map +1 -1
  25. package/bundles/types/checkout/instructions/v1/instruction.paypal_form.show.d.ts.map +1 -1
  26. package/bundles/types/checkout/instructions/v1/instruction.zip_checkout_form.show.d.ts.map +1 -1
  27. package/bundles/types/checkout/layout-widgets/additionals.d.ts +1 -1
  28. package/bundles/types/checkout/layout-widgets/additionals.d.ts.map +1 -1
  29. package/bundles/types/checkout/layout-widgets/payment-methods-template.d.ts +3 -0
  30. package/bundles/types/checkout/layout-widgets/payment-methods-template.d.ts.map +1 -1
  31. package/bundles/types/checkout/layout-widgets/payment-methods.d.ts +1 -1
  32. package/bundles/types/checkout/layout-widgets/payment-methods.d.ts.map +1 -1
  33. package/bundles/types/checkout/layout-widgets/payment-template.d.ts +1 -1
  34. package/bundles/types/components/iframe-event.d.ts +39 -27
  35. package/bundles/types/components/iframe-event.d.ts.map +1 -1
  36. package/bundles/types/components/iframe.d.ts +2 -2
  37. package/bundles/types/components/iframe.d.ts.map +1 -1
  38. package/bundles/types/components/param.d.ts +2 -0
  39. package/bundles/types/components/param.d.ts.map +1 -1
  40. package/bundles/types/configs/env/environment.paydock.d.ts.map +1 -1
  41. package/bundles/types/fraud-prevention/constants.d.ts +4 -0
  42. package/bundles/types/fraud-prevention/constants.d.ts.map +1 -0
  43. package/bundles/types/fraud-prevention/events.d.ts +44 -0
  44. package/bundles/types/fraud-prevention/events.d.ts.map +1 -0
  45. package/bundles/types/fraud-prevention/fraud-prevention.service.d.ts +69 -0
  46. package/bundles/types/fraud-prevention/fraud-prevention.service.d.ts.map +1 -0
  47. package/bundles/types/fraud-prevention/index.d.ts +4 -0
  48. package/bundles/types/fraud-prevention/index.d.ts.map +1 -0
  49. package/bundles/types/fraud-prevention/providers/forter/forter-device-agent.service.d.ts +78 -0
  50. package/bundles/types/fraud-prevention/providers/forter/forter-device-agent.service.d.ts.map +1 -0
  51. package/bundles/types/fraud-prevention/providers/forter/templates/forter-snippet-2025-02-06T14:19:34Z.template.d.ts +2 -0
  52. package/bundles/types/fraud-prevention/providers/forter/templates/forter-snippet-2025-02-06T14:19:34Z.template.d.ts.map +1 -0
  53. package/bundles/types/helper/browser.d.ts.map +1 -1
  54. package/bundles/types/helper/custom-error.d.ts +8 -0
  55. package/bundles/types/helper/custom-error.d.ts.map +1 -0
  56. package/bundles/types/index-cba.d.ts +6 -1
  57. package/bundles/types/index-cba.d.ts.map +1 -1
  58. package/bundles/types/index.d.ts +4 -1
  59. package/bundles/types/index.d.ts.map +1 -1
  60. package/bundles/types/paypal-data-collector/index.d.ts +23 -0
  61. package/bundles/types/paypal-data-collector/index.d.ts.map +1 -0
  62. package/bundles/types/paypal-data-collector/paypal-data-collector.d.ts +58 -0
  63. package/bundles/types/paypal-data-collector/paypal-data-collector.d.ts.map +1 -0
  64. package/bundles/types/paypal-data-collector/paypal-data-collector.interfaces.d.ts +21 -0
  65. package/bundles/types/paypal-data-collector/paypal-data-collector.interfaces.d.ts.map +1 -0
  66. package/bundles/types/paypal-data-collector/paypal-data-collector.service.d.ts +17 -0
  67. package/bundles/types/paypal-data-collector/paypal-data-collector.service.d.ts.map +1 -0
  68. package/bundles/types/paypal-save-payment-source/index.d.ts +61 -0
  69. package/bundles/types/paypal-save-payment-source/index.d.ts.map +1 -0
  70. package/bundles/types/paypal-save-payment-source/paypal-save-payment-source.d.ts +85 -0
  71. package/bundles/types/paypal-save-payment-source/paypal-save-payment-source.d.ts.map +1 -0
  72. package/bundles/types/paypal-save-payment-source/paypal-save-payment-source.interfaces.d.ts +83 -0
  73. package/bundles/types/paypal-save-payment-source/paypal-save-payment-source.interfaces.d.ts.map +1 -0
  74. package/bundles/types/paypal-save-payment-source/paypal-save-payment-source.service.d.ts +35 -0
  75. package/bundles/types/paypal-save-payment-source/paypal-save-payment-source.service.d.ts.map +1 -0
  76. package/bundles/types/secure-remote-commerce/click-to-pay-secure-remote-commerce.d.ts +1 -1
  77. package/bundles/types/secure-remote-commerce/click-to-pay-secure-remote-commerce.d.ts.map +1 -1
  78. package/bundles/types/secure-remote-commerce/index.d.ts +2 -0
  79. package/bundles/types/secure-remote-commerce/index.d.ts.map +1 -1
  80. package/bundles/types/secure-remote-commerce/interfaces.d.ts +8 -1
  81. package/bundles/types/secure-remote-commerce/interfaces.d.ts.map +1 -1
  82. package/bundles/types/shared/services/configuration-validation/configuration-validation.d.ts +12 -0
  83. package/bundles/types/shared/services/configuration-validation/configuration-validation.d.ts.map +1 -0
  84. package/bundles/types/shared/services/configuration-validation/types.d.ts +73 -0
  85. package/bundles/types/shared/services/configuration-validation/types.d.ts.map +1 -0
  86. package/bundles/types/wallet-buttons/enums.d.ts +12 -0
  87. package/bundles/types/wallet-buttons/enums.d.ts.map +1 -0
  88. package/bundles/types/wallet-buttons/index.d.ts +5 -1
  89. package/bundles/types/wallet-buttons/index.d.ts.map +1 -1
  90. package/bundles/types/wallet-buttons/wallet-buttons.d.ts +28 -15
  91. package/bundles/types/wallet-buttons/wallet-buttons.d.ts.map +1 -1
  92. package/bundles/types/wallet-buttons/wallet-services/wallet-service.d.ts +1 -1
  93. package/bundles/types/wallet-buttons/wallet-services/wallet-service.d.ts.map +1 -1
  94. package/bundles/types/wallet-buttons-express/base.wallet-button-express.d.ts +10 -10
  95. package/bundles/types/wallet-buttons-express/base.wallet-button-express.d.ts.map +1 -1
  96. package/bundles/types/wallet-buttons-express/index.d.ts +1 -0
  97. package/bundles/types/wallet-buttons-express/index.d.ts.map +1 -1
  98. package/bundles/types/wallet-buttons-express/interfaces/wallet-capture-request.interface.d.ts +1 -0
  99. package/bundles/types/wallet-buttons-express/interfaces/wallet-capture-request.interface.d.ts.map +1 -1
  100. package/bundles/types/wallet-buttons-express/services/apple-pay/apple-pay.wallet-button-express.d.ts.map +1 -1
  101. package/bundles/types/wallet-buttons-express/services/paypal/interfaces/paypal-wallet-meta.interface.d.ts +1 -0
  102. package/bundles/types/wallet-buttons-express/services/paypal/interfaces/paypal-wallet-meta.interface.d.ts.map +1 -1
  103. package/bundles/types/wallet-buttons-express/services/paypal/paypal.wallet-button-express.d.ts.map +1 -1
  104. package/bundles/types/widget/configuration.d.ts +13 -9
  105. package/bundles/types/widget/configuration.d.ts.map +1 -1
  106. package/bundles/types/widget/html-multi-widget.d.ts +1 -2
  107. package/bundles/types/widget/html-multi-widget.d.ts.map +1 -1
  108. package/bundles/types/widget/html-widget.d.ts +2 -1
  109. package/bundles/types/widget/html-widget.d.ts.map +1 -1
  110. package/bundles/types/widget/multi-widget.d.ts +5 -1
  111. package/bundles/types/widget/multi-widget.d.ts.map +1 -1
  112. package/bundles/widget.umd.js +1559 -229
  113. package/bundles/widget.umd.js.d.ts +2503 -2052
  114. package/bundles/widget.umd.js.min.d.ts +2503 -2052
  115. package/bundles/widget.umd.min.js +1 -61
  116. package/docs/api-widget.md +21 -16
  117. package/docs/click-to-pay.md +1 -0
  118. package/docs/fraud-prevention-examples.md +195 -0
  119. package/docs/fraud-prevention.md +0 -0
  120. package/docs/install/npm.example.md +1 -1
  121. package/docs/paypal-data-collector-examples.md +59 -0
  122. package/docs/paypal-data-collector.md +149 -0
  123. package/docs/paypal-save-payment-source-examples.md +63 -0
  124. package/docs/paypal-save-payment-source.md +256 -0
  125. package/docs/wallet-buttons-examples.md +1 -1
  126. package/docs/wallet-buttons-express-examples.md +1 -1
  127. package/docs/wallet-buttons-express.md +1 -0
  128. package/docs/wallet-buttons.md +3 -0
  129. package/docs/widget-examples.md +48 -3
  130. package/examples/multi-html-widget/extend.html +5 -0
  131. package/package.json +7 -7
  132. package/slate.md +246 -5
package/README.md CHANGED
@@ -59,7 +59,7 @@ const widget = new Paydock.HtmlWidget('#selector', 'publicKey', 'gatewayId');
59
59
  ```
60
60
 
61
61
  ```js
62
- // default import - We do not provide default exports. They are handled differently by different tools!
62
+ // default import - Not officially supported . They are handled differently by different tools / settings!
63
63
 
64
64
  import paydock from '@paydock/client-sdk'
65
65
  >>> "Uncaught SyntaxError: The requested module does not provide an export named 'default'"
@@ -199,6 +199,20 @@ widget.setSupportedCardIcons(['mastercard', 'visa']); // add icons of supported
199
199
 
200
200
  This example shows how you can use a lot of other methods to settings your form
201
201
 
202
+
203
+ ### Error handling
204
+
205
+ ```javascript
206
+ widget.on('error', (error) => {
207
+ const errorDiv = document.getElementById('error');
208
+ const errorMessage = document.getElementById('error-message');
209
+
210
+ errorMessage.textContent = error.data.message;
211
+ errorDiv.style.display = 'block';
212
+ });
213
+ ```
214
+
215
+
202
216
  ### Full example
203
217
 
204
218
  ```html
@@ -214,7 +228,34 @@ This example shows how you can use a lot of other methods to settings your form
214
228
  <div id="widget"
215
229
  widget-style="text-color: #FFFFAA; border-color: #yellow"
216
230
  title="Payment form"
217
- finish-text="Payment resource was successfully accepted"></div>
231
+ finish-text="Payment resource was successfully accepted">
232
+ </div>
233
+
234
+ <div
235
+ id="error"
236
+ style="
237
+ display: none;
238
+ max-width: 600px;
239
+ margin: 16px auto;
240
+ padding: 16px 20px;
241
+ border-radius: 8px;
242
+ background-color: #FEF2F2;
243
+ border: 1px solid #FEE2E2;
244
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
245
+ font-family: system-ui, -apple-system, sans-serif;
246
+ color: #991B1B;
247
+ line-height: 1.5;
248
+ font-size: 14px;
249
+ "
250
+ title="error"
251
+ >
252
+ <div style="display: flex; align-items: flex-start; gap: 12px;">
253
+ <div>
254
+ <h4 style="margin: 0 0 4px 0; font-size: 14px; font-weight: 600;">Access Error</h4>
255
+ <div id="error-message"></div>
256
+ </div>
257
+ </div>
258
+ </div>
218
259
  </form>
219
260
 
220
261
  <script src="https://widget.paydock.com/sdk/latest/widget.umd.js" ></script>
@@ -224,11 +265,15 @@ This example shows how you can use a lot of other methods to settings your form
224
265
  widget.setSupportedCardIcons(['mastercard', 'visa']);
225
266
  widget.setFormFields(['phone', 'email']);
226
267
  widget.setRefId('custom-ref-id');
227
- widget.onFinishInsert('input[name="payment_source_token"]', 'payment_source');z
268
+ widget.onFinishInsert('input[name="payment_source_token"]', 'payment_source');
228
269
 
270
+ widget.on('error', (error) => {
271
+ document.getElementById('error-message').textContent = error.data.message;
272
+ document.getElementById('error').style.display = 'block';
273
+ });
229
274
  widget.load();
230
275
  </script>
231
- </script>
276
+
232
277
  </body>
233
278
  </html>
234
279
  ```
@@ -250,6 +295,14 @@ This example shows how you can use a lot of other methods to settings your form
250
295
  </dd>
251
296
  </dl>
252
297
 
298
+ ## Members
299
+
300
+ <dl>
301
+ <dt><a href="#user-content-w_PURPOSE">PURPOSE</a> : <code>object</code></dt>
302
+ <dd><p>Purposes</p>
303
+ </dd>
304
+ </dl>
305
+
253
306
  ## Constants
254
307
 
255
308
  <dl>
@@ -262,9 +315,6 @@ This example shows how you can use a lot of other methods to settings your form
262
315
  <dt><a href="#user-content-w_PAYMENT_TYPE">PAYMENT_TYPE</a> : <code>object</code></dt>
263
316
  <dd><p>List of available payment source types</p>
264
317
  </dd>
265
- <dt><a href="#user-content-w_PURPOSE">PURPOSE</a> : <code>object</code></dt>
266
- <dd><p>Purposes</p>
267
- </dd>
268
318
  <dt><a href="#user-content-w_FORM_FIELD">FORM_FIELD</a> : <code>object</code></dt>
269
319
  <dd><p>Current constant include available type of fields which can be included to widget</p>
270
320
  </dd>
@@ -2502,6 +2552,19 @@ Method for setting a custom language code
2502
2552
  ```javascript
2503
2553
  config.setLanguage('en');
2504
2554
  ```
2555
+ <a name="w_PURPOSE" id="w_PURPOSE" href="#user-content-w_PURPOSE">&nbsp;</a>
2556
+
2557
+ ## PURPOSE : <code>object</code>
2558
+ Purposes
2559
+
2560
+ **Kind**: global variable
2561
+
2562
+ | Param | Type | Default |
2563
+ | --- | --- | --- |
2564
+ | PAYMENT_SOURCE | <code>string</code> | <code>&quot;payment_source&quot;</code> |
2565
+ | CARD_PAYMENT_SOURCE_WITH_CVV | <code>string</code> | <code>&quot;card_payment_source_with_cvv&quot;</code> |
2566
+ | CARD_PAYMENT_SOURCE_WITHOUT_CVV | <code>string</code> | <code>&quot;card_payment_source_without_cvv&quot;</code> |
2567
+
2505
2568
  <a name="w_EVENT" id="w_EVENT" href="#user-content-w_EVENT">&nbsp;</a>
2506
2569
 
2507
2570
  ## EVENT : <code>object</code>
@@ -2551,19 +2614,6 @@ List of available payment source types
2551
2614
  | BANK_ACCOUNT | <code>string</code> | <code>&quot;bank_account&quot;</code> |
2552
2615
  | CHECKOUT | <code>string</code> | <code>&quot;checkout&quot;</code> |
2553
2616
 
2554
- <a name="w_PURPOSE" id="w_PURPOSE" href="#user-content-w_PURPOSE">&nbsp;</a>
2555
-
2556
- ## PURPOSE : <code>object</code>
2557
- Purposes
2558
-
2559
- **Kind**: global constant
2560
-
2561
- | Param | Type | Default |
2562
- | --- | --- | --- |
2563
- | PAYMENT_SOURCE | <code>string</code> | <code>&quot;payment_source&quot;</code> |
2564
- | CARD_PAYMENT_SOURCE_WITH_CVV | <code>string</code> | <code>&quot;card_payment_source_with_cvv&quot;</code> |
2565
- | CARD_PAYMENT_SOURCE_WITHOUT_CVV | <code>string</code> | <code>&quot;card_payment_source_without_cvv&quot;</code> |
2566
-
2567
2617
  <a name="w_FORM_FIELD" id="w_FORM_FIELD" href="#user-content-w_FORM_FIELD">&nbsp;</a>
2568
2618
 
2569
2619
  ## FORM\_FIELD : <code>object</code>
@@ -5575,7 +5625,7 @@ _(Required `meta` fields: - . Optional `meta` fields: -)_
5575
5625
  },
5576
5626
  );
5577
5627
  button.setEnv('sandbox');
5578
- button.onUnavailable(() => console.log("No wallet buttons available"));
5628
+ button.onUnavailable((data) => console.log("No wallet buttons available"));
5579
5629
  button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5580
5630
  button.onPaymentError((data) => console.log("The payment was not successful"));
5581
5631
  button.onAuthTokensChanged((data) => console.log('Authentication tokens changed'));
@@ -5918,6 +5968,8 @@ Interface of data from an unavailable event.
5918
5968
  | Param | Type | Description |
5919
5969
  | --- | --- | --- |
5920
5970
  | [wallet] | <code>string</code> | For gateways with more than one wallet button available (e.g: MPGS with ApplePay and GooglePay). Possible values for wallet are 'apple' or 'google'. |
5971
+ | [type] | <code>string</code> | Event Code. Value can be 'create_order_id_error' on FlypayV2 order creation failure. Optional for [Flypay V2]. N/A for other wallets. |
5972
+ | [error_code] | <code>string</code> | Event Error Code. Value can be any error code return from Paydock's API. Optional for [Flypay V2]. N/A for other wallets. + |
5921
5973
 
5922
5974
  <a name="IWalletUpdateData" id="IWalletUpdateData" href="#IWalletUpdateData">&nbsp;</a>
5923
5975
 
@@ -5942,6 +5994,7 @@ Interface of data used by the wallet checkout and payment proccess.
5942
5994
  | [amount_label] | <code>string</code> | Label shown next to the total amount to be paid. Required for [Stripe, ApplePay, GooglePay]. N/A for [FlyPay, Flypay V2, PayPal, Afterpay]. |
5943
5995
  | [country] | <code>string</code> | Country of the user. 2 letter ISO code format. Required for [Stripe, ApplePay, GooglePay, Afterpay]. N/A for [FlyPay, Flypay V2, PayPal]. |
5944
5996
  | [pay_later] | <code>boolean</code> | Used to enable Pay Later feature in PayPal Smart Checkout WalletButton integration when available. Optional for [PayPal]. N/A for other wallets. |
5997
+ | [hide_message] | <code>boolean</code> | Used to hide Pay Later message in PayPal Smart Checkout WalletButton integration. Optional for [PayPal]. N/A for other wallets. |
5945
5998
  | [standalone] | <code>boolean</code> | Used to enable Standalone Buttons feature in PayPal Smart Checkout WalletButton integration. Used together with `pay_later`. Optional for [PayPal]. N/A for other wallets. |
5946
5999
  | [show_billing_address] | <code>boolean</code> | Used to hide/show the billing address on ApplePay and GooglePay popups. Default value is false. Optional for [ApplePay, GooglePay]. N/A for other wallets. |
5947
6000
  | [request_payer_name] | <code>boolean</code> | Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets. |
@@ -6471,7 +6524,7 @@ A full description of the meta parameters for [ApplePayWalletButtonExpress](#App
6471
6524
  }
6472
6525
  );
6473
6526
 
6474
- button.setEnv(sandbox);
6527
+ button.setEnv('sandbox');
6475
6528
 
6476
6529
  button.onUnavailable(function() {
6477
6530
  console.log("Button not available");
@@ -6721,6 +6774,7 @@ For in-depth information, please refer to the [Paypal documentation](https://dev
6721
6774
  | amount | <code>number</code> | Total amount of the transaction. Represents the money to be charged. |
6722
6775
  | currency | <code>string</code> | Currency of the transaction in ISO 4217 currency code format. |
6723
6776
  | [pay_later] | <code>boolean</code> | Flag to enable Pay Later feature of PayPal, allowing Pay in 4. Default false. |
6777
+ | [hide_message] | <code>boolean</code> | Used to hide Pay Later message in PayPal Smart Checkout WalletButton integration. Optional for [PayPal]. N/A for other wallets. |
6724
6778
  | [standalone] | <code>boolean</code> | Flag to specify if the PayPal standalone button should be used. Default false. |
6725
6779
  | [capture] | <code>boolean</code> | Flag to specify if the transaction amount should be captured immediately or authorized for later capture. Default false. |
6726
6780
  | [style] | <code>object</code> | Styling configurations for the PayPal widget. |
@@ -7732,6 +7786,7 @@ When the flow type is src, masked checkoutData available is also returned
7732
7786
  | --- | --- | --- |
7733
7787
  | type | <code>string</code> | type of the checkout, can be `src` or `manual`. |
7734
7788
  | token | <code>string</code> | one time token value. |
7789
+ | token_type | <code>string</code> | one time token type value, can be `card` or `card_scheme_token`. |
7735
7790
  | [checkoutData] | <code>object</code> | Optional checkout data related to the checkout information. Only available on src flow. |
7736
7791
  | [checkoutData.card_number_bin] | <code>string</code> | The BIN of the card used for the transaction. |
7737
7792
  | [checkoutData.card_number_last4] | <code>string</code> | The last four digits of the card number. |
@@ -7964,5 +8019,733 @@ List of available event data types
7964
8019
  | SUCCESS | <code>string</code> | <code>&quot;Success&quot;</code> | |
7965
8020
 
7966
8021
 
8022
+ # Fraud prevention
8023
+
8024
+ The Fraud Prevention module allows you to add security layers to your payment workflows
8025
+ by integrating with any of our underlying fraud prevention providers.
8026
+
8027
+ ## Real time user behavior analysis
8028
+
8029
+ ### Forter
8030
+
8031
+ One of Forter's key features is our ability to track the user's real-time behavior on
8032
+ the site and use it to separate fraudsters from legitimate buyers. To take advantage
8033
+ of Forter's technology, a JavaScript snippet needs to be placed on EVERY page
8034
+ of your commerce site beginning with the homepage and up to and including the final
8035
+ "Thank you for your purchase" page.
8036
+
8037
+ The integration is simple and straightforward - you only need to configure event
8038
+ listeners and then instantiate a FraudPreventionService with your site configuration.
8039
+
8040
+ Additional setup is required in case your website uses Content Security Policies (CSP)
8041
+
8042
+ #### Forter: Code snippet
8043
+
8044
+ ```html
8045
+ <!doctype html>
8046
+ <html lang="en">
8047
+
8048
+ <head>
8049
+ <meta charset="utf-8">
8050
+ <title>Real time user behaviour anaylsis - Forter example</title>
8051
+ <base href="/">
8052
+ <meta name="viewport" content="width=device-width, initial-scale=1">
8053
+ <link rel="icon" type="image/x-icon" href="favicon.ico">
8054
+ <script src="../../../bundles/widget.umd.js"></script>
8055
+ <style>
8056
+ body {
8057
+ min-width: 320px;
8058
+ max-width: 1440px;
8059
+ min-height: 100svh;
8060
+ }
8061
+
8062
+ main {
8063
+ padding: 2rem;
8064
+ margin: 0 auto;
8065
+ }
8066
+
8067
+ .forter-test {
8068
+ padding: 1rem;
8069
+ border-radius: 8px;
8070
+ background: #f5f5f5;
8071
+ }
8072
+
8073
+ .status-card {
8074
+ background: white;
8075
+ padding: 1rem;
8076
+ border-radius: 4px;
8077
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
8078
+ }
8079
+
8080
+ .status {
8081
+ display: inline-block;
8082
+ padding: 0.25rem 0.5rem;
8083
+ border-radius: 4px;
8084
+ font-weight: 500;
8085
+ }
8086
+
8087
+ .status.success {
8088
+ background: #e6ffe6;
8089
+ color: #006600;
8090
+ }
8091
+
8092
+ .status.pending {
8093
+ background: rgb(255, 249, 205);
8094
+ color: rgb(255, 204, 0);
8095
+ }
8096
+
8097
+ .status.error {
8098
+ background: #ffe6e6;
8099
+ color: #cc0000;
8100
+ }
8101
+
8102
+ .error {
8103
+ display: inline-block;
8104
+ padding: 0.25rem 0.5rem;
8105
+ border-radius: 4px;
8106
+ background: #ffe6e6;
8107
+ color: #cc0000;
8108
+ font-weight: 500;
8109
+ }
8110
+
8111
+ code {
8112
+ background: #f0f0f0;
8113
+ padding: 0.2rem 0.4rem;
8114
+ border-radius: 4px;
8115
+ font-family: monospace;
8116
+ }
8117
+ </style>
8118
+ </head>
8119
+
8120
+ <body>
8121
+ <main>
8122
+ <h1>Real time user behaviour anaylsis - Forter example</h1>
8123
+ <div class="forter-test">
8124
+ <h2>Forter Integration Test</h2>
8125
+
8126
+ <div class="status-card">
8127
+ <p>
8128
+ <strong>Integration Status:</strong>
8129
+ <span data-fraud-prevention="status-indicator" class="status pending">
8130
+ Pending
8131
+ </span>
8132
+ </p>
8133
+ <p>
8134
+ <strong>Token Value:</strong>
8135
+ <code data-fraud-prevention="forter-token">Not available</code>
8136
+ </p>
8137
+ <p data-fraud-prevention="error-container" style="display: none;">
8138
+ <strong>Error Code:</strong>
8139
+ <span data-fraud-prevention="error-code" class="error"></span>
8140
+ </p>
8141
+ </div>
8142
+ </div>
8143
+ </main>
8144
+ <script>
8145
+ const { FraudPreventionEvents, FraudPreventionService } = window.paydock
8146
+
8147
+ let token = '';
8148
+ let errorCode = '';
8149
+
8150
+ const render = () => {
8151
+ const statusIndicator = document.querySelector('[data-fraud-prevention="status-indicator"]');
8152
+ const tokenValue = document.querySelector('[data-fraud-prevention="forter-token"]');
8153
+ const errorContainer = document.querySelector('[data-fraud-prevention="error-container"]');
8154
+ const errorCodeElement = document.querySelector('[data-fraud-prevention="error-code"]');
8155
+
8156
+ if (token) {
8157
+ statusIndicator.className = 'status success';
8158
+ statusIndicator.textContent = 'Active';
8159
+ tokenValue.textContent = token;
8160
+ } else {
8161
+ statusIndicator.className = 'status pending';
8162
+ statusIndicator.textContent = 'Pending';
8163
+ tokenValue.textContent = 'Not available';
8164
+ }
8165
+
8166
+ if (errorCode) {
8167
+ errorCodeElement.textContent = errorCode;
8168
+ errorContainer.style.display = 'block';
8169
+ } else {
8170
+ errorContainer.style.display = 'none';
8171
+ }
8172
+ };
8173
+
8174
+ document.addEventListener(FraudPreventionEvents.namespace, (event) => {
8175
+ switch (event.detail.type) {
8176
+ case FraudPreventionEvents.types.fingerprintTokenReady: {
8177
+ token = event.detail.payload.token;
8178
+ break;
8179
+ }
8180
+ case FraudPreventionEvents.types.fingerprintTokenError: {
8181
+ errorCode = event.detail.payload.code;
8182
+ break;
8183
+ }
8184
+ default: {
8185
+ throw new Error(
8186
+ `${FraudPreventionEvents.namespace} emitted an unsupported event: ${JSON.stringify(event.detail)}.`,
8187
+ );
8188
+ }
8189
+ }
8190
+
8191
+ render();
8192
+ });
8193
+
8194
+ new FraudPreventionService().withForter({
8195
+ siteId: 'YOUR_SITE_ID_OR_SUBSITE_ID',
8196
+ mode: 'test',
8197
+ csp: false, // set to true if your website uses Content-Security-Policies
8198
+ });
8199
+ </script>
8200
+ </body>
8201
+
8202
+ </html>
8203
+ ```
8204
+
8205
+ #### Forter: Content Security Policies
8206
+
8207
+ If your site enforces Content Security Policies (CSP), make sure to:
8208
+
8209
+ 1. Set the `csp` option to `true` when invoking `withForter` on your `FraudPreventionService` instance.
8210
+ 2. Allowlist Forter's domains on `connect-src`, `script-src` and `worker-src` as shown below.
8211
+
8212
+ ```bash
8213
+ connect-src https://*.forter.com wss://cdn0.forter.com https://d2o5idwacg3gyw.cloudfront.net https://dz8rit8v72mig.cloudfront.net https://db7q4jg5rkhk8.cloudfront.net https://1.1.1.1 https://d94qwxh6czci4.cloudfront.net https://dr6vcclmzwk74.cloudfront.net https://d6rak4b14t5gp.cloudfront.net https://d3k4bt74u9esq1.cloudfront.net https://d1ezzflfzltk6e.cloudfront.net https://d3nocrch4qti4v.cloudfront.net https://duuytoqss3gu4.cloudfront.net https://df45ay5pw60dy.cloudfront.net
8214
+ script-src https://*.forter.com https://dlthst9q2beh8.cloudfront.net https://d2nww8zpyj5pk0.cloudfront.net https://d2w2nqfk3z9hdt.cloudfront.net
8215
+ worker-src blob:
8216
+ ```
8217
+
8218
+
8219
+ ## PayPalSavePaymentSource Widget
8220
+
8221
+ PayPalSavePaymentSource Widget allows to obtain a Paydock one time token linked with a Paypal payment source from the customer.
8222
+
8223
+ The general flow to use the widgets is:
8224
+ 1. Configure your PayPal gateway and connect it using Paydock API or Dashboard.
8225
+ 2. Create a container in your site
8226
+ ```html
8227
+ <div id="widget"></div>
8228
+ ```
8229
+ 3. Initialize the specific `PayPalSavePaymentSourceWidget`, providing your Access token or Public Key, the Gateway ID that Paydock provides plus required and optional config parameter for the widget in use. The general format is:
8230
+ ```js
8231
+ new paydock.PayPalSavePaymentSourceWidget(
8232
+ "#widget",
8233
+ accessTokenOrPublicKey,
8234
+ gatewayId,
8235
+ widgetSpecificConfig,
8236
+ );
8237
+ ```
8238
+ 4. Handle the `onSuccess`, `onError` and `onCancel` for paypal setup token results.
8239
+ 5. If `onSuccess` event is emmited, event data should contain `token` and `email` ready to use.
8240
+
8241
+ ### Example
8242
+
8243
+ A full description of the config parameters for [PayPalSavePaymentSourceWidget](#PayPalSavePaymentSourceWidget) meta parameters can be found [here](#PayPalSavePaymentSourceWidgetConfig). Below you will find a fully working html example.
8244
+
8245
+ ```html
8246
+ <!DOCTYPE html>
8247
+ <html lang="en">
8248
+ <head>
8249
+ <meta charset="UTF-8">
8250
+ <title>Title</title>
8251
+ </head>
8252
+ <body>
8253
+ <h2>Using PayDock PayPalSavePaymentSourceWidget!</h2>
8254
+ <div id="widget"></div>
8255
+ </body>
8256
+ <script src="https://widget.paydock.com/sdk/latest/widget.umd.min.js" ></script>
8257
+ <script>
8258
+ let button = new paydock.PayPalSavePaymentSourceWidget(
8259
+ "#widget",
8260
+ accessTokenOrPublicKey,
8261
+ gatewayId,
8262
+ {
8263
+ style: {
8264
+ layout: 'vertical',
8265
+ color: 'gold',
8266
+ shape: 'pill',
8267
+ label: 'paypal'
8268
+ }
8269
+ }
8270
+ );
8271
+
8272
+ payPalSavePaymentSourceWidget.onSuccess((data) => console.log('On success: ', data));
8273
+ payPalSavePaymentSourceWidget.onError((data) => console.log('On error: ', data));
8274
+ payPalSavePaymentSourceWidget.onCancel(() => console.log('On cancelled'));
8275
+
8276
+ button.setEnv('sandbox');
8277
+
8278
+ button.load();
8279
+ </script>
8280
+ </html>
8281
+ ```
8282
+
8283
+ ## Classes
8284
+
8285
+ <dl>
8286
+ <dt><a href="#PayPalSavePaymentSourceWidget">PayPalSavePaymentSourceWidget</a></dt>
8287
+ <dd><p>PayPal Save Payment Source Widget constructor</p>
8288
+ </dd>
8289
+ </dl>
8290
+
8291
+ ## Typedefs
8292
+
8293
+ <dl>
8294
+ <dt><a href="#OnSuccessCallback">OnSuccessCallback</a> : <code>function</code></dt>
8295
+ <dd><p>Callback for onSuccess method.</p>
8296
+ </dd>
8297
+ <dt><a href="#OnErrorCallback">OnErrorCallback</a> : <code>function</code></dt>
8298
+ <dd><p>Callback for onError method.</p>
8299
+ </dd>
8300
+ <dt><a href="#OnCancelCallback">OnCancelCallback</a> : <code>function</code></dt>
8301
+ <dd><p>Callback for onCancel method.</p>
8302
+ </dd>
8303
+ </dl>
8304
+
8305
+ ## Interfaces
8306
+
8307
+ <dl>
8308
+ <dt><a href="#PayPalSavePaymentSourceWidgetConfig">PayPalSavePaymentSourceWidgetConfig</a> : <code>object</code></dt>
8309
+ <dd><p>Interface of data used for PayPal configuration. For further information refer to <a href="https://developer.paypal.com/sdk/js/reference/#style">the documentation</a>.</p>
8310
+ </dd>
8311
+ <dt><a href="#ErrorCodes">ErrorCodes</a> : <code>object</code></dt>
8312
+ <dd><p>Interface of possible error codes inside onError event data.</p>
8313
+ </dd>
8314
+ <dt><a href="#IOnSuccessEventData">IOnSuccessEventData</a> : <code>object</code></dt>
8315
+ <dd><p>Interface for IOnSuccessEventData</p>
8316
+ </dd>
8317
+ <dt><a href="#IOnErrorEventData">IOnErrorEventData</a> : <code>object</code></dt>
8318
+ <dd><p>Interface for IOnErrorEventData</p>
8319
+ </dd>
8320
+ <dt><a href="#IOnCancelEventData">IOnCancelEventData</a> : <code>object</code></dt>
8321
+ <dd><p>Interface for IOnCancelEventData</p>
8322
+ </dd>
8323
+ </dl>
8324
+
8325
+ <a name="PayPalSavePaymentSourceWidgetConfig" id="PayPalSavePaymentSourceWidgetConfig" href="#PayPalSavePaymentSourceWidgetConfig">&nbsp;</a>
8326
+
8327
+ ## PayPalSavePaymentSourceWidgetConfig : <code>object</code>
8328
+ Interface of data used for PayPal configuration. For further information refer to [the documentation](https://developer.paypal.com/sdk/js/reference/#style).
8329
+
8330
+ **Kind**: global interface
8331
+
8332
+ | Param | Type | Description |
8333
+ | --- | --- | --- |
8334
+ | [style.layout] | <code>&#x27;vertical&#x27;</code> \| <code>&#x27;horizontal&#x27;</code> | Used for indicating the PayPal Button layout. |
8335
+ | [style.color] | <code>&#x27;blue&#x27;</code> \| <code>&#x27;gold&#x27;</code> \| <code>&#x27;silver&#x27;</code> \| <code>&#x27;black&#x27;</code> \| <code>&#x27;white&#x27;</code> | Used for indicating the main color of the PayPal Button. |
8336
+ | [style.shape] | <code>&#x27;rect&#x27;</code> \| <code>&#x27;sharp&#x27;</code> \| <code>&#x27;pill&#x27;</code> | Used for indicating the shape of the PayPal Button. |
8337
+ | [style.label] | <code>&#x27;paypal&#x27;</code> \| <code>&#x27;checkout&#x27;</code> \| <code>&#x27;buynow&#x27;</code> \| <code>&#x27;pay&#x27;</code> | Used for indicating the label of the PayPal Button. |
8338
+ | [style.disableMaxWidth] | <code>boolean</code> | Used for indicating if the max width will be disabled. |
8339
+ | [style.disableMaxHeight] | <code>boolean</code> | Used for indicating the max height will be disabled. |
8340
+ | [style.height] | <code>number</code> | Used for indicating the height of the PayPal Button, if disableMaxHeight is true. |
8341
+ | [style.borderRadius] | <code>number</code> | Used for indicating the border radius of the PayPal Button. |
8342
+ | [style.tagline] | <code>boolean</code> | Used for indicating the tagline of the PayPal Button. |
8343
+ | [message.amount] | <code>number</code> | Used for indicating an amount before the payment. |
8344
+ | [message.align] | <code>&#x27;center&#x27;</code> \| <code>&#x27;left&#x27;</code> \| <code>&#x27;right&#x27;</code> | Used for indicating the align of the message. |
8345
+ | [message.color] | <code>&#x27;black&#x27;</code> \| <code>&#x27;white&#x27;</code> | Used for indicating the color of the message. |
8346
+ | [message.position] | <code>&#x27;top&#x27;</code> \| <code>&#x27;bottom&#x27;</code> | Used for indicating the position of the message. |
8347
+
8348
+ <a name="ErrorCodes" id="ErrorCodes" href="#ErrorCodes">&nbsp;</a>
8349
+
8350
+ ## ErrorCodes : <code>object</code>
8351
+ Interface of possible error codes inside onError event data.
8352
+
8353
+ **Kind**: global interface
8354
+
8355
+ | Param | Type | Description |
8356
+ | --- | --- | --- |
8357
+ | [unavailable] | <code>string</code> | Error code when an error occurs loading the widget. |
8358
+ | [onPaypalVaultSetupTokenError] | <code>string</code> | Error code when an error occrus on PayPal side. |
8359
+ | [onGetIdTokenError] | <code>string</code> | Error code when trying to get ID token from PayPal. |
8360
+ | [onGetWalletConfigError] | <code>string</code> | Error code when trying to get wallet config from Paydock. |
8361
+ | [onGetSetupTokenError] | <code>string</code> | Error code when trying to get the setup token from PayPal. |
8362
+ | [onOneTimeTokenError] | <code>string</code> | Error code when trying to get the one time token from Paydock. |
8363
+
8364
+ <a name="IOnSuccessEventData" id="IOnSuccessEventData" href="#IOnSuccessEventData">&nbsp;</a>
8365
+
8366
+ ## IOnSuccessEventData : <code>object</code>
8367
+ Interface for IOnSuccessEventData
8368
+
8369
+ **Kind**: global interface
8370
+
8371
+ | Param | Type | Description |
8372
+ | --- | --- | --- |
8373
+ | event | <code>EVENTS</code> | Event Name is 'ON_SUCCESS' |
8374
+ | data | <code>object</code> | Data object |
8375
+ | data.token | <code>string</code> | One Time Token to be exchanged for a Paydock Customer. |
8376
+ | [data.email] | <code>string</code> | Paypal account customer email if retrieved from Paypal servers. |
8377
+
8378
+ <a name="IOnErrorEventData" id="IOnErrorEventData" href="#IOnErrorEventData">&nbsp;</a>
8379
+
8380
+ ## IOnErrorEventData : <code>object</code>
8381
+ Interface for IOnErrorEventData
8382
+
8383
+ **Kind**: global interface
8384
+
8385
+ | Param | Type | Description |
8386
+ | --- | --- | --- |
8387
+ | event | <code>EVENTS</code> | Event Name is 'ON_ERROR' |
8388
+ | data | <code>object</code> | Error data object |
8389
+ | data.error_code | [<code>ErrorCodes</code>](#ErrorCodes) | Error code. One of ErrorCodes. |
8390
+ | [data.details] | <code>string</code> | Error details. |
8391
+ | [data.message] | <code>string</code> | Error message. |
8392
+
8393
+ <a name="IOnCancelEventData" id="IOnCancelEventData" href="#IOnCancelEventData">&nbsp;</a>
8394
+
8395
+ ## IOnCancelEventData : <code>object</code>
8396
+ Interface for IOnCancelEventData
8397
+
8398
+ **Kind**: global interface
8399
+
8400
+ | Param | Type | Description |
8401
+ | --- | --- | --- |
8402
+ | event | <code>EVENTS</code> | Event Name is 'ON_CANCEL' |
8403
+
8404
+ <a name="PayPalSavePaymentSourceWidget" id="PayPalSavePaymentSourceWidget" href="#PayPalSavePaymentSourceWidget">&nbsp;</a>
8405
+
8406
+ ## PayPalSavePaymentSourceWidget
8407
+ PayPal Save Payment Source Widget constructor
8408
+
8409
+ **Kind**: global class
8410
+
8411
+ * [PayPalSavePaymentSourceWidget](#PayPalSavePaymentSourceWidget)
8412
+ * [new PayPalSavePaymentSourceWidget(selector, publicKey, gatewayId, config)](#new_PayPalSavePaymentSourceWidget_new)
8413
+ * [.load()](#PayPalSavePaymentSourceWidget+load)
8414
+ * [.setEnv(env, [alias])](#PayPalSavePaymentSourceWidget+setEnv)
8415
+ * [.onSuccess([callback])](#PayPalSavePaymentSourceWidget+onSuccess)
8416
+ * [.onError([callback])](#PayPalSavePaymentSourceWidget+onError)
8417
+ * [.onCancel([callback])](#PayPalSavePaymentSourceWidget+onCancel)
8418
+
8419
+ <a name="new_PayPalSavePaymentSourceWidget_new" id="new_PayPalSavePaymentSourceWidget_new" href="#new_PayPalSavePaymentSourceWidget_new">&nbsp;</a>
8420
+
8421
+ ### new PayPalSavePaymentSourceWidget(selector, publicKey, gatewayId, config)
8422
+
8423
+ | Param | Type | Description |
8424
+ | --- | --- | --- |
8425
+ | selector | <code>string</code> | Selector of html element. Container for PayPal Save Payment Source Widget. |
8426
+ | publicKey | <code>string</code> | PayDock users public key. |
8427
+ | gatewayId | <code>string</code> | PayDock's PayPal gatewayId. |
8428
+ | config | [<code>PayPalSavePaymentSourceWidgetConfig</code>](#PayPalSavePaymentSourceWidgetConfig) | Extra configuration for the widget, like styles. |
8429
+
8430
+ **Example**
8431
+ ```js
8432
+ var payPalSavePaymentSourceWidget = new PayPalSavePaymentSourceWidget('#paypalButton', 'public_key', 'gateway_id');
8433
+ ```
8434
+ <a name="PayPalSavePaymentSourceWidget+load" id="PayPalSavePaymentSourceWidget+load" href="#PayPalSavePaymentSourceWidget+load">&nbsp;</a>
8435
+
8436
+ ### payPalSavePaymentSourceWidget.load()
8437
+ The final method after configuring the PayPalSavePaymentSource Widget to
8438
+ start the load process.
8439
+
8440
+ **Kind**: instance method of [<code>PayPalSavePaymentSourceWidget</code>](#PayPalSavePaymentSourceWidget)
8441
+ <a name="PayPalSavePaymentSourceWidget+setEnv" id="PayPalSavePaymentSourceWidget+setEnv" href="#PayPalSavePaymentSourceWidget+setEnv">&nbsp;</a>
8442
+
8443
+ ### payPalSavePaymentSourceWidget.setEnv(env, [alias])
8444
+ Current method can change environment. By default environment = sandbox.
8445
+ Also we can change domain alias for this environment. By default domain_alias = paydock.com
8446
+
8447
+ **Kind**: instance method of [<code>PayPalSavePaymentSourceWidget</code>](#PayPalSavePaymentSourceWidget)
8448
+
8449
+ | Param | Type | Description |
8450
+ | --- | --- | --- |
8451
+ | env | <code>string</code> | sandbox, production |
8452
+ | [alias] | <code>string</code> | Own domain alias |
8453
+
8454
+ **Example**
8455
+ ```js
8456
+ payPalSavePaymentSourceWidget.setEnv('production');
8457
+ ```
8458
+ <a name="PayPalSavePaymentSourceWidget+onSuccess" id="PayPalSavePaymentSourceWidget+onSuccess" href="#PayPalSavePaymentSourceWidget+onSuccess">&nbsp;</a>
8459
+
8460
+ ### payPalSavePaymentSourceWidget.onSuccess([callback])
8461
+ If the setup token was successfully approved and a OTT was generated, the function passed as parameter will be called.
8462
+ Important: Do not perform thread blocking operations in callback such as window.alert() calls.
8463
+
8464
+ **Kind**: instance method of [<code>PayPalSavePaymentSourceWidget</code>](#PayPalSavePaymentSourceWidget)
8465
+
8466
+ | Param | Type | Description |
8467
+ | --- | --- | --- |
8468
+ | [callback] | [<code>OnSuccessCallback</code>](#OnSuccessCallback) | Function to be called when the result is successful. |
8469
+
8470
+ **Example**
8471
+ ```js
8472
+ payPalSavePaymentSourceWidget.onSuccess((eventData) => console.log('One time token and email obtained successfully'));
8473
+ ```
8474
+ <a name="PayPalSavePaymentSourceWidget+onError" id="PayPalSavePaymentSourceWidget+onError" href="#PayPalSavePaymentSourceWidget+onError">&nbsp;</a>
8475
+
8476
+ ### payPalSavePaymentSourceWidget.onError([callback])
8477
+ If in the process for obtaining the setup token fails, the function passed as parameter will be called.
8478
+ Important: Do not perform thread blocking operations in callback such as window.alert() calls.
8479
+
8480
+ **Kind**: instance method of [<code>PayPalSavePaymentSourceWidget</code>](#PayPalSavePaymentSourceWidget)
8481
+
8482
+ | Param | Type | Description |
8483
+ | --- | --- | --- |
8484
+ | [callback] | [<code>OnErrorCallback</code>](#OnErrorCallback) | Function to be called when there is an error in the flow. |
8485
+
8486
+ **Example**
8487
+ ```js
8488
+ payPalSavePaymentSourceWidget.onError((eventData) => console.log('Some error occurred'));
8489
+ ```
8490
+ <a name="PayPalSavePaymentSourceWidget+onCancel" id="PayPalSavePaymentSourceWidget+onCancel" href="#PayPalSavePaymentSourceWidget+onCancel">&nbsp;</a>
8491
+
8492
+ ### payPalSavePaymentSourceWidget.onCancel([callback])
8493
+ If in the process for obtaining the setup token was cancelled, the function passed as parameter will be called.
8494
+ Important: Do not perform thread blocking operations in callback such as window.alert() calls.
8495
+
8496
+ **Kind**: instance method of [<code>PayPalSavePaymentSourceWidget</code>](#PayPalSavePaymentSourceWidget)
8497
+
8498
+ | Param | Type | Description |
8499
+ | --- | --- | --- |
8500
+ | [callback] | [<code>OnCancelCallback</code>](#OnCancelCallback) | Function to be called when the operation is cancelled. |
8501
+
8502
+ **Example**
8503
+ ```js
8504
+ payPalSavePaymentSourceWidget.onCancel(() => console.log('Operation cancelled'));
8505
+ ```
8506
+ <a name="OnSuccessCallback" id="OnSuccessCallback" href="#OnSuccessCallback">&nbsp;</a>
8507
+
8508
+ ## OnSuccessCallback : <code>function</code>
8509
+ Callback for onSuccess method.
8510
+
8511
+ **Kind**: global typedef
8512
+
8513
+ | Param | Type |
8514
+ | --- | --- |
8515
+ | data | [<code>IOnSuccessEventData</code>](#IOnSuccessEventData) |
8516
+
8517
+ <a name="OnErrorCallback" id="OnErrorCallback" href="#OnErrorCallback">&nbsp;</a>
8518
+
8519
+ ## OnErrorCallback : <code>function</code>
8520
+ Callback for onError method.
8521
+
8522
+ **Kind**: global typedef
8523
+
8524
+ | Param | Type |
8525
+ | --- | --- |
8526
+ | data | [<code>IOnErrorEventData</code>](#IOnErrorEventData) |
8527
+
8528
+ <a name="OnCancelCallback" id="OnCancelCallback" href="#OnCancelCallback">&nbsp;</a>
8529
+
8530
+ ## OnCancelCallback : <code>function</code>
8531
+ Callback for onCancel method.
8532
+
8533
+ **Kind**: global typedef
8534
+
8535
+ | Param | Type |
8536
+ | --- | --- |
8537
+ | data | [<code>IOnCancelEventData</code>](#IOnCancelEventData) |
8538
+
8539
+
8540
+ ## PayPalDataCollector Widget
8541
+
8542
+ Widget that collect browser-based data to help reduce fraud. Upon checkout, these data elements are sent directly to PayPal Risk Services for fraud and risk assessment.
8543
+
8544
+ The general flow to use the widgets is:
8545
+ 1. Initialize the PayPal Data Collector Widget, providing a Source Website Identifier (Flow ID), plus optional config parameters for the widget. The general format is:
8546
+ ```js
8547
+ vat paypalDataCollector = new paydock.PayPalDataCollector(
8548
+ sourceWebsiteIdentifier,
8549
+ widgetConfigParams,
8550
+ );
8551
+ ```
8552
+ 2. Handle the `collectDeviceData` function, that will return the generated correlation ID, like following:
8553
+ ```js
8554
+ const collectedDeviceData = await paypalDataCollector.collectDeviceData();
8555
+ const correlationId = collectedDeviceData.correlation_id;
8556
+ ```
8557
+ 3. Use freely the correlation_id value as is needed.
8558
+ 4. Handle the `onError` callback.
8559
+ 5. If you are using Content Security Policy (CSP), you must allowlist the paypal fraudnet script URL: `https://c.paypal.com`. See reference [here](https://developer.paypal.com/limited-release/fraudnet/integrate/#link-contentsecuritypolicyintegration).
8560
+
8561
+ ### PayPalDataCollector Widget example
8562
+
8563
+ A full description of the config parameters for [PayPalDataCollector](#PayPalDataCollector) meta parameters can be found [here](#PayPalDataCollectorConfig). Below you will find a fully working html example.
8564
+
8565
+ ```html
8566
+ <!DOCTYPE html>
8567
+ <html lang="en">
8568
+ <head>
8569
+ <meta charset="UTF-8">
8570
+ <title>Title</title>
8571
+ </head>
8572
+ <body>
8573
+ <h2>Using PayDock PayPalDataCollector Widget!</h2>
8574
+ <div id="widget"></div>
8575
+ </body>
8576
+ <script src="https://widget.paydock.com/sdk/latest/widget.umd.min.js" ></script>
8577
+ <script>
8578
+ let payPalDataCollector = new paydock.PayPalDataCollector(
8579
+ 'FLOW_ID',
8580
+ {
8581
+ mouse_movement: true
8582
+ }
8583
+ );
8584
+
8585
+ payPalDataCollector.setEnv('test');
8586
+
8587
+ payPalDataCollector.onError(function(error) {
8588
+ console.log("On Error Callback", error);
8589
+ });
8590
+
8591
+ payPalDataCollector.collectDeviceData().then(function(collectedDeviceData) {
8592
+ //Here when the promise is resolved, it should be able to see the correlation_id.
8593
+ const correlationId = collectedDeviceData.correlation_id;
8594
+ console.log("On Success", correlationId);
8595
+ });
8596
+ </script>
8597
+ </html>
8598
+ ```
8599
+
8600
+ ## Classes
8601
+
8602
+ <dl>
8603
+ <dt><a href="#PayPalDataCollector">PayPalDataCollector</a></dt>
8604
+ <dd><p>PayPal Data Collector Widget constructor</p>
8605
+ </dd>
8606
+ </dl>
8607
+
8608
+ ## Typedefs
8609
+
8610
+ <dl>
8611
+ <dt><a href="#OnErrorCallback">OnErrorCallback</a> : <code>function</code></dt>
8612
+ <dd><p>Callback for onError method.</p>
8613
+ </dd>
8614
+ </dl>
8615
+
8616
+ ## Interfaces
8617
+
8618
+ <dl>
8619
+ <dt><a href="#PayPalDataCollectorConfig">PayPalDataCollectorConfig</a> : <code>object</code></dt>
8620
+ <dd><p>Interface of data used for PayPal configuration. For further information refer to <a href="https://developer.paypal.com/sdk/js/reference/#style">the documentation</a>.</p>
8621
+ </dd>
8622
+ <dt><a href="#CollectedDeviceData">CollectedDeviceData</a> : <code>object</code></dt>
8623
+ <dd><p>Data object with the corresponding <code>correlation_id</code>.</p>
8624
+ </dd>
8625
+ <dt><a href="#IOnErrorEventData">IOnErrorEventData</a> : <code>object</code></dt>
8626
+ <dd><p>Interface for IOnErrorEventData</p>
8627
+ </dd>
8628
+ </dl>
8629
+
8630
+ <a name="PayPalDataCollectorConfig" id="PayPalDataCollectorConfig" href="#PayPalDataCollectorConfig">&nbsp;</a>
8631
+
8632
+ ## PayPalDataCollectorConfig : <code>object</code>
8633
+ Interface of data used for PayPal configuration. For further information refer to [the documentation](https://developer.paypal.com/sdk/js/reference/#style).
8634
+
8635
+ **Kind**: global interface
8636
+
8637
+ | Param | Type | Description |
8638
+ | --- | --- | --- |
8639
+ | [mouse_movement] | <code>boolean</code> | Used for indicating if is enabled mouse movement collection. |
8640
+
8641
+ <a name="CollectedDeviceData" id="CollectedDeviceData" href="#CollectedDeviceData">&nbsp;</a>
8642
+
8643
+ ## CollectedDeviceData : <code>object</code>
8644
+ Data object with the corresponding `correlation_id`.
8645
+
8646
+ **Kind**: global interface
8647
+
8648
+ | Param | Type | Description |
8649
+ | --- | --- | --- |
8650
+ | [correlation_id] | <code>string</code> | The correlation ID that was used on the subsecuent requests. |
8651
+
8652
+ <a name="IOnErrorEventData" id="IOnErrorEventData" href="#IOnErrorEventData">&nbsp;</a>
8653
+
8654
+ ## IOnErrorEventData : <code>object</code>
8655
+ Interface for IOnErrorEventData
8656
+
8657
+ **Kind**: global interface
8658
+
8659
+ | Param | Type | Description |
8660
+ | --- | --- | --- |
8661
+ | error_code | <code>string</code> | Error code. One of 'promise_not_enabled' or 'script_error'. |
8662
+
8663
+ <a name="PayPalDataCollector" id="PayPalDataCollector" href="#PayPalDataCollector">&nbsp;</a>
8664
+
8665
+ ## PayPalDataCollector
8666
+ PayPal Data Collector Widget constructor
8667
+
8668
+ **Kind**: global class
8669
+
8670
+ * [PayPalDataCollector](#PayPalDataCollector)
8671
+ * [new PayPalDataCollector([flowId], [config])](#new_PayPalDataCollector_new)
8672
+ * [.collectDeviceData()](#PayPalDataCollector+collectDeviceData) ⇒ [<code>Promise.&lt;CollectedDeviceData&gt;</code>](#CollectedDeviceData)
8673
+ * [.onError([callback])](#PayPalDataCollector+onError)
8674
+ * [.setEnv(env)](#PayPalDataCollector+setEnv)
8675
+
8676
+ <a name="new_PayPalDataCollector_new" id="new_PayPalDataCollector_new" href="#new_PayPalDataCollector_new">&nbsp;</a>
8677
+
8678
+ ### new PayPalDataCollector([flowId], [config])
8679
+
8680
+ | Param | Type | Description |
8681
+ | --- | --- | --- |
8682
+ | [flowId] | <code>string</code> | This string identifies the source website of the FraudNet request. |
8683
+ | [config] | [<code>PayPalDataCollectorConfig</code>](#PayPalDataCollectorConfig) | Extra configuration for the widget. |
8684
+
8685
+ **Example**
8686
+ ```js
8687
+ var payPalDataCollector = new PayPalDataCollector('FLOW_ID', {});
8688
+ ```
8689
+ <a name="PayPalDataCollector+collectDeviceData" id="PayPalDataCollector+collectDeviceData" href="#PayPalDataCollector+collectDeviceData">&nbsp;</a>
8690
+
8691
+ ### payPalDataCollector.collectDeviceData() ⇒ [<code>Promise.&lt;CollectedDeviceData&gt;</code>](#CollectedDeviceData)
8692
+ After configuring the PayPalDataCollector Widget, starts the process and returns
8693
+ the correlation id used among the requests asynchronously.
8694
+
8695
+ **Kind**: instance method of [<code>PayPalDataCollector</code>](#PayPalDataCollector)
8696
+ **Returns**: [<code>Promise.&lt;CollectedDeviceData&gt;</code>](#CollectedDeviceData) - Promise when resolved, returns an object
8697
+ that contains the `correlation_id` key.
8698
+ **Example**
8699
+ ```js
8700
+ const collectedDeviceData = await payPalDataCollectorWidget.collectDeviceData();
8701
+ console.log(collectedDeviceData.correlation_id)
8702
+ ```
8703
+ <a name="PayPalDataCollector+onError" id="PayPalDataCollector+onError" href="#PayPalDataCollector+onError">&nbsp;</a>
8704
+
8705
+ ### payPalDataCollector.onError([callback])
8706
+ If the process fails, the function passed as parameter will be called.
8707
+ Important: Do not perform thread blocking operations in callback such as window.alert() calls.
8708
+
8709
+ **Kind**: instance method of [<code>PayPalDataCollector</code>](#PayPalDataCollector)
8710
+
8711
+ | Param | Type | Description |
8712
+ | --- | --- | --- |
8713
+ | [callback] | [<code>OnErrorCallback</code>](#OnErrorCallback) | Function to be called when there is an error in the flow. |
8714
+
8715
+ **Example**
8716
+ ```js
8717
+ PayPalDataCollector.onError((eventData) => console.log('Some error occur'));
8718
+ ```
8719
+ <a name="PayPalDataCollector+setEnv" id="PayPalDataCollector+setEnv" href="#PayPalDataCollector+setEnv">&nbsp;</a>
8720
+
8721
+ ### payPalDataCollector.setEnv(env)
8722
+ Current method can change environment. By default environment = test.
8723
+ This method does not affect Paydock's API calls or environments, is only for PayPal Data Collector
8724
+ script, in order to know if the script is injected on a live server or is a testing
8725
+ environment. The available values are `test` and `live`. This should match with the used
8726
+ `gateway.mode` in Paydock to process the transaction.
8727
+
8728
+ **Kind**: instance method of [<code>PayPalDataCollector</code>](#PayPalDataCollector)
8729
+
8730
+ | Param | Type | Description |
8731
+ | --- | --- | --- |
8732
+ | env | <code>string</code> | test, live |
8733
+
8734
+ **Example**
8735
+ ```js
8736
+ PayPalDataCollector.setEnv('live');
8737
+ ```
8738
+ <a name="OnErrorCallback" id="OnErrorCallback" href="#OnErrorCallback">&nbsp;</a>
8739
+
8740
+ ## OnErrorCallback : <code>function</code>
8741
+ Callback for onError method.
8742
+
8743
+ **Kind**: global typedef
8744
+
8745
+ | Param | Type |
8746
+ | --- | --- |
8747
+ | data | [<code>IOnErrorEventData</code>](#IOnErrorEventData) \| <code>null</code> |
8748
+
8749
+
7967
8750
  ## License
7968
8751
  Copyright (c) 2024 paydock