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
'simportData
function:There are two reasons you may be getting this error, either:
Firstly, check that the method for Cheque / Money Order is enabled in
System
→Configuration
→Sales
→Payment Methods
Secondly, check that your quotation is satisfying the requirements of the payment method (minimum order total, maximum order total, allowed countries etc.)