137 lines
4.5 KiB
PHP
137 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Lib;
|
|
|
|
/**
|
|
* This class is an old version taken in GGW
|
|
* it should not be used anymore once mesBR is upgraded to a stable state
|
|
*/
|
|
class MesBROld
|
|
{
|
|
private $endpoint;
|
|
|
|
private $refSite;
|
|
|
|
private $refCamp;
|
|
|
|
public function __construct($endpoint, $refSite, $refCamp)
|
|
{
|
|
$this->endpoint = $endpoint;
|
|
$this->refSite = $refSite;
|
|
$this->refCamp = $refCamp;
|
|
}
|
|
|
|
/** Update contact *
|
|
* NOT USED - SHOULD BE DELETED
|
|
*
|
|
* @param $oCrmUser
|
|
* @return boolean
|
|
*/
|
|
public function updateContact($oCrmUser)
|
|
{
|
|
// dd($oCrmUser);
|
|
$datas = [
|
|
'refsite' => $this->refSite,
|
|
'refadherent' => $oCrmUser->crm_id,
|
|
'nom' => $oCrmUser->lastname,
|
|
'prenom' => $oCrmUser->firstname,
|
|
'email' => $oCrmUser->email,
|
|
'date_naissance' => $oCrmUser->birth_date,
|
|
'code_postal' => $oCrmUser->postcode,
|
|
'commune' => $oCrmUser->city,
|
|
'pays' => $this->getCountry($oCrmUser->country),
|
|
'hashcode' => $oCrmUser->hashcode
|
|
];
|
|
|
|
$this->callAPI("GET", "/updatecontact", $datas);
|
|
// TODO : Verif statut du call ? (Nouvelle API MesBR)
|
|
return true;
|
|
}
|
|
|
|
/** Update panier *
|
|
*
|
|
* @param $oCrmUser
|
|
* @param $couponId
|
|
* @param integer $quantity
|
|
* @return array
|
|
*/
|
|
public function updatePanier($oCrmUser, $refid, $couponId, $quantity = 1)
|
|
{
|
|
$datas = [
|
|
'refsite' => $this->refSite,
|
|
'refcamp' => $this->refCamp,
|
|
// TODO : ici il faut une id qui est ajoutée au code barre du coupon donc un hascode c'est trop long
|
|
'refadherent' => $refid,
|
|
'nom' => $oCrmUser->lastname,
|
|
'prenom' => $oCrmUser->firstname,
|
|
'email' => $oCrmUser->email,
|
|
'code_postal' => $oCrmUser->postcode,
|
|
'commune' => $oCrmUser->city,
|
|
'pays' => $this->getCountry($oCrmUser->country),
|
|
'panier' => "($quantity)$couponId"
|
|
];
|
|
$res = $this->callAPI("GET", "/updatebasket", $datas);
|
|
if (!$res) {
|
|
error_log("MESBR - CODE : 999 - MESSAGE : Cannot read API Response (non json)");
|
|
return ['status' => 'KO', 'code' => 999, 'message' => 'Cannot read API Response (non json)'];
|
|
}
|
|
if ($res->Statut === 'KO') {
|
|
error_log("MESBR - CODE : $res->Code - MESSAGE : $res->Message");
|
|
return ['status' => 'KO', 'code' => $res->Code, 'message' => $res->Message];
|
|
}
|
|
$panierVerification = $this->endpoint . '/showbasket?basketid=' . $res->Panier->Panier;
|
|
$panier_link = $this->endpoint . '/?basketid=' . $res->Panier->Panier;
|
|
return ['status' => 'OK', 'link' => $panier_link, 'verif' => $panierVerification, 'basketId' => $res->Panier->Panier];
|
|
}
|
|
/** Génère le lien vers le mur (ou panier préprogrammé) **/
|
|
public function GetMurBDRLink($br_refsite, $br_refcamp, $crmUser)
|
|
{
|
|
return $this->endpoint . "/?refsite=" . trim($br_refsite) . "&refcamp=" . trim($br_refcamp) . "&email=" . $crmUser->email;
|
|
}
|
|
private function getCountry($country)
|
|
{
|
|
switch ($country) {
|
|
case 'Belgique':
|
|
return 56;
|
|
break;
|
|
case 'Luxembourg':
|
|
return 442;
|
|
break;
|
|
default:
|
|
return 250;
|
|
// France
|
|
break;
|
|
}
|
|
}
|
|
private function callAPI($method, $url, $data)
|
|
{
|
|
$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, $data);
|
|
}
|
|
break;
|
|
default:
|
|
if ($data) {
|
|
$url = sprintf("%s?%s", $url, http_build_query($data));
|
|
}
|
|
}
|
|
curl_setopt($curl, CURLOPT_URL, $this->endpoint . $url);
|
|
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
$result = curl_exec($curl);
|
|
if (!$result) {
|
|
die("Connection Failure");
|
|
}
|
|
curl_close($curl);
|
|
return json_decode($result);
|
|
}
|
|
}
|