/** * Class constructor * */ private function __construct() { $this->balanceDao = USERCREDITS_BOL_BalanceDao::getInstance(); $this->actionDao = USERCREDITS_BOL_ActionDao::getInstance(); $this->packDao = USERCREDITS_BOL_PackDao::getInstance(); $this->logDao = USERCREDITS_BOL_LogDao::getInstance(); }
public function purchase() { $creditValue = (double) $_POST['creditValue']; $buyingUser = (int) $_POST['buyingUser']; $itemName = $_POST['itemName']; $itemPrice = $_POST['itemPrice']; $itemCurrency = $_POST['itemCurrency']; $saleHash = $_POST['custom']; $transId = $_POST['transId']; $billingService = BOL_BillingService::getInstance(); $adapter = new BILLINGCREDITS_CLASS_CreditsAdapter(); $sale = $billingService->getSaleByHash($saleHash); if ($sale && $sale->status != BOL_BillingSaleDao::STATUS_DELIVERED) { $sale->transactionUid = $transId; if ($billingService->verifySale($adapter, $sale)) { $sale = $billingService->getSaleById($sale->id); $productAdapter = $billingService->getProductAdapter($sale->entityKey); if ($productAdapter) { $billingService->deliverSale($productAdapter, $sale); USERCREDITS_BOL_CreditsService::getInstance()->decreaseBalance($buyingUser, $creditValue); $actionId = 0; foreach (USERCREDITS_BOL_ActionDao::getInstance()->findActionsByPluginKey('billingcredits') as $action) { if ($action->actionKey == 'creditsbuy') { $actionId = $action->id; } } if ($actionId) { $log = new USERCREDITS_BOL_Log(); $log->actionId = $actionId; $log->userId = $buyingUser; $log->amount = (int) $creditValue; $log->logTimestamp = time(); USERCREDITS_BOL_LogDao::getInstance()->save($log); } } } } $this->redirect(BOL_BillingService::getInstance()->getOrderCompletedPageUrl()); }
public function getCreditHistoryCountForAllUsers() { $logDao = USERCREDITS_BOL_LogDao::getInstance(); $actionDao = USERCREDITS_BOL_ActionDao::getInstance(); $query = "SELECT COUNT(*)\n FROM " . $logDao->getTableName() . " l," . $actionDao->getTableName() . " a\n WHERE l.actionId = a.id\n AND l.actionId = " . $this->getSentActionId() . "\n AND a.isHidden = 0\n AND a.active = 1"; return (int) OW::getDbo()->queryForColumn($query); }