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:
`<?php
require(‘autoload.php’);
//$paymentsApi = $client->getPaymentsApi();
$amount_money = new \Square\Models\Money();
$amount_money->setAmount(35);
$amount_money->setCurrency(‘USD’);
$app_fee_money = new \Square\Models\Money();
$app_fee_money->setAmount(9);
$app_fee_money->setCurrency(‘USD’);
$billing_address = new \Square\Models\Address();
$billing_address->setAddressLine1(‘Address’);
$billing_address->setLocality(‘City’);
$billing_address->setAdministrativeDistrictLevel1(‘State’);
$billing_address->setPostalCode(‘12345’);
$billing_address->setCountry(‘US’);
$billing_address->setFirstName(‘John’);
$billing_address->setLastName(‘Doe’);
$shipping_address = new \Square\Models\Address();
$shipping_address->setAddressLine1(‘Address’);
$shipping_address->setLocality(‘City’);
$shipping_address->setAdministrativeDistrictLevel1(‘State’);
$shipping_address->setPostalCode(‘12345’);
$shipping_address->setCountry(‘US’);
$shipping_address->setFirstName(‘John’);
$shipping_address->setLastName(‘Doe’);
$body = new \Square\Models\CreatePaymentRequest(
‘cnon:card-nonce-ok’,
‘idempotency_key_washerebutIputthisjustincaseIshouldntshareit’,
$amount_money
);
$body->setAppFeeMoney($app_fee_money);
$body->setAutocomplete(true);
$body->setLocationId(‘MYLOCATIONHERE’);
$body->setReferenceId(‘234567890dfgvb fghj’);
$body->setBuyerEmailAddress(‘[email protected]’);
$body->setBillingAddress($billing_address);
$body->setShippingAddress($shipping_address);
$body->setStatementDescriptionIdentifier(‘Testing’);
$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!