/** * Validates pre-conditions on the callback. These represent things that likely wouldn't get fixed * (and generally shouldn't happen), so retries are not necessary. * * @return boolean */ public function validatePreConditions() { $itemParts = explode('|', $this->_filtered['custom'], 4); if (count($itemParts) != 4) { $this->logMessages[] = 'Invalid item (custom)'; return false; } list($userId, $userUpgradeId, $validationType, $validation) = $itemParts; $this->_user = XenForo_Model::create('XenForo_Model_User')->getFullUserById($userId); $this->_upgrade = $this->_upgradeModel->getUserUpgradeById($userUpgradeId); $tokenParts = explode(',', $validation); $transaction = $this->_upgradeModel->getProcessedTransactionLog($this->_filtered['ref']); $continue = $this->handleValidate(array(array('result' => $this->_user, 'message' => 'Invalid user'), array('result' => !(count($tokenParts) != 3 || sha1($tokenParts[1] . $this->_user['csrf_token']) != $tokenParts[2]), 'message' => 'Invalid validation'), array('result' => $this->_upgrade, 'message' => 'Invalid user upgrade'), array('result' => $this->_filtered['ref'], 'message' => 'No reference ID'))); if (!$continue) { return $continue; } if ($transaction) { if ($this->_filtered['type'] != self::PAYMENT_CHARGE_BACK) { $this->alreadyprocessed = true; $this->logMessages[] = 'Transaction already processed'; return false; } } $this->_upgradeRecord = $this->_upgradeModel->getActiveUserUpgradeRecord($this->_user['user_id'], $this->_upgrade['user_upgrade_id']); if ($this->_upgradeRecord) { $this->_upgradeRecordId = $this->_upgradeRecord['user_upgrade_record_id']; } return true; }
/** * Validates pre-conditions on the callback. These represent things that likely wouldn't get fixed * (and generally shouldn't happen), so retries are not necessary. * * @param string $errorString * * @return boolean */ public function validatePreConditions(&$errorString) { $itemParts = explode(',', $this->_filtered['custom'], 4); if (count($itemParts) != 4) { $errorString = 'Invalid item (custom)'; return false; } list($userId, $userUpgradeId, $validationType, $validation) = $itemParts; // $validationType allows validation method changes $user = XenForo_Model::create('XenForo_Model_User')->getFullUserById($userId); if (!$user) { $errorString = 'Invalid user'; return false; } $this->_user = $user; $tokenParts = explode(',', $validation); if (count($tokenParts) != 3 || sha1($tokenParts[1] . $user['csrf_token']) != $tokenParts[2]) { $errorString = 'Invalid validation'; return false; } $upgrade = $this->_upgradeModel->getUserUpgradeById($userUpgradeId); if (!$upgrade) { $errorString = 'Invalid user upgrade'; return false; } $this->_upgrade = $upgrade; if (!$this->_filtered['txn_id']) { $errorString = 'No txn_id'; return false; } $transaction = $this->_upgradeModel->getProcessedTransactionLog($this->_filtered['txn_id']); if ($transaction) { $errorString = 'Transaction already processed'; return false; } $upgradeRecord = $this->_upgradeModel->getActiveUserUpgradeRecord($this->_user['user_id'], $this->_upgrade['user_upgrade_id']); if ($upgradeRecord) { $this->_upgradeRecordId = $upgradeRecord['user_upgrade_record_id']; $this->_upgradeRecord = $upgradeRecord; } switch ($this->_filtered['txn_type']) { case 'web_accept': case 'subscr_payment': if ($upgradeRecord) { $extra = unserialize($upgradeRecord['extra']); $cost = $extra['cost_amount']; $currency = $extra['cost_currency']; } else { $cost = $upgrade['cost_amount']; $currency = $upgrade['cost_currency']; } if (round($this->_filtered['mc_gross'], 2) != round($cost, 2) || strtolower($this->_filtered['mc_currency']) != $currency) { $errorString = 'Invalid payment amount'; return false; } } return true; }
/** * Validates pre-conditions on the callback. These represent things that likely wouldn't get fixed * (and generally shouldn't happen), so retries are not necessary. * * @param string $errorString * * @return boolean */ public function validatePreConditions(&$errorString) { $itemParts = explode(',', $this->_filtered['custom'], 4); if (count($itemParts) != 4) { $errorString = 'Invalid item (custom)'; return false; } list($userId, $userUpgradeId, $validationType, $validation) = $itemParts; // $validationType allows validation method changes $user = XenForo_Model::create('XenForo_Model_User')->getFullUserById($userId); if (!$user) { $errorString = 'Invalid user'; return false; } $this->_user = $user; $tokenParts = explode(',', $validation); if (count($tokenParts) != 3 || sha1($tokenParts[1] . $user['csrf_token']) != $tokenParts[2]) { $errorString = 'Invalid validation'; return false; } $upgrade = $this->_upgradeModel->getUserUpgradeById($userUpgradeId); if (!$upgrade) { $errorString = 'Invalid user upgrade'; return false; } $this->_upgrade = $upgrade; if (!$this->_filtered['txn_id']) { $errorString = array('info', 'No txn_id. No action to take.'); return false; } $transaction = $this->_upgradeModel->getProcessedTransactionLog($this->_filtered['txn_id']); if ($transaction) { $errorString = array('info', 'Transaction already processed. Skipping.'); return false; } $upgradeRecord = $this->_upgradeModel->getActiveUserUpgradeRecord($this->_user['user_id'], $this->_upgrade['user_upgrade_id']); if ($upgradeRecord) { $this->_upgradeRecordId = $upgradeRecord['user_upgrade_record_id']; $this->_upgradeRecord = $upgradeRecord; } if (!$upgradeRecord && $this->_filtered['subscr_id']) { // do we have a log from a previous part of this subscription to work with? $parentLogs = $this->_upgradeModel->getLogsBySubscriberId($this->_filtered['subscr_id']); foreach (array_reverse($parentLogs) as $parentLog) { if ($parentLog['user_upgrade_record_id']) { $upgradeRecord = $this->_upgradeModel->getExpiredUserUpgradeRecordById($parentLog['user_upgrade_record_id']); if ($upgradeRecord) { $this->_upgradeRecordId = $upgradeRecord['user_upgrade_record_id']; $this->_upgradeRecord = $upgradeRecord; break; } } } } if (!$upgradeRecord && $this->_filtered['parent_txn_id']) { // do we have a log from a previous part of this transaction to work with? $parentLogs = $this->_upgradeModel->getLogsByTransactionId($this->_filtered['parent_txn_id']); foreach (array_reverse($parentLogs) as $parentLog) { if ($parentLog['user_upgrade_record_id']) { $upgradeRecord = $this->_upgradeModel->getExpiredUserUpgradeRecordById($parentLog['user_upgrade_record_id']); if ($upgradeRecord) { $this->_upgradeRecordId = $upgradeRecord['user_upgrade_record_id']; $this->_upgradeRecord = $upgradeRecord; break; } } } } switch ($this->_filtered['txn_type']) { case 'web_accept': case 'subscr_payment': $paymentAmountPassed = round($this->_filtered['mc_gross'], 2) == round($upgrade['cost_amount'], 2) && strtolower($this->_filtered['mc_currency']) == $upgrade['cost_currency']; if ($upgradeRecord && $upgradeRecord['extra']) { $extra = unserialize($upgradeRecord['extra']); $cost = $extra['cost_amount']; $currency = $extra['cost_currency']; $paymentAmountPassed = $paymentAmountPassed || round($this->_filtered['mc_gross'], 2) == round($cost, 2) && strtolower($this->_filtered['mc_currency']) == $currency; } if (!$paymentAmountPassed) { $errorString = 'Invalid payment amount'; return false; } } return true; }