DwollaSwagger for PHP and Plaid

I’m not able to add a funding source using dwollaswagger for php and Plaid. I first obtain the plaid token and then use the following code to create a new funding source. It’s not failing but I am getting the message “The request body contains bad syntax or is incomplete”.

$url = $this->_root_endpoint . "/customers/" . $params['dwollaCustomerId'];
DwollaSwagger\Configuration::$access_token = $this->_access_token;
$f = new DwollaSwagger\FundingsourcesApi($this->_api_client);
	
try{		
	$fundingSource = $f->createCustomerFundingSource([
		"publicToken" => $params['plaidToken'],
		"name" => $params['name']
	], $url);
} catch (Exception $e) {
	return 'ERROR: ' . $e->getResponseBody() . "<br>\n";
}
1 Like

Hi Pat – try replacing "publicToken" with "plaidToken" in the following line of code,

You can also look up the raw request body for reference in our guide.
Let me know if that worked!

Hi Shreya, Thanks for the tips. I changed the the parameter name from publicToken to plaidToken but no luck. I am getting a different error though. Now it’s telling me that the Plaid Token is invalid.

code":“Invalid”,“message”:“Token is invalid.”,“path”:"/plaidToken","_links"

I don’t know what to do with the Raw requests. Am I supposed to use cURL or similar to implement it?

Hey Pat, it sounds like the token being passed is invalid. If this is in Sandbox, I would check that the Processor token is being generated in Plaid’s Sandbox environment. Same for Production, I would check that the token from Plaid is being generated in their Production environment.

What you’re currently doing is fine for creating a funding-source using the PHP code. I posted the raw request just to reference what the parameter names and the request body should look like.

I did switch my code to use cUrl and it’s working a lot better. Unfortunately, I’m still getting the same message regarding invalid token. I’ve gone through the process of exchanging the plaidToken for an access token as outlined on this page https://plaid.com/docs/dwolla/ in " Step 4: Write server-side handler". An example of what I’m then sending to dwolla in order to add a funding source is:

$data = array( “plaidToken” => ‘processor-sandbox-414140e7-522c-4474-b619-58e8ffa1c0bd0’,
“name” => ‘Plaid Savings’);

I’m sending the call to:
https://api-sandbox.dwolla.com/[dwollaCustomerId]/funding-sources

What I get back is:
[errors] => Array
(
[0] => stdClass Object
(
[code] => Invalid
[message] => Token is invalid.
[path] => /plaidToken
[_links] => stdClass Object
(
)

                            )

                    )

Hmm that’s definitely weird. Would you be able to post the Customer ID here? I could take a look at our logs to see if we’re receiving anything different.

Also, would you be to confirm that when logging in to the bank account using Plaid Link, you’re using the user_good testing credentials and not user_custom?

I wasn’t aware there was a user_custom login. I’m using the user_good/user_good login/pw for Plaid.

The customer id is 9e9bee44-5ba4-46af-b688-8cb6ccc459ca. So the actual url I’m using is:
https://api-sandbox.dwolla.com/9e9bee44-5ba4-46af-b688-8cb6ccc459ca/funding-sources

Thanks for that ID, Pat! I was able to look into some of these requests that we’ve received that threw the “Invalid Token” error, and it looks like sometimes we’re also receiving random characters and information for the “plaidToken” value. For example, one of the requests was as follows -

{
    "plaidToken": "************************\nstdClass Object\n(\n [access_token] => access-sandbox-15ce98e4-6629-4fdc-ab95-baf5860c4bd9\n [item_id] => mRo76bdwNQH6xAz5bqlMuWba8jolEVfgLJPle\n [request_id] => HTzFV7s9UEntcpZ\n)\n************************\nprocessor-sandbox-6812e959-95fd-4ec2-b12e-d4bbd183b5f70",
    "name":"Plaid Saving"
}

I’d just check again that just the Processor token is being sent in that parameter. Other than that, we haven’t heard of any other reports on the Plaid token integration, but I’ll keep my eyes out and let you know!

Right. That was some debug that got into the request by mistake. I’ve sent it without that since then with no luck.

Hi @Pat, we call off to Plaid’s API behind the scenes when a processor token is sent to us. Here is the message we’re getting back from their API: provided processor token is in an invalid format. expected format: processor-<environment>-<identifier>. Have you validated that the identifier and format is accurate before submitting the request? Definitely seems strange nonetheless. We have several consumers calling this endpoint without issue in sandbox or production.

An example of the token I’m sending is exactly as you describe.

RESOLVED: To anyone else reading this thread with a similar issue here’s what I learned.

I’m writing a custom plugin for Wordpress to use Plaid with Dwolla. To exchange the public token returned by Plaid with a processor token required for further communication with Dwolla I used an AJAX call. In WordPress you have to end any called function using AJAX with an exit -1 or better, wp_die() function call to insure that a 1 or 0 won’t be appended to the result. I had left out the wp_die() and was getting a trailing zero (0) on my processor token. That caused to be rejected on subsequent use. Hope that helps someone.

1 Like