Web Payment API/PHP SDK HTTP Header Text

Hi all, This is probably a daft question but here goes. I’m working with the Web Payments SDK and the PHP SDK. When a card payment is submitted it calls a PHP script and while I have got my system setting the HTTP Status Code I can’t for the life of me work out how to get the response attributes of “text” or “json” configured.

Can any PHP developers out there point me in the right direction? I’ve got the system setting the header to indicate the response is JSON and outputting the json encoded errors but still when I inspect the return values there’s nothing there.

Any help would be appreciated.
Thanks

:wave: In our examples we echo the results or the error. For example:

try {
  $create_payment_request = new CreatePaymentRequest($token, Uuid::uuid4(), $money);

  $response = $payments_api->createPayment($create_payment_request);

  if ($response->isSuccess()) {
    echo json_encode($response->getResult());
  } else {
    echo json_encode(array('errors' => $response->getErrors()));
  }
} catch (ApiException $e) {
  echo json_encode(array('errors' => $e));
}

Also feel free to checkout our PHP example with the Web Payments SDK.

Hi Bryan, Thanks for the reply. Unfortunately that doesn’t work. It’s exactly what I tried funnily enough but on the calling end there is never any content in the paymentResponse.json or paymentResponse.text objects. I’m glad at least you’ve confirmed I have some idea what I’m doing!!! Started to question it.

Not sure what else I can even provide to help debug. It just doesn’t work the way it should. The odd part is that it’s nothing to do with Square really, it’s the HTTP protocol and the HTTP response object that don’t appear to be cooperating.