2

I'm building a script to work with PxPost from Payment Express and I've used their sample code as can be found at http://www.paymentexpress.com/Technical_Resources/Sample_code_-_PHP/PX_Post_-_cURL.aspx

How it works: It's built into an automated script that queries orders from my database, processes them, and returns a value.

My only problem is I want the function to return more than one value, so this is what I've done.

Code to run through functions (Line 201):

$once_complete = process_request($billingID, $order_total, $merchRef);

Which send the payment to be processed, that then gets the returns and processes the XML using the sample code. At the end of the code I've removed all the $html info and just replaced it with the following (line 111):

return $CardHolderResponseDescription.":".$MerchantResponseText.":".$AuthCode.":".$MerchantError;

Which should as far as I understand, return that to what started it. I then want to split those values and return them as strings using the following (line 202):

list($RespDesc, $MerchResp, $AuthCode, $MerchError) = explode(":", $once_complete);

But for some reason that's not working.

I've tried echo-ing the return and it works fine then, but then after that it seems to disappear. What may be going wrong?

You can see the entire page's code at http://pastebin.com/LJjFutne. This code is a work in progress.

halfer
  • 19,824
  • 17
  • 99
  • 186
dpDesignz
  • 1,909
  • 10
  • 34
  • 70
  • 2
    Instead of packing the values like that, consider returning an array (or even better, create a class to hold these values and return an object of that class). Please stop writing new code with the ancient mysql_* functions. They are no longer maintained and community has begun the [deprecation process](http://news.php.net/php.internals/53799). Instead you should learn about prepared statements and use either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). If you care to learn, [here is a quite good PDO-related tutorial](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers). – DCoder Sep 19 '12 at 09:25
  • @DCoder Thanks for the tip. I'm reading that now. Will start converting my script. :). Would returning an array work with it being processed in the loops like it is? – dpDesignz Sep 19 '12 at 09:27

3 Answers3

10

Return an array.

function process_request(){
    ...
    return array( $CardHolderResponseDescription, $MerchantResponseText, $AuthCode, $MerchantError );
}

And pick it up via:

$_result = process_request();
$CardHolderResponseDescription = $_result[0];
$MerchantResponseText = $_result[1];
...

Tip: use shorter vars for better reading :)

Linkmichiel
  • 2,110
  • 4
  • 23
  • 27
1

In your function process_request:

return array($CardHolderResponseDescription, $MerchantResponseText, $AuthCode, $MerchantError);

When calling your function:

list($RespDesc, $MerchResp, $AuthCode, $MerchError) = process_request($billingID,$order_total,$merchRef);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alain Tiemblo
  • 36,099
  • 17
  • 121
  • 153
1

The simplest thing you can do is putting the return values in an array which you can access later:

return array("CardHolderResponseDescription"=>$CardHolderResponseDescription, "MerchantResponseText" => $MerchantResponseText, "AuthCode" => $AuthCode );

And later:

list($RespDesc, $MerchResp, $AuthCode, $MerchError) = $my_return_value

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ramon Ott
  • 51
  • 2