paylike / php-api

A PHP client for accessing the API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bad (invalid) request - see $e->getJsonBody() for the error

meyn11 opened this issue · comments

Hi,

When i try to create new transaction, it return this error (i have a test merchant):

Bad (invalid) request - see $e->getJsonBody() for the error

When i try to check the $e->getJsonBody(), it's empty. this is my code:

$merchant_id      = '****my-merchant-id****';
$public_api_key   = '*****my-public-key*****';

  $paylike = new \Paylike\Paylike($private_api_key);
  try {
      $transactions = $paylike->transactions();
      $transactions->create($merchant_id, array(
    	   'transactionId' => 'ACH0001',
           'currency' => 'EUR',
    	   'amount' => "1700"
      ));

  } catch (\Paylike\Exception\NotFound $e) {
      // The transaction was not found
  } catch (\Paylike\Exception\InvalidRequest $e) {
      // Bad (invalid) request - see $e->getJsonBody() for the error
      $body = $e->getJsonBody();
      print_r($body);
  } catch (\Paylike\Exception\Forbidden $e) {
      // You are correctly authenticated but do not have access.
  } catch (\Paylike\Exception\Unauthorized $e) {
      // You need to provide credentials (an app's API key)
  } catch (\Paylike\Exception\Conflict $e) {
      // Everything you submitted was fine at the time of validation, but something changed in the meantime and came into conflict with this (e.g. double-capture).
  } catch (\Paylike\Exception\ApiConnection $e) {
      // Network error on connecting via cURL
  } catch (\Paylike\Exception\ApiException $e) {
      // Unknown api error
  }

Any help plaise ? Thank you

After discussing this trough support the issue was identified.
In this particular case, the 400 error has no additional message, so nothing gets displayed back.
One option is to display the entire object using print_r($e);

As for the cause of the error, the transaction id's must be a prior transaction id. In this case, this transaction id did not exist.