Magento – The requested Payment Method is not available

magento-1.9sales-order

I'm trying to create order programmatically by following code but getting payment not available.

$customer = Mage::getModel('customer/customer')->load($data->user);
$quote =Mage::getSingleton('checkout/session')->getQuote(); 
// Assign Customer To Sales Order Quote
$quote->assignCustomer($customer);          
$quote->getBillingAddress();
$quote->getShippingAddress();

// Collect Rates and Set Shipping & Payment Method
$shippingAddress->setCollectShippingRates(true)
          ->collectShippingRates()
          ->setShippingMethod('flatrate_flatrate')
          ->setPaymentMethod('checkmo');
$quote->getPayment()->importData(array('method' => 'checkmo'));
try {
    // Collect Totals & Save Quote
    $quote->collectTotals()->save();
    // Create Order From Quote
    $service = Mage::getModel('sales/service_quote', $quote);
    $service->submitAll();
    $increment_id = $service->getOrder()->getRealOrderId();
}
catch (Exception $ex) {
    echo $ex->getMessage();
}
catch (Mage_Core_Exception $e) {
    echo $e->getMessage();
}
$quote = $customer = $service = null;
// Finished
echo  $increment_id;

Best Answer

It's difficult to track without the full quote information & your store configuration, but have a look at the source of the error, from app/code/core/Mage/Sales/Model/Quote/Payment.php's importData function:

...
$this->getQuote()->collectTotals();

if (!$method->isAvailable($this->getQuote())
    || !$method->isApplicableToQuote($this->getQuote(), $data->getChecks())
) {
    Mage::throwException(Mage::helper('sales')->__('The requested Payment Method is not available.'));
}

There are two reasons you may be getting this error, either:

  1. The method is not available, or,
  2. The method is not applicable to the quote

Firstly, check that the method for Cheque / Money Order is enabled in SystemConfigurationSalesPayment Methods

Secondly, check that your quotation is satisfying the requirements of the payment method (minimum order total, maximum order total, allowed countries etc.)

Related Topic