We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22574
    • 181 Posts
    Hi Guys,

    I have a standard script from a payment gateway which works when its in its own file, but as soon as I add it as a snippet to modx it stops working.
    Even if its on a blank template.

    I get this:

    Fatal error: Call to a member function makeRequest() on a non-object in /home/brighton/public_html/manager/includes/document.parser.class.inc.php(814) : eval()'d code on line 297

    There is an includes file which is definitely linked up correctly but the function isnt reaching the includes file?

    I google the problem and lots of results pop up for wordpress and joomla but no modx suggestions.

    Any ideas?
      • 27708 MODX Staff
      • 2,502 Posts
      What code are you inserting? Is this php or javascript? You can't put php directly into modx resources. You will need to place them in a snippet an place the snippet code in the resource and there may be some minor refactoring required to return valus ot for output.
        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
        • 22574
        • 181 Posts
        yeah its php and its in a snippet, so it works in that sense but when I click their button (standard code from the gateway) it brings up that error.

        All they have said is that modx is somehow blocking the call, its a global call I think and it works in a normal file just not in modx.

        Main bits of code:
        include "assets/templates/sitefiles/PxPay_Curl.inc.php";
        $pxpay = new PxPay_Curl( $PxPay_Url, $PxPay_Userid, $PxPay_Key );
        $request_string = $pxpay->makeRequest($request);
        
          • 26903
          • 1,336 Posts
          try
          $assetsPath = $modx->getOption('assets_path');
          $inc = $assetsPath . "templates/sitefiles/PxPay_Curl.inc.php";
          include_once "$inc";
            Use MODx, or the cat gets it!
            • 27708 MODX Staff
            • 2,502 Posts
            What's being returned? Are you seeing errors in your error log perhaps coming from the parser?
              Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
              • 22574
              • 181 Posts
              Thanks Guys,

              Shamblett your code didnt work, I forgot to mention that I am on evo. But I used the evo equivalent and still the same so its definitely including the file as when I change it says file not found.

              When I click their buy button it shows this error if logged in:
              Fatal error: Call to a member function makeRequest() on a non-object in /home/brighton/public_html/manager/includes/document.parser.class.inc.php(814) : eval()'d code on line 300

              I 500 if not logged in.

              Using the code from here - phpcurl:
              http://www.paymentexpress.com/technical_resources/ecommerce_hosted/pxpay.html

              My thinking is that the function needs to be global or passed to the file as somehow modx is stopping it.

              Thanks!

                • 22574
                • 181 Posts
                Here is an example - paste this code into a snippet and call it from a page.

                <?php
                #******************************************************************************
                #* Name          	: PxPay_Sample_Curl.php
                #* Description   	: Direct Payment Solutions Payment Express PxPay PHP cURL Sample
                #* Copyright	 	: Direct Payment Solutions 2009(c)
                #* Date          	: 2009-10-21
                #* References    	: http://www.paymentexpress.com/technical_resources/ecommerce_hosted/pxpay.html
                #*@version 			: 1.0
                #* Author 			: Thomas Treadwell
                #******************************************************************************
                
                # This file is a sample demonstrating integration with the PxPay interface using PHP with the cURL extension installed.  
                #Inlcude PxPay objects
                include "PxPay_Curl.inc.php";
                
                  $PxPay_Url    = "https://sec.paymentexpress.com/pxpay/pxaccess.aspx";
                  $PxPay_Userid = "UserId"; #Important! Update with your UserId
                  $PxPay_Key    =  "Key"; #Important! Update with your Key
                  
                  #
                  # MAIN
                  #
                
                  $pxpay = new PxPay_Curl( $PxPay_Url, $PxPay_Userid, $PxPay_Key );
                
                  if (isset($_REQUEST["result"]))
                  {
                    # this is a redirection from the payments page.
                    print_result();
                  }
                  elseif (isset($_REQUEST["Submit"]))
                  {
                    # this is a post back -- redirect to payments page.
                    redirect_form();
                  }
                  else
                  {
                    # this is a fresh request -- display the purchase form.
                    print_form();
                  }
                
                
                #******************************************************************************
                # This function receives information back from the payments page,
                # and displays it to the user.
                #******************************************************************************
                function print_result()
                {
                  global $pxpay;
                
                  $enc_hex = $_REQUEST["result"];
                  #getResponse method in PxPay object returns PxPayResponse object
                  #which encapsulates all the response data
                  $rsp = $pxpay->getResponse($enc_hex);
                
                
                  # the following are the fields available in the PxPayResponse object
                  $Success           = $rsp->getSuccess();   # =1 when request succeeds
                  $AmountSettlement  = $rsp->getAmountSettlement();
                  $AuthCode          = $rsp->getAuthCode();  # from bank
                  $CardName          = $rsp->getCardName();  # e.g. "Visa"
                  $CardNumber        = $rsp->getCardNumber(); # Truncated card number
                  $DateExpiry        = $rsp->getDateExpiry(); # in mmyy format
                  $DpsBillingId      = $rsp->getDpsBillingId();
                  $BillingId    	 = $rsp->getBillingId();
                  $CardHolderName    = $rsp->getCardHolderName();
                  $DpsTxnRef	     = $rsp->getDpsTxnRef();
                  $TxnType           = $rsp->getTxnType();
                  $TxnData1          = $rsp->getTxnData1();
                  $TxnData2          = $rsp->getTxnData2();
                  $TxnData3          = $rsp->getTxnData3();
                  $CurrencySettlement= $rsp->getCurrencySettlement();
                  $ClientInfo        = $rsp->getClientInfo(); # The IP address of the user who submitted the transaction
                  $TxnId             = $rsp->getTxnId();
                  $CurrencyInput     = $rsp->getCurrencyInput();
                  $EmailAddress      = $rsp->getEmailAddress();
                  $MerchantReference = $rsp->getMerchantReference();
                  $ResponseText		 = $rsp->getResponseText();
                  $TxnMac            = $rsp->getTxnMac(); # An indication as to the uniqueness of a card used in relation to others
                
                  if ($rsp->getSuccess() == "1")
                  {
                    $result = "The transaction was approved.";
                	
                		# Sending invoices/updating order status within database etc.
                	
                	if (!isProcessed($TxnId))
                	{
                		# Send emails, generate invoices, update order status etc.
                	}
                	
                  }
                  else
                  {
                    $result = "The transaction was declined.";
                  }
                
                  print <<<HTMLEOF
                <html>
                <head>
                <title>Direct Payment Solutions PxPay transaction result</title>
                </head>
                <body>
                <h1>Direct Payment Solutions PxPay transaction result</h1>
                <p>$result</p>
                  <table border=1>
                	<tr><th>Name</th>				<th>Value</th> </tr>
                	<tr><td>Success</td>			<td>$Success</td></tr>
                	<tr><td>TxnType</td>			<td>$TxnType</td></tr>
                	<tr><td>CurrencyInput</td>		<td>$CurrencyInput</td></tr>
                	<tr><td>MerchantReference</td>	<td>$MerchantReference</td></tr>
                	<tr><td>TxnData1</td>			<td>$TxnData1</td></tr>
                	<tr><td>TxnData2</td>			<td>$TxnData2</td></tr>
                	<tr><td>TxnData3</td>			<td>$TxnData3</td></tr>
                	<tr><td>AuthCode</td>			<td>$AuthCode</td></tr>
                	<tr><td>CardName</td>			<td>$CardName</td></tr>
                	<tr><td>CardHolderName</td>		<td>$CardHolderName</td></tr>
                	<tr><td>CardNumber</td>			<td>$CardNumber</td></tr>
                	<tr><td>DateExpiry</td>			<td>$DateExpiry</td></tr>
                	<tr><td>CardHolderName</td>		<td>$CardHolderName</td></tr>
                	<tr><td>ClientInfo</td>			<td>$ClientInfo</td></tr>
                	<tr><td>TxnId</td>				<td>$TxnId</td></tr>
                	<tr><td>EmailAddress</td>		<td>$EmailAddress</td></tr>
                	<tr><td>DpsTxnRef</td>			<td>$DpsTxnRef</td></tr>
                	<tr><td>BillingId</td>			<td>$BillingId</td></tr>
                	<tr><td>DpsBillingId</td>		<td>$DpsBillingId</td></tr>
                	<tr><td>AmountSettlement</td>	<td>$AmountSettlement</td></tr>
                	<tr><td>CurrencySettlement</td>	<td>$CurrencySettlement</td></tr>
                	<tr><td>TxnMac</td>				<td>$TxnMac</td></tr>
                	<tr><td>ResponseText</td>		<td>$ResponseText</td></tr>
                </table>
                </body>
                </html>
                HTMLEOF;
                }
                
                #******************************************************************************
                # Database lookup to check the status of the order or shopping cart
                #******************************************************************************
                
                function isProcessed($TxnId)
                {
                	# Check database if order relating to TxnId has alread been processed
                	return false;
                }
                
                #******************************************************************************
                # This function prints a blank purchase form.
                #******************************************************************************
                function print_form()
                {
                  print <<<HTMLEOF
                <html>
                <head>
                <title>Direct Payment Solutions PxPay transaction sample</title>
                </head>
                <body>
                <h1>Direct Payment Solutions PxPay transaction result</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>@ $19.95 ea</td>
                  </tr>
                  <tr>
                    <td>Reference:</td>
                    <td><input name="Reference" type="text"/></td>
                  </tr>  
                  <tr>
                    <td>Ship to</td>
                    <td></td>
                  </tr>
                  <tr>
                    <td>Address line 1:</td>
                    <td><input name="Address1" type="text"/></td>
                  </tr>
                  <tr>
                    <td>Address line 2</td>
                    <td><input name="Address2" type="text"/></td>
                  </tr>
                    <tr>
                    <td>Address line 3</td>
                    <td><input name="Address3" type="text"/></td>
                  </tr>
                </table>
                <input name="Submit" type="submit" value="Submit"/>
                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 $pxpay;
                
                  $request = new PxPayRequest();
                
                  $http_host   = getenv("HTTP_HOST");
                  $request_uri = getenv("SCRIPT_NAME");
                  $server_url  = "http://$http_host";
                  #$script_url  = "$server_url/$request_uri"; //using this code before PHP version 4.3.4
                  #$script_url  = "$server_url$request_uri"; //Using this code after PHP version 4.3.4
                  $script_url = (version_compare(PHP_VERSION, "4.3.4", ">=")) ?"$server_url$request_uri" : "$server_url/$request_uri";
                
                
                  # the following variables are read from the form
                  $Quantity = $_REQUEST["Quantity"];
                  $MerchantReference = $_REQUEST["Reference"];  
                  $Address1 = $_REQUEST["Address1"];
                  $Address2 = $_REQUEST["Address2"];
                  $Address3 = $_REQUEST["Address3"];
                  
                  #Calculate AmountInput
                  $AmountInput = 19.95 * $Quantity;
                  
                  #Generate a unique identifier for the transaction
                  $TxnId = uniqid("ID");
                  
                  #Set PxPay properties
                  $request->setMerchantReference($MerchantReference);
                  $request->setAmountInput($AmountInput);
                  $request->setTxnData1($Address1);
                  $request->setTxnData2($Address2);
                  $request->setTxnData3($Address3);
                  $request->setTxnType("Purchase");
                  $request->setCurrencyInput("NZD");
                  $request->setEmailAddress("[email protected]");
                  $request->setUrlFail($script_url);			# can be a dedicated failure page
                  $request->setUrlSuccess($script_url);			# can be a dedicated success page
                  $request->setTxnId($TxnId);  
                  
                  #The following properties are not used in this case
                  # $request->setEnableAddBillCard($EnableAddBillCard);    
                  # $request->setBillingId($BillingId);
                  # $request->setOpt($Opt);
                  
                
                  
                  #Call makeRequest function to obtain input XML
                  $request_string = $pxpay->makeRequest($request);
                   
                  #Obtain output XML
                  $response = new MifMessage($request_string);
                  
                  #Parse output XML
                  $url = $response->get_element_text("URI");
                  $valid = $response->get_attribute("valid");
                   
                   #Redirect to payment page
                   header("Location: ".$url);
                }
                ?>
                


                Then save this code below to a php file and upload it to your server.
                Then on the code/snippet above change the path on line 14 to this files path.

                <?php
                
                #******************************************************************************
                #* Name          : PxPay_Curl.inc.php
                #* Description   : Classes used interact with the PxPay interface using PHP with the cURL extension installed 
                #* Copyright	 : Direct Payment Solutions 2009(c)
                #* Date          : 2009-04-10
                #* Version		 : 1.0
                #* Author		 : Thomas Treadwell
                #******************************************************************************
                
                # Use this class to parse an XML document
                class MifMessage
                {
                  var $xml_;
                  var $xml_index_;
                  var $xml_value_;
                
                  # Constructor:
                  # Create a MifMessage with the specified XML text.
                  # The constructor returns a null object if there is a parsing error.
                  function MifMessage($xml)
                  {
                    $p = xml_parser_create();
                    xml_parser_set_option($p,XML_OPTION_CASE_FOLDING,0);
                    $ok = xml_parse_into_struct($p, $xml, $value, $index);
                    xml_parser_free($p);
                    if ($ok)
                    {
                      $this->xml_ = $xml;
                      $this->xml_value_ = $value;
                      $this->xml_index_ = $index;
                    }
                  }
                
                  # Return the value of the specified top-level attribute.
                  # This method can only return attributes of the root element.
                  # If the attribute is not found, return "".
                  function get_attribute($attribute)
                  {
                    $attributes = $this->xml_value_[0]["attributes"];
                    return $attributes[$attribute];
                  }
                
                  # Return the text of the specified element.
                  # The element is given as a simplified XPath-like name.
                  # For example, "Link/ServerOk" refers to the ServerOk element
                  # nested in the Link element (nested in the root element).
                  # If the element is not found, return "".
                  function get_element_text($element)
                  {
                    $index = $this->get_element_index($element, 0);
                    if ($index == 0)
                    {
                      return "";
                    }
                    else
                    {
                	#When element existent but empty
                    $elementObj = $this->xml_value_[$index];
                    if (! array_key_exists("value", $elementObj))
                      return "";
                   
                    return $this->xml_value_[$index]["value"];
                    }
                  }
                
                  # (internal method)
                  # Return the index of the specified element,
                  # relative to some given root element index.
                  #
                  function get_element_index($element, $rootindex = 0)
                  {
                    #$element = strtoupper($element);
                    $pos = strpos($element, "/");
                    if ($pos !== false)
                    {
                      # element contains '/': find first part
                      $start_path = substr($element,0,$pos);
                      $remain_path = substr($element,$pos+1);
                      $index = $this->get_element_index($start_path, $rootindex);
                      if ($index == 0)
                      {
                        # couldn't find first part give up.
                        return 0;
                      }
                      # recursively find rest
                      return $this->get_element_index($remain_path, $index);
                    }
                    else
                    {
                      # search from the parent across all its children
                      # i.e. until we get the parent's close tag.
                      $level = $this->xml_value_[$rootindex]["level"];
                      if ($this->xml_value_[$rootindex]["type"] == "complete")
                      {
                        return 0;   # no children
                      }
                      $index = $rootindex+1;
                      while ($index<count($this->xml_value_) && 
                             !($this->xml_value_[$index]["level"]==$level && 
                               $this->xml_value_[$index]["type"]=="close"))
                      {
                        # if one below parent and tag matches, bingo
                        if ($this->xml_value_[$index]["level"] == $level+1 &&
                            $this->xml_value_[$index]["tag"] == $element)
                        {
                          return $index;
                        }
                        $index++;
                      }
                      return 0;
                    }
                  }
                }
                
                class PxPay_Curl
                {
                	var $PxPay_Key;
                	var $PxPay_Url;
                	var $PxPay_Userid;
                	function PxPay_Curl($Url, $UserId, $Key){
                		error_reporting(E_ERROR);
                		$this->PxPay_Key = $Key;
                		$this->PxPay_Url = $Url;
                		$this->PxPay_Userid = $UserId;
                	}
                	
                	#******************************************************************************
                	# Create a request for the PxPay interface
                	#******************************************************************************
                	function makeRequest($request)
                	{
                		#Validate the Request
                		if($request->validData() == false) return "" ;
                
                		$request->setUserId($this->PxPay_Userid);
                		$request->setKey($this->PxPay_Key);
                		
                		$xml = $request->toXml();
                		
                		$result = $this->submitXml($xml);
                  
                		return $result;
                		
                	}
                			
                	#******************************************************************************
                	# Return the transaction outcome details
                	#******************************************************************************
                	function getResponse($result){
                				
                		$inputXml = "<ProcessResponse><PxPayUserId>".$this->PxPay_Userid."</PxPayUserId><PxPayKey>".$this->PxPay_Key.
                		"</PxPayKey><Response>".$result."</Response></ProcessResponse>";
                		
                		$outputXml = $this->submitXml($inputXml);
                		
                		$pxresp = new PxPayResponse($outputXml);
                		return $pxresp;	
                	}
                	
                	#******************************************************************************
                	# Actual submission of XML using cURL. Returns output XML
                	#******************************************************************************
                	function submitXml($inputXml){
                		
                		$ch = curl_init(); 
                		curl_setopt($ch, CURLOPT_URL, $this->PxPay_Url);
                		
                		curl_setopt($ch, CURLOPT_POST, 1);
                		curl_setopt($ch, CURLOPT_POSTFIELDS,$inputXml);
                		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                		
                		#set up proxy, this may change depending on ISP, please contact your ISP to get the correct cURL settings
                		#curl_setopt($ch,CURLOPT_PROXY , "proxy:8080");
                		#curl_setopt($ch,CURLOPT_PROXYUSERPWD,"username:password");
                
                		$outputXml = curl_exec ($ch); 		
                			
                		curl_close ($ch);
                  
                		return $outputXml;
                	}
                	
                }
                
                #******************************************************************************
                # Class for PxPay request messages.
                #******************************************************************************
                class PxPayRequest extends PxPayMessage
                {
                	var $UrlFail,$UrlSuccess;
                	var $AmountInput;
                	var $EnableAddBillCard;
                	var $PxPayUserId;
                	var $PxPayKey;
                	var $Opt;
                	
                	
                	#Constructor
                 	function PxPayRequest(){
                		$this->PxPayMessage();
                		
                	}
                	
                	function setEnableAddBillCard($EnableBillAddCard){
                	 $this->EnableAddBillCard = $EnableBillAddCard;
                	}
                	function setUrlFail($UrlFail){
                		$this->UrlFail = $UrlFail;
                	}
                	function setUrlSuccess($UrlSuccess){
                		$this->UrlSuccess = $UrlSuccess;
                	}
                	function setAmountInput($AmountInput){
                		$this->AmountInput = sprintf("%9.2f",$AmountInput); 
                	}
                	function setUserId($UserId){
                		$this->PxPayUserId = $UserId;
                	}
                	function setKey($Key){
                		$this->PxPayKey = $Key;
                	}
                	function setOpt($Opt){
                		$this->Opt = $Opt;
                	}
                	
                
                	#******************************************************************
                	#Data validation 
                	#******************************************************************
                	function validData(){
                		$msg = "";
                		if($this->TxnType != "Purchase")
                			if($this->TxnType != "Auth")
                				$msg = "Invalid TxnType[$this->TxnType]<br>";
                		
                		if(strlen($this->MerchantReference) > 64)
                			$msg = "Invalid MerchantReference [$this->MerchantReference]<br>";
                		
                		if(strlen($this->TxnId) > 16)
                			$msg = "Invalid TxnId [$this->TxnId]<br>";
                		if(strlen($this->TxnData1) > 255)
                			$msg = "Invalid TxnData1 [$this->TxnData1]<br>";
                		if(strlen($this->TxnData2) > 255)
                			$msg = "Invalid TxnData2 [$this->TxnData2]<br>";
                		if(strlen($this->TxnData3) > 255)
                			$msg = "Invalid TxnData3 [$this->TxnData3]<br>";
                			
                		if(strlen($this->EmailAddress) > 255)
                			$msg = "Invalid EmailAddress [$this->EmailAddress]<br>";
                			
                		if(strlen($this->UrlFail) > 255)
                			$msg = "Invalid UrlFail [$this->UrlFail]<br>";
                		if(strlen($this->UrlSuccess) > 255)
                			$msg = "Invalid UrlSuccess [$this->UrlSuccess]<br>";
                		if(strlen($this->BillingId) > 32)
                			$msg = "Invalid BillingId [$this->BillingId]<br>";
                		
                		if ($msg != "") {
                		    trigger_error($msg,E_USER_ERROR);
                			return false;
                		}
                		return true;
                	}
                
                }
                
                #******************************************************************************
                # Abstract base class for PxPay messages.
                # These are messages with certain defined elements,  which can be serialized to XML.
                
                #******************************************************************************
                class PxPayMessage {
                	var $TxnType;
                	var $CurrencyInput;
                  	var $TxnData1;
                  	var $TxnData2;
                  	var $TxnData3;
                  	var $MerchantReference;
                  	var $EmailAddress;
                  	var $BillingId;
                	var $TxnId;
                	
                	function PxPayMessage(){
                	
                	}
                
                	function setBillingId($BillingId){
                		$this->BillingId = $BillingId;
                	}
                	function getBillingId(){
                		return $this->BillingId;
                	}
                	function setTxnType($TxnType){
                		$this->TxnType = $TxnType;
                	}
                	function getTxnType(){
                		return $this->TxnType;
                	}
                	function setCurrencyInput($CurrencyInput){
                		$this->CurrencyInput = $CurrencyInput;
                	}
                	function getCurrencyInput(){
                		return $this->CurrencyInput;
                	}
                	function setMerchantReference($MerchantReference){
                		$this->MerchantReference = $MerchantReference;
                	}
                	function getMerchantReference(){
                		return $this->MerchantReference;
                	}
                	function setEmailAddress($EmailAddress){
                		$this->EmailAddress = $EmailAddress;
                	}
                	function getEmailAddress(){
                		return $this->EmailAddress;
                	}
                	function setTxnData1($TxnData1){
                		$this->TxnData1 = $TxnData1;
                	}
                	function getTxnData1(){
                		return $this->TxnData1;
                	}
                	function setTxnData2($TxnData2){
                		$this->TxnData2 = $TxnData2;
                	}
                	function getTxnData2(){
                		return $this->TxnData2;
                	}
                	function getTxnData3(){
                		return $this->TxnData3;
                	}
                	function setTxnData3($TxnData3){
                		$this->TxnData3 = $TxnData3;
                	}
                	function setTxnId( $TxnId)
                	{
                		$this->TxnId = $TxnId;
                	}
                	function getTxnId(){
                		return $this->TxnId;
                	}
                	
                	function toXml(){
                		$arr = get_object_vars($this);
                
                		$xml  = "<GenerateRequest>";
                    	while (list($prop, $val) = each($arr))
                        	$xml .= "<$prop>$val</$prop>" ;
                
                		$xml .= "</GenerateRequest>";
                		return $xml;
                	}
                	
                	
                }
                
                #******************************************************************************
                # Class for PxPay response messages.
                #******************************************************************************
                
                class PxPayResponse extends PxPayMessage
                {
                	var $Success;
                	var $AuthCode;
                	var $CardName;
                	var $CardHolderName;	
                	var $CardNumber;
                	var $DateExpiry;
                	var $ClientInfo;
                	var $DpsTxnRef;
                  	var $DpsBillingId;	
                	var $AmountSettlement;
                	var $CurrencySettlement;
                	var $TxnMac;
                	var $ResponseText;
                
                 
                	function PxPayResponse($xml){
                		$msg = new MifMessage($xml);
                		$this->PxPayMessage();
                		
                		$this->Success = $msg->get_element_text("Success");
                		$this->setTxnType($msg->get_element_text("TxnType"));	
                		$this->CurrencyInput = $msg->get_element_text("CurrencyInput");	
                		$this->setMerchantReference($msg->get_element_text("MerchantReference"));	
                		$this->setTxnData1($msg->get_element_text("TxnData1"));
                		$this->setTxnData2($msg->get_element_text("TxnData2"));
                		$this->setTxnData3($msg->get_element_text("TxnData3"));
                		$this->AuthCode = $msg->get_element_text("AuthCode");
                		$this->CardName = $msg->get_element_text("CardName");		
                		$this->CardHolderName = $msg->get_element_text("CardHolderName");	
                		$this->CardNumber = $msg->get_element_text("CardNumber");	
                		$this->DateExpiry = $msg->get_element_text("DateExpiry");	
                		$this->ClientInfo = $msg->get_element_text("ClientInfo");
                		$this->TxnId = $msg->get_element_text("TxnId");		
                		$this->setEmailAddress($msg->get_element_text("EmailAddress"));
                		$this->DpsTxnRef = $msg->get_element_text("DpsTxnRef");		
                		$this->BillingId = $msg->get_element_text("BillingId");
                		$this->DpsBillingId = $msg->get_element_text("DpsBillingId");
                		$this->AmountSettlement = $msg->get_element_text("AmountSettlement");
                		$this->CurrencySettlement = $msg->get_element_text("CurrencySettlement");
                		$this->TxnMac = $msg->get_element_text("TxnMac");
                		$this->ResponseText = $msg->get_element_text("ResponseText");
                	
                	}
                
                
                	function getSuccess(){
                		return $this->Success;
                	}
                	function getAuthCode(){
                		return $this->AuthCode;
                	}
                	function getCardName(){
                		return $this->CardName;
                	}
                	function getCardHolderName(){
                		return $this->CardHolderName;
                	}
                	function getCardNumber(){
                		return $this->CardNumber;
                	}
                	function getDateExpiry(){
                		return $this->DateExpiry;
                	}
                	function getClientInfo(){
                		return $this->ClientInfo;
                	}
                	function getDpsTxnRef(){
                		return $this->DpsTxnRef;
                	}
                	function getDpsBillingId(){
                		return $this->DpsBillingId;
                	}
                	function getAmountSettlement(){
                		return $this->AmountSettlement;
                	}	
                	function getCurrencySettlement(){
                		$this->CurrencySettlement;
                	}
                	function getTxnMac(){
                		return $this->TxnMac;
                	}
                	function getResponseText(){
                		return $this->ResponseText;
                	}
                }
                
                ?>


                Go to the live modx page with the snippet on it and click the pay button and you will see the same error.

                Any ideas?
                  • 16348
                  • 64 Posts
                  The error message indicates that the PxPay_Curl object isn't available when you call the makeRequest method. Is the parameters $PxPay_Url, $PxPay_Userid and $PxPay_Key defined in your snippet as per the example?

                  You can try something like this to handle the errors:
                  $assetsPath = //the path to your assets folder
                  $inc = $assetsPath . "templates/sitefiles/PxPay_Curl.inc.php";
                  include_once "$inc";
                  $PxPay_Url = "Url";
                  $PxPay_Userid = "UserId"; #Important! Update with your UserId
                  $PxPay_Key =  "Key"; #Important! Update with your Key
                  $pxpay = new PxPay_Curl( $PxPay_Url, $PxPay_Userid, $PxPay_Key);
                  if(is_object($pxpay) {
                    // continue with the request
                  } else {
                    // do something else
                  }
                  
                    • 22574
                    • 181 Posts
                    Hi Kristoffer,

                    I added your code:
                    if(is_object($pxpay)) {
                    echo "yes";
                    } else {
                    echo "no";
                    }

                    And it outputs yes even when clicking the pay button and the error comes up.

                    Again if I copy and paste all of this into a plain php file it works - but in modx it somehow stops the object getting reached . I just dont get why.

                    Thanks
                      • 22574
                      • 181 Posts
                      Hi all,

                      Got a fix from the makers - might help someone out in the future.

                      to fix this I have added this bit of code redirect_form
                      
                       
                      
                      function redirect_form()
                      
                      {
                      
                        //global $pxpay;
                      
                      $PxPay_Url    = "https://sec.paymentexpress.com/pxpay/pxaccess.aspx";
                      
                        $PxPay_Userid = "BrightonHotelDev"; #Important! Update with your UserId
                      
                        $PxPay_Key    = "2b592e4a6f457bbaa4ebf6f9ee5acf54db042f5031c3f52dd6699b72c3f28e96"; #Important! Update with your Key
                      
                       
                      
                         $pxpay = new PxPay_Curl( $PxPay_Url, $PxPay_Userid, $PxPay_Key );