This removes api authentication with token in favor of signature method. Refactored code and clean up. It add more unit test plus code coverage in test/coverage. - Added : mardown documentation. - Changed : model Stats::getQuestionStats to pass question as route parameter - Changed : now requests need to have a signature generated with a private key (crm password) using hmac sha256 wrapping url, method and parameters - Changed : now timestamp will timeout if request is slower than "timestampTimeout", this means crm will reject the request - Changed : throw ValidationException s instead of TypeErrors - Changed : timestamp has to be send in request with a DateTime format, it also has to a UTC value - Fixed : Change WPCRM dynamic session key, this could prevent spoofing session in some cases. - Fixed : closure validation - Fixed : model mutator not catching reflectionException - Fixed : really send json request using Guzzle internal lib methods. - Removed : Api AUTH system with api token - Removed : ApiError::needAuth - Removed : composer vlucas/dotenv, .env file is not handled any more. - Removed : LoginException - Removed : memcached dependency - Removed : need of memcached - Removed : unused service provider - Removed : WpCrm::forceLogin - Removed : WpCrm::sendArcadiaMailDefault - Removed : WpCrm::sendArcadiaMailGame - Updated : PHPCS rules, phpcs fixes and refactored code
55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
use LDC\LDCCRM\CrmApiV2;
|
|
use LDC\LDCCRM\Enums\ApiError;
|
|
use LDC\LDCCRM\Enums\Country;
|
|
use LDC\LDCCRM\Exceptions\ApiErrorException;
|
|
use LDC\LDCCRM\Models\Customer;
|
|
|
|
$api = new CrmApiV2();
|
|
$customer = $api->getCustomerOrNew('123e4567-e89b-12d3-a456-426614174000');
|
|
|
|
echo $customer->firstname;
|
|
|
|
$customer->firstname = 'new firstname';
|
|
|
|
try {
|
|
if ($customer->save()) {
|
|
echo 'Customer was updated';
|
|
}
|
|
} catch (ApiErrorException $e) {
|
|
if ($e->getApiError()->equals(ApiError::modelNotFound())) {
|
|
echo 'This customer does not exists in crm therefore we cannot update it';
|
|
echo $e->getMessage();
|
|
}
|
|
if ($e->getApiError()->equals(ApiError::validationFailed())) {
|
|
echo 'Some of the provided fields were not ok';
|
|
echo $e->getMessage();
|
|
}
|
|
}
|
|
|
|
$customer = new Customer();
|
|
|
|
$customer->firstname = 'toto';
|
|
$customer->lastname = 'delarogerie';
|
|
$customer->email = 'toto.delarogerie@gmail.com';
|
|
$customer->password = 'Complic4tEd!P4assW0rd';
|
|
$customer->birth_date = '1992-03-08';
|
|
$customer->phone = '0673891160';
|
|
$customer->address = 'rue des totos';
|
|
$customer->city = 'Toto ville';
|
|
$customer->postcode = '72160';
|
|
$customer->country = Country::france();
|
|
|
|
try {
|
|
if ($customer->save()) {
|
|
echo 'Customer is saved in crm';
|
|
} else {
|
|
echo 'Customer was not saved in crm';
|
|
}
|
|
} catch (ApiErrorException $e) {
|
|
echo 'Something went wrong';
|
|
echo $e->getMessage();
|
|
// phpcs:ignore Squiz.PHP.DiscouragedFunctions.Found
|
|
print_r($e->getApiError());
|
|
}
|