fix: use hashcode instead of customer_id to update mesbr basket

This commit is contained in:
Noah Lancien 2025-04-01 11:45:01 +02:00
parent dc559dc1e7
commit a28885f74e
3 changed files with 20 additions and 14 deletions

View file

@ -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)
);

View file

@ -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
};
}

View file

@ -1,6 +1,6 @@
{
"name": "uwil/gen-game-web",
"version": "2.4.3",
"version": "2.4.4",
"type": "project",
"description": "Game generator",
"support": {