<?php
 namespace App\Utils\CreditCard; class MatchCardFromGDS extends \App\Utils\CreditCard\MatchCard { public function matchByAgencyCreditCards() :int|false { if (!$this->cardNumberTruncated) { return false; } if (!$this->expireDate) { return false; } $agencyCreditCardsObj = new \App\EntityList\AgencyCreditCards(); $agencyCreditCardsList = $agencyCreditCardsObj->exportRecords(); foreach ($agencyCreditCardsList as $card) { $ccEnt = \Entity\AgencyCreditCard::selectForUpdate($card['id']); if ($this->matchCardLooseByDetails($ccEnt->cardDetails['truncatedNumber'], $ccEnt->cardDetails['expireDate'])) { return $card['id']; } } return false; } private function matchCardLooseByDetails(string $DBcardNumber, ?string $DBexpireDate) :bool { if (!$this->expireDate || !$DBexpireDate) { return false; } if ($this->expireDate!==$DBexpireDate) { return false; } if ($this->cardNumberTruncated===$DBcardNumber) { return true; } if (substr($this->cardNumberTruncated, 0, 6)===substr($DBcardNumber, 0, 6) && substr($this->cardNumberTruncated, -4)===substr($DBcardNumber, -4)) { return true; } if (substr($this->cardNumberTruncated, 0, 6)==='000000' && substr($this->cardNumberTruncated, -4)===substr($DBcardNumber, -4)) { return true; } return false; } } 