Magento – Need help passing form values from checkout to a redirect page that goes to an external payment gateway

externalmodulepayment-gateway

I need help in developing an external payment method module.

I have so far already managed to get the method to appear correctly on the admin, and on the checkout page. The next step is to send some of the values gathered in the form through a POST method that I have already set up on a redirect page, after "Place Order"

And this is where I have a problem.

I don't know how to call the values gathered on the form so I can send them on my redirect page to their destination.

That's my current problem. The problem I will have next is setting up a response page that gathers the information received by the external service and acts accordingly.

If I can't bother you to check out all of my code which I link bellow, I'll try to summarize here. I have made a mix of a couple of payment method tutorials, and the default Cc payment method, so there may be a few extra lines I am not requiring. I'm using the exact same form that Cc uses, since I need the exact same values, with the exact same validation (minus a few card types). (I probably should have extended the Cc method, right? I just realized while writing this…)

Form is the same as Cc, so a card number field looks like this:

<label for="<?php echo $_code ?>_cc_number" class="required"><em>*</em><?php echo $this->__('Credit Card Number') ?></label>
        <div class="input-box">
            <input type="text" id="<?php echo $_code ?>_cc_number" name="payment[cc_number]" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type" value="" />
        </div>    

The model gathers the data in a method called assign data like this:

public function assignData($data)
{
    if (!($data instanceof Varien_Object)) {
        $data = new Varien_Object($data);
    }
    $info = $this->getInfoInstance();
    $info->setCcType($data->getCcType())
        ->setCcOwner($data->getCcOwner())
        ->setCcLast4(substr($data->getCcNumber(), -4))
        ->setCcNumber($data->getCcNumber())
        ->setCcCid($data->getCcCid())
        ->setCcExpMonth($data->getCcExpMonth())
        ->setCcExpYear($data->getCcExpYear())
        ->setCcSsIssue($data->getCcSsIssue())
        ->setCcSsStartMonth($data->getCcSsStartMonth())
        ->setCcSsStartYear($data->getCcSsStartYear())
        ;

    return $this;
}

And my redirect method, (which is already being properly called, but with default values) is a bunch of these:

<input type="hidden" value="5111111111111118" name="Card">

I need to be able to take the data from the form and place it in the values on my redirect. I have some ideas gathered from here and there, which involve using checkout session variables, but I'm open to anything.

https://dl.dropbox.com/u/17685301/app.rar

I'm copying my code in this dropbox link if you can be bothered. I am aware I'm mixing from a lot of places here but I think it's mostly ok since Magento tends to die if just one piece is missing from the puzzle.

Yes, I'm a noob, but I'm really trying hard to get the hang of Magento. Thanks in advance.

Best Answer

Im not sure if the payment platform you are talking about is something self build or a payment platform that doesn't have a Magento module.

If we're talking about an existing payment platform that doesn't have a Magento module you're wise to consult their documentation on how to transfer the data to them. They should have that. It depends on their architecture what the best method is.

If you are talkin about a self build platform this might help a little: I think you're best of using cUrl to send the initial data to the platform you're redirecting to. Sending the data while redirecting makes it vulnerable to tampering.

define('SECRET_SALT', 'randomstring');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/createtoken");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
    'amount' => 5.00,
    'orderid' => '1000000007',
    'checksum' => hash('sha512', SECRET_SALT . '5.00' . '1000000007'),
), '', '&'));

$token = curl_exec($ch);
curl_close($ch);

header('location: http://www.example.com/redirectpage.php?token='.$token);

This will first send all the information to the platform that processes the transaction, returns a token that you include when you redirect the user. On this custom build payment platform you can then use the token to retrieve the information you previously posted to the platform.

Let me know if you have any more questions or information. Also, the method discribed above is in no way 100% secure, you might need to look into building extra checks to make sure the right amount is payed and linked to the right order