cancel
Showing results for 
Search instead for 
Did you mean: 

SIM - Unique $amount for each Payment

Hey everybody!

I've build a calendar on my WordPress website, which contains different events. Some of these events cost money to attend to and for processing the payments I've chosen Authorize.Net. I spoke to Brandon from the "Live Help" tap and he said I should use SIM for this. I've therefore found the sample code on www.authorize.net for this.

 

</head>
<body>

<!-- This section generates the "Submit Payment" button using PHP           -->
<?php
// This sample code requires the mhash library for PHP versions older than
// 5.1.2 - http://hmhash.sourceforge.net/
	
// the parameters for the payment can be configured here
// the API Login ID and Transaction Key must be replaced with valid values
$loginID		= "API_LOGIN_ID";
$transactionKey = "TRANSACTION_KEY";
$amount 		= "19.99";
$description 	= "Sample Transaction";
$label 			= "Submit Payment"; // The is the label on the 'submit' button
$testMode		= "false";
// By default, this sample code is designed to post to our test server for
// developer accounts: https://test.authorize.net/gateway/transact.dll
// for real accounts (even in test mode), please make sure that you are
// posting to: https://secure.authorize.net/gateway/transact.dll
$url			= "https://test.authorize.net/gateway/transact.dll";

// If an amount or description were posted to this page, the defaults are overidden
if (array_key_exists("amount",$_REQUEST))
	{ $amount = $_REQUEST["amount"]; }
if (array_key_exists("amount",$_REQUEST))
	{ $description = $_REQUEST["description"]; }

// an invoice is generated using the date and time
$invoice	= date(YmdHis);
// a sequence number is randomly generated
$sequence	= rand(1, 1000);
// a timestamp is generated
$timeStamp	= time();

// The following lines generate the SIM fingerprint.  PHP versions 5.1.2 and
// newer have the necessary hmac function built in.  For older versions, it
// will try to use the mhash library.
if( phpversion() >= '5.1.2' )
	{ $fingerprint = hash_hmac("md5", $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey); }
else 
	{ $fingerprint = bin2hex(mhash(MHASH_MD5, $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey)); }
?>

<!-- Print the Amount and Description to the screen. -->
Amount: <?php echo $amount; ?> <br />
Description: <?php echo $description; ?> <br />

<!-- Create the HTML form containing necessary SIM post values -->
<form method='post' action='<?php echo $url; ?>' >
<!--  Additional fields can be added here as outlined in the SIM integration
 guide at: http://developer.authorize.net -->
	<input type='hidden' name='x_login' value='<?php echo $loginID; ?>' />
	<input type='hidden' name='x_amount' value='<?php echo $amount; ?>' />
	<input type='hidden' name='x_description' value='<?php echo $description; ?>' />
	<input type='hidden' name='x_invoice_num' value='<?php echo $invoice; ?>' />
	<input type='hidden' name='x_fp_sequence' value='<?php echo $sequence; ?>' />
	<input type='hidden' name='x_fp_timestamp' value='<?php echo $timeStamp; ?>' />
	<input type='hidden' name='x_fp_hash' value='<?php echo $fingerprint; ?>' />
	<input type='hidden' name='x_test_request' value='<?php echo $testMode; ?>' />
	<input type='hidden' name='x_show_form' value='PAYMENT_FORM' />
	<input type='submit' value='<?php echo $label; ?>' />
</form>

</body>
</html>

 

My question is then. Since each event has a different price-tag, how do I manage this? Because in this sample code I'm only capable of assigning one $amount and that's when modifying with the "sim.php"-file. What I'm interested in is creating a unique $amount for each event and through some sort of Adminstrator Panel rather then the client have to dig into a ton of code.

Could you help me or guide me in the right direction? I've been battling for a week now searching through every inch of the Internet without any promising result.

FredrixDesign
Member
1 ACCEPTED SOLUTION

Accepted Solutions

You have to store the events they want to sign up for in some way that allows you to total them up and then generate a form for just that amount using the method you already listed. I suggest looking into PHP sessions if you aren't experienced with databases and cookies:

http://www.php.net/manual/en/book.session.php

View solution in original post

TJPride
Expert
1 REPLY 1

You have to store the events they want to sign up for in some way that allows you to total them up and then generate a form for just that amount using the method you already listed. I suggest looking into PHP sessions if you aren't experienced with databases and cookies:

http://www.php.net/manual/en/book.session.php

TJPride
Expert