0

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;
  • Did you enable cheque or money order payment method in admin panel ? – Kishan Patadia Jul 18 '17 at 6:16
  • yes it is enabled , i'm creating these orders by custom extension ,normal order works fine – HARI Jul 18 '17 at 6:19
  • check all condition is satisfied or not ( Payment from Specific Countries , Minimum Order Total ) for Check / Money order – Camit1dk Jul 18 '17 at 6:34
1

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.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.