karlhepler / plaid

PHP Plaid API Client with some Laravel extras

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Connecting Users with Credentials to an Institution

AstroBoy269 opened this issue · comments

I apologize for asking a generic/easy question here but I have to admit that I'm currently stymied. I'm relatively young at Laravel and broader OOP. I've been "Googling" and going through the test code all afternoon.

I need to interface with Plaid and your package seems like it's exactly what I need. I've figured out how to connect with Plaid and I can get lists of institutions and the categories, what not. But for the life of me, I can't figure out how to connect a user to an institution so I can query their accounts. I'm sure my issues are around the user credentials but I sure can't figure it out.

I've been beating my head against the wall for a while and will take another run through the test code tomorrow to see if I can figure out what I'm missing. Any advice or even pointing me in the right direction would be greatly appreciated.

Kudos, to you for putting this together, sorry I'm not smart enough to figure it out.
Thanks

Hi Lance,

Your question reminds me to update the readme. Thanks - hopefully I can get to that this week.

First thing - while the Plaid client was written to take advantage of Laravel, it's not required. So don't feel like you're stuck with Laravel if you are using a different (or no) framework/platform.

As far as your question, while the official documentation should help you, it may not be straight-forward when putting it into practice. I'll do my best below to give you an example of one way you might want to tackle this.

$plaid = /* Get an instance of OldTimeGuitarGuy\Plaid\Plaid */

/* Create and instantiate an instance of a class that implements OldTimeGuitarGuy\Plaid\Contracts\Credentials */
use OldTimeGuitarGuy\Plaid\Contracts\Credentials;
class MyCredentialsClass implements Credentials
{
    protected $username;
    protected $password;
    protected $pin;

    public function __construct($username, $password, $pin)
    {
        $this->username = $username;
        $this->password = $password;
        $this->pin = $pin;
    }

    public function username()
    {
        return $this->username;
    }

    public function password()
    {
        return $this->password;
    }

    public function pin()
    {
        return $this->pin;
    }
}

$credentials = new MyCredentialsClass('plaid_test', 'plaid_good', 1234);

/* Add the user to Plaid, specifying the bank name from the Plaid docs */
$response = $plaid->connect()->user()->add('wells', $credentials);

/* You should receive an access token in the response per the docs */
$accessToken = $response->access_token;

/*
   NOTE: There is a chance you might receive a response that requires a "step"
*/

/* Throw that access token into a class instance that implements OldTimeGuitarGuy\Plaid\Contracts\User */
use OldTimeGuitarGuy\Plaid\Contracts\User;
class MyUserClass implements User
{
    protected $accessToken;

    public function __construct($accessToken)
    {
        $this->accessToken = $accessToken;
    }

    public function accessToken()
    {
        return $this->accessToken;
    }
}

$user = new MyUserClass($accessToken);

/* Now you can submit to all of the other endpoints with this user */
$plaid->connect()->get($user);
$plaid->balance()->get($user);
$plaid->info()->get($user);

/* ... etc */

Awesome, thanks so much for the example I'll dig through it today. I'm sure it's enough of a nudge to help me put everything together. I really appreciate your willingness to help a newbie out. I'm pretty comfortable with Laravel but certainly not an expert. Perhaps when I get this working I can help you with the docs. It's the least I can do.

Thanks again for putting this together.
Lance

Quick Update
This really helped me out. I've gotten everything hooked up and am working my way through understanding the various Plaid services. This has been a great help to me. Thanks so much for taking the time to help!