I'm working on changing various "order states" based on their statuses in magento when they come in via kount Ens.php. I've had some success with a couple of them but I can't seem to figure out the last three.
- When approved manually the state code needs to change to processing instead of payment_review.
- When declined maually the state code needs to change to holded instead of payment_review.
- When auto declined the state code needs to changed to canceled instead of payment_review.
Here's what I have currently:
/**
* Approve an order from Kount
*
* @param \Mage_Sales_Model_Order $order
*
* @return bool
*/
protected function _approveOrder(Mage_Sales_Model_Order $order)
{
// Ensure the status has not moved from it's payment review state
if ($order->getStatus() == Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW) {
// Inform the system that this update is occurring from an ENS update
Mage::register('kount_ens_update', true);
try {
$order->setStatus("fraud_cleared");
$order->save();
} catch (Exception $e) {
Gene_Braintree_Model_Debug::log('Accept Kount transaction failed to be accepted in Magento: ' . $e->getMessage());
Gene_Braintree_Model_Debug::log($e);
return false;
}
Mage::unregister('kount_ens_update');
$order->addStatusHistoryComment('Order approved through Kount.')->save();
return true;
}
return false;
}
/**
* Decline an order in Magento
*
* If the payment is only voidable, we void the invoice cancelling the order. If the payment has settled we create
* a credit memo and close the order that way.
*
* @param \Mage_Sales_Model_Order $order
*
* @return bool
*/
protected function _declineOrder(Mage_Sales_Model_Order $order)
{
// Ensure the status has not moved from it's payment review state
if ($order->getStatus() == Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW) {
// Inform the system that this update is occurring from an ENS update
Mage::register('kount_ens_update', true);
try {
$order->setState(Mage_Sales_Model_Order::STATE_HOLDED, "suspected_fraud_after_review");
$order->save();
} catch (Exception $e) {
Gene_Braintree_Model_Debug::log('Declined Kount transaction failed to be declined in Magento: ' . $e->getMessage());
Gene_Braintree_Model_Debug::log($e);
return false;
}
}
return false;
}
Here's some things i'm working on to fix:
try {
$order->setStatus("fraud_cleared")
->setState(Mage_Sales_Model_Order::STATE_PROCESSING)
->save();
} catch (Exception $e) {
Gene_Braintree_Model_Debug::log('Accept Kount transaction failed to be accepted in Magento: ' . $e->getMessage());
Gene_Braintree_Model_Debug::log($e);
return false;
}