Integration and Testing

Authorize.Net API questions and help with your payment integration.

Reply
Member
Posts: 3
Registered: ‎09-28-2011
Accepted Solution

Split exp date, and join them

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?


Accepted Solutions
Solution
Accepted by topic author ggeiger
‎08-21-2015 01:58 AM
Posts: 1,609
Topics: 15
Kudos: 209
Solutions: 121
Registered: ‎06-23-2011

Re: Split exp date, and join them

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;"

 

View solution in original post


All Replies
Posts: 1,609
Topics: 15
Kudos: 209
Solutions: 121
Registered: ‎06-23-2011

Re: Split exp date, and join them

[ Edited ]

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.

Member
Posts: 3
Registered: ‎09-28-2011

Re: Split exp date, and join them

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?

 

 

Solution
Accepted by topic author ggeiger
‎08-21-2015 01:58 AM
Posts: 1,609
Topics: 15
Kudos: 209
Solutions: 121
Registered: ‎06-23-2011

Re: Split exp date, and join them

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;"

 

Contributor
Posts: 12
Registered: ‎09-28-2011

Re: Split exp date, and join them

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();
Administrator
Posts: 591
Registered: ‎08-21-2009

Re: Split exp date, and join them

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.

Member
Posts: 3
Registered: ‎09-28-2011

Re: Split exp date, and join them

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;

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

Re: Split exp date, and join them

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;"