The form I've developed asks for an expiration date MONTH and YEAR as separate input values, since people can have trouble entering the format expected by Authorize.net.
I'm coding in PHP and using the suggested three files used in the DPM developer's guide: checkout_form.php, response_relay.php, and receipt_page.php
How do I take these input values (MM and YY) and combine them (MM/YY) before sending them to ANet for authentication? And at what point do I do that?
Solved! Go to Solution.
09-28-2011 02:43 PM
Include a hidden field called x_exp_date, then try putting this in your form tag (untested, but it should theoretically work):
onSubmit="this.x_exp_date.value = this.exp_month.value + '/' + this.exp_year.value;"
09-30-2011 01:48 AM
That's a good question. The AIM interface uses (for April 2017) 0417, the ARB interface uses 2017-04, and the default test value for DPM indicates 04/17. All of those -might- work, but if I had to guess, I'd say use that last one. In answer to your question - you could hack the form and have a hidden field called x_card_num that gets filled onSubmit() for the form, or you could have a pulldown that gives all possible year / month possibilities for the next 15 years or so. Neither option is really optimal, however. You could also just make it a text field (like in the sample form) and include a note saying to fill it out in MM/YY format. If you put in a maxlength of 5 characters, most people will take the hint. Sadly, you can't just layer in an extra form and combine the values yourself before auto-submitting to Authorize.net, because that would require collecting credit card data on your server and void all the advantages of using DPM in the first place.
To be honest, I don't know why there isn't obvious support for month / year fields.
09-28-2011 10:22 PM - edited 09-28-2011 10:22 PM
I like the onSubmit idea, though I don't know how to write that into the form.
If my form HTML is the following:
<input type="text" name="exp_month" maxlength="2" />
<input type="text" name="exp_year" maxlength="2" />
<input type="submit" value="GO" />
How do I write the onSubmit to combine the fields to be MM/YY?
09-29-2011 10:11 AM
Include a hidden field called x_exp_date, then try putting this in your form tag (untested, but it should theoretically work):
onSubmit="this.x_exp_date.value = this.exp_month.value + '/' + this.exp_year.value;"
09-30-2011 01:48 AM
TJPrides solution should work. Alternatively, I created a variable in my verification script that runs after the form is submitted. The $ signs are used for jQuery.
var cc_exp_date = $('#cc-exp_month').val() + "/" + $('#cc-exp_year').val();
09-30-2011 11:46 AM
Make sure that you also clear the entry fields for month and year after you have combined them into the correct value. Otherwise, Authorize.Net will treat them as merchant defined fields and echo them back to you in the transaction results. This could have potential PCI implications, since it means you would be recieving the expiration date to your server.
09-30-2011 03:23 PM
Thanks, all!
I used TJPride's idea of adding the onSubmit script to the form tag. For anyone following along, my working form looks like this (as added to the AuthorizeNetDPM.php). Please excuse the escaping quotes all over the place!
$form = "
<form method=\"post\" action=\"$post_url\" id=\"paymentForm\" onSubmit=\"this.x_exp_date.value = this.exp_month.value + '/' + this.exp_year.value;\">
$hidden_fields
<input type=\"text\" name=\"x_card_num\" />
<input type=\"text\" name=\"exp_month\" />
<input type=\"text\" name=\"exp_year\" />
<input type=\"submit\" name=\"submit\" value=\"Pay with Credit Card\" />
<input type=\"hidden\" name=\"x_exp_date\" />
</form>";
return $form;
10-03-2011 11:02 AM
If as Trevor noted, you need to clear the month and year fields as well, then the Javascript should instead read like:
onSubmit="this.x_exp_date.value = this.exp_month.value + '/' + this.exp_year.value; this.exp_month.value = null; this.exp_year.value = null;"
10-03-2011 08:09 PM