Magento – How to capture automatically Paypal authorization payment

cronmagento-1.9paypal

The payment action of PayPal it's set to authorization (I need it, I can't set to sale), therefore then I need to capture the payment.

I know that I can do it manually from the invoice sending page, but I need to capture the payment automatically after 6 hours from the order time.

Could you suggest how to do that cron, and the function to capture the money automatically after 6 hours?

Best Answer

The code to do it is fairly simple, you would need to create a cronjob and a datetime check.

if($order->getPayment()->getMethodInstance()->getCode() == 'paypal_express') {
    $invoice = $order->prepareInvoice();
    $invoice->register()->capture();
     Mage::getModel('core/resource_transaction')
        ->addObject($invoice)
        ->addObject($invoice->getOrder())
        ->save();
}
Related Topic