OpenMage / magento-lts

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
https://www.openmage.org
Open Software License 3.0
869 stars 436 forks source link

PayPal missing transaction types #1426

Open Rahza opened 3 years ago

Rahza commented 3 years ago

In the Ipn model, only txn_type "recurring_payment" will be processed for recurring payments. However, PayPal also sends IPN messages with other txn_types such as "recurring_payment_profile_created" or "recurring_payment_suspended".

if (isset($this->_request['txn_type']) && 'recurring_payment' == $this->_request['txn_type']) {
    $this->_getRecurringProfile();
    if ($httpAdapter) {
        $this->_postBack($httpAdapter);
    }
    $this->_processRecurringProfile();
} else {
    $this->_getOrder();
    if ($httpAdapter) {
        $this->_postBack($httpAdapter);
    }
    $this->_processOrder();
}

The request will enter the else {} branch above and consequently fail and return HTTP 503, because _getOrder will try to load an order, but there is not parameter "invoice" in the request.

protected function _getOrder()
{
    if (empty($this->_order)) {
        // get proper order
        $id = $this->_request['invoice'];
        $this->_order = Mage::getModel('sales/order')->loadByIncrementId($id);
        if (!$this->_order->getId()) {
            $this->_debugData['exception'] = sprintf('Wrong order ID: "%s".', $id);
            $this->_debug();
            Mage::app()->getResponse()
                ->setHeader('HTTP/1.1','503 Service Unavailable')
                ->sendResponse();
            exit;
        }
        // re-initialize config with the method code and store id
        $methodCode = $this->_order->getPayment()->getMethod();
        $this->_config = Mage::getModel('paypal/config', array($methodCode, $this->_order->getStoreId()));
        if (!$this->_config->isMethodActive($methodCode) || !$this->_config->isMethodAvailable()) {
            throw new Exception(sprintf('Method "%s" is not available.', $methodCode));
        }

        $this->_verifyOrder();
    }
    return $this->_order;
}

Are there any plans to implement the missing txn_types? Has anybody already solved this issue?

colinmollenhour commented 3 years ago

Hi @Rahza, thanks for opening this issue. OpenMage is very much a community project and we depend on the community to provide patches that are important to them. If you can provide a Pull Request with the fix we will review it and merge it into the core once it passes review. The entire OpenMage community would be very grateful to you for contributing, especially the IPN users!