| Total Complexity | 9 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class Transaction |
||
| 14 | { |
||
| 15 | use Injectable; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var |
||
| 19 | */ |
||
| 20 | private $transaction; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Transaction constructor. |
||
| 24 | * @param $transactionID |
||
| 25 | * @param $data |
||
| 26 | * @throws ValidationException |
||
| 27 | */ |
||
| 28 | public function __construct($transactionID, $data) |
||
| 29 | { |
||
| 30 | $this->setTransaction($transactionID, $data); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param $transactionID |
||
| 35 | * @param $data |
||
| 36 | * @return $this |
||
| 37 | * @throws ValidationException |
||
| 38 | */ |
||
| 39 | public function setTransaction($transactionID, $data) |
||
| 40 | { |
||
| 41 | $decryptedData = $this->getDecryptedData($data); |
||
| 42 | |||
| 43 | foreach ($decryptedData->transactions->transaction as $transaction) { |
||
| 44 | if ($transactionID == (int)$transaction->id) { |
||
| 45 | $this->transaction = $transaction; |
||
| 46 | break; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | if (!$this->transaction) { |
||
| 51 | $this->transaction = false; |
||
| 52 | } |
||
| 53 | |||
| 54 | return $this; |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @return mixed |
||
| 59 | */ |
||
| 60 | public function getTransaction() |
||
| 61 | { |
||
| 62 | return $this->transaction; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @return bool |
||
| 67 | */ |
||
| 68 | public function exists() |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param $data |
||
| 75 | * @return \SimpleXMLElement |
||
| 76 | * @throws \SilverStripe\ORM\ValidationException |
||
| 77 | */ |
||
| 78 | private function getDecryptedData($data) |
||
| 84 |