Example #1
0
 public static function completeTransaction(Config $cfg, DB $db, Purchase $p)
 {
     $w = $cfg->getWalletProvider();
     if ($p->isCompleted()) {
         throw new Exception("completeTransaction() was attempted twice on purchase ticket: " . $p->getId());
     }
     try {
         $db->beginTransaction();
         $tx = $w->sendTransaction($p->getCustomerAddress(), $p->recalculateBitcoinAmount());
         $p->setTXID($tx->getId())->setNTXID(self::normalizeTXID($tx->getId()))->setStatus(self::COMPLETE)->setMessage($tx->getMessage())->setNotice($tx->getNotice());
         self::finalize($db, $p);
         self::save($db, $p);
         $db->commit();
     } catch (Exception $e) {
         $db->rollback();
         $erroredOut = self::load($cfg, $db, $p->getId());
         $erroredOut->setStatus(self::ERROR);
         self::save($db, $erroredOut);
         throw $e;
     }
 }