JSON_ERROR_SYNTAX response when using Dwolla\Transactions() send (PHP)

(AAG) #1


I’m trying to do a send transaction in the dev environment. Everything was OK until some days ago I started getting a ParseException. I think it’s the response from Dwolla but I’m not certain.

Code is:
$Transactions = new Dwolla\Transactions();
$result = $Transactions->send("$send_to_email", $amount, [
‘destinationType’ => ‘Email’, ‘pin’ => “$dwolla_user_pin”,
‘oauth_token’ => “$access_token”,
‘fundsSource’ => “$funding_source” ]);

Error is:

Fatal error: Uncaught exception ‘GuzzleHttp\Exception\ParseException’ with message ‘Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, malformed JSON’ in /home/YYY/public_html/lib/guzzlehttp/guzzle/src/Message/Response.php:148 Stack trace: #0 /home/YYY/public_html/lib/client.php(182): GuzzleHttp\Message\Response->json() #1 /home/YYY/public_html/lib/transactions.php(49): Dwolla\RestClient->_post(’/transactions/s…’, Array) #2 /home/YYY/public_html/lib/util.php(294): Dwolla\Transactions->send(‘XXXX@yahoo.c…’, ‘$200’, Array) #3 /home/YYY/public_html/user_make_payment_script.php(61): dwollaSendPayment(‘3’, ‘1111’, ‘HKI8LBbt8gvhH3O…’, ‘26345393be07f62…’, ‘XXXX@yahoo.c…’, ‘$200’) #4 {main} thrown in /home/YYY/public_html/lib/guzzlehttp/guzzle/src/Message/Response.php on line 148

(Spencer Hunter) #2

@asterix_le_gaul, Are you using Composer to install Guzzle? What version of dwolla-php are you using? Additionally, It looks like the latest release of dwolla-php has a fixes the response to be psr7 compliant…this may or may not be related.

(AAG) #3

Yes, I used Composer. I’ve updated to the latest dwolla-php but I still this problem :frowning:

(AAG) #4

I’ve found the problem. I was sending the “amount” field with a “$” so, for example, instead of sending “300” I would send “$300”. What’s strange is that I understood it to be a response exception as if my end was generating an exception from a Dwolla response.

(Spencer Hunter) #5

Ah, glad you were able to figure it out. The exception was likely thrown because the client was expecting a JSON response when you likely were getting a 500 XML response. In special cases for API v1, where there is an uncaught exception on our system, or when the API request is malformed (JSON syntax error, duplicated keys) Dwolla will return an HTTP 500 with an XML response body. Mentioned briefly here: https://docs.dwolla.com/#errors