merchant:epaymentform:randominvoice

Generating a unique invoice number with Javascript

On your web page

You can generate a unique invoice number for each transaction by adding a small script above the code you use to link to the payment form. It's not visible to your client. Providing an invoice number with every transaction may also give you a better qualifying transaction rate - ask your merchant service provider for information about transaction rates and fees.

Source Code

<form action="https://www.usaepay.com/interface/epayform/" name="form">
<input type="hidden" name="UMkey" value="SOURCE_KEY_GOES_HERE">
<input type="hidden" name="UMcommand" value="sale">
<input type="hidden" name="UMamount" value="10.99">
<input type="hidden" name="UMinvoice" value="">
 
<input type="hidden" name="UMdescription" value="Thank you for your payment">
<input type="submit" value="Continue to Payment Form">
</form>
 
<script language="JavaScript">
var d = new Date();
function f(n) {	return n < 10 ? '0' + n : n; }	
 
var random_num = Math.floor(Math.random() * (99999999999 -  10000000000)) + 10000000000;
random_num = d.getFullYear() + f(d.getMonth()+1) + f(d.getDate()) + random_num; 
document.form.UMinvoice.value = random_num;
</script>

Where it goes

This code would go on your site, not on the actual payment form itself. This will generate a value that appears on your form with any other data you've posted to it.

What it looks like

The Order Number is the resulting unique invoice number for your transaction.

Download Source Code

The Zip file contains an HTML page with the above code. Just plug in your source key to make it live.

Download Here

On the payment form

In the header of the document, add the following code:

<script>
function addInvoice() {
var d = new Date();
function f(n) {	return n < 10 ? '0' + n : n; }	
 
var random_num = Math.floor(Math.random() * (99999999999 -  10000000000)) + 10000000000;
document.epayform.UMinvoice.value = random_num;
document.getElementById('invoice').innerHTML = random_num ;
 
}
</script> 

Locate the below command in the list of hidden values, and delete it:

<input type="hidden" name="UMinvoice" value="[UMinvoice]">

Find the following code in your form:

      <tr>
      <td bgcolor="#F0F0F0" width="234" align="right"><font size="2" face="Verdana">Order Amount:</font></td>
      <td bgcolor="#F0F0F0" width="450">[UMamount]
      </td>
      </tr>

And replace it with this:

                 <tr>
			<td bgcolor="#F0F0F0" width="234" align="right"><font face="Verdana" size="2">Order Amount:
			</font></td>
			<td bgcolor="#F0F0F0" width="450">
			<input type="text" name="UMamount" onClick="addInvoice()" size="25" value="[UMamount]"></td>
		</tr>

Find the following code in your form:

      <tr>
      <td bgcolor="#F0F0F0" width="234" align="right"><font size="2" face="Verdana">Order Number:</font></td>
      <td bgcolor="#F0F0F0" width="450">[UMinvoice]
      </td>
      </tr>

and replace with the following:

                 <tr>
			<td bgcolor="#F0F0F0" width="234" align="right"><font size="2" face="Verdana">Order Number:</font></td>
			<td bgcolor="#F0F0F0" width="450"><input type="hidden" name="UMinvoice"><div id="invoice"></div></td>
		</tr>

Save the changes to your form. Once the form is saved, the customer will be able to type in the amount they are paying and automatically have an invoice number.

What it looks like

The Order Number is the resulting unique invoice number for your transaction.

merchant/epaymentform/randominvoice.txt · Last modified: 2010/08/24 14:03 by irina

Page Tools