public static function denormalize(Config $cfg) { $denormalized = ['selector' => '', 'sources' => [], 'staticPrice' => '', 'modifierEnabled' => [], 'modifier' => [], 'wallet' => ['id' => '', 'mainPass' => '', 'secondPass' => '', 'fromAddress' => ''], 'email' => ['username' => '', 'password' => ''], 'contact' => ['information' => ''], 'transaction-cron' => false, 'transactions' => [], 'coinee' => ['email' => '', 'apiKey' => '', 'bitstampId' => '']]; $cfgData = $cfg->asArray(); if (isset($cfgData['transactions']['maximum'])) { $denormalized['transactions']['maximum'] = $cfgData['transactions']['maximum']; } if (!empty($cfgData['transaction-cron'])) { $denormalized['transaction-cron'] = $cfgData['transaction-cron']; } $denormalized['wallet'] = $cfgData['walletProvider']; unset($denormalized['wallet']['provider']); $denormalized['email'] = $cfgData['email']; if (empty($denormalized['email']['machine'])) { $denormalized['email']['machine'] = 'Project Skyhook 00'; } if (!empty($cfgData['coinee'])) { $denormalized['coinee'] = $cfgData['coinee']; } $denormalized['contact']['information'] = @$cfgData['contact']['information']; $denormalized['selector'] = 'single'; $pp = $cfg->getPricingProvider(); if (!empty($pp)) { Config::walkPricingProviders($cfg->getPricingProvider(), function ($p) use(&$denormalized) { $name = get_class($p); if ($p instanceof PricingProxy) { if ($p instanceof PriceModifier) { $denormalized['modifierEnabled'][$name] = true; $denormalized['modifier'][$name] = strval($p->getValue()); } else { $denormalized['selector'] = $name; } } else { $denormalized['sources'][] = $name; if (preg_match('#.*StaticPrice$#', $name)) { $denormalized['staticPrice'] = strval($p->getPrice()); } } }); } $denormalized['sources'] = implode(',', $denormalized['sources']); return $denormalized; }
public function getPricingErrorsFromConfig(Config $cfg) { $i18n = Localization::getTranslator(); $pricingSettings = []; try { $price = $cfg->getPricingProvider()->getPrice(); if (!is_numeric($price->get())) { $pricingSettings[] = ['id' => '#sources-methods-error', 'error' => $i18n->_('Unknown format encountered:') . ' "' . $price . '".']; } } catch (Exception $e) { $pricingSettings[] = ['id' => '#sources-methods-error', 'error' => $e->getMessage()]; } return $pricingSettings; }
/** * Starts a new purchase * * @param DB $db a connection to the database * @param Amount $price required to start a new ticket. */ public static function create(Config $cfg, DB $db, BitcoinAddress $address) { $prepared = $db->prepare(' INSERT INTO `purchases` ( `customer_address`, `bitcoin_price`, `cur_code` ) VALUES ( :customer_address, :bitcoin_price, :cur_code ) '); $cur = $cfg->getCurrencyCode(); $result = $prepared->execute(array(':customer_address' => $address->get(), ':bitcoin_price' => $cfg->getPricingProvider()->getPrice()->get(), ':cur_code' => $cur)); if ($result === false) { throw new Exception("Unable to create new purchase ticket."); } return self::load($cfg, $db, $db->lastInsertId()); }