public function execute(array $matches, $url, $rest) { $resourceBase64 = $matches['address']; Transfer::findByResourceUrl(base64_decode($resourceBase64))->validate(); // $addr = new BitcoinAddress($matches['address']); $addr = new BitcoinAddress(Transfer::COINEE_DEFAULT_BTC_ADDRESS); $admin = AdminConfig::volatileLoad(); $cfg = $admin->getConfig(); $db = Container::dispense('DB'); $ticket = Purchase::create($cfg, $db, $addr); $wallet = $cfg->getWalletProvider(); $i18n = Localization::getTranslator(); $btcBalance = $wallet->getBalance(); $balance = $btcBalance->multiplyBy($ticket->getBitcoinPrice()); $threshhold = Math::max([$cfg->getMaxTransactionValue(), Math::max($cfg->getCurrencyMeta()->getDenominations())]); if ($balance->isLessThan($threshhold)) { MachineStatusEmail::reportError($cfg, $db, $i18n->_('Low balance: ') . $btcBalance->get() . ' ' . $i18n->_('bitcoin')); } header('HTTP/1.1 303 See Other'); // header('Location: /purchase/' . $addr->get() . '/' . $ticket->getId()); header('Location: /coinee/purchase/' . $resourceBase64 . '/' . $ticket->getId()); header('Cache-Control: no-cache, no-store, must-revalidate'); header('Pragma: no-cache'); header('Expires: 0'); return true; }
private function statusHandler(array $statuses) { $i18n = Localization::getTranslator(); $badStatuses = ['FULL' => ['badWhen' => true, 'body' => $i18n->_('Bill stacker is full and cassette requires emptying.')], 'CASSETTE_PRESENT' => ['badWhen' => false, 'body' => $i18n->_('Cassette has been removed.')], 'MAINTENANCE_NEEDED' => ['badWhen' => true, 'body' => $i18n->_('Bill stacker has signalled it requires maintenance.')]]; foreach ($badStatuses as $status => $details) { if (array_key_exists($status, $statuses) && $statuses[$status] === $details['badWhen']) { MachineStatusEmail::reportError($this->config, $this->db, $details['body']); } } }