From 23488e9f709266c094e89d63d9c463254daad49a Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 10 Mar 2024 23:43:21 -0400 Subject: [PATCH 1/3] feat: find cobuyer --- src/Leads/Lead.php | 96 ++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 59 deletions(-) diff --git a/src/Leads/Lead.php b/src/Leads/Lead.php index 41f60fa..c413c3d 100644 --- a/src/Leads/Lead.php +++ b/src/Leads/Lead.php @@ -1,4 +1,5 @@ id, $user->id); $client->useDigitalShowRoomKey(); @@ -67,14 +59,8 @@ public static function getAll(Dealer $dealer, User $user, array $params = []) : /** * Get a contact by its ID. - * - * @param Dealer $dealer - * @param User $user - * @param int $leadsId - * - * @return self */ - public static function getById(Dealer $dealer, User $user, int $leadsId) : self + public static function getById(Dealer $dealer, User $user, int $leadsId): self { $client = new Client($dealer->id, $user->id); $client->useDigitalShowRoomKey(); @@ -92,14 +78,8 @@ public static function getById(Dealer $dealer, User $user, int $leadsId) : self /** * Create a new contact. - * - * @param Dealer $dealer - * @param User $user - * @param array $data - * - * @return self */ - public static function create(Dealer $dealer, User $user, array $data) : self + public static function create(Dealer $dealer, User $user, array $data): self { $client = new Client($dealer->id, $user->id); $data['DealerId'] = $dealer->id; @@ -113,8 +93,8 @@ public static function create(Dealer $dealer, User $user, array $data) : self json_encode($data), [ 'headers' => [ - 'Content-Type' => 'application/vnd.coxauto.v3+json' - ] + 'Content-Type' => 'application/vnd.coxauto.v3+json', + ], ] ); @@ -123,13 +103,8 @@ public static function create(Dealer $dealer, User $user, array $data) : self /** * Create a new contact. - * - * @param Dealer $dealer - * @param User $user - * - * @return self */ - public function update(Dealer $dealer, User $user) : self + public function update(Dealer $dealer, User $user): self { $client = new Client($dealer->id, $user->id); @@ -145,17 +120,17 @@ public function update(Dealer $dealer, User $user) : self json_encode($data), [ 'headers' => [ - 'Content-Type' => 'application/vnd.coxauto.v3+json' - ] + 'Content-Type' => 'application/vnd.coxauto.v3+json', + ], ] ); $data['LeadId'] = $this->id; + return new self($data); } - - public function addNotes(Dealer $dealer, User $user, string $notes) : self + public function addNotes(Dealer $dealer, User $user, string $notes): self { $client = new Client($dealer->id, $user->id); $client->useDigitalShowRoomKey(); @@ -170,18 +145,14 @@ public function addNotes(Dealer $dealer, User $user, string $notes) : self ); $data['LeadId'] = $this->id; + return new self($data); } /** * Start a show room. - * - * @param Dealer $dealer - * @param User $user - * - * @return self */ - public function startShowRoom(Dealer $dealer, User $user) : self + public function startShowRoom(Dealer $dealer, User $user): self { $client = new Client($dealer->id, $user->id); $client->useDigitalShowRoomKey(); @@ -200,16 +171,28 @@ public function startShowRoom(Dealer $dealer, User $user) : self return new self($response); } + public static function getCoBuyer(Dealer $dealer, User $user, int $leadsId): ?int + { + $client = new Client($dealer->id, $user->id); + $data['DealerId'] = $dealer->id; + $data['UserId'] = $user->id; + + $response = $client->get( + '/leads/id/' . $leadsId, + [ + 'headers' => [ + 'Accept' => 'application/vnd.coxauto.v1+json', + ], + ] + ); + + return $response['coBuyerContact'] ?? null; + } + /** * Add a trade in to the vehicle. - * - * @param Dealer $dealer - * @param User $user - * @param array $data - * - * @return array */ - public function addTradeIn(Dealer $dealer, User $user, array $data) : array + public function addTradeIn(Dealer $dealer, User $user, array $data): array { $client = new Client($dealer->id, $user->id); @@ -223,8 +206,8 @@ public function addTradeIn(Dealer $dealer, User $user, array $data) : array json_encode($request), [ 'headers' => [ - 'Content-Type' => 'application/vnd.coxauto.v1+json' - ] + 'Content-Type' => 'application/vnd.coxauto.v1+json', + ], ] ); @@ -233,13 +216,8 @@ public function addTradeIn(Dealer $dealer, User $user, array $data) : array /** * Get the list of trade-in vehicles. - * - * @param Dealer $dealer - * @param User $user - * - * @return array */ - public function getTradeIn(Dealer $dealer, User $user) : array + public function getTradeIn(Dealer $dealer, User $user): array { $client = new Client($dealer->id, $user->id); @@ -247,8 +225,8 @@ public function getTradeIn(Dealer $dealer, User $user) : array '/vehicles/trade?leadId=' . $this->id, [ 'headers' => [ - 'Accept' => 'application/vnd.coxauto.v1+json' - ] + 'Accept' => 'application/vnd.coxauto.v1+json', + ], ] ); From dc93ebacac4b5abd14957f71fa2d29a7c7ab8576 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 12 Mar 2024 01:01:00 -0400 Subject: [PATCH 2/3] refact: fix cms --- src/Leads/Lead.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Leads/Lead.php b/src/Leads/Lead.php index c413c3d..8b31177 100644 --- a/src/Leads/Lead.php +++ b/src/Leads/Lead.php @@ -171,7 +171,7 @@ public function startShowRoom(Dealer $dealer, User $user): self return new self($response); } - public static function getCoBuyer(Dealer $dealer, User $user, int $leadsId): ?int + public static function getCoBuyer(Dealer $dealer, User $user, int $leadsId): ?string { $client = new Client($dealer->id, $user->id); $data['DealerId'] = $dealer->id; @@ -181,12 +181,16 @@ public static function getCoBuyer(Dealer $dealer, User $user, int $leadsId): ?in '/leads/id/' . $leadsId, [ 'headers' => [ - 'Accept' => 'application/vnd.coxauto.v1+json', + 'Accept' => 'application/vnd.coxauto.v3+json', ], ] ); - return $response['coBuyerContact'] ?? null; + if (preg_match("/\/id\/(\d+)/", $response['coBuyerContact'], $matches)) { + return $matches[1]; // $matches[1] contains the first captured group, which is the ID + } + + return null; } /** From ddc657ea2665b4144292102a67f1dff1c74847af Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 12 Mar 2024 01:01:49 -0400 Subject: [PATCH 3/3] refact: fix cms --- src/Leads/Lead.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Leads/Lead.php b/src/Leads/Lead.php index 8b31177..c856ac0 100644 --- a/src/Leads/Lead.php +++ b/src/Leads/Lead.php @@ -187,7 +187,7 @@ public static function getCoBuyer(Dealer $dealer, User $user, int $leadsId): ?st ); if (preg_match("/\/id\/(\d+)/", $response['coBuyerContact'], $matches)) { - return $matches[1]; // $matches[1] contains the first captured group, which is the ID + return $matches[1]; } return null;