Last active
December 21, 2015 12:49
-
-
Save dakira/6308663 to your computer and use it in GitHub Desktop.
cronjob to fix magento orders marked as fraudulent because of paypal rounding error
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
#!/usr/bin/php | |
<?php | |
/* | |
* cronjob to fix ridiculous rounding bug with paypal | |
* @Author fabian krueger | |
* | |
* use this script on your risk! | |
* | |
* - modified to use SOAP-API, needs SOAP user with admin rights | |
* - needs to live in mage installation folder | |
* - creates invoices | |
* - needed to set memory_limit in /etc/php5/cli/php.ini to 256M | |
* (Matthias Niess <mniess at gmail com>) | |
*/ | |
// example for cron entry | |
// */10 * * * * /var/www/httpdocs/mage/fraud-cron.php >/dev/null 2>&1 | |
$user='apiuser'; $pass='apipassword'; | |
$email = "me@wherever.com"; | |
set_time_limit(1800); | |
require_once(dirname(__FILE__).'/app/Mage.php'); | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
if(Mage::getModel('api/user')->authenticate($user,$pass)){ | |
try { | |
$fraudOrders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status', 'fraud'); | |
foreach($fraudOrders as $fraudOrder){ | |
$orderId = $fraudOrder["increment_id"]; | |
$payment = $fraudOrder->getPayment(); | |
if(abs($payment["base_amount_ordered"] - $payment["base_amount_paid_online"]) <= 0.014){ | |
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId); | |
$state = 'processing'; | |
$status = 'processing'; | |
$comment = "Rundungsfehler durch Paypal. Der Status wurde automatisiert auf 'In Bearbeitung' gesetzt."; | |
$isCustomerNotified = false; | |
$order->setState($state, $status, $comment, $isCustomerNotified); | |
$order->save(); | |
if($order->canInvoice()) { | |
$invoiceId = Mage::getModel('sales/order_invoice_api')->create($order->getIncrementId(), array()); | |
$invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceId); | |
$invoice->pay(); | |
} | |
$order->sendNewOrderEmail(); | |
mail($email, "Changed fraudulent Order state", "Order: ".$orderId); | |
} | |
} | |
} catch (Exception $ex) { | |
Log::error($ex->getMessage()); | |
Log::error($ex->getTraceAsString()); | |
mail($email, "Error while attempting to change fraudulent Order state",print_r($ex)); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment