Showing results for 
Search instead for 
Did you mean: 

Newbie needs help with SIM.php

Hello all,


I'm a newbie at this and I just need some advice on how to take the default SIM.php page provides and set it up so the user can enter a custom dollar amount to pay. I'm not proficient enough in PHP to make it happen on my own. I understand that I have to make the x_amount field visible, etc. and from there I would think I should just make the value blank so a user can enter their own amount. But from there, don't know how to code it. Any help would be greatly appreciated.

This is the default:


require_once 'anet_php_sdk/AuthorizeNet.php'; // Include the SDK you downloaded in Step 2
$api_login_id = 'xxxxxxxxxx';
$transaction_key = 'xxxxxxxxx';
$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)

<form method='post' action="">
<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?>" />
<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="Click here for the secure payment form">


The problem is that the $fingerprint value is calculated partly based off amount, so if the amount is not pre-determined, the fingerprint will be incorrect and the form will fail. So there is essentially only one way you can do this - you have to have a page where they fill out the amount (using a form with just a single field 'amount'), then that submits to another page which does all the stuff you listed (only with $amount being $_POST['amount'] and $_POST['amount'] being validated using round() to make sure they aren't trying to inject something bad). That second page can either be a verification page "You chose to donate x amount, click Go to donate now" or it can be auto-submit (onload="document.forms.myformname.submit();" in your body tag) so they are forwarded more or less invisibly and don't know it's a two-step process rather than one. Personally, I'd choose auto-submit.


Really, this is fairly simple.