vteam #602 was required to develop a recurring cart extension for Magento. The client wanted its customers to place orders automatically using a Cron script.
Creation of recurring cart functionality was a straight forward task. But the payment method for automatic orders was problematic. vteams engineer Tahir Yasin had to use Authorize.Net CIM Payment Gateway recommended by the client. This method was used to gather credit cards’ account information of customers. Once the account data was stored in the CIM, there would be no need of requiring that particular individual’s card number to access the information.
It was impossible to fetch the stored credit card account details and create a new order using that information. The data was tokenized and Magento required full credit card number, CVV, card expiry and billing address. Hence, the information was clearly unavailable. The following attempt didn’t work:
$savedCards = Mage::getModel('tokenbase/card')->getCollection(); $savedCards->addFieldToFilter('active', 1)->addFieldToFilter('customer_id', $customer_id); $card = $savedCards->getFirstItem(); $additional = $card->getAdditional(); $orderPayment = Mage::getModel('sales/order_payment') ->setStoreId(1) ->setCustomerPaymentId($card->getPaymentId()) ->setMethod('authnetcim') ->setCcNumberEnc($card->getHash()) ->setCcOwner('Tahir Yasin') ->setCcType($additional['cc_type']) ->setCcExpMonth($additional['cc_exp_month']) ->setCcExpYear($additional['cc_exp_year']) ->setCcLast4($additional['cc_last4']); $this->_order->setPayment($orderPayment);
Tahir tried taking the help from support team of cart extension that gave him a clue to use card hash instead of encrypted card number. He had to come up with a solution as the information wasn’t available on any internet forum.
Based on research, Tahir created a quote and converted it into order. After that, Authorize.Net CIM payment gateway was applied to the quote. The card hash was then added to the quote/order payment object. Using tokenized information, the payment method handled its billing.
The following cron script solved the issue using saved credit cards that placed orders automatically:
$quote->getPayment()->importData(array( 'method' => ‘authnetcim’, 'card_id' => $card->getHash(), ));