diff --git a/.env.example b/.env.example index 0ad3568..45ddda4 100644 --- a/.env.example +++ b/.env.example @@ -27,4 +27,3 @@ MAIL_PASSWORD=null MAIL_ENCRYPTION=null CRM_ENDPOINT= -CRM_API_TOKEN= diff --git a/app/Http/Controllers/Api/v1/CouponsController.php b/app/Http/Controllers/Api/v1/CouponsController.php index 8b4fd6a..7a1407e 100644 --- a/app/Http/Controllers/Api/v1/CouponsController.php +++ b/app/Http/Controllers/Api/v1/CouponsController.php @@ -14,7 +14,7 @@ use App\Traits\CouponTrait; use App\Traits\GenerateBR; use PDF; -use App\Lib\LDCCRM\ApiV1; +use LDC\LDCCRM\CrmApiV2; class CouponsController extends Controller { @@ -25,22 +25,35 @@ class CouponsController extends Controller { $datas = $request->validated(); $campagne = Campagne::find($datas['refcamp']); - $customer = Customers::find($datas['crm_id']); + $customer = Customers::find($datas['hashcode']); $couponsToPrint = explode(",", $datas['coupons']); if ($campagne->site->crm_token === null) { return new StatusResource(['status' => 'KO', 'code' => 500, 'message' => 'CRM Token is missing for site_id : '. $campagne->site->site_id]); } + if ($campagne->site->crm_password === null) { + return new StatusResource(['status' => 'KO', 'code' => 500, 'message' => 'CRM Password is missing for site_id : '. $campagne->site->site_id]); + } + if (empty($couponsToPrint)) { return new StatusResource(['status' => 'KO', 'code' => 422, 'message' => 'Coupons not found.']); } - $crm = new ApiV1(config('crm.CRM_ENDPOINT'), $campagne->site->crm_token); - $crmInfos = $crm->getCustomer($customer->crm_id); - if ($crmInfos->status === "OK") { - $crmInfos = $crmInfos->user; - } else { + $crm = new CrmApiV2(config('crm.CRM_ENDPOINT'), $campagne->site->crm_token, $campagne->site->crm_password); + + try { + /** + * @var \LDC\LDCCRM\Models\Customer + */ + $crmInfos = $crm->getCustomer($customer->hashcode); + + }catch (\Exception $e) { + // TODO : Update error message + return new StatusResource(['status' => 'KO', 'code' => 422, 'message' => 'Customer not found.']); + } + + if (is_null($crmInfos)) { return new StatusResource(['status' => 'KO', 'code' => 422, 'message' => 'Customer not found.']); } diff --git a/app/Http/Controllers/Api/v1/CustomerController.php b/app/Http/Controllers/Api/v1/CustomerController.php index 141ea55..97a6df2 100644 --- a/app/Http/Controllers/Api/v1/CustomerController.php +++ b/app/Http/Controllers/Api/v1/CustomerController.php @@ -2,16 +2,23 @@ namespace App\Http\Controllers\Api\v1; +use App\Calendrier; +use App\Campagne; use App\Http\Requests\Customers\StoreRequest; -use App\Http\Requests\Customers\UpdateRequest; use App\Http\Resources\CustomersResource; use App\Http\Resources\StatusResource; use App\Models\Customers; use App\Http\Controllers\Controller; +use App\Http\Requests\Customers\MurRequest; +use App\Http\Resources\CouponsResource; +use App\Traits\CouponTrait; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Request; class CustomerController extends Controller { + use CouponTrait; + /** * Display a listing of the resource. * @@ -43,7 +50,7 @@ class CustomerController extends Controller $datas = $request->validated(); try { $customer = Customers::where([ - ['crm_id', $datas['crm_id']], + ['hashcode', $datas['hashcode']], ['email', $datas['email']] ])->firstOrNew(); $customer->fill($datas); @@ -99,4 +106,56 @@ class CustomerController extends Controller { return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']); } + + public function mur(MurRequest $request) + { + $datas = $request->validated(); + + $customer = Customers::where('hashcode', $datas['hashcode'])->first(); + $campagne = Campagne::find($datas['refcamp']); + if ($campagne->camp_published === 0) { + return new StatusResource(['status' => 'KO', 'code' => 404, 'message' => 'Campaign not found.']); + } + + $coupons = $campagne->coupons()->whereRaw("coupon_published = 1 AND (coupon_mindatediffusion IS NULL OR coupon_mindatediffusion <= NOW()) AND (coupon_maxdatediffusion IS NULL OR coupon_maxdatediffusion >= NOW()) AND (coupon_maxdatevalidity IS NULL OR coupon_maxdatevalidity >= NOW())")->get(); + + $montantDispo = 0; + $montantTotal = 0; + + // TODO : Improve + foreach ($coupons as $key => $coupon) { + // ---- Contrôle des calendriers de diffusion + $calendars = Calendrier::where(['calendrier_couponId' => $coupon->coupon_id])->get(); + if (!$calendars->isEmpty()) { + $pub = false; + foreach ($calendars as $calendar) { + if (strtotime(date('Y-m-d H:i:s')) > strtotime($calendar->calendrier_startdate) && strtotime(date('Y-m-d H:i:s')) < strtotime($calendar->calendrier_enddate)) { + $pub = true; + } + } + if (!$pub) { + $coupons->forget($key); + continue; + } + } + + // Available for user + $coupon->isUsed = $this->isUsed($coupon, $campagne, $customer); + + $montantTotal += $coupon->coupon_value; + if (!$coupon->isUsed) { + $montantDispo += $coupon->coupon_value; + } + } + + return new StatusResource([ + 'status' => "OK", + 'name' => $campagne->camp_name, + 'limited_printing' => $campagne->camp_limitedPrinting, + 'total' => count($coupons), + 'available_amount' => $montantDispo, + 'total_amount' => $montantTotal, + 'coupons' => CouponsResource::collection($coupons) + ]); + } } diff --git a/app/Http/Controllers/Api/v1/MurController.php b/app/Http/Controllers/Api/v1/MurController.php index 2827274..b166e1b 100644 --- a/app/Http/Controllers/Api/v1/MurController.php +++ b/app/Http/Controllers/Api/v1/MurController.php @@ -5,25 +5,26 @@ namespace App\Http\Controllers\Api\v1; use App\Calendrier; use App\Campagne; use App\Http\Controllers\Controller; -use App\Http\Requests\Murs\IndexRequest; +use App\Http\Requests\Murs\MursShowRequest; use App\Http\Resources\CouponsResource; use App\Http\Resources\StatusResource; -use App\Models\Customers; use App\Traits\CouponTrait; class MurController extends Controller { use CouponTrait; - public function index(IndexRequest $request) + public function show(MursShowRequest $request) { $datas = $request->validated(); - $customer = Customers::where('crm_id', $datas['crm_id'])->first(); $campagne = Campagne::find($datas['refcamp']); if ($campagne->camp_published === 0) { return new StatusResource(['status' => 'KO', 'code' => 404, 'message' => 'Campaign not found.']); } + if ($campagne->camp_type !== 0) { + return new StatusResource(['status' => 'KO', 'code' => 403, 'message' => 'Campaign type error.']); + } $coupons = $campagne->coupons()->whereRaw("coupon_published = 1 AND (coupon_mindatediffusion IS NULL OR coupon_mindatediffusion <= NOW()) AND (coupon_maxdatediffusion IS NULL OR coupon_maxdatediffusion >= NOW()) AND (coupon_maxdatevalidity IS NULL OR coupon_maxdatevalidity >= NOW())")->get(); @@ -47,9 +48,6 @@ class MurController extends Controller } } - // Available for user - $coupon->isUsed = $this->isUsed($coupon, $campagne, $customer); - $montantTotal += $coupon->coupon_value; if (!$coupon->isUsed) { $montantDispo += $coupon->coupon_value; @@ -58,6 +56,8 @@ class MurController extends Controller return new StatusResource([ 'status' => "OK", + 'name' => $campagne->camp_name, + 'limited_printing' => $campagne->camp_limitedPrinting, 'total' => count($coupons), 'available_amount' => $montantDispo, 'total_amount' => $montantTotal, diff --git a/app/Http/Requests/Coupons/PrintRequest.php b/app/Http/Requests/Coupons/PrintRequest.php index aa65995..cf071e3 100644 --- a/app/Http/Requests/Coupons/PrintRequest.php +++ b/app/Http/Requests/Coupons/PrintRequest.php @@ -28,8 +28,8 @@ class PrintRequest extends FormRequest { // TODO : Validate coupons formats return [ - 'refcamp' => 'exists:campagne,camp_id|required', - 'crm_id' => 'exists:customers,crm_id|required', + 'refcamp' => 'string|exists:campagne,camp_id|required', + 'hashcode' => 'string|exists:customers,hashcode|required', 'coupons' => 'required' ]; } diff --git a/app/Http/Requests/Customers/UpdateRequest.php b/app/Http/Requests/Customers/MurRequest.php similarity index 80% rename from app/Http/Requests/Customers/UpdateRequest.php rename to app/Http/Requests/Customers/MurRequest.php index d99bc0a..5abcea7 100644 --- a/app/Http/Requests/Customers/UpdateRequest.php +++ b/app/Http/Requests/Customers/MurRequest.php @@ -7,7 +7,7 @@ use Illuminate\Contracts\Validation\Validator; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Http\Exceptions\HttpResponseException; -class UpdateRequest extends FormRequest +class MurRequest extends FormRequest { /** * Determine if the user is authorized to make this request. @@ -26,10 +26,9 @@ class UpdateRequest extends FormRequest */ public function rules() { - $customer = $this->route('customer'); return [ - 'email' => "email|unique:customers,email," . $customer->crm_id . ",crm_id|required", - 'country' => 'string|required' + 'refcamp' => 'string|exists:campagne,camp_id|required', + 'hashcode' => 'string|exists:customers,hashcode|required' ]; } diff --git a/app/Http/Requests/Customers/StoreRequest.php b/app/Http/Requests/Customers/StoreRequest.php index 4e8da11..88163d5 100644 --- a/app/Http/Requests/Customers/StoreRequest.php +++ b/app/Http/Requests/Customers/StoreRequest.php @@ -27,7 +27,7 @@ class StoreRequest extends FormRequest public function rules() { return [ - 'crm_id' => 'numeric|required', + 'hashcode' => 'string|required', 'email' => 'email|required', 'country' => 'string|required' ]; diff --git a/app/Http/Requests/Murs/IndexRequest.php b/app/Http/Requests/Murs/MursShowRequest.php similarity index 85% rename from app/Http/Requests/Murs/IndexRequest.php rename to app/Http/Requests/Murs/MursShowRequest.php index 8f7b447..957ab01 100644 --- a/app/Http/Requests/Murs/IndexRequest.php +++ b/app/Http/Requests/Murs/MursShowRequest.php @@ -7,7 +7,7 @@ use Illuminate\Contracts\Validation\Validator; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Http\Exceptions\HttpResponseException; -class IndexRequest extends FormRequest +class MursShowRequest extends FormRequest { /** * Determine if the user is authorized to make this request. @@ -27,8 +27,7 @@ class IndexRequest extends FormRequest public function rules() { return [ - 'refcamp' => 'exists:campagne,camp_id|required', - 'crm_id' => 'exists:customers,crm_id|required' + 'refcamp' => 'exists:campagne,camp_id|required' ]; } diff --git a/app/Lib/LDCCRM/ApiV1.php b/app/Lib/LDCCRM/ApiV1.php deleted file mode 100644 index 2dc28d8..0000000 --- a/app/Lib/LDCCRM/ApiV1.php +++ /dev/null @@ -1,225 +0,0 @@ -endpoint = $endpoint; - $this->api_key = $api_key; - } - - public function getCustomer($id) - { - return $this->callApi('GET', "/customer/id/$id"); - } - - public function getCustomerByEmail($email) - { - return $this->callApi('GET', "/customer/email/$email"); - } - - public function createCustomer( - $email, - $password, - $firstname, - $lastname, - $optin, - $birthdate = null, - $phone = null, - $address = null, - $address2 = null, - $city = null, - $postcode = null, - $country = null - ) { - $user = [ - 'email' => $email, - 'password' => $password, - 'firstname' => $firstname, - 'lastname' => $lastname, - 'opt_in' => $optin, - 'birth_date' => $birthdate, - 'phone' => $phone, - 'address' => $address, - 'address2' => $address2, - 'city' => $city, - 'postcode' => $postcode, - 'country' => $country - ]; - return $this->callApi('POST', '/customer/create', $user); - } - - public function updateCustomer( - $crmId, - $firstname = null, - $lastname = null, - $optin = null, - $birthdate = null, - $phone = null, - $address = null, - $address2 = null, - $city = null, - $postcode = null, - $country = null - ) { - $user = []; - - if ($firstname !== null) { - $user['firstname'] = $firstname; - } - - if ($lastname !== null) { - $user['lastname'] = $lastname; - } - - if ($optin !== null) { - $user['opt_in'] = $optin; - } - - if ($birthdate !== null) { - $user['birth_date'] = $birthdate; - } - - if ($phone !== null) { - $user['phone'] = $phone; - } - - if ($address !== null) { - $user['address'] = $address; - } - - if ($address2 !== null) { - $user['address2'] = $address2; - } - - if ($city !== null) { - $user['city'] = $city; - } - - if ($postcode !== null) { - $user['postcode'] = $postcode; - } - - if ($country !== null) { - $user['country'] = $country; - } - - return $this->callApi('PUT', "/customer/$crmId", $user); - } - - public function deleteCustomer($id) - { - return $this->callApi('DELETE', "/customer/$id"); - } - - public function changePwdCustomer($id, $password) - { - return $this->callApi('POST', "/customer/$id/change-password", ['password' => $password]); - } - - public function activateCustomer($id) - { - return $this->callApi('POST', "/customer/$id/activate"); - } - - public function toggleOptInCustomer($id) - { - return $this->callApi('POST', "/customer/$id/toggle-optin"); - } - - public function loginCustomer($email, $password) - { - return $this->callApi('POST', "/customer/login", ['email' => $email, 'password' => $password]); - } - - public function createSingleOptin($email) - { - return $this->callApi('POST', '/single-optin', ['email' => $email]); - } - - public function arcadiaOutgoingMail($crm_id, $fields, $type) - { - return $this->callApi( - 'POST', - '/arcadia/outgoing-mail', - ['crm_id' => $crm_id, 'fields' => json_encode($fields), 'type' => $type] - ); - } - - private function callApi($method, $url, $data = false) - { - - if (strpos($this->endpoint, "dev")) { - if ($data !== false) { - $data = array_merge($data, ['api_token' => $this->api_key]); - } else { - $data = ['api_token' => $this->api_key]; - } - } - - $url = $this->endpoint . '/api/v1' . $url; - $curl = curl_init(); - switch ($method) { - case "POST": - curl_setopt($curl, CURLOPT_POST, 1); - if ($data) { - curl_setopt($curl, CURLOPT_POSTFIELDS, $data); - } - break; - case "PUT": - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); - if ($data) { - curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); - } - break; - case "DELETE": - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); - if ($data) { - curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); - } - break; - default: - if ($data) { - $url = sprintf("%s?%s", $url, http_build_query($data)); - } - } - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_COOKIESESSION, true); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - if (!strpos($this->endpoint, "dev")) { - curl_setopt($curl, CURLOPT_HTTPHEADER, array( - 'Accept: application/json', - 'Authorization: Bearer ' . $this->api_key - )); - } - - $result = curl_exec($curl); - - if (!curl_errno($curl)) { - $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); - if (!in_array($http_code, [200, 201])) { - return (object)[ - 'status' => 'KO', - 'code' => 500, - 'message' => 'Connection to API failed - Code HTTP : ' . $http_code - ]; - } - } else { - return (object)[ - 'status' => 'KO', - 'code' => 500, - 'message' => 'Connection to API failed : ' . curl_error($curl) - ]; - } - - curl_close($curl); - return json_decode($result); - } -} diff --git a/app/Models/Customers.php b/app/Models/Customers.php index c081c2b..63dbdc1 100644 --- a/app/Models/Customers.php +++ b/app/Models/Customers.php @@ -7,9 +7,10 @@ use Illuminate\Database\Eloquent\Model; class Customers extends Model { - protected $primaryKey = 'crm_id'; + protected $primaryKey = 'hashcode'; + protected $keyType = 'string'; - protected $fillable = ['crm_id', 'email', 'country']; + protected $fillable = ['hashcode', 'email', 'country']; protected static function booted() { diff --git a/app/Traits/CouponTrait.php b/app/Traits/CouponTrait.php index 64a4bb6..3c8751b 100644 --- a/app/Traits/CouponTrait.php +++ b/app/Traits/CouponTrait.php @@ -341,20 +341,20 @@ trait CouponTrait // VB 22/04/2021 public function isUsed(Coupon $coupon, Campagne $campagne, Customers $customer) { - $available = false; + $isUsed = false; // ---- Contrôle le nombre limite d'impression if ($coupon->coupon_enablelimitquantity === 1) { $count = PrintedWalls::where( [ - ['camp_id', '=', $campagne->id], - ['coupon_id', '=', $coupon->id], + ['camp_id', '=', $campagne->camp_id], + ['coupon_id', '=', $coupon->coupon_id], ['customer_id', '=', $customer->id] ] )->count(); if ($count >= $coupon->coupon_limitquantity) { - $available = true; + $isUsed = true; } } @@ -362,8 +362,8 @@ trait CouponTrait if ($coupon->coupon_enablelimitperiod === 1 && $coupon->coupon_limitperiod > 0) { $count = PrintedWalls::where( [ - ['camp_id', '=', $campagne->id], - ['coupon_id', '=', $coupon->id], + ['camp_id', '=', $campagne->camp_id], + ['coupon_id', '=', $coupon->coupon_id], ['customer_id', '=', $customer->id] ] )->orderBy('created_at', 'DESC')->first(); @@ -371,10 +371,10 @@ trait CouponTrait if ($count && $count->count() > 0) { $date = date('Y-m-d', strtotime($count->created_at . " +" . $coupon->coupon_limitperiod . " days")); if ($date > date('Y-m-d')) { - $available = true; + $isUsed = true; } } } - return $available; + return $isUsed; } } diff --git a/clients/MesBR_V1.php b/clients/MesBR_V1.php index 72a3ad5..9ba8119 100644 --- a/clients/MesBR_V1.php +++ b/clients/MesBR_V1.php @@ -7,32 +7,37 @@ class MesBR private $endpoint; - private $api_key; + private $refCamp; - public function __construct($endpoint, $api_key) + public function __construct($endpoint, $refCamp) { $this->endpoint = $endpoint; - $this->api_key = $api_key; + $this->refCamp = $refCamp; } - public function createCustomer(int $crmId, string $email, string $country) + public function createCustomer(string $hashcode, string $email, string $country) { - return $this->callAPI("POST", '/customer', ['crm_id' => $crmId, 'email' => $email, 'country' => $country]); + return $this->callAPI("POST", '/customer', ['hashcode' => $hashcode, 'email' => $email, 'country' => $country]); } - public function updateCustomer(int $crmId, string $email, string $country) + public function updateCustomer(string $hashcode, string $email, string $country) { - return $this->callAPI("POST", '/customer', ['crm_id' => $crmId, 'email' => $email, 'country' => $country]); + return $this->callAPI("POST", '/customer', ['hashcode' => $hashcode, 'email' => $email, 'country' => $country]); } - public function getMur(int $refCamp, int $crmId) + public function getMurCustomer(string $hashcode) { - return $this->callAPI("POST", '/mur', ['refcamp' => $refCamp, 'crm_id' => $crmId]); + return $this->callAPI("GET", '/customer/mur', ['refcamp' => $this->refCamp, 'hashcode' => $hashcode]); } - public function printCoupons(int $refCamp, int $crmId, array $coupons) + public function getMur() { - return $this->callAPI("POST", '/coupons/print', ['refcamp' => $refCamp, 'crm_id' => $crmId, 'coupons' => implode(",", $coupons)]); + return $this->callAPI("GET", '/mur', ['refcamp' => $this->refCamp]); + } + + public function printCoupons(string $hashcode, array $coupons) + { + return $this->callAPI("GET", '/coupons/print', ['refcamp' => $this->refCamp, 'hashcode' => $hashcode, 'coupons' => implode(",", $coupons)]); } private function callAPI($method, $url, $data = []) diff --git a/composer.json b/composer.json index 28fff7d..a21392c 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,8 @@ "type": "project", "require": { "php": "^7.3", + "ext-curl": "*", + "ext-json": "*", "barryvdh/laravel-dompdf": "^0.9.0", "doctrine/dbal": "^2.8", "fideloper/proxy": "^4.0", @@ -13,11 +15,10 @@ "laravel/tinker": "^2.0", "laravel/ui": "^3.0", "laravelcollective/html": "6.*", + "ldc/ldccrmv2client": "2.0.14", "picqer/php-barcode-generator": "^0.3.0", "szymach/c-pchart": "^3.0", - "uxweb/sweet-alert": "^2.0", - "ext-curl": "*", - "ext-json": "*" + "uxweb/sweet-alert": "^2.0" }, "require-dev": { "barryvdh/laravel-debugbar": "^3.2", @@ -30,6 +31,13 @@ "phpunit/phpunit": "^9.0", "squizlabs/php_codesniffer": "^3.3" }, + "repositories": [ + { + "name": "ldc/ldccrmv2client", + "type": "vcs", + "url": "https://voight001.lesidc.com/crm-client" + } + ], "autoload": { "classmap": [ "database/seeds", diff --git a/composer.lock b/composer.lock index c00eb1b..5607df4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "294c501d3dece337ac5cc4c4ba4e14b8", + "content-hash": "5a3ebedda9d69b70bcd95eec2618c1fb", "packages": [ { "name": "barryvdh/laravel-dompdf", @@ -971,6 +971,299 @@ ], "time": "2020-04-13T13:17:36+00:00" }, + { + "name": "guzzlehttp/guzzle", + "version": "7.3.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "7008573787b430c1c1f650e3722d9bba59967628" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/7008573787b430c1c1f650e3722d9bba59967628", + "reference": "7008573787b430c1c1f650e3722d9bba59967628", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.4", + "guzzlehttp/psr7": "^1.7 || ^2.0", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "ext-curl": "*", + "php-http/client-integration-tests": "^3.0", + "phpunit/phpunit": "^8.5.5 || ^9.3.5", + "psr/log": "^1.1" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.3-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.3.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://github.com/alexeyshockov", + "type": "github" + }, + { + "url": "https://github.com/gmponos", + "type": "github" + } + ], + "time": "2021-03-23T11:33:13+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/8e7d04f1f6450fef59366c399cfad4b9383aa30d", + "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "symfony/phpunit-bridge": "^4.4 || ^5.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/1.4.1" + }, + "time": "2021-03-07T09:25:29+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "1dc8d9cba3897165e16d12bb13d813afb1eb3fe7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/1dc8d9cba3897165e16d12bb13d813afb1eb3fe7", + "reference": "1dc8d9cba3897165e16d12bb13d813afb1eb3fe7", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "http-interop/http-factory-tests": "^0.9", + "phpunit/phpunit": "^8.5.8 || ^9.3.10" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.0.0" + }, + "time": "2021-06-30T20:03:07+00:00" + }, + { + "name": "kwaadpepper/enum", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/Kwaadpepper/enum.git", + "reference": "036cc602c05d9b2d141def57620f73d7190a60f2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Kwaadpepper/enum/zipball/036cc602c05d9b2d141def57620f73d7190a60f2", + "reference": "036cc602c05d9b2d141def57620f73d7190a60f2", + "shasum": "" + }, + "require-dev": { + "orchestra/testbench": "^6.13", + "phpunit/phpunit": "~9.0", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Kwaadpepper\\Enum\\EnumServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Kwaadpepper\\Enum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jérémy Munsch", + "email": "github@jeremydev.ovh", + "homepage": "https://jeremydev.ovh" + } + ], + "description": "Enums to use for any project", + "homepage": "https://github.com/kwaadpepper/enum", + "keywords": [ + "enum", + "laravel" + ], + "support": { + "issues": "https://github.com/Kwaadpepper/enum/issues", + "source": "https://github.com/Kwaadpepper/enum/tree/2.0.0" + }, + "time": "2021-08-13T10:11:43+00:00" + }, { "name": "laravel/framework", "version": "v8.38.0", @@ -1337,6 +1630,66 @@ }, "time": "2020-12-15T20:20:05+00:00" }, + { + "name": "ldc/ldccrmv2client", + "version": "2.0.14", + "source": { + "type": "git", + "url": "https://voight001.lesidc.com/crm-client", + "reference": "b1d3c5fa5b23a1e1afc5dc426a85da260965cec6" + }, + "require": { + "ext-curl": "^7.3", + "guzzlehttp/guzzle": "^7.3", + "kwaadpepper/enum": "^2.0", + "php": "^7.3", + "respect/validation": "^2.2", + "vlucas/phpdotenv": "^5.3" + }, + "require-dev": { + "orchestra/testbench": "^6.13", + "phpunit/phpunit": "~9.0", + "slevomat/coding-standard": "^7.0", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "LDC\\LDCCRM\\Providers\\CrmClientV2Provider" + ] + } + }, + "autoload": { + "psr-4": { + "LDC\\LDCCRM\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "LDC\\LDCCRM\\Tests\\": "tests" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jérémy Munsch", + "email": "jeremy.munsch@ldc.fr", + "homepage": "https://jeremydev.ovh" + } + ], + "description": "LDC CRM Client V2", + "homepage": "https://github.com/kwaadpepper", + "keywords": [ + "CRM", + "Client", + "LDC", + "Laravel" + ], + "time": "2021-08-18T06:48:33+00:00" + }, { "name": "league/commonmark", "version": "1.5.8", @@ -2224,6 +2577,166 @@ }, "time": "2019-01-08T18:20:26+00:00" }, + { + "name": "psr/http-client", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client/tree/master" + }, + "time": "2020-06-29T06:28:15+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/master" + }, + "time": "2019-04-30T12:38:16+00:00" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/master" + }, + "time": "2016-08-06T14:39:51+00:00" + }, { "name": "psr/log", "version": "1.1.3", @@ -2400,6 +2913,50 @@ }, "time": "2021-04-10T16:23:39+00:00" }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, { "name": "ramsey/collection", "version": "1.1.3", @@ -2569,6 +3126,130 @@ ], "time": "2020-08-18T17:17:46+00:00" }, + { + "name": "respect/stringifier", + "version": "0.2.0", + "source": { + "type": "git", + "url": "https://github.com/Respect/Stringifier.git", + "reference": "e55af3c8aeaeaa2abb5fa47a58a8e9688cc23b59" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Respect/Stringifier/zipball/e55af3c8aeaeaa2abb5fa47a58a8e9688cc23b59", + "reference": "e55af3c8aeaeaa2abb5fa47a58a8e9688cc23b59", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.8", + "malukenho/docheader": "^0.1.7", + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Respect\\Stringifier\\": "src/" + }, + "files": [ + "src/stringify.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Respect/Stringifier Contributors", + "homepage": "https://github.com/Respect/Stringifier/graphs/contributors" + } + ], + "description": "Converts any value to a string", + "homepage": "http://respect.github.io/Stringifier/", + "keywords": [ + "respect", + "stringifier", + "stringify" + ], + "support": { + "issues": "https://github.com/Respect/Stringifier/issues", + "source": "https://github.com/Respect/Stringifier/tree/0.2.0" + }, + "time": "2017-12-29T19:39:25+00:00" + }, + { + "name": "respect/validation", + "version": "2.2.3", + "source": { + "type": "git", + "url": "https://github.com/Respect/Validation.git", + "reference": "4c21a7ffc9a4915673cb2c2843963919e664e627" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Respect/Validation/zipball/4c21a7ffc9a4915673cb2c2843963919e664e627", + "reference": "4c21a7ffc9a4915673cb2c2843963919e664e627", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0", + "respect/stringifier": "^0.2.0", + "symfony/polyfill-mbstring": "^1.2" + }, + "require-dev": { + "egulias/email-validator": "^3.0", + "malukenho/docheader": "^0.1", + "mikey179/vfsstream": "^1.6", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-deprecation-rules": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpunit/phpunit": "^9.3", + "psr/http-message": "^1.0", + "respect/coding-standard": "^3.0", + "squizlabs/php_codesniffer": "^3.5", + "symfony/validator": "^3.0||^4.0", + "zendframework/zend-validator": "^2.1" + }, + "suggest": { + "egulias/email-validator": "Strict (RFC compliant) email validation", + "ext-bcmath": "Arbitrary Precision Mathematics", + "ext-fileinfo": "File Information", + "ext-mbstring": "Multibyte String Functions", + "symfony/validator": "Use Symfony validator through Respect\\Validation", + "zendframework/zend-validator": "Use Zend Framework validator through Respect\\Validation" + }, + "type": "library", + "autoload": { + "psr-4": { + "Respect\\Validation\\": "library/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Respect/Validation Contributors", + "homepage": "https://github.com/Respect/Validation/graphs/contributors" + } + ], + "description": "The most awesome validation engine ever created for PHP", + "homepage": "http://respect.github.io/Validation/", + "keywords": [ + "respect", + "validation", + "validator" + ], + "support": { + "issues": "https://github.com/Respect/Validation/issues", + "source": "https://github.com/Respect/Validation/tree/2.2.3" + }, + "time": "2021-03-19T14:12:45+00:00" + }, { "name": "sabberworm/php-css-parser", "version": "8.3.1", @@ -3564,16 +4245,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.22.1", + "version": "v1.23.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", "shasum": "" }, "require": { @@ -3585,7 +4266,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.22-dev" + "dev-main": "1.23-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3623,7 +4304,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" }, "funding": [ { @@ -3639,7 +4320,7 @@ "type": "tidelift" } ], - "time": "2021-01-07T16:49:33+00:00" + "time": "2021-02-19T12:13:01+00:00" }, { "name": "symfony/polyfill-iconv", @@ -3975,16 +4656,16 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.22.1", + "version": "v1.23.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "5232de97ee3b75b0360528dae24e73db49566ab1" + "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/5232de97ee3b75b0360528dae24e73db49566ab1", - "reference": "5232de97ee3b75b0360528dae24e73db49566ab1", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9174a3d80210dca8daa7f31fec659150bbeabfc6", + "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6", "shasum": "" }, "require": { @@ -3996,7 +4677,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.22-dev" + "dev-main": "1.23-dev" }, "thanks": { "name": "symfony/polyfill", @@ -4035,7 +4716,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.22.1" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.1" }, "funding": [ { @@ -4051,7 +4732,7 @@ "type": "tidelift" } ], - "time": "2021-01-22T09:19:47+00:00" + "time": "2021-05-27T12:26:48+00:00" }, { "name": "symfony/polyfill-php72", @@ -4210,16 +4891,16 @@ }, { "name": "symfony/polyfill-php80", - "version": "v1.22.1", + "version": "v1.23.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "dc3063ba22c2a1fd2f45ed856374d79114998f91" + "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/dc3063ba22c2a1fd2f45ed856374d79114998f91", - "reference": "dc3063ba22c2a1fd2f45ed856374d79114998f91", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/1100343ed1a92e3a38f9ae122fc0eb21602547be", + "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be", "shasum": "" }, "require": { @@ -4228,7 +4909,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.22-dev" + "dev-main": "1.23-dev" }, "thanks": { "name": "symfony/polyfill", @@ -4273,7 +4954,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.22.1" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.23.1" }, "funding": [ { @@ -4289,7 +4970,7 @@ "type": "tidelift" } ], - "time": "2021-01-07T16:49:33+00:00" + "time": "2021-07-28T13:41:28+00:00" }, { "name": "symfony/process", @@ -7952,8 +8633,10 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^7.3" + "php": "^7.3", + "ext-curl": "*", + "ext-json": "*" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.1.0" } diff --git a/config/crm.php b/config/crm.php index 590111c..58aaf9a 100644 --- a/config/crm.php +++ b/config/crm.php @@ -3,6 +3,5 @@ return [ 'CRM_ENDPOINT' => env('CRM_ENDPOINT'), - 'CRM_API_TOKEN' => env('CRM_API_TOKEN'), ]; diff --git a/database/migrations/2021_04_20_105237_create_customers_table.php b/database/migrations/2021_04_20_105237_create_customers_table.php new file mode 100644 index 0000000..44b9882 --- /dev/null +++ b/database/migrations/2021_04_20_105237_create_customers_table.php @@ -0,0 +1,34 @@ +increments('id'); + $table->string('hashcode', 36)->unique(); + $table->string('email')->unique(); + $table->integer('country')->default('250'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('customers'); + } +} diff --git a/routes/api.php b/routes/api.php index e4478a9..800b6d3 100644 --- a/routes/api.php +++ b/routes/api.php @@ -15,7 +15,8 @@ use Illuminate\Http\Request; Route::prefix('v1') ->group(function () { + Route::get('/customer/mur', 'Api\v1\CustomerController@mur'); Route::resource('customer', 'Api\v1\CustomerController'); - Route::post('/mur', 'Api\v1\MurController@index'); - Route::post('/coupons/print', 'Api\v1\CouponsController@print'); + Route::get('/mur', 'Api\v1\MurController@show'); + Route::get('/coupons/print', 'Api\v1\CouponsController@print'); });