cancel
Showing results for 
Search instead for 
Did you mean: 

code for a form allowing customers to input the amount

I'm trying to setup a form allowing the customers to input the amount to be paid.

 

SIM seems to be the one that will work, but I can't get it to accept the amount that is not fixed in the code. I just need it so there is a field for the customer to enter the amount on the invoice then click to go to the gateway.

 

Someone please tell me what and how I need to change it.  Thanks.

 

Here is the code.

 

<?php 
require_once
'anet_php_sdk/AuthorizeNet.php';// Include the SDK you downloaded in Step 2 
$api_login_id
='YOUR_API_LOGIN_ID'; 
$transaction_key
='YOUR_TRANSACTION_KEY'; 
$amount
="5.99"; 
$fp_timestamp
= time(); 
$fp_sequence
="123". time();// Enter an invoice or other unique number. 
$fingerprint
=AuthorizeNetSIM_Form::getFingerprint($api_login_id, 
  $transaction_key
, $amount, $fp_sequence, $fp_timestamp) 
?> 
 
<formmethod='post'action="https://test.authorize.net/gateway/transact.dll"> 
<input type='hidden' name="x_login" value="
<?php echo $api_login_id?>" /> 
<input type='hidden' name="x_fp_hash" value="
<?php echo $fingerprint?>" /> 
<input type='hidden' name="x_amount" value="
<?php echo $amount?>" /> 
<input type='hidden' name="x_fp_timestamp" value="
<?php echo $fp_timestamp?>" /> 
<input type='hidden' name="x_fp_sequence" value="
<?php echo $fp_sequence?>" /> 
<inputtype='hidden'name="x_version"value="3.1"> 
<inputtype='hidden'name="x_show_form"value="payment_form"> 
<inputtype='hidden'name="x_test_request"value="false"/> 
<inputtype='hidden'name="x_method"value="cc"> 
<inputtype='submit'value="Click here for the secure payment form"> 
</form>

nyakuro
Member
5 REPLIES 5

The problem is that the transaction fingerprint is generated partially based on the amount, so if you don't know what the amount is BEFORE you generate the fingerprint, you're going to get an error.

 

What you could do is have one form with just an amount field, that submits to another page that actually generates the form to submit to Authorize.net (either with an auto-submit, or with an order verification message with the amount displayed but not editable). This will solve your problem.

TJPride
Expert

Thanks for your response.

 

I was doing some reading and I guess form with amount field, post that to a verification page, then go to the gateway would be the method I would like to go. 

 

But what code do I need to put in the form to post to the verification page?  I'm assuming it will look similar to this, but I can't get this to work. Do do something with the form method?  I'm fairly new at this so I lost.

 

<FORM METHOD=POST ACTION="https://secure.authorize.net/gateway/transact.dll">

<span class="style7">By entering the information below, you agree to all the terms and conditons set above</span>.<br />
<% ret = InsertFP (loginid, txnkey, amount, sequence) %>

<INPUT TYPE=HIDDEN NAME="x_Login" VALUE="xxxxxxxxxxx">

<span class="style5">Please enter your Invoice Number</span>
<INPUT TYPE=TEXT NAME="x_invoice_num"><br />

<span class="style5">Please enter your Invoice Amount</span>
<INPUT TYPE=TEXT NAME="x_Amount"><br />

<INPUT TYPE=HIDDEN NAME="x_Login" VALUE="62ySJs2r3d6">

<INPUT TYPE=HIDDEN NAME="x_Show_Form" VALUE="PAYMENT_FORM">

<INPUT TYPE=SUBMIT VALUE="Click here for secure payment form">

</FORM>

Here's what the first page might have. Edit verify.php to whatever the name of your second page is.

 

<form method="post" action="verify.php">
I would like to pay $<input type="text" name="amount" size="6" maxlength="8" /><br />
<input type="submit" value="Verify Amount" />
</form>

 

And here's what the second page might have (untested):

 

<?php 
require_once 'anet_php_sdk/AuthorizeNet.php';
    // Include the SDK you downloaded in Step 2 

$api_login_id ='YOUR_API_LOGIN_ID'; 
$transaction_key ='YOUR_TRANSACTION_KEY'; 

$amount = round($_POST['amount'], 2);
if ($amount <= 2) {
    // Below cut-off, do something
}

$fp_timestamp = time(); 
$fp_sequence = '123' . time();
    // Enter an invoice or other unique number. 

$fingerprint = AuthorizeNetSIM_Form::getFingerprint($api_login_id,
    $transaction_key, $amount, $fp_sequence, $fp_timestamp) 

print <<<BLOCK
I am paying <b>\${$amount}</b>

<form method="post" action="https://test.authorize.net/gateway/transact.dll"> 
<input type="hidden" name="x_login" value="{$api_login_id}" /> 
<input type="hidden" name="x_fp_hash" value="{$fingerprint}" /> 
<input type="hidden" name="x_amount" value="{$amount}" /> 
<input type="hidden" name="x_fp_timestamp" value="{$fp_timestamp}" /> 
<input type="hidden" name="x_fp_sequence" value="{$fp_sequence}" /> 
<input type="hidden" name="x_version" value="3.1" /> 
<input type="hidden" name="x_show_form" value="payment_form" /> 
<input type="hidden" name="x_test_request" value="false" /> 
<input type="hidden" name="x_method" value="cc" /> 
<input type="submit" value="To the Secure Payment Form" /> 
</form>
BLOCK;
?>

 Anything further is left up to you. I do enjoy helping but there's limits to what you'll get for free :)

Thanks for your help TJPride.

 

I tried your solution but it doesn't work.  The first form works.  Then I created a verify.php and used the second part of the script.  Added the API and transaction key, uploaded to the server and tried.  I went to the first form, entered the amount then clicked the button to go to verify.php, but it brings up a blank page.  Not even a error.  I tried to change the test.authorize..... to secure.authorize.... and still nothing.

 

My knowledge on this is very limited and I'm not sure what else to try.

 

Ple~se help.

Well, the second page was untested for syntax errors, so something might theoretically have slipped through. Afraid I don't have the time to set up a test right now, however - this was just a concept demonstration and implementation is really more your job than mine. You can probably hire a local programmer for an hour or two to fix things up from here.