From a28885f74ef8e243124cee33c09899cc0e984928 Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Tue, 1 Apr 2025 11:45:01 +0200 Subject: [PATCH] fix: use hashcode instead of customer_id to update mesbr basket --- .../Controllers/Fo/ParticipateController.php | 12 +++++------ app/Lib/vendor/LDCWEB/MesBr.php | 20 ++++++++++++------- composer.json | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Fo/ParticipateController.php b/app/Http/Controllers/Fo/ParticipateController.php index d4cfe27..aae6f8f 100644 --- a/app/Http/Controllers/Fo/ParticipateController.php +++ b/app/Http/Controllers/Fo/ParticipateController.php @@ -190,8 +190,8 @@ class ParticipateController extends Controller $mesBr = app('mesBrAPI'); // * MaJ Customer - /** @var integer */ - $crm_customer_id = retry(3, function () use ($mesBr, $crmUser) { + /** @var string */ + $crm_customer_hashcode = retry(3, function () use ($mesBr, $crmUser) { /** * Parce que MesBr n'est pas fiable il faut retenter pour avoir * l'id client, des fois cet id sera dans hashcode... @@ -210,19 +210,19 @@ class ParticipateController extends Controller } /** @var object|null */ $crm_customer = optional($result)->customer; - if (empty(optional($crm_customer)->id)) { + if (empty(optional($crm_customer)->hashcode)) { throw new \RuntimeException( - 'MESBR : Une erreur est survenue. Update Customer n\'as pas retourné le customer id' + 'MESBR : Une erreur est survenue. Update Customer n\'as pas retourné le customer hashcode' ); } - return intval($crm_customer->id); + return $crm_customer->hashcode; }, 100); // * Maj Panier $result = $mesBr->updatePanier( $crmUser, - $crm_customer_id, + $crm_customer_hashcode, $settings->discounts_site, strval($discount->web_coupon_identifiant) ); diff --git a/app/Lib/vendor/LDCWEB/MesBr.php b/app/Lib/vendor/LDCWEB/MesBr.php index 594807e..45c12b5 100644 --- a/app/Lib/vendor/LDCWEB/MesBr.php +++ b/app/Lib/vendor/LDCWEB/MesBr.php @@ -36,7 +36,9 @@ class MesBr public function printCoupons(string $hashcode, array $coupons) { return $this->callApi("GET", '/coupons/print', [ - 'refcamp' => $this->refCamp, 'hashcode' => $hashcode, 'coupons' => implode(",", $coupons) + 'refcamp' => $this->refCamp, + 'hashcode' => $hashcode, + 'coupons' => implode(",", $coupons) ]); } private function callApi($method, $url, $data = [], $path = '/api/v1') @@ -71,12 +73,16 @@ class MesBr $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 + '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) + 'status' => 'KO', + 'code' => 500, + 'message' => 'Connection to API failed : ' . curl_error($curl) ]; } curl_close($curl); @@ -89,7 +95,7 @@ class MesBr * Update panier * * @param \LDC\LDCCRM\Models\Customer $crm_customer - * @param integer $crm_customer_id + * @param string $crm_customer_hashcode * @param string $ref_site * @param string $coupon_id * @param integer $quantity @@ -101,7 +107,7 @@ class MesBr */ public function updatePanier( Customer $crm_customer, - int $crm_customer_id, + string $crm_customer_hashcode, string $ref_site, string $coupon_id, int $quantity = 1 @@ -109,7 +115,7 @@ class MesBr $res = $this->callAPI("GET", "/updatebasket", [ 'refsite' => $ref_site, 'refcamp' => $this->refCamp, - 'refadherent' => $crm_customer_id, + 'refadherent' => $crm_customer_hashcode, 'nom' => $crm_customer->lastname, 'prenom' => $crm_customer->firstname, 'email' => $crm_customer->email, @@ -143,7 +149,7 @@ class MesBr return match ($country) { Country::belgium() => 56, Country::luxembourg() => 442, - // * France + // * France default => 250 }; } diff --git a/composer.json b/composer.json index 96d38d1..06d6f9a 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "uwil/gen-game-web", - "version": "2.4.3", + "version": "2.4.4", "type": "project", "description": "Game generator", "support": {