2

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.

2

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

  • Ok, allow me to explain further. The payment method i'm implementing is similar to any 3dsecure payment method. – Unckmania Apr 2 '13 at 18:28
  • I'm afraid that doesn't tell me a whole lot more but to be honest I've never worked on custom credit card modules. I'm kinda guessing here that the electronic banking platforms in the Netherlands work somewhat in the same way – Sander Mangel Apr 2 '13 at 18:35
  • Ok, allow me to explain further. The payment method i'm implementing is similar to any 3dsecure payment method, You have to send some values via POST, and then the process travel to another page, where more data could be asked of the client, depending on their card provider, then after it's done, it returns to a page defined by the developer with return variables that determine stuff like amount payed, status, result, etc. I'm not sure if curl could work that way, regarding the fact that sometimes it asks more information to the client. – Unckmania Apr 2 '13 at 18:36
  • I pressed enter too soon, on my first comment, sorry. – Unckmania Apr 2 '13 at 18:39
  • Then it's exactly like the methods I worked with, in most cases the company will provide you with some documentation and it's required to sent an XML or post first then redirect the client afterwards. I'd ask the credit card issuer for some documentation. Im afraid I can't help you more with this – Sander Mangel Apr 2 '13 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.