Created
November 21, 2012 10:36
-
-
Save centerax/4124198 to your computer and use it in GitHub Desktop.
Cron.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Ebizmarts_SagePayReporting_Model_Cron | |
{ | |
public function getThirdmanScores($cron) | |
{ | |
$tblName = Mage::getSingleton('core/resource')->getTableName('sagepayreporting_fraud'); | |
$sagepayOrders = Mage::getResourceModel('sales/order_grid_collection'); | |
$sagepayOrders->getSelect() | |
->joinLeft(array ( | |
'pmnt' => $sagepayOrders->getTable('sales/order_payment' | |
)), | |
'main_table.entity_id = pmnt.parent_id', array ()) | |
->joinLeft(array ( | |
'sls' => $sagepayOrders->getTable('sales/order') | |
), | |
'main_table.entity_id = sls.entity_id', array ()) | |
->where("(pmnt.method = 'sagepaydirectpro' OR pmnt.method = 'sagepayserver' OR pmnt.method = 'sagepayserver_moto' OR pmnt.method = 'sagepaydirectpro_moto' OR pmnt.method = 'sagepayform' OR pmnt.method = 'sagepaypaypal') AND (main_table.entity_id NOT IN (SELECT order_id FROM ". $tblName ."))") | |
->limit(10); | |
$now = strtotime("now"); | |
foreach ($sagepayOrders as $_order) { | |
$_order = Mage::getModel('sales/order')->load($_order->getId()); | |
if(is_object($_order->getSagepayInfo())) { | |
$dbtrn = Mage::getModel('sagepaysuite2/sagepaysuite_transaction')->loadByVendorTxCode($_order->getSagepayInfo()->getVendorTxCode()); | |
//Get up to date transaction data from API | |
$update = $dbtrn->updateFromApi(); | |
//$rs = Mage::getModel('sagepayreporting/sagepayreporting')->getTransactionDetails($_order->getSagepayInfo()->getVendorTxCode()); | |
if (!$update->getFraud()) { | |
continue; | |
} | |
try { | |
$rs = $update->getFraud(); | |
$noresult = ((string)$rs->getThirdmanAction() == 'NORESULT'); | |
$orderPusOneDay = strtotime("+1 day", strtotime($_order->getCreatedAt())); | |
if(!$noresult || ($now > $orderPusOneDay)) { | |
# Update Thirdman score on DB | |
//Mage::getModel('sagepayreporting/fraud')->updateThirdMan($_order->getId(), $rs); | |
//This is done by $dbtrn->updateFromApi(); now | |
/** | |
* Automatic fulfill | |
*/ | |
$canAuthorise = ($dbtrn->getTxType() == 'AUTHENTICATE' && !$dbtrn->getAuthorised()); | |
$canRelease = ($dbtrn->getTxType() == 'DEFERRED' && !$dbtrn->getReleased()); | |
$rank = ( $this->_getCanRank() && ($this->_getRank() <= (int)$rs->getThirdmanScore()) ); | |
if(($canAuthorise || $canRelease) && $rank){ | |
Mage::getModel('sagepaysuite/api_payment')->invoiceOrder($_order->getId(), Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE); | |
} | |
/** | |
* Automatic fulfill | |
*/ | |
} | |
} catch (Exception $e) { | |
Sage_Log :: logException($e); | |
} | |
} | |
} | |
} | |
protected function _getCanRank() | |
{ | |
return Mage::getStoreConfigFlag('payment/sagepaysuite/auto_fulfill_low_risk_trn'); | |
} | |
protected function _getRank() | |
{ | |
return (int)Mage::getStoreConfig('payment/sagepaysuite/auto_fulfill_low_risk_trn_value'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment