Coder Social home page Coder Social logo

plaid / react-plaid-link Goto Github PK

View Code? Open in Web Editor NEW
256.0 53.0 148.0 2.79 MB

React bindings for Plaid Link

Home Page: https://plaid.github.io/react-plaid-link

License: MIT License

Makefile 4.12% JavaScript 22.91% Shell 1.25% TypeScript 71.71%
plaid-link react plaid react-component

react-plaid-link's Introduction

react-plaid-link npm version

React hook and components for integrating with Plaid Link

Compatibility

React 16.8+

Install

With npm:

npm install --save react-plaid-link

With yarn

yarn add react-plaid-link

Documentation

Please refer to the official Plaid Link docs for a more holistic understanding of Plaid Link.

Examples

Head to the react-plaid-link storybook to try out a live demo.

See the examples folder for various complete source code examples.

Using React hooks

This is the preferred approach for integrating with Plaid Link in React.

Note: token can be null initially and then set once you fetch or generate a link_token asynchronously.

ℹ️ See a full source code examples of using hooks:

import { usePlaidLink } from 'react-plaid-link';

// ...

const { open, ready } = usePlaidLink({
  token: '<GENERATED_LINK_TOKEN>',
  onSuccess: (public_token, metadata) => {
    // send public_token to server
  },
});

return (
  <button onClick={() => open()} disabled={!ready}>
    Connect a bank account
  </button>
);

Available Link configuration options

ℹ️ See src/types/index.ts for exported types.

Please refer to the official Plaid Link docs for a more holistic understanding of the various Link options and the link_token.

usePlaidLink arguments

key type
token string | null
onSuccess (public_token: string, metadata: PlaidLinkOnSuccessMetadata) => void
onExit (error: null | PlaidLinkError, metadata: PlaidLinkOnExitMetadata) => void
onEvent (eventName: PlaidLinkStableEvent | string, metadata: PlaidLinkOnEventMetadata) => void
onLoad () => void
receivedRedirectUri string | null | undefined

usePlaidLink return value

key type
open () => void
ready boolean
error ErrorEvent | null
exit (options?: { force: boolean }, callback?: () => void) => void

OAuth / opening Link without a button click

Handling OAuth redirects requires opening Link without any user input (such as clicking a button). This can also be useful if you simply want Link to open immediately when your page or component renders.

ℹ️ See full source code example at examples/oauth.tsx

import { usePlaidLink } from 'react-plaid-link';

// ...

const { open, ready } = usePlaidLink(config);

// open Link immediately when ready
React.useEffect(() => {
  if (ready) {
    open();
  }
}, [ready, open]);

return <></>;

Using the pre-built component instead of the usePlaidLink hook

If you cannot use React hooks for legacy reasons such as incompatibility with class components, you can use the PlaidLink component.

ℹ️ See full source code example at examples/component.tsx

import { PlaidLink } from "react-plaid-link";

const App extends React.Component {
  // ...
  render() {
    return (
      <PlaidLink
        token={this.state.token}
        onSuccess={this.onSuccess}
        // onEvent={...}
        // onExit={...}
      >
        Link your bank account
      </PlaidLink>
    );
  }
}

Typescript support

TypeScript definitions for react-plaid-link are built into the npm package. If you have previously installed @types/react-plaid-link before this package had types, please uninstall it in favor of built-in types.

react-plaid-link's People

Contributors

aesopwolf avatar anjiren avatar cgfarmer4 avatar clayallsopp avatar dcripplinger avatar dependabot[bot] avatar dianeliu21 avatar edwinychu avatar furcic avatar gilakos avatar hlibco avatar itsvs avatar jclem avatar jlaramie avatar jparadasb avatar jung35 avatar kulek1 avatar nas887 avatar otherchen avatar pbernasconi avatar phoenixy1 avatar piton4eg avatar rcbm avatar rurabe avatar skylarmb avatar strawbee avatar symphon-y avatar timruffles avatar tzha-plaid avatar wokkaflokka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-plaid-link's Issues

Failed to execute 'postMessage' on 'DOMWindow'.

Looks like that there is some infrastructure changes on Plaid's side that lead to unexpected behavior in plaid-link. We're using plaid's postMessages to handle all authorization cases. But when user selects bank that requires OAuth authorization type and completes necessary steps (or not), Plaid doesn't send postMessage about that.
Steps to reproduce:

  • set plaid env to "sandbox"
  • start auth flow in plaid
  • Select bank that requires OAuth in banks search page (i've used almost all UK banks (HSBC (UK), Barclays))
  • on bank's OAuth page(which is Plaid's mocked page since we're on sandbox) press any button "Grant access", "Simulate Error" ect.
  • look into browser console
    postMessage

Not sure if it affects "development" and "production" env.

During bank connectivity in Android landscape view, the bank user name field enters text backwards.

This issue occurs for Android users in landscape (not portrait) mode.

When a user attempts to connect a bank using their bank credentials, the characters entered into the user name field are entered in reverse order. This image displays the user experience when the user enters "user_good" as their user name:

UI

The following is the OS and build information of the device used to recreate this defect:

OSandBuild

Thanks!

Extract account balance data from http call

When inspecting the network traffic during the Plaid link widget flow, I can see that we are getting account balances when calling https://sandbox.plaid.com/link/item/create. But none of the onXXXXX callbacks are getting this in their payload. Is there a way to retrieve this data from the client side?

Request URL: https://sandbox.plaid.com/link/item/create
Request Method: POST
Status Code: 200 OK

Payload in network inspection

{
  "accounts": [
    {
      "account_id": "4WLLyEd7ZrukbWNrkJfefe3FEgrFREGREGERG",
      "balances": {
        "available": 100,
        "currency": "USD",
        "current": 110,
        "localized": {
          "available": "$100.00",
          "current": "$110.00"
        }
      },
      "mask": "0000",
      "name": "Plaid Checking",
      "subtype": "checking",
      "type": "depository"
    },
    {
      "account_id": "NZKKa4yzPuoU8hHJBIHHHhhhNaFWDXjaz",
      "balances": {
        "available": 200,
        "currency": "USD",
        "current": 210,
        "localized": {
          "available": "$200.00",
          "current": "$210.00"
        }
      },
      "mask": "1111",
      "name": "Plaid Saving",
      "subtype": "savings",
      "type": "depository"
    },
    {
      "account_id": "P1zzNPAokeogpkreogkrefkwLkGmaF7MXkjb",
      "balances": {
        "available": null,
        "currency": "USD",
        "current": 1000,
        "localized": {
          "available": null,
          "current": "$1,000.00"
        }
      },

Plaid opens in tiny window at the top of the page

I'm having an issue here Plaid is opening in a tiny section on the top of the page - and I'm running short on ideas of how to address this since all of the code is coming from Plaid when it appends to the body. The image should explain everything... Is there a way I can create a div or modal for this to live in, instead of plaid appending to the body?

Screenshot from 2020-03-05 13-59-58

Release 0.1.8?

I saw you updated the src but NPM still has you at a release pegged to January, I believe. Would love to use v2 (apiVersion) but would rather keep an external dependency. Let me know if you can release this out (if it's ready!) or if I should just clone my own.

Thanks!

give button type="button"

right now, without it, initializing this inside a form will trigger the Plaid Modal when hitting enter to submit said form. Should be a straightforward fix.

Support for the experimental syntax 'classProperties' isn't currently enabled

I've just got this error after installing react-plaid-link package in my React.js project.

I bootstrapped it with create-react-app which means adding babel plugins is a pain.

I'm creating this issue because I assume there are many developers doing their react applications by using the very popular Facebook's create-react-app tool and having to install a plugin is so weird.

Would love to know if I'm doing something wrong or if there's anyone else experiencing the same issue.

Longtail option deprecated

link-initialize.js:26 Warning: The Plaid Link option "longtail" is deprecated

That option is nowhere to be found in the current Plaid Link documentation, but react-plaid-link adds the prop with a false value currently.

Cannot find module 'react-plaid-link'

I'm seeing this error newly within the past 24 hours, in a docker app that has react-plaid-link as a dependency. Changing my package.json to restrict the dep to v1.2.0 fixed the issue. It seems potentially related to commit f48fed5

Error: Cannot find module 'react-plaid-link'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/usr/src/app/dist/server.bundle.js:3998:18)

Depreciation of React.createClass

#Hi,

  • Thank you very much for your time, and your amazing work, I am using plaidlink for one week and it works perfectly, thank you again. The only issue is that React. createClass is deprecated, do you plan to start using class PlaidLinks extends Component?
  • Best Regards and thank you again for your time.

Question: Why does the usePlaid hook require the config to be destructured to reinitialize?

Hey Plaid team,

I have a quick question regarding the need to destructure the config that passed into the usePlaid hook. In your example, https://github.com/plaid/react-plaid-link/blob/master/src/PlaidLink.tsx#L8 you destructure and restructure the config object.

Initially, I tried to pass in an object into usePlaid like this:

const config_object = {
   ......
}
// Does not reinitialize Plaid when the config_object changes
const { error, open } = usePlaidLink(config_object)

// Reinitialized Plaid when the config_object changes
const { error, open } = usePlaidLink({ ...config_object})

but this would not reinitialize the plaid module. However, destructuring the config object works. Why is this the case?

Cheers,
Stephan

Loading Plaid fails on initial page load

I get Error loading Plaid null when using usePlaidLink every time I initially load my app in the browser. When I navigate away from the place where I use Plaid and navigate back, everything works.

The reason seems to be this check:

if (error || !window.Plaid) {

From what I can tell, loading becomes false, but window.Plaid is not yet available (perhaps react-script-hook sets loading to false as soon as the script is downloaded but not when it's parsed/executed?). Checking window.Plaid in browser's console indicates that the library is loaded properly soon after the error.

Expose the onClick function to Support Custom Buttons

Styling the button is unnecessarily complicated if you are not using standard CSS rules, for example we use styled components and already have a styled button, but it's not possible to use it instead of the build in Plaid button.

Also, there's no way to add extra tags to the button, such as tags for accessibility.

It is possible to do this, but it results in a nested button, which again is bad for accessibility:

<PlaidLink
  ...
>
  <StyledButton>Testing</StyledButton>
</PlaidLink>

It'd be great if a function was exposed that would allow disabling the built in button and using the custom one instead. Something like:

import {PlaidLink, startPlaid} from 'react-plaid-link';
<PlaidLink
  buttonDisabled={true}
>
  <StyledButton onClick={() => startPlaid()}>Testing</StyledButton>
</PlaidLink>

@pbernasconi

How about some tests?

'use strict';
/* globals describe, it */



describe('PlaidLink', () => {

  it('should load all basic components on creation', () => {
  });

});

Cause there are none really...

linkCustomizationName prop on 'react-plaid-link'

unable to pass in linkCustomizationName prop into to get customized plaid link

import PlaidLink from 'react-plaid-link';

<PlaidLink
clientName="plaid"
env="sandbox"
publicKey="ADD_PUBLIC_KEY_HERE"
product={['assets']}
onSuccess={this.handleOnSuccess}
linkCustomizationName="my_customized_plaid"

Connect bank account

this prop does not exist in 'react-plaid-link'

is there another way around this or do i have to wait for a new version of 'react-plaid-link' to have that prop?

There is neither CHANGELOG.md nor Release Descriptions

As a user of this package it is very difficult to tell what changes between versions so very hard to know if upgrading versions is safe, if there are new features that can be used, or if there are useful fixes. Please add some description of releases. Thanks!

Make `PlaidLink` completely unaware of children visual properties

Right now PlaidLink passes down some styling to its children by default. In order to overcome that one must pass down an empty object as style.
In my opinion it would make more sense if PlaidLink didn't care at all about what's being rendered.

If you do agree I can send a PR that makes this possible.

Thanks.

Customizing the Plaid Link Component

How can I add the react-plaid-link to the source of my react app and customize it? Say if I were to also use Material UI?

I placed the PlaidLink.js source file in to my src directory and installed the reactscriptloader mixin. When I go to build with webpack, I am receiving an error Plaid is not defined.

By downloading this repository and adding material ui there, I am able to build in that directory and then load the output as a node module successfully. So I'm assuming that I am missing something in webpack config potentially or in some other way do not properly understand the build process.

Delay PlaidLink initialization

I am building a mobile webapp which allows user to select their bank from a list of banks (with institution set in each PlaidLink component. The current behavior of PlaidLink is once it's rendered, a number of initialization will occur, which makes the performance of the loading quite slow. I am wondering if there is a way to postpone the init steps, that is, making calls to Plaid servers only when a button is clicked.

Plaid link props not refreshing on wrapper receive new props.

When I tried to use manual link for plaid I had to update the token property in order to display the manual link screen.
FIX:

  onScriptLoaded( callback = () => {}) {
    this.linkHandler = window.Plaid.create({
      apiVersion: this.props.apiVersion,
      clientName: this.props.clientName,
      countryCodes: this.props.countryCodes,
      language: this.props.language,
      env: this.props.env,
      key: this.props.publicKey,
      onEvent: this.props.onEvent,
      onExit: this.props.onExit,
      onLoad: this.handleLinkOnLoad,
      onSuccess: this.props.onSuccess,
      product: this.props.product,
      selectAccount: this.props.selectAccount,
      token: this.props.token,
      user: this.props.user,
      webhook: this.props.webhook,
    });

    this.setState({ disabledButton: false }, callback);
  }
handleOnClick(event) {
    if (this.props.onClick != null) {
      this.props.onClick(event);
    }
    if (this.linkHandler) {

      this.onScriptLoaded(()=> {
        this.linkHandler.open();
      });


    }
  }

It makes more sense to me linking the props on the click event.

Hiding unsupported products

Kinecta Federal Credit Union is not part of the default set of banks that are displayed on the bank selection screen, so we have to search for it:
image

After going through the regular flow we get back PlaidError : PRODUCTS_NOT_SUPPORTED when making a POST:/identity/get request after retrieving the access token from a POST /item/public_token/exchange request . This is happening on the sandbox and production instances.

We would prefer to hide banks that do not support products that we make use, is there a configuration to achieve this behaviour?

Alternatively, is there a way to provide a list of banks for the PlaidLink component to display? We would have to find a way to filter the list of banks based on the products they support.

We are are v1.5.0.

EDIT: More details.

Metadata is null

At the top of handleOnSuccess, the console log shows metadata is null and therefore metadata.account_id is null, token is the correct value.

import React, { Component } from 'react'
import PlaidLink from 'react-plaid-link'
import axios from 'axios';

class Plaid extends Component {
constructor(props) {
super(props);
}
handleOnSuccess(token, metadata) {
console.log(token)
console.log(metadata.account_id)

axios.post(...
  }).then(function (response) {
    console.log(response)
  }).catch(function (error) {
    console.log(error.message)
  });

}
handleOnExit() {
console.log('link: user exited');
console.log(error, metadata);
}
handleOnLoad() {
console.log('link: loaded');
}
handleOnEvent(eventname, metadata) {
console.log('link: user event', eventname, metadata);
}
render() {
return (
<PlaidLink
clientName="CoName"
env="sandbox"
product={["transactions"]}
publicKey="MY_KEY"
onExit={this.handleOnExit}
onSuccess={this.handleOnSuccess}>
Open Link and connect your bank!

)
}
}
export default Plaid

PlaidLink propTypes Issue

Version: 2.0.1

When using the PlaidLink component, I get the following error if key is not specified as a prop to PlaidLink:

Property 'key' is missing in type '{ children: string; clientName: string; env: string; product: string[]; publicKey: string; onSuccess: () => void; }' but required in type 'Pick<InferProps<{ className: Validator<string>; clientName: Validator<string>; env: Validator<string>; key: Validator<string>; product: Validator<(string | null | undefined)[]>; onSuccess: Validator<(...args: any[]) => any>; ... 9 more ...; children: Requireable<...>; }>, "key">'.

This appears to be cause by key being specified as a required propType in the PlaidLink definition. Is that that is supposed to be publicKey instead of key?

declare const PlaidLink: { (props: PlaidLinkPropTypes): JSX.Element; displayName: string; propTypes: { className: PropTypes.Validator<string>; clientName: PropTypes.Validator<string>; env: PropTypes.Validator<string>; key: PropTypes.Validator<string>; product: PropTypes.Validator<(string | null | undefined)[]>; onSuccess: PropTypes.Validator<(...args: any[]) => any>; countryCodes: PropTypes.Requireable<any[]>; language: PropTypes.Requireable<string>; onEvent: PropTypes.Requireable<(...args: any[]) => any>; onExit: PropTypes.Requireable<(...args: any[]) => any>; onLoad: PropTypes.Requireable<(...args: any[]) => any>; token: PropTypes.Requireable<string>; userEmailAddress: PropTypes.Requireable<string>; userLegalName: PropTypes.Requireable<string>; webhook: PropTypes.Requireable<string>; children: PropTypes.Requireable<PropTypes.ReactElementLike>; }; };

Let me know if you need more information.

'Link with account numbers' button does not appear on 2.0.3

The verify with microdeposits functionality is not available under 2.0.3. Under version 1.5.1, to enable this functionality you would pass in:

user={{
  legalName: homeowner.fullName,
  emailAddress: homeowner.email,
}}

However, these props are unavailable under version 2.0.3 - the current version of the library allows a user to pass in

userLegalName={fullName}
userEmailAddress={email}

However these props do not enable microdeposits.

options.webhook must be a non-empty string URL

I'm using this (templated) command in my javascript:

    var handler = Plaid.create({
      clientName: 'Plaid Quickstart',
      env: '{{ .plaid_environment }}',
      product: products,
      key: '{{ .plaid_public_key }}',
      webhook: '{{ .plaid_webhook_url }}',
      onSuccess: function(public_token) {
        authenticatedRequest(
          'POST',
          '/api/v1/add_plaid_item',
          { "public_token": public_token },
          function(data) {
            $('#intro').hide();
            refreshAccountTable();
            $('#app, #steps').fadeIn('slow');
          }
        )
      },
      onExit: function(err, metadata) {
        // The user exited the Link flow.
        if (err != null) {
          // The user encountered a Plaid API error prior to exiting.
          console.log(err, '{{ .plaid_webhook_url }}');
        }
        // metadata contains information about the institution
        // that the user selected and the most recent API request IDs.
        // Storing this information can be helpful for support.
      },
    });

    $('#link-btn').on('click', function(e) {
      handler.open();
    });

I can confirm that webhook is being set to /api/v1/webhook as I want. But when I go through the login flow, it ends with a 400 response from https://sandbox.plaid.com/link/item/create with this body:

{
  "display_message": null,
  "error_code": "INVALID_FIELD",
  "error_message": "options.webhook must be a non-empty string URL",
  "error_type": "INVALID_REQUEST",
  "request_id": "...",
  "suggested_action": null
}

When I check the response body, I see the following underneath the top level:
Screen Shot 2019-10-09 at 10 07 06 PM
so the field appears to be set.

TypeError: React.createClass is not a function

I am using react-plaid-link, Now i am upgrade my react-js version from 15.6.1 to 16.4.1.
From that, I am getting following issue.
I know this is version problem, But i want latest version of react-js. So any one can help to resolve it.

TypeError: React.createClass is not a function

`Object../node_modules/react-plaid-link/dist/PlaidLink.js
node_modules/react-plaid-link/dist/PlaidLink.js:7
4 | var PropTypes = require('prop-types');
5 | var ReactScriptLoaderMixin = require('react-script-loader').ReactScriptLoaderMixin;
6 |

7 | var PlaidLink = React.createClass({
8 | displayName: 'PlaidLink',
9 |
10 | mixins: [ReactScriptLoaderMixin],
View compiled
webpack_require
/home/santhi/Documents/mvp_testing/webpack/bootstrap 46193b11a979a174f68b:659
656 | };
657 |
658 | // Execute the module function
659 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
660 |
661 | // Flag the module as loaded
662 | module.l = true;`

Styling button

Is there any way to custom style the button that comes with this?

Update on new props

It appears that the component doesn't update when props are changed. Specifically, I would like to generate a new public token at the time my users hit the page, which means the PlaidLink won't be initialized with the token prop, but I will pass it down once it's loaded. Is it possible to have a ComponentDidUpdate?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.