magento auto order creation using credit card payment not saving order

magento auto order creation using credit card payment not saving order

October 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
magento auto order creation using credit card payment not saving order

Solving Magento Auto Order Creation Issues with Credit Card Payments

As a senior developer for Laravel Company, I frequently encounter challenges faced by our clients when working with e-commerce platforms like Magento. One common issue is the inability to automatically create orders using credit card payments.

The developer in this case has already attempted to set up automatic order creation using both ‘purchaseorder’ and ‘ccsave’ as payment methods. The script works perfectly for purchase orders but fails when trying to use a credit card:

$orderPayment = Mage::getModel('sales/order_payment')
    ->setStoreId($storeId)
    ->setCustomerPaymentId(0)
    ->setMethod('ccsave')
    ->setCcNumber('6011111111111117')
    ->setCcOwner('ooooo')
    ->setCcType('Discover')
    ->setCcExpMonth('9')
    ->setCcExpYear('2014')
    ->setCcLast4(substr('6011111111111117',-4));

The key to resolving this issue lies in properly validating and processing the credit card information.

Understanding Magento’s Credit Card Payment Processing

Magento uses a third-party payment method called PayPal Pro, which handles all credit card transactions securely. When you set up a new order using the ‘ccsave’ method, Magento expects certain additional parameters to be set for proper validation:

  1. CcCid: The card verification value (CVV) or card code ID is required by most payment gateways.

  2. CcStartMonth and CcStartYear: These fields are used to validate the card’s issue date.

  3. Add_data: This field contains additional data required by the specific payment gateway being used.

Setting Up Credit Card Payment Properly

To resolve the auto-order creation issue with credit card payments, you need to ensure that the following changes are made in your script:

  1. Set the missing parameters:
$orderPayment->setCcCid('123') // Example CVV value
    ->setCcStartMonth('07') // Example card issue month
    ->setCcStartYear('2021'); // Example card issue year
  1. Set the appropriate payment method code based on your configured gateway:
->setMethod('paypalpro')
    ->setAdditionalInformation(array(
        'cc_type' => 'Discover',
        'cc_number_encrypted' => base64_encode('6011111111111117'),
        'cc_exp_month' => '9',
        'cc_exp_year' => '2014'
    ))
  1. Ensure that the credit card information is properly encrypted before being passed to the payment gateway.

Encrypting Credit Card Information

Magento provides a built-in function called Mage::helper('core')->encrypt() for encrypting sensitive data like credit card numbers. You should use this function to securely handle and store credit card information:

$encryptedCardNumber = Mage::helper('core')->encrypt($cc_number);

Testing the Updated Script

After making these changes, your updated script should look something like this:

$orderPayment = Mage::getModel('sales/order_payment')
    ->setStoreId($storeId)
    ->setCustomerPaymentId(0)
    ->setMethod('paypalpro')
    ->setCcOwner('ooooo')
    ->setAdditionalInformation(array(
        'cc_type' => 'Discover',
        'cc_number_encrypted' => base64_encode('6011111111111117'),
        'cc_exp_month' => '9',
        'cc_exp_year' => '2014'
    ))
    ->setCcCid('123')
    ->setCcStartMonth('07')
    ->setCcStartYear('2021');

$order->setPayment($orderPayment);

Conclusion

Successfully automating the creation of orders using credit card payments in Magento requires a thorough understanding of the platform’s payment systems and proper handling of sensitive credit card information. By setting up the appropriate parameters for the chosen gateway and ensuring that data is encrypted before processing, you can create reliable automatic order generation scripts.

I encourage you to explore our comprehensive guides on e-commerce development at Laravel Company. If you have any further questions or need personalized assistance with your Magento projects, feel free to reach out to our expert team.

Orders Customers SEO Errors

Our network