n1concepts Posted September 9, 2014 Share Posted September 9, 2014 Hi,I I'm trying to setup Paypal Pro on a website - have everything working - but need to grab the 4th & 6th key values from the results given from the Paypal response and having difficulty with the task. See the code that prints the response and the response sent from Paypal below - I need to grab the values for [TRXRESULT] and [TRXRESPMSG] echo('<pre>'); print_r($PayFlow->getResponse()); echo('</pre>'); and here's the response I get from Paypal on script execution - this is an example of a failed transaction: Paypal Response Array ( [RESULT] => 36 [RPREF] => RPC5B24581A2 [RESPMSG] => Transaction failed: Fail to obtain approval for the online transaction [TRXRESULT] => 23 [TRXPNREF] => EUJPC36F2092 [TRXRESPMSG] => Invalid account number: Unsupported Credit Card type ) Again, I want to grab the values from [TRXRESULT] and [TRXRESPMSG] and assign them to local variables so i can work with them within the local php script. Example: $trxresult and $trxrespmsg Here's part of the class (file name is Class.Payflow.php find on Github) that pertains to this snippet of code in question: Class.Payflow.php /** * @uses Gets the response from Paypal. * @access Public * @param None. * @return Array/String - Returns an array of Paypal's response or empty string if not return. * @example $PayFlow->getResponse(); */ public function getResponse() { if($this->response) { return $this->response; } else { return ''; } } Thanks in advance for help w/this one! Quote Link to comment Share on other sites More sharing options...
Solution Jacques1 Posted September 9, 2014 Solution Share Posted September 9, 2014 So you're asking how to access an element of an associative array? $paypal_response = $PayFlow->getResponse(); var_dump($paypal_response['TRXRESULT']); If you're just confused because of the bracket syntax, use var_dump() instead of print_r(). There's actually no need to put all elements into separate variables. The values in the array are just as good as any other value. 1 Quote Link to comment Share on other sites More sharing options...
n1concepts Posted September 11, 2014 Author Share Posted September 11, 2014 (edited) Hi, This works great and exactly what i need to get the data I want - specifically. However, I'm having trouble assigning those var_dumps to local variables - see example below which yields nothing: $var1 = var_dump($paypal_response['TRXRESULT']); echo $var1; // doesn't produce any value for $var1 I need to assign the results to variables so i can work with them to insert / update MySQL database. I tried var_export and other methods but unable to get the results/value(s) assigned as with this example. Thx for help - really appreciated! Edited September 11, 2014 by n1concepts Quote Link to comment Share on other sites More sharing options...
n1concepts Posted September 11, 2014 Author Share Posted September 11, 2014 Never mind - think I got it figured out... Need to clean up the results but not got value from var_dump into local var as shown below: ob_start(); var_dump($api_response1['RESULT']); $var1 = ob_get_contents(); ob_end_clean(); echo $var1; Thanks again for help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.