Skip to content

Instantly share code, notes, and snippets.

@frostiq
Last active August 16, 2019 04:55
Show Gist options
  • Save frostiq/e891dc0e9d984ef1c78b6aad06074aa4 to your computer and use it in GitHub Desktop.
Save frostiq/e891dc0e9d984ef1c78b6aad06074aa4 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<script type="text/javascript">
// 1. Obtain a webview config from Wyre API
function getConfig(env) {
var baseUrl;
switch (env) {
case "test":
baseUrl = "https://api.testwyre.com";
break;
case "production":
baseUrl = "https://api.sendwyre.com";
break;
default:
throw new Error("Unknown env: " + env);
}
return $.get(baseUrl + "/v2/client/config/plaid");
}
getConfig("test").then(function (config) {
// 2. Build a URL for a WebView with Plaid widget
var queryString = {
env: config.plaidEnvironment,
key: config.plaidPublicKey,
webhook: config.plaidWebhook,
product: "identity",
selectAccount: true,
isWebview: true,
isMobile: true
};
var url = "https://cdn.plaid.com/link/v2/stable/link.html?" + $.param(queryString);
console.log("url", url);
// 3. Open a WebView with built URL
window.location = url;
// 4. Intercept a redirect URL from Plaid Widget
// Example of a redirect URL after a sucessfull bank account connection:
/* plaidlink://connected?
account_id=91jgPnXPv3Fla9X94g9nsmpz1GdVmlhRmAJoJ&
account_mask=0000&
account_name=Plaid%20Checking&
account_subtype=checking&
account_type=depository&
accounts=%5B%7B%22_id%22%3A%2291jgPnXPv3Fla9X94g9nsmpz1GdVmlhRmAJoJ%22%2C%22balance%22%3A%7B%22available%22%3A100%2C%22current%22%3A110%7D%2C%22meta%22%3A%7B%22name%22%3A%22Plaid%20Checking%22%2C%22number%22%3A%220000%22%7D%2C%22type%22%3A%22depository%22%2C%22subtype%22%3A%22checking%22%7D%5D&
institution_id=ins_3&
institution_name=Chase&
link_session_id=ee12dc10-f584-4790-a6e8-2c80e456138c&
public_token=public-sandbox-b595febb-b2f0-43c3-9f3c-ed960efb16e0
*/
// Don't forget to intercept unsuccessful connection attempt:
// plaidlink://exit?[...]
// public token to use for Wyre API POST request = `publicToken` + "|" + `account_id` (concatenation with '|' in the middle)
// where `publicToken` and `account_id` are query params from sucessfull `plaidlink` above
// MORE INFO: https://plaid.com/docs/#webview-integration
// iOS EXAMPLE: https://github.com/plaid/plaid-link-examples/blob/master/webviews/wkwebview/wkwebview/LinkViewController.swift
});
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment