Reply
Highlighted
Member
Posts: 1
Registered: ‎07-23-2013

How do I pass user entered info to the DPM form?

This is the first project I have ever done using authorize.net as a service, so bear with me please.  I have used the "Quick Start Guide" for DPM and was easily able to generate the payents.  I then took that form in the AuthrizeNetDMP.php file and modified it to match the sites style.  Test payments performed flawlessly.

 

Now that I know the data is talking back and forth, I now would like to integrate it into the workflow the client desires.

 

After doing some research, I've generated a 2-step process that works like this to process 1 time payments while allowing users to enter their payment amount:

  1. User enters Account Number nad Payment Amount into a simple form.  That info gets passed onto a second page.
  2. They enter their address & card info on the second page.
  3. Payment gets sent to Authorize.net

The first form is very simple

<form action="LINK TO PAYMENT PAGE" method="post">

<input name="amount" /></input>

<input name="account" /></input>

 <input type="submit" value="Go"></input>

</form>

 

Then on the second page, I've tried modifying the form like this:

 

<?php

require_once 'anet_php_sdk/AuthorizeNet.php'; // The SDK
$url = "PAGE URL";
$api_login_id = 'MY LOGIN ID';
$transaction_key = 'MY TRANSACTION KEY';
$md5_setting = 'MY LOGIN ID'; // Your MD5 Setting
$amount = $_POST['amount'];

$account=$_POST['account'];
AuthorizeNetDPM::directPostDemo($url, $api_login_id, $transaction_key, $amount, $md5_setting);
?>

 

Now, I have verified that $amount & $account ate receiving the posted data, but when I attempt to do this, I get the following error.

 

"Error -- not AuthorizeNet. Check your MD5 Setting."

 

I would also like to pass  the $account variable to the AuthorizeNetDPM Page to include in the processing as well

 

Any help with this would be greatly appreciated.

 

 

 

 

 

Highlighted
Administrator Administrator
Administrator
Posts: 563
Registered: ‎08-03-2011

Re: How do I pass user entered info to the DPM form?

 

Hi,
 
The error you are getting (Error -- not AuthorizeNet. Check your MD5 Setting) is not related to the transaction flow that you are using. This error indicates that you have an invalid hash value in your account settings and in your code.

 

 

The DirectPostDemo is one specific demonstration of how DPM may be implemented. If you want to explore more flexibility and make your own implementation I recommend that you look at the code behind direct post demo.

 

Thanks,

Joy

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: How do I pass user entered info to the DPM form?

A proper implementation of DPM requires Javascript pre-validation of input, including using the Luhn algorithm to verify that the credit card number was typed properly. Things get even more messy if you have to deal with foreign addresses, since Authorize.net has no address2 field, so you have to smush address2 onto the end of address and hope it fits within the rather small character limit. I cheat and use AJAX to update my database as they type the address, so I don't have to rely on the address output from Authorize.net being 100% accurate.

 

Short version - this is only a starting point, but yes, you do have to look at the code inside getCreditCardForm() in the AuthorizeNetDPM.php file in in the lib folder of your SDK and adapt from there. To speed things up, here's a Javascript function for validating the credit card number.

 

function validate_credit_card(card) {
    // Remove valid separators
    card = card.replace(/[ \\-]/g, ''); 

    // Still contains non-digit characters
    if (card.match(/\\D/)) return;

    // American Express
    if (card.charAt(0) == '3') {
        if (card.length != 15 ||
            card.substr(0,2) != '34' && card.substr(0,2) != '37') return;
    }
    // Visa
    else if (card.charAt(0) == '4') {
        if (card.length != 13 && card.length != 16) return;
    }
    // MasterCard
    else if (card.charAt(0) == '5') {
        if (card.length != 16 ||
            card.substr(0,2) < '51' || card.substr(0,2) > '55') return;
    }
    // Discover
    else if (card.charAt(0) == '6') {
        if (card.length != 16 ||
            card.substr(0,4) != '6011' &&
           (card.substr(0,6) < '622126' || card.substr(0,6) > '622925') &&
           (card.substr(0,3) < '644' || card.substr(0,3) > '649') &&
            card.substr(0,2) != '65') return;
    }

    // Validate using Luhn algorithm
    var i, sum = 0, nums = card.split('');

    for (i = 0; i < nums.length; i++)
        nums[i] = parseInt(nums[i]);    
    for (i = nums.length - 2; i >= 0; i -= 2) {
        nums[i] *= 2;
    }
    
    for (i = 0; i < nums.length; i++) {
        if (nums[i] < 10) sum += nums[i];
        else {
            nums[i] = nums[i].toString();
            sum += parseInt(nums[i].charAt(0)) + parseInt(nums[i].charAt(1));
        }
    }

    if (sum % 10 == 0) return true;
}

Note that there are double \\ because I'm printing this out inside my PHP page. If you want this to work inside a regular HTML or Javascript file, you'll need to change \\ to \