cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating x_amount on second page?

I found some posts similar to mine but not enough to resolve the issue I'm having with the x_amount field.  I'm already doing 2 pages but the user is not putting the price into the first form, it's being calculated on the 2nd page.  If I hard code any number into $amount (on the 2nd page) then everything works (other than the amount will obviously be wrong).  If I leave it as shown below, then I get (99) "This transaction cannot be accepted".  From what Ive read, it's probably because the amount is not calculated before the fingerprint is generated... how I can get around that without adding a 3rd page?

Here is my code (simplified down to 1 item). I have an initial form where the user selects quantities they want of each item (how many of item1, how many of item2, etc).

-First Form---------------------

<form  method="post" action="order_summary.php">
      <table width="376" border="1" cellspacing="0" cellpadding="0">
        <tr>
          <td align="right"><font size="5">Item</font></td>
          <td align="center"><font size="5">Quantity</font></td>
        </tr>
        <tr>
          <td width="241" align="right"><font size="5">Item1</font></td>
          <td width="129" align="center"><input name="item1" type="text" id="item1" size="3" maxlength="2" /></td>
        </tr>
        <tr>
          <td colspan="2" align="center"><input type="submit" name="submit" id="submit" value="View Order Summary" /></td>
        </tr>
      </table>
      </form>

-Second Form---------------------

<?php
require_once 'anet_php_sdk/AuthorizeNet.php';
$api_login_id = 'my login id';
$transaction_key = 'my transaction key';

if (isset($_POST['item1'])) $item1 = sanitizeString($_POST['item1']);
else $item1 = "0";

$item1total = 670.00 * $item1;

$totalall = array($item1total, $item2total... );

$formamount = array_sum($totalall) . "\n";

$amount = $formamount;

$fp_timestamp = time();
$fp_sequence = "123" . time();
$fingerprint = AuthorizeNetSIM_Form::getFingerprint($api_login_id,
  $transaction_key, $amount, $fp_sequence, $fp_timestamp)
?>

 <form method='post' action="https://test.authorize.net/gateway/transact.dll">    
          
          <table width="600" border="1" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td align="right"><font size="5">Item</font></td>
              <td align="center"><font size="5">Quantity</font></td>
              <td align="center"><font size="5">Total</font></td>
            </tr>
            <tr>
              <td width="452" align="right"><font size="5">Item1</font></td>
              <td width="142" align="center"><font size="5"><?php echo $item1 ?></font></td>
              <td width="142" align="center"><font size="5">$<?php echo $item1total ?></font></td>
            </tr>
            <tr>
              <td align="center">
 
 <?php

if ($item1 > 0)
  echo <<<_END
   <input type="HIDDEN" name="x_line_item" value="Item<|>State Fair item1<|>QVS-350<|>$item1<|>$item1total<|>Y" />
_END;
?>
                <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="Continue to secure order form" />
              </td>
              <td align="center"><font size="5">Order Subtotal</font></td>
              <td align="center"><font size="5">$<?php echo $formamount ?></font></td>
            </tr>
          </table>
        </form>
<?php           
</table>
<p></p>

 

Thanks in advance!

:smileytongue:

M~

 

nyliram
Member
1 ACCEPTED SOLUTION

Accepted Solutions

What I'm saying is that your page 2 would have people enter an amount, then post to page 3, which would essentially have a hard-coded amount because they entered it in page 2 and you'd know what it is now in advance. As I said before, put in $_POST['amount'] (or whatever your field name is on page 2) wherever it has $amount. After first verifying that $_POST['amount'] is a dollar amount greater than 0 (or your transaction minimum, whatever that is).

View solution in original post

6 REPLIES 6

You add a third page, but have it auto-submit so the user doesn't really notice. Something like:

 

<body onload="document.forms.myformname.submit();">
or:
<body onload="document.forms[0].submit();">

 

TJPride
Expert

Thank  you! (didn't know you could do that!)  :)

 

So... would I need to move the "logon ID and Transaction key, etc" variables to that 3rd page, or just pass all the variables from page 2 to page 3?

 

Sorry, but could you give me an example of what would be on the 3rd page?

 

Thanks,

:smileyfrustrated:

M~

The form where the person enters the amount they're paying would submit to the third page, which would use something pretty close to the sample code. For instance, if using the PHP SIM API:

https://developer.authorize.net/integration/fifteenminutes/#hosted

 

Substitute $_POST['amount'] for $amount. Note that you will want to verify on the previous page that they're actually submitting with a valid (greater than 0) amount, so when you go to this page it can submit straight to Authorize.net without causing an error. You'd use a snippet of Javascript for that as well, triggered <form onsubmit="code here"

hmm... using the sample code (https://developer.authorize.net/integration/fifteenminutes/#hosted) yields the exact same results.  I can "echo" the amount when this page loads, so I know it's posting the correct number, but submitting this 3rd page yields the same "(99) This transaction cannot be accepted".  If I hard code in an amount ($amount ="5.99"; like in the sample code) then it goes through... so I dont' think this 3rd page is buying me anything after all.


wouldn't it be common to pass a variable for the total as opposed to a hard-coded number?  I don't have to add in tax or shipping, but when people do have to do calculations, are they (and if so how) are they passing a hard-coded number?

 

Thanks (in advance again)

M~

What I'm saying is that your page 2 would have people enter an amount, then post to page 3, which would essentially have a hard-coded amount because they entered it in page 2 and you'd know what it is now in advance. As I said before, put in $_POST['amount'] (or whatever your field name is on page 2) wherever it has $amount. After first verifying that $_POST['amount'] is a dollar amount greater than 0 (or your transaction minimum, whatever that is).

I see it now... thank you very much TJPride

:smileywink: