public function getErrors(Config $cfg) { $i18n = Localization::getTranslator(); $walletSettings = []; $emailSettings = []; $providerClass = ''; try { $provider = $cfg->getWalletProvider(); $providerClass = get_class($provider); $provider->verifyOwnership(); } catch (Exception $e) { if (strpos($providerClass, 'CoinbaseWallet') !== false) { $walletSettings[] = ['id' => '#wallet-coinbaseApiKey-error', 'error' => $e->getMessage()]; } else { $walletSettings[] = ['id' => '#wallet-id-error', 'error' => $e->getMessage()]; } } try { $t = new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'); $t->setUsername($cfg->getEmailUsername())->setPassword($cfg->getEmailPassword())->start(); } catch (Exception $e) { $emailSettings[] = ['id' => '#email-username-error', 'error' => $e->getMessage()]; } $errors = []; if (!empty($pricingSettings)) { $errors['#pricing-settings'] = self::getPricingErrorsFromConfig($cfg); } if (!empty($walletSettings)) { $errors['#wallet-settings'] = $walletSettings; } if (!empty($emailSettings)) { $errors['#email-settings'] = $emailSettings; } return $errors; }
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; } }