Использование Square Connect PHP SDK, фатальная ошибка UpsertCatalogObject
Я использую квадратное соединение php SDK, и я получаю следующую ошибку, и не смог найти никакого решения. Я пытаюсь выдвинуть несколько новых категорий, которые были добавлены в мое приложение (в базе данных mysql).
Сборка catelogObject
foreach ($push_array as $key => $cat_name) {
$category = $this->products_lib->get_category($cat_name);
$idempotency_key = uniqid('',true);
$push_obj = new stdClass();
$push_obj->type = 'CATEGORY';
$push_obj->id = '#' . trim($category->name);
$push_obj->category_data = ['name'=>trim($category->name)];
$push_obj->present_at_all_locations = true;
$catelogObject = ["idempotency_key" => $idempotency_key, 'object' => $push_obj];
print_r($catelogObject);
$response = $square_connect->upsert_category($catelogObject);
}
Производит
(
[idempotency_key] => 5996186208eae4.27853833
[object] => stdClass Object
(
[type] => CATEGORY
[id] => #Drinks
[category_data] => Array
(
[name] => Drinks
)
[present_at_all_locations] => 1
)
)
класс square_connect
class SquareConnect {
private $access_token = "***********************";
private $sandbox_access_token = "sandbox-*********************";
public function get_locations() {
SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken($this->access_token);
$locations_api = new \SquareConnect\Api\LocationsApi();
echo $locations_api->listLocations();
}
public function get_categories() {
SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken($this->access_token);
$api = new \SquareConnect\Api\CatalogApi();
$retobj = json_decode($api->listCatalog(null, 'CATEGORY'));
// $categories = $retobj->objects;
return $retobj->objects;
}
public function upsert_category($category_object) {
SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken($this->access_token);
$api = new \SquareConnect\Api\CatalogApi();
// return $apiResponse = json_decode($api->UpsertCatalogObject($category_object));
print_r(json_decode($api->UpsertCatalogObject($category_object))) ;
}
public function get_items() {
SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken($this->access_token);
$api = new \SquareConnect\Api\CatalogApi();
echo $api->listCatalog(null, 'ITEM');
}
}
Когда я запускаю код, я получаю следующую ошибку:
Неустранимая ошибка: доступ к необъявленному статическому свойству: stdClass::$swaggerTypes в /vendor/square/connect/lib/ObjectSerializer.php в строке 43
Надеюсь, что это достаточно ясно, и заранее спасибо за помощь
редактировать
[DEBUG] HTTP Request body ~BEGIN~
~END~
[DEBUG] HTTP Response body ~BEGIN~
{"objects":[{"type":"CATEGORY","id":"52IJHDSD67VAQNJ3GQB5TVRX","updated_at":"2017-08-16T19:50:58.373Z","version":1502913058373,"is_deleted":false,"custom_attributes":[{"name":"straight_fire_type","int_value":0}],"present_at_all_locations":true,"category_data":{"name":"Candy"}},{"type":"CATEGORY","id":"KFB7DDQYPG532F66SYAYAD4W","updated_at":"2017-06-13T19:45:27.653Z","version":1497383127653,"is_deleted":false,"present_at_all_locations":true,"category_data":{"name":"Sandwiches"}},{"type":"CATEGORY","id":"SJVUDRCAMQBSRM7FAEBQATBS","updated_at":"2017-06-13T19:45:35.181Z","version":1497383135181,"is_deleted":false,"present_at_all_locations":true,"category_data":{"name":"Specials"}}]}
~END~
* Hostname was NOT found in DNS cache
* Trying 74.122.190.85...
* Connected to connect.squareup.com (74.122.190.85) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
* subject: C=US; ST=California; L=San Francisco; O=Square, Inc.; CN=*.squareup.com
* start date: 2016-12-07 00:44:04 GMT
* expire date: 2017-12-16 01:14:02 GMT
* subjectAltName: connect.squareup.com matched
* issuer: C=US; O=Entrust, Inc.; OU=See www.entrust.net/legal-terms; OU=(c) 2012 Entrust, Inc. - for authorized use only; CN=Entrust Certification Authority - L1K
* SSL certificate verify ok.
> GET /v2/catalog/list?types=CATEGORY HTTP/1.1
User-Agent: Square-Connect-PHP/2.2.1
Host: connect.squareup.com
Accept: application/json
Content-Type: application/json
Authorization: Bearer sq0atp-WrF2m45lEzQVzCqAxSA_oA
< HTTP/1.1 200 OK
< Content-Type: application/json
< Vary: Origin, Accept-Encoding
< X-Content-Type-Options: nosniff
< X-Download-Options: noopen
< X-Frame-Options: SAMEORIGIN
< X-Permitted-Cross-Domain-Policies: none
< X-Xss-Protection: 1; mode=block
< Date: Fri, 18 Aug 2017 02:29:24 GMT
< Keep-Alive: timeout=60
< Strict-Transport-Security: max-age=631152000
< content-length: 687
<
* Connection #0 to host connect.squareup.com left intact
РЕДАКТИРОВАТЬ - Решение: Необходимо изменить свойство объекта $catelogObject на массив, а не объект, как указано в документации по квадратному соединению API.
foreach ($push_array as $key => $cat_name) {
$category = $this->products_lib->get_category($cat_name);
$idempotency_key = uniqid('',true);
$push_obj = [];
$push_obj['type'] = 'CATEGORY';
$push_obj['id'] = '#' . trim($category->name);
$push_obj['category_data'] = ['name'=>trim($category->name)];
$push_obj['present_at_all_locations'] = true;
$catelogObject = ["idempotency_key" => $idempotency_key, 'object' => $push_obj];
print_r($catelogObject);
$response = $square_connect->upsert_category($catelogObject);
}