Question

Ok. This is getting a little frustrating. I am trying to create a custom payment module for Magento. The purpose is to use Authorize.net's CIM so that we don't have to worry so much about PCI compliance. The issue I am having is that the users need to be able to access their previous credit cards and use those for purchasing. I have the previous cards being stored in the database. They are also being displayed in the form in the checkout process.

My issue comes when I click continue after selecting the payment method. How do I get the values I submitted in the form? Specifically, the value of the radio button the saved code is attached to?

I am not sure what if any code is needed for me to post, so let me know if you need anything in particular.

Thanks.

Was it helpful?

Solution

Looking at the onepage checkout, payment data is retrieved from the payment[] form elements on the checkout page like this:

$data = $this->getRequest()->getPost('payment', array());
$result = $this->getOnepage()->savePayment($data);

That info gets saved into an actual payment using:

$payment->importData($data);

That means that fields imported this way should be available to your module's authorize() method, at which point you can go retrieve the right information to do the auth.

I hope that made sense. If not, post the HTML for the form as well as your authorize() method in the module.

Thanks, Joe

OTHER TIPS

There are a few good places where this post data is available to your payment method.

The best place to gain access to the post data fields is to override the assignData method in your payment method class. It should look something like this:

/**
 * Assign data to info model instance
 */
public function assignData($data)
{
    // Call parent assignData
    parent::assignData($data);

    // Get Mage_Payment_Model_Info instance from quote 
    $info = $this->getInfoInstance();

    // Add some arbitrary post data to the Mage_Payment_Model_Info instance 
    // so it is saved in the DB in the 'additional_information' field        
    $info->setAdditionalInformation(
        'arbitrary_post_field', 
        $data['arbitrary_post_field'];

    return $this;
}

Alternatively, you can rewrite Mage_Sales_Model_Quote_Payment::importData() and Mage_Checkout_Model_Type_Onepage::savePayment, which gives you more flexibility, as these methods will be called before Magento selects your specific payment method based on the payment code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top