Payment Proccess Form help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Payment Proccess Form help

Post by C_Calav »

hi guys, im in the final steps of completeing my website and i have got a sample form here from a payments mechant in nz (like paypal etc) now this code gives a sample form and the company said i just need to intergrate my summary page or how ever i want to do it into the code below. but i think it is way over my head?

this bit from here under

#******************************************************************************
# This function prints a blank purchase form.
#******************************************************************************

is where i need to put my code but i cant seem to get it to work. how do i do this if anyone knows or has used something like this before?

thanx alot im very very confused!

Code: Select all

<?php
#******************************************************************************
#* Name          : PxAccess_Sample.php
#* Description   : Direct Payment Solutions Payment Express PHP Sample
#* Copyright (c) : Direct Payment Solutions 2002
#* Date          : 2002-06-23 
#* References    : http://www.paymentexpress.co.nz/px/pxxml.asp
#* Modifications : 2002-08-12 JH update encryption for libmcrypt 2.4.x
#*                 2003-10-13 JH change root element to <Request>
#*				   2004-08-30 JZ Implements 3DES and MAC Key 
#*@version 		 : 2.01.01
#******************************************************************************

# This file is a SAMPLE showing redirect to Payments Page from PHP.
# See the full documentation of the Payment Express XML message format at
#   http://www.paymentexpress.co.nz/px/pxxml.asp
#
#Inlcude PxAccess Objects
include "pxaccess.inc";

  $PxAccess_Url    = "https://www.payment.co.nz/pxpay/pxpay.asp";
  $PxAccess_Userid = "***"; #Change to your user ID
  $PxAccess_Key    = "***"; #Your DES Key from DPS
  $Mac_Key ="***"; #Your MAC key from DPS


  #
  # MAIN
  #
  
  $pxaccess = new PxAccess($PxAccess_Url, $PxAccess_Userid, $PxAccess_Key, $Mac_Key);
  
  if (isset($_REQUEST["result"]))
  {
    # this is a redirection BACK from the Payments Page.
    print_result();
  }
  elseif (isset($_REQUEST["Submit"]))
  {
    # this is a form submission -- redirect to Payments Page.
    redirect_form();
  }
  else
  {
    # this is a fresh request -- show the purchase form.
    print_form();
  }


#******************************************************************************
# This function receives information back from the Payments Page, 
# and displays it to the user.
#******************************************************************************
function print_result()
{
  global $pxaccess;

  $enc_hex = $_REQUEST["result"];
  #getResponse method in PxAccess object returns PxPayResponse object 
  #which encapsulates all the response data
  $rsp = $pxaccess->getResponse($enc_hex);
  

  if ($rsp->getStatusRequired() == "1")
  {
    $result = "An error has occurred.";
  }
  elseif ($rsp->getSuccess() == "1")
  {
    $result = "The transaction was approved.";
  }
  else
  {
    $result = "The transaction was declined.";
  }

  # the following are the fields available in the PxPayResponse object
  $Success           = $rsp->getSuccess();   # =1 when request succeeds
  $Retry             = $rsp->getRetry();     # =1 when a retry might help
  $StatusRequired    = $rsp->getStatusRequired;      # =1 when transaction "lost"
  $AmountSettlement  = $rsp->getAmountSettlement();    
  $AuthCode          = $rsp->getAuthCode();  # from bank
  $CardName          = $rsp->getCardName();  # e.g. "Visa"

  # the following values are returned, but are from the original request
  $TxnType           = $rsp->getTxnType();
  $TxnData1          = $rsp->getTxnData1();
  $TxnData2          = $rsp->getTxnData2();
  $TxnData3          = $rsp->getTxnData3();
  $CurrencyInput     = $rsp->getCurrencyInput();
  $EmailAddress      = $rsp->getEmailAddress();
  $MerchantReference = $rsp->getMerchantReference();

  # is there a nice way to print all the XML values returned?

  print <<<HTMLEOF
<html>
<head>
<title>Direct Payment Solutions: Secure Payments Page PHP Results</title>
</head>
<body>
<h1>Direct Payment Solutions: Secure Payments Page PHP Results</h1>
<p>$result</p>
<table>                        
  <tr><th>Element</th>          <th>Value</th> </tr>
  <tr><td>Success</td>          <td>$Success</td></tr>
  <tr><td>Retry</td>            <td>$Retry</td></tr>
  <tr><td>StatusRequired</td>   <td>$StatusRequired</td></tr>
  <tr><td>AmountSettlement</td> <td>$AmountSettlement</td></tr>
  <tr><td>AuthCode</td>         <td>$AuthCode</td></tr>
  <tr><td>CardName</td>         <td>$CardName</td></tr>
</table>
</body>
</html>
HTMLEOF;
}

#******************************************************************************
# This function prints a blank purchase form.
#******************************************************************************
function print_form()
{
  print <<<HTMLEOF
<html>
<head>
<title>Direct Payment Solutions: Secure Payments Page PHP Sample</title>
</head>
<body>
<h1>Direct Payment Solutions: Secure Payments Page PHP Sample</h1>
<p>
You have indicated you would like to buy some widgets.
</p>
<p>
Please enter the number of widgets below, and enter your
shipping details.
</p>
<form method="post">
<table>
  <tr>
    <td>Quantity:</td>
    <td><input name="Quantity" type="text"/></td>
    <td>@ \$1.20 ea</td>
  </tr>
  <tr>
    <td>Ship to</td>
    <td></td>
  </tr>
  <tr>
    <td>Address:</td>
    <td><input name="Address1" type="text"/></td>
  </tr>
  <tr>
    <td>City:</td>
    <td><input name="Address2" type="text"/></td>
  </tr>
</table>
<input name="Submit" type="submit" value="Submit"/>
&nbsp;Click submit to go to the secure payment page.
</form>
</body>
</html>
HTMLEOF;
}

#******************************************************************************
# This function formats data into a request and redirects to the 
# Payments Page.
#******************************************************************************
function redirect_form()
{
  global $pxaccess;
  
  $request = new PxPayRequest();
  
  $http_host   = getenv("HTTP_HOST");
  $request_uri = getenv("REQUEST_URI");
  $server_url  = "http://$http_host";
  //$script_url  = "$server_url/$request_uri"; //using this code before PHP version 4.3.6
  $script_url  = "$server_url$request_uri"; //Using this code after PHP version 4.3.6

  
  # the following variables are read from the form
  $Quantity = $_REQUEST["Quantity"];    
  $Address1 = $_REQUEST["Address1"];    
  $Address2 = $_REQUEST["Address2"];    
  $AmountInput = 1.20 * $Quantity;
  #Set up PxPayRequest Object
  $request->setAmountInput($AmountInput);
  $request->setTxnData1("Widget order");# whatever you want to appear
  $request->setTxnData2($Address1);		# whatever you want to appear
  $request->setTxnData3($Address2);		# whatever you want to appear
  $request->setTxnType("Purchase");
  $request->setInputCurrency("NZD");
  $request->setMerchantReference("123456"); # fill this with your order number
  $request->setEmailAddress("your_email@dps.co.nz");
  $request->setUrlFail($script_url);
  $request->setUrlSuccess($script_url);
  
  
  #Call makeResponse of PxAccess object to obtain the 3-DES encrypted payment request 
  $request_string = $pxaccess->makeRequest($request);
  
  header("Location: $request_string");
}
?>
Post Reply