diff --git a/composer.json b/composer.json index 28c83a0..e99a56b 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "ursuleacv/oauth2-lightspeed", "description": "LightSpeed OAuth 2.0 Client Provider for The PHP League OAuth2-Client", "license": "MIT", - "version": "2.0.24", + "version": "2.0.25", "authors": [ { "name": "Valentin Ursuleac", diff --git a/src/Provider/MerchantOS.php b/src/Provider/MerchantOS.php index 350a976..505f8e1 100644 --- a/src/Provider/MerchantOS.php +++ b/src/Provider/MerchantOS.php @@ -573,6 +573,68 @@ public function createCustomField($data) return []; } + /** + * @param integer $customFieldId + * @param array $params + * @return mixed + */ + public function getAllCustomFieldChoices($customFieldId, $params = []) + { + $response = $this->makeAPICall('Account.Customer/CustomField/' + . $customFieldId . '/CustomFieldChoice', 'GET', null, $params, null); + + //validate the response + if (isset($response['CustomFieldChoice']) && $this->itemsCount($response) == 1) { + return [$response['CustomFieldChoice']]; + } elseif (isset($response['CustomFieldChoice']) && $this->itemsCount($response) > 1) { + return $response['CustomFieldChoice']; + } + + return []; + } + + /** + * @param integer $customFieldId + * @param integer $customFieldChoiceID + * @param array $params + * @return mixed + */ + public function getCustomFieldChoice($customFieldId, $customFieldChoiceID, $params = []) + { + $response = $this->makeAPICall('Account.Customer/CustomField/' + . $customFieldId . '/CustomFieldChoice', 'GET', $customFieldChoiceID, $params, null); + + //validate the response + if (isset($response['CustomFieldChoice']) && $this->itemsCount($response) == 1) { + return $response['CustomFieldChoice']; + } elseif (isset($response['CustomFieldChoice']) && $this->itemsCount($response) > 1) { + return $response['CustomFieldChoice']; + } + + return []; + } + + /** + * @param integer $customFieldId + * @param array $data + * @return mixed + */ + public function createCustomFieldChoice($customFieldId, $data) + { + $params = []; + $response = $this->makeAPICall('Account.Customer/CustomField/' + . $customFieldId . '/CustomFieldChoice', 'POST', null, $params, $data); + + //validate the response + if (isset($response['CustomFieldChoice']) && $this->itemsCount($response) == 1) { + return $response['CustomFieldChoice']; + } elseif (isset($response['CustomFieldChoice']) && $this->itemsCount($response) > 1) { + return $response['CustomFieldChoice']; + } + + return []; + } + /** * @param array $data * @return mixed @@ -886,7 +948,7 @@ public function makeAPICall($controlUrl, $action, $uniqueId, $params, $data) $response = $client->request($action, $url, [ 'headers' => $headers, 'json' => $data, - 'connect_timeout' => $this->connectTimeout + 'connect_timeout' => $this->connectTimeout, ]); } else { $response = $client->request($action, $url, ['headers' => $headers, 'json' => $data]);