cancel
Showing results for 
Search instead for 
Did you mean: 

Integrating DPM into my php smarty template

HI,  I have a php/smarty shopping cart program for restaurants that allows them to order online.  I have a billing page and would like to add the necessary script from DPM into this page as opposed to using the form that is in the DPM (found it on AuthorizeNetDPM.php in the SDK).  I have it working when I use the DPM alone...but I need it to be on my template instead (billing.php).  What is the best way for me to combine these two?  I have inserted the billing.php below.

 

<?

require_once("config.php");

if(!session_id()) session_start();

if(!empty($_POST)) {
@include_once($options['gateways_dir'].$_SESSION["pgw"].".class.php");
if(class_exists($_SESSION["pgw"])) {
$cl=$_SESSION["pgw"];
$tmpobj=new $cl();
if(!empty($tmpobj->name))
if($options[$cl."_enabled"]==1) {
$form=$tmpobj->action();
header("Location: index.php?id=2");
die;
}
}
}

$maintemplate="template.tpl";
$options["keywords"]=$options["name"].",".$options["city"].",".$options["address"].",".$options["keywords"];


require_once("user_header.php");
if(is_dir($options['gateways_dir'])) {
if($dh=opendir($options['gateways_dir'])) {
while(($file=readdir($dh))!==false) {
if(($file!='.')&&($file!='..'))
if(!is_dir($options['gateways_dir'].$file)) {
$fp=explode(".",$file);
if($fp[1]=="class" && $fp[2]=="php" && $fp[0]==$_SESSION["pgw"]) {
include_once($options['gateways_dir'].$file);
if(class_exists($fp[0])) {
$cl=$fp[0];
$tmpobj=new $cl();
if(!empty($tmpobj->name))
if($options[$cl."_enabled"]==1)
$form=$tmpobj->form();
}
}
}
}
closedir($dh);
}
}
$SMARTY->assign("form",$form);
$tpl="billing";

require_once("footer.php");

?>

 

I have read through the DPM instructions, but I guess that I really don't understand this process, can anyone help?

Thank you.

 

ommannet
Member
5 REPLIES 5

I'm not familiar with smarties, but I do know PHP, and that's rather messy, and I'm not talking about the indenting (you should repost in a code box - fourth option from the left in Rich Text mode). What part of this did you not understand, exactly?

 



// These are from further up in the code
const LIVE_URL = 'https://secure.authorize.net/gateway/transact.dll';
const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll';

$time = time();       
// $fp_sequence should be an invoice number or random number
$fp = self::getFingerprint($api_login_id, $transaction_key, $amount, $fp_sequence, $time);
$sim = new AuthorizeNetSIM_Form(
	array(
	'x_amount'        => $amount,
	'x_fp_sequence'   => $fp_sequence,
	'x_fp_hash'       => $fp,
	'x_fp_timestamp'  => $time,
	'x_relay_response'=> "TRUE",
	// Configure relay response URL in your control panel
	'x_relay_url'     => $relay_response_url,
	'x_login'         => $api_login_id,
	)
);
$hidden_fields = $sim->getHiddenFieldString();
// Need to redefine this line, you could just set the URL directly
$post_url = ($test_mode ? self::SANDBOX_URL : self::LIVE_URL);

print '
<form method="post" action="'.$post_url.'">
		'.$hidden_fields.'
	<fieldset>
		<div>
			<label>Credit Card Number</label>
			<input type="text" class="text" size="15" name="x_card_num" value="'.($prefill ? '6011000000000012' : '').'"></input>
		</div>
		<div>
			<label>Exp.</label>
			<input type="text" class="text" size="4" name="x_exp_date" value="'.($prefill ? '04/17' : '').'"></input>
		</div>
		<div>
			<label>CCV</label>
			<input type="text" class="text" size="4" name="x_card_code" value="'.($prefill ? '782' : '').'"></input>
		</div>
	</fieldset>
	<fieldset>
		<div>
			<label>First Name</label>
			<input type="text" class="text" size="15" name="x_first_name" value="'.($prefill ? 'John' : '').'"></input>
		</div>
		<div>
			<label>Last Name</label>
			<input type="text" class="text" size="14" name="x_last_name" value="'.($prefill ? 'Doe' : '').'"></input>
		</div>
	</fieldset>
	<fieldset>
		<div>
			<label>Address</label>
			<input type="text" class="text" size="26" name="x_address" value="'.($prefill ? '123 Main Street' : '').'"></input>
		</div>
		<div>
			<label>City</label>
			<input type="text" class="text" size="15" name="x_city" value="'.($prefill ? 'Boston' : '').'"></input>
		</div>
	</fieldset>
	<fieldset>
		<div>
			<label>State</label>
			<input type="text" class="text" size="4" name="x_state" value="'.($prefill ? 'MA' : '').'"></input>
		</div>
		<div>
			<label>Zip Code</label>
			<input type="text" class="text" size="9" name="x_zip" value="'.($prefill ? '02142' : '').'"></input>
		</div>
		<div>
			<label>Country</label>
			<input type="text" class="text" size="22" name="x_country" value="'.($prefill ? 'US' : '').'"></input>
		</div>
	</fieldset>
	<input type="submit" value="BUY" class="submit buy">
</form>';

Then go to the PHP implementation section in the DPM documentation:

http://www.authorize.net/support/DirectPost_guide.pdf

 

The rest of the sequence (relay response page, receipt page) should be fairly straightforward, I would think.

TJPride
Expert

Well.., I think I am confused with the directpost.php demo...,

 

1. Can I just place this code at the top of my billing page? Including the API login and Transaction?  It then calls the Demo

    AuthorizeNetDPM::directPostDemo($url, $api_login_id, $transaction_key, $amount, $md5_setting);

    

2.  The billing.php already includes a form, so can I use that form instead of the form in your example above?

 

3. With this type of arrangement PHP/Smarty, should I just use AIM instead?

 

Thanks for your help..,

1. What do you mean by "this code"? Your code, the code in the DPM documentation PDF, the code I supplied you with here, or the sample code on this page?

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

 

2. You can substitute any form you want, so long as it includes the minimum required data fields, as well as the contents of $hidden_fields (which contains all the security stuff like timestamp, fp_sequence, fp_hash, etc.) I'd say use your existing form, make sure it includes all the fields in this form and that the fields are named to match the names in the documentation, then slap on those top two lines of the form and the rest of the code above it (modified as necessary).

 

3. AIM is a bit simpler to implement, probably, but has more PCI requirements, since the credit card information does pass through your server on the way to Authorize.net. Up to you.

yes the sample code in step 3 of the Direct Post Method integration looks like this:

<?php
require_once
'anet_php_sdk/AuthorizeNet.php';// The SDK
$url
="http://YOUR_DOMAIN.com/direct_post.php";
$api_login_id
='YOUR_API_LOGIN_ID';
$transaction_key
='YOUR_TRANSACTION_KEY';
$md5_setting
='YOUR_API_LOGIN_ID';// Your MD5 Setting
$amount
="5.99";
AuthorizeNetDPM::directPostDemo($url, $api_login_id, $transaction_key, $amount, $md5_setting);
?>

 

The code you supplied is in the AuthorizeNetDPM.php, correct?

 

I see what you mean for the second question

(2. You can substitute any form you want, so long as it includes the minimum required data fields, as well as the contents of $hidden_fields (which contains all the security stuff like timestamp, fp_sequence, fp_hash, etc.) I'd say use your existing form, make sure it includes all the fields in this form and that the fields are named to match the names in the documentation, then slap on those top two lines of the form and the rest of the code above it (modified as necessary).)

 

Thanks TJ

Yes, it's in the DPM library file.