<?php
 namespace App\ImportedOrder; class CreditCard extends EntityAbstract { public $encryptedNumberRef; public $number; public $expireDate; public $company; public $approvalCode; public $entityType; public $entityId; protected function validateEntityFields(\App\MessagesCollector $messagesCollector): void { } public function getOriginalNumber() { if ($this->encryptedNumberRef) { $ccEncryptStorageObj = new \App\Utils\CreditCard\Storage(); $cardDetails = $ccEncryptStorageObj->getCard($this->encryptedNumberRef); return $cardDetails['number']; } else { return $this->number; } } public function getMaskedNumber() { if ($this->encryptedNumberRef) { return $this->number; } elseif ($this->number===null) { return null; } else { return \App\Utils\CreditCard\NumberDetails::create($this->number)->getMaskedNumber(); } } public function getCleanExpireDate() :?string { if (!$this->expireDate) { return null; } if (validDate($this->expireDate)) { $datetimeObj = \Engine\DateTime::createFromIsoDate($this->expireDate); return $datetimeObj->format('Y-m-t'); } $datetimeObj = \Engine\DateTime::createFromFormatsArr(['Ym-d', 'Y-m-d'], $this->expireDate.'-01'); if ($datetimeObj->isValid() and !$datetimeObj->isEmpty()) { return $datetimeObj->format('Y-m-t'); } return null; } public function getMatchedCardEntityDetails(bool $agencyCardsManualMatch, int $idCorporate) : array { switch ($this->entityType) { case 'agency': if ($this->entityId) { $ccEnt = \Entity\AgencyCreditCard::select($this->entityId); if ($ccEnt->recordExists() and !$ccEnt->deleted) { return ['type'=>'agency', 'id'=>$this->entityId]; } } break; case 'corporate': if ($this->entityId) { $ccEnt = \Entity\CorporateCreditCard::select($this->entityId); if ($ccEnt->recordExists() and !$ccEnt->deleted) { return ['type'=>'corporate', 'id'=>$this->entityId]; } } break; case 'customer': if ($this->entityId) { $ccEnt = \Entity\CustomerCreditCard::select($this->entityId); if ($ccEnt->recordExists() and !$ccEnt->deleted) { return ['type'=>'customer', 'id'=>$this->entityId]; } } break; case 'manual': if ($this->entityId) { $ccStorageObj = new \App\Utils\CreditCard\Storage(); if ($ccStorageObj->getCard($this->entityId)) { return ['type'=>'manual', 'id'=>$this->entityId]; } } break; } if ($agencyCardsManualMatch and $this->number) { $cardMatch = new \App\Utils\CreditCard\MatchCard($this->getOriginalNumber(), $this->getCleanExpireDate()); $idMatchedAgencyCreditCard = $cardMatch->matchByAgencyCreditCards(); if ($idMatchedAgencyCreditCard) { return ['type'=>'agency', 'id'=>$idMatchedAgencyCreditCard]; } } if ($idCorporate and $this->number) { $cardMatch = new \App\Utils\CreditCard\MatchCard($this->getOriginalNumber(), $this->getCleanExpireDate()); $idMatchedAgencyCreditCard = $cardMatch->matchByCorporateCreditCards($idCorporate); if ($idMatchedAgencyCreditCard) { return ['type'=>'corporate', 'id'=>$idMatchedAgencyCreditCard]; } } if ($this->encryptedNumberRef) { $ccStorageObj = new \App\Utils\CreditCard\Storage(); if ($ccStorageObj->getCard($this->encryptedNumberRef)) { return ['type'=>'manual', 'id'=>$this->encryptedNumberRef]; } } return []; } } 