@paydock/client-sdk
Version:
Paydock client sdk
150 lines (110 loc) • 5.87 kB
Markdown
## Classes
<dl>
<dt><a href="#PayPalDataCollector">PayPalDataCollector</a></dt>
<dd><p>PayPal Data Collector Widget constructor</p>
</dd>
</dl>
## Typedefs
<dl>
<dt><a href="#OnErrorCallback">OnErrorCallback</a> : <code>function</code></dt>
<dd><p>Callback for onError method.</p>
</dd>
</dl>
## Interfaces
<dl>
<dt><a href="#PayPalDataCollectorConfig">PayPalDataCollectorConfig</a> : <code>object</code></dt>
<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>
</dd>
<dt><a href="#CollectedDeviceData">CollectedDeviceData</a> : <code>object</code></dt>
<dd><p>Data object with the corresponding <code>correlation_id</code>.</p>
</dd>
<dt><a href="#IOnErrorEventData">IOnErrorEventData</a> : <code>object</code></dt>
<dd><p>Interface for IOnErrorEventData</p>
</dd>
</dl>
<a name="PayPalDataCollectorConfig" id="PayPalDataCollectorConfig" href="#PayPalDataCollectorConfig"> </a>
## PayPalDataCollectorConfig : <code>object</code>
Interface of data used for PayPal configuration. For further information refer to [the documentation](https://developer.paypal.com/sdk/js/reference/#style).
**Kind**: global interface
| Param | Type | Description |
| --- | --- | --- |
| [mouse_movement] | <code>boolean</code> | Used for indicating if is enabled mouse movement collection. |
<a name="CollectedDeviceData" id="CollectedDeviceData" href="#CollectedDeviceData"> </a>
## CollectedDeviceData : <code>object</code>
Data object with the corresponding `correlation_id`.
**Kind**: global interface
| Param | Type | Description |
| --- | --- | --- |
| [correlation_id] | <code>string</code> | The correlation ID that was used on the subsecuent requests. |
<a name="IOnErrorEventData" id="IOnErrorEventData" href="#IOnErrorEventData"> </a>
## IOnErrorEventData : <code>object</code>
Interface for IOnErrorEventData
**Kind**: global interface
| Param | Type | Description |
| --- | --- | --- |
| error_code | <code>string</code> | Error code. One of 'promise_not_enabled' or 'script_error'. |
<a name="PayPalDataCollector" id="PayPalDataCollector" href="#PayPalDataCollector"> </a>
## PayPalDataCollector
PayPal Data Collector Widget constructor
**Kind**: global class
* [PayPalDataCollector](#PayPalDataCollector)
* [new PayPalDataCollector([flowId], [config])](#new_PayPalDataCollector_new)
* [.collectDeviceData()](#PayPalDataCollector+collectDeviceData) ⇒ [<code>Promise.<CollectedDeviceData></code>](#CollectedDeviceData)
* [.onError([callback])](#PayPalDataCollector+onError)
* [.setEnv(env)](#PayPalDataCollector+setEnv)
<a name="new_PayPalDataCollector_new" id="new_PayPalDataCollector_new" href="#new_PayPalDataCollector_new"> </a>
### new PayPalDataCollector([flowId], [config])
| Param | Type | Description |
| --- | --- | --- |
| [flowId] | <code>string</code> | This string identifies the source website of the FraudNet request. |
| [config] | [<code>PayPalDataCollectorConfig</code>](#PayPalDataCollectorConfig) | Extra configuration for the widget. |
**Example**
```js
var payPalDataCollector = new PayPalDataCollector('FLOW_ID', {});
```
<a name="PayPalDataCollector+collectDeviceData" id="PayPalDataCollector+collectDeviceData" href="#PayPalDataCollector+collectDeviceData"> </a>
### payPalDataCollector.collectDeviceData() ⇒ [<code>Promise.<CollectedDeviceData></code>](#CollectedDeviceData)
After configuring the PayPalDataCollector Widget, starts the process and returns
the correlation id used among the requests asynchronously.
**Kind**: instance method of [<code>PayPalDataCollector</code>](#PayPalDataCollector)
**Returns**: [<code>Promise.<CollectedDeviceData></code>](#CollectedDeviceData) - Promise when resolved, returns an object
that contains the `correlation_id` key.
**Example**
```js
const collectedDeviceData = await payPalDataCollectorWidget.collectDeviceData();
console.log(collectedDeviceData.correlation_id)
```
<a name="PayPalDataCollector+onError" id="PayPalDataCollector+onError" href="#PayPalDataCollector+onError"> </a>
### payPalDataCollector.onError([callback])
If the process fails, the function passed as parameter will be called.
Important: Do not perform thread blocking operations in callback such as window.alert() calls.
**Kind**: instance method of [<code>PayPalDataCollector</code>](#PayPalDataCollector)
| Param | Type | Description |
| --- | --- | --- |
| [callback] | [<code>OnErrorCallback</code>](#OnErrorCallback) | Function to be called when there is an error in the flow. |
**Example**
```js
PayPalDataCollector.onError((eventData) => console.log('Some error occur'));
```
<a name="PayPalDataCollector+setEnv" id="PayPalDataCollector+setEnv" href="#PayPalDataCollector+setEnv"> </a>
### payPalDataCollector.setEnv(env)
Current method can change environment. By default environment = test.
This method does not affect Paydock's API calls or environments, is only for PayPal Data Collector
script, in order to know if the script is injected on a live server or is a testing
environment. The available values are `test` and `live`. This should match with the used
`gateway.mode` in Paydock to process the transaction.
**Kind**: instance method of [<code>PayPalDataCollector</code>](#PayPalDataCollector)
| Param | Type | Description |
| --- | --- | --- |
| env | <code>string</code> | test, live |
**Example**
```js
PayPalDataCollector.setEnv('live');
```
<a name="OnErrorCallback" id="OnErrorCallback" href="#OnErrorCallback"> </a>
## OnErrorCallback : <code>function</code>
Callback for onError method.
**Kind**: global typedef
| Param | Type |
| --- | --- |
| data | [<code>IOnErrorEventData</code>](#IOnErrorEventData) \| <code>null</code> |