getPaymentsApi() not working

Hi! I am trying to use the Square PHP SDK on my website, and there is an issue I’m finding very difficult to solve. In my PHP page, the getPaymentsApi() does not seem to work(I receive a 500 error). I commented out various parts of the code, and that was the only part that seemed problematic. Here’s my full code:

//$paymentsApi = $client->getPaymentsApi();
$amount_money = new \Square\Models\Money();

$app_fee_money = new \Square\Models\Money();

$billing_address = new \Square\Models\Address();

$shipping_address = new \Square\Models\Address();

$body = new \Square\Models\CreatePaymentRequest(
$body->setReferenceId(‘234567890dfgvb fghj’);
$body->setBuyerEmailAddress(‘[email protected]’);

$api_response = $paymentsApi->createPayment($body); // THIS LINE HERE is the one that is problematic.

// if ($api_response->isSuccess()) {
// $result = $api_response->getResult();
// } else {
// $errors = $api_response->getErrors();
// }

Thanks in advance!

Apologies for the delay here. You’re saying you receive a 500 error from Square? Can you provide your Square application id? I also do not see you setting your access token anywhere in the above code, so have you already done that elsewhere?


The 500 error is on my website, caused by the getPaymentsApi() function not working. The access token is included in the JavaScript SDK in the front end.

The application ID is sandbox-sq0idb-mhw-MKpT3J0YSK9dwL0pSA.


I’m not seeing any 500 errors from us. I do see one error:

response=errors { code: MISSING_REQUIRED_PARAMETER detail: "Field must be set" field: "amount_money" category: INVALID_REQUEST_ERROR }

from the CreatePayment request, but it does look like you’ve successfully added the money in the above code, so I’m assuming you got past this error. I’m also not sure what you mean by you set the access token in the frontend; it should never be set in the frontend, as that means anyone would be able to view your secret access token.

Since this came from CreatePayment, that means you got past the getPaymentsApi() function.