I first want to say I’m a beginner with PHP and my code is definitely not efficient to say the least.
The issue I’m having currently is I want to parse the CURL response in a manner to grab several field name values and assign them to a variable. Once I have the variables I’ll display some fields back to the customer and some to a database. I know what fields will be sent back as I’m working with PayPal’s APIs however I am unsure on how to “grab” them from the response.
Here is my script I’m currently using, again not very efficient however I’m stuck after the CURL request. Any help is greatly appreciated!!
<?php
include_once "constants.php";
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$wppro = "$key=$value";
}
$ipaddress = "216.113.168.139";
$creditcardtype = $_POST["creditcardtype"];
$acct = $_POST["acct"];
$expmo = $_POST["expmo"];
$expyear = $_POST["expyear"];
$cvv = $_POST["cvv"];
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$street = $_POST["street"];
$street2 = $_POST["street2"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$countrycode = $_POST["countrycode"];
$amt = $_POST["amt"];
$expdate = $expmo . $expyear;
$method = "DoDirectPayment";
$nvp = "version=$version&method=$method&user=$api_user&pwd=$api_pwd&signature=$api_sig&ipaddress=$ipaddress&$creditcardtype=$creditcardtype&acct=$acct&expdate=$expdate&cvv=$cvv&firstname=$firstname&lastname=$lastname&street=$street&street2=$street2&city=$city&state=$state&zip=$zip&countrycode=$countrycode&amt=$amt";
$ch = curl_init(); // Starts the curl handler
curl_setopt($ch, CURLOPT_URL,$sburl); // Sets the paypal address for curl
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // Returns result to a variable instead of echoing
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Sets a time limit for curl in seconds (do not set too low)
curl_setopt($ch, CURLOPT_POST, 1); // Set curl to send data using post
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp); // Add the request parameters to the post
$httpResponse = curl_exec($ch); // run the curl process (and return the result to $result
curl_close($ch);
Thank you,
Matt
How about this? It’s not super elegant, but I think it will work.
A
print_r($data)results in…