Beispiel #1
0
 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;
 }
Beispiel #2
0
 public function execute(array $matches, $url, $rest)
 {
     $this->stopScanner();
     $transferResourceBase64 = $matches['address'];
     $transfer = Transfer::findByResourceUrl(base64_decode($transferResourceBase64));
     $addr = new BitcoinAddress(Transfer::COINEE_DEFAULT_BTC_ADDRESS);
     $admin = AdminConfig::volatileLoad();
     $cfg = $admin->getConfig();
     $ticket = Purchase::load($cfg, Container::dispense('DB'), intval($matches['ticket']));
     if (strval($addr->get()) !== strval($ticket->getCustomerAddress()->get())) {
         error_log("Tampering detected on ticket #" . $ticket->getId() . ' at ' . time());
         return false;
     }
     $isZero = $ticket->getCurrencyAmount()->isEqualTo(new Amount("0"));
     if ($ticket->getStatus() !== Purchase::PENDING || $isZero === false) {
         header('HTTP/1.1 303 See Other');
         header('Location: /start');
         header('Cache-Control: no-cache, no-store, must-revalidate');
         header('Pragma: no-cache');
         header('Expires: 0');
         return false;
     }
     header('Cache-Control: no-cache, no-store, must-revalidate');
     header('Pragma: no-cache');
     header('Expires: 0');
     $tmpl = new Template('coinee/purchase');
     $tmpl->render(['ticket' => $ticket, 'config' => $cfg, 'transfer' => $transfer->getInfo()]);
     return true;
 }
Beispiel #3
0
 public function execute(array $matches, $url, $rest)
 {
     $get = Container::dispense('Environment\\Get');
     $cfg = AdminConfig::volatileLoad()->getConfig();
     $db = Container::dispense('DB');
     $p = Purchase::load($cfg, $db, $matches['ticket']);
     $scanner = Container::dispense('BillScannerDriver');
     $scanner->stop();
     $error = false;
     if (!empty($get['error'])) {
         $error = true;
     }
     $sent = false;
     if (!empty($get['sent'])) {
         $sent = true;
     }
     $transferResourceBase64 = $matches['transfer'];
     $transfer = Transfer::findByResourceUrl(base64_decode($transferResourceBase64));
     $coineeConfig = $cfg->getCoinee();
     $userEmail = $coineeConfig['email'];
     $apiKey = $coineeConfig['apiKey'];
     $orderId = $matches['order'];
     $transfer->orderPaid($orderId, $userEmail, $apiKey);
     $tmpl = new Template('coinee/receipt');
     $tmpl->render(['purchase' => $p, 'config' => $cfg, 'error' => $error, 'sent' => $sent]);
     return true;
 }
Beispiel #4
0
 public function send($lastOverride = false)
 {
     $i18n = Localization::getTranslator();
     $lastFn = '/home/pi/phplog/last-tx-sent';
     $last = 0;
     if (file_exists($lastFn)) {
         $last = intval(trim(file_get_contents($lastFn)));
     }
     if ($lastOverride !== false) {
         $last = $lastOverride;
     }
     $csvMaker = Container::dispense('TransactionCSV');
     $config = Admin::volatileLoad()->getConfig();
     $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername($config->getEmailUsername())->setPassword($config->getEmailPassword());
     $msg = Swift_Message::newInstance()->setSubject($config->getMachineName() . $i18n->_(': Transaction Log'))->setFrom([$config->getEmailUsername() => $config->getMachineName()])->setTo(array($config->getEmailUsername()))->setBody($i18n->_('See attached for transaction log.'));
     $file = $csvMaker->save($last);
     if (!$file) {
         throw new Exception('Unable to save CSV');
     }
     $msg->attach(Swift_Attachment::fromPath($file));
     file_put_contents($lastFn, $csvMaker->getLastID());
     $mailer = Swift_Mailer::newInstance($transport);
     if (!$mailer->send($msg)) {
         throw new Exception('Unable to send: unkown cause');
     }
 }
Beispiel #5
0
 public function execute(array $matches, $url, $rest)
 {
     $this->stopScanner();
     $this->notifyBalanceChange();
     $admin = AdminConfig::volatileLoad();
     $contactInfo = $admin->getConfig()->getContactInformation();
     $tmpl = new Template('coinee/account');
     $tmpl->render(['contactInfo' => $contactInfo]);
     return true;
 }
Beispiel #6
0
 public function send()
 {
     $i18n = Localization::getTranslator();
     $config = Admin::volatileLoad()->getConfig();
     $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername($config->getEmailUsername())->setPassword($config->getEmailPassword());
     $msg = Swift_Message::newInstance()->setSubject($config->getMachineName() . $i18n->_(': Transaction Log'))->setFrom([$config->getEmailUsername() => $config->getMachineName()])->setTo(array($config->getEmailUsername()))->setBody($i18n->_('There have been no transactions since the last email.'));
     $mailer = Swift_Mailer::newInstance($transport);
     if (!$mailer->send($msg)) {
         throw new Exception('Unable to send: unkown cause');
     }
 }
Beispiel #7
0
 public function __construct(DB $db, BillScannerDriver $driver)
 {
     $this->db = $db;
     $this->driver = $driver;
     $admin = AdminConfig::volatileLoad();
     $this->config = $admin->getConfig();
     $this->currencyMeta = $this->config->getCurrencyMeta();
     $this->denoms = $this->currencyMeta->getDenominations();
     $this->largest = Math::max($this->denoms);
     $this->threshhold = $this->largest->multiplyBy(new Amount("2"));
     $this->lowest = Math::min($this->denoms);
     $this->balance = new Amount("0");
 }
Beispiel #8
0
 public function execute(array $matches, $rest, $url)
 {
     Debug::setLogger(new STDOUTLogger());
     $argv = Container::dispense('Environment\\Arguments');
     if (isset($argv[2])) {
         $addr = new BitcoinAddress($argv[2]);
     } else {
         $addr = AdminConfig::volatileLoad()->getConfig()->getWalletProvider()->getWalletAddress();
     }
     $am = new BlockchainAddressMonitor($addr);
     $am->updateCache();
     echo $am->getBalance()->get(), "\n";
 }
Beispiel #9
0
 private function start($unvalidated)
 {
     $addr = new BitcoinAddress($unvalidated);
     $admin = AdminConfig::volatileLoad();
     $cfg = $admin->getConfig();
     $ticket = Purchase::create($cfg, Container::dispense('DB'), $addr);
     $isZero = $ticket->getCurrencyAmount()->isEqualTo(new Amount("0"));
     if ($ticket->getStatus() !== Purchase::PENDING || $isZero === false) {
         throw new Exception("That purchase was already started.");
     }
     $scanner = Container::dispense('BillScanner');
     if ($scanner->isRunning()) {
         $scanner->stop();
     }
     $scanner->start();
     $price = $ticket->getBitcoinPrice();
     return ['ticketId' => $ticket->getId(), 'price' => ['value' => $price->get(), 'formatted' => $cfg->getCurrencyMeta()->format($price, true)]];
 }
Beispiel #10
0
 public function execute(array $matches, $rest, $url)
 {
     // keep working for up to 4 minutes
     $until = time() + 60 * 4;
     Hourly::doWork([function () {
         $config = AdminConfig::volatileLoad()->getConfig();
         if (!$config->shouldSendLog()) {
             return;
         }
         try {
             $mailer = new CSVMailer();
             $mailer->send();
         } catch (TransactionCSVException $e) {
             $mailer = new HeartBeatMailer();
             $mailer->send();
         }
     }]);
     $manager = Container::dispense('JobManager');
     $manager->doWork($until);
 }
Beispiel #11
0
 public static function test()
 {
     require "autoload.php";
     $cfg = Admin::volatileLoad()->getConfig();
     $d = self::denormalize($cfg);
     $n = self::normalize(new Post($d));
     var_dump($d);
     echo str_repeat("=", 80), "\n";
     $cfgData = $cfg->asArray();
     ksort($cfgData);
     ksort($n);
     var_dump($cfgData);
     echo str_repeat("=", 80), "\n";
     var_dump($n);
 }