This repository has been archived by the owner on Sep 14, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathindex.js
108 lines (99 loc) · 2.68 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React, { Component } from 'react';
import { WebView } from 'react-native-webview';
import { PropTypes } from 'prop-types';
import omit from 'object.omit';
const injectedJavaScript = `(function() {
window.postMessage = function(data) {
window.ReactNativeWebView.postMessage(data);
};
})()`;
class PlaidAuthenticator extends Component {
render() {
const {
clientName,
countryCodes,
env,
plaidRef,
product,
publicKey,
selectAccount,
style,
token,
userEmail,
userLegalName,
webhook
} = this.props;
let uri = `https://cdn.plaid.com/link/v2/stable/link.html?key=${
publicKey
}&apiVersion=v2&env=${env}&product=${product}&clientName=${
clientName
}&isWebView=true&isMobile=true&selectAccount=${
selectAccount
}`;
uri = countryCodes !== undefined ? `${uri}&countryCodes=${countryCodes}` : uri;
uri = token !== undefined ? `${uri}&token=${token}` : uri;
uri = userEmail !== undefined ? `${uri}&userEmail=${userEmail}` : uri;
uri = userLegalName !== undefined ? `${uri}&userLegalName=${userLegalName}` : uri;
uri = webhook !== undefined ? `${uri}&webhook=${webhook}` : uri;
return (
<WebView
{...omit(this.props, [
'clientName',
'countryCodes',
'env',
'product',
'publicKey',
'ref',
'selectAccount',
'token',
'userEmail',
'userLegalName',
'webhook'
])}
ref={plaidRef}
source={{ uri }}
onMessage={this.onMessage}
useWebKit
injectedJavaScript={injectedJavaScript}
/>
);
}
onMessage = e => {
/*
Response example for success
{
"action": "plaid_link-undefined::connected",
"metadata": {
"account": {
"id": null,
"name": null
},
"account_id": null,
"public_token": "public-sandbox-e697e666-9ac2-4538-b152-7e56a4e59365",
"institution": {
"name": "Chase",
"institution_id": "ins_3"
}
}
}
*/
this.props.onMessage(JSON.parse(e.nativeEvent.data));
};
}
PlaidAuthenticator.propTypes = {
clientName: PropTypes.string,
countryCodes: PropTypes.string,
env: PropTypes.string.isRequired,
onMessage: PropTypes.func.isRequired,
plaidRef: PropTypes.func,
product: PropTypes.string.isRequired,
publicKey: PropTypes.string.isRequired,
userEmail: PropTypes.string,
userLegalName: PropTypes.string,
webhook: PropTypes.string
};
PlaidAuthenticator.defaultProps = {
clientName: '',
plaidRef: () => {}
};
export default PlaidAuthenticator;