Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Expert’s help required - order is created but only credit card number is not displayed. 
 
katherinbridges
Jr. Member
 
Total Posts:  29
Joined:  2009-08-27
 

Hi,

I am using magento 1.6, i have a code to create order. This code is working fine and order is being created. Below is my code

$customer_id 2
$shopping_cart=array();
$part=array(\"PartId\"=>17\"Quantity\"=>5);
$shopping_cart[]=$part//repeat as necessary
$params=array(\"AccountNo\"=>$customer_id\"PartCart\"=>$shopping_cart);
$qoteid $this->PrepareOrder($params);        //workin
$this->createOrder($qoteid,\'ccsave\',true);    //working

function PrepareOrder($params
{
    
require_once \'app/Mage.php\';
    
$app Mage::app();
    
Mage::register(\'isSecureArea\'true); //no output before here, will get a session header error
    
foreach($params as $k=>$v
        
$$k=$v
    
}    
    $customerObj
=Mage::getModel(\'customer/customer\')->load($AccountNo);
    
$storeId=$customerObj->getStoreId();
    
$quoteObj=Mage::getModel(\'sales/quote\')->assignCustomer($customerObj); //sets ship/bill address
    
$storeObj=$quoteObj->getStore()->load($storeId);
    
$quoteObj->setStore($storeObj);
    
$productModel=Mage::getModel(\'catalog/product\');
    foreach(
$PartCart as $part{
        
foreach($part as $k=>$v
            
$$k=$v
        
}
        $productObj
=$productModel->load($PartId);
        
$quoteItem=Mage::getModel(\'sales/quote_item\')->setProduct($productObj);
        
$quoteItem->setQuote($quoteObj);
        
$quoteItem->setQty($Quantity);
        
$quoteObj->addItem($quoteItem);
    
}
    $quoteObj 
-> addMessage(\'Auto Order Code\');   //after separately
    
$quoteObj->collectTotals();
    
$quoteObj->save();
    
$quoteId=$quoteObj->getId();
    return 
$quoteId;
//end of function PrepareOrder

public function createOrder($quoteId$paymentMethod$paymentData
{
    $quoteObj 
Mage::getModel(\'sales/quote\')->load($quoteId); // Mage_Sales_Model_Quote
    
$items $quoteObj->getAllItems();
    
$quoteObj->reserveOrderId();
    
// set payment method 
    
$quotePaymentObj $quoteObj->getPayment(); // Mage_Sales_Model_Quote_Payment
    
$quotePaymentObj->setMethod($paymentMethod);
    
$quoteObj->setPayment($quotePaymentObj);
    
// convert quote to order
    
$convertQuoteObj Mage::getSingleton(\'sales/convert_quote\');
    
$orderObj $convertQuoteObj->addressToOrder($quoteObj->getShippingAddress());
    
$orderPaymentObj $convertQuoteObj->paymentToOrderPayment($quotePaymentObj);
    
// convert quote addresses
    
$orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getBillingAddress()));
    
$orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()));
    
// set payment options
    
$orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
    if (
$paymentData{
        
/*        $orderObj->getPayment()->setCcNumber($paymentData->ccNumber);
        $orderObj->getPayment()->setCcType($paymentData->ccType);
        $orderObj->getPayment()->setCcExpMonth($paymentData->ccExpMonth);
        $orderObj->getPayment()->setCcExpYear($paymentData->ccExpYear);
        $orderObj->getPayment()->setCcLast4(substr($paymentData->ccNumber,-4));
*/                
        
$orderObj->getPayment()->setCcNumber(\'6011111111111117\');
        
$orderObj->getPayment()->setCcOwner(\'ooooo\');
        
$orderObj->getPayment()->setCcType(\'Discover\');
        
//$orderObj->getPayment()->setCcType(\'DI\');
        
$orderObj->getPayment()->setCcExpMonth(\'9\');
        
$orderObj->getPayment()->setCcExpYear(\'2014\');
        
$orderObj->getPayment()->setCcLast4(substr(\'6011111111111117\',-4));
    
}
    
// convert quote items
    
foreach ($items as $item{
        
// @var $item Mage_Sales_Model_Quote_Item
        
$orderItem $convertQuoteObj->itemToOrderItem($item);
        
$options = array();
        if (
$productOptions $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct())) {
            $options 
$productOptions;
        
}
        
if ($addOptions $item->getOptionByCode(\'additional_options\')) {
            $options[\
'additional_options\'unserialize($addOptions->getValue());
        
}
        
if ($options{
            $orderItem
->setProductOptions($options);
        
}
        
if ($item->getParentItem()) {
            $orderItem
->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId()));
        
}
        $orderObj
->addItem($orderItem);
    
}    
    $orderObj
->setCanShipPartiallyItem(false);  
    try 
{
        $orderObj
->place();
    
catch (Exception $e){
        Mage
::log($e->getMessage());
        
Mage::log($e->getTraceAsString());
    
}    
    $orderObj
->save(); 
    
//$orderObj->sendNewOrderEmail(); 
    
return $orderObj->getId();    
}
The problem is that only credit card number is not stored and not displayed when you go in order detail page in admin panel. I think the parameter ($paymentData) need to be set according to the code which is commented.
$orderObj->getPayment()->setCcNumber($paymentData->ccNumber);
        
$orderObj->getPayment()->setCcType($paymentData->ccType);
        
$orderObj->getPayment()->setCcExpMonth($paymentData->ccExpMonth);
        
$orderObj->getPayment()->setCcExpYear($paymentData->ccExpYear);
        
$orderObj->getPayment()->setCcLast4(substr($paymentData->ccNumber,-4));
I am not getting understand how I can make this parameter\’s value before to pass it to function, therefore I passed (true).
I believe if I pass the correct value of this parameter it would work correctly. So I need to make this parameter value. I have spent 3 days to adjust this but in vain.
I have got this code from this Thank youURL , there is post by
[michael_g08] where a file (createOrder.php) has been attached.
I am very thankful for any sort of help.
 
Magento Community Magento Community
Magento Community
Magento Community
 
suneth2
Jr. Member
 
Total Posts:  9
Joined:  2011-02-27
 

hello did u found a solution smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
farik
Jr. Member
 
Total Posts:  1
Joined:  2012-11-22
 

Hello. I had the same problem. I replaced
if ($paymentData) {

/* $orderObj->getPayment()->setCcNumber($paymentData->ccNumber);
$orderObj->getPayment()->setCcType($paymentData->ccType);
$orderObj->getPayment()->setCcExpMonth($paymentData->ccExpMonth);
$orderObj->getPayment()->setCcExpYear($paymentData->ccExpYear);
$orderObj->getPayment()->setCcLast4(substr($paymentData->ccNumber,-4));
*/
$orderObj->getPayment()->setCcNumber(\\\’6011111111111117\\\’);
$orderObj->getPayment()->setCcOwner(\\\’ooooo\\\’);
$orderObj->getPayment()->setCcType(\\\’Discover\\\’);
//$orderObj->getPayment()->setCcType(\\\’DI\\\’);
$orderObj->getPayment()->setCcExpMonth(\\\’9\\\’);
$orderObj->getPayment()->setCcExpYear(\\\’2014\\\’);
$orderObj->getPayment()->setCcLast4(substr(\\\’6011111111111117\\\’,-4));
}
to this
$orderObj->getPayment()->importData(array(\’method\’ => \’ccsave\’,
\’cc_number\’=>\’4111111111111111\’,
\’cc_owner\’=>\’gr\’,
\’cc_type\’=>\’VI\’,
\’cc_exp_month\’=>\’12\’,
\’cc_exp_year\’=>\’2016\’,
\’cc_last4\’=>\’1111\’,
\’cc_cid\’=>123
));
Credit card verification still doesn\’t work, so i had to comment out in class Mage_Payment_Model_Method_Cc
//validate credit card verification number
/* if ($errorMsg === false && $this->hasVerification()) {
$verifcationRegEx = $this->getVerificationRegEx();
$regExp = isset($verifcationRegEx[$info->getCcType()]) ? $verifcationRegEx[$info->getCcType()] : \’\’;
if (!$info->getCcCid() || !$regExp || !preg_match($regExp ,$info->getCcCid())){
$errorMsg = Mage::helper(\’payment\’)->__(\’Please enter a valid credit card verification number.\’);
}
} */
I suppouse you also have problem with credit card verification
PS sorry for my english

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top