Skip to content

Instantly share code, notes, and snippets.

@yankeyhotel
Created April 10, 2015 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yankeyhotel/bdc9a9259f8bd4bb2a8f to your computer and use it in GitHub Desktop.
Save yankeyhotel/bdc9a9259f8bd4bb2a8f to your computer and use it in GitHub Desktop.
FoxyCart API - Ajax to PHP and back for customer info
$.ajax({
url: '../assets/php/get_customer_id.php',
data: { email: "email@email.com" },
type: 'post',
success: function(data) {
var xmlDoc = $.parseXML(data),
$xml = $(xmlDoc);
console.log($xml.find("customer_id").text());
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("ERROR", jqXHR, textStatus, errorThrown);
}
});
<?php
//Checks if action value exists
if (isset($_POST["email"]) && !empty($_POST["email"])) {
$email = $_POST["email"];
$foxy_domain = "yourdomain.foxycart.com";
$foxyData = array();
$foxyData["api_token"] = "XXX Your Key XXX";
$foxyData["api_action"] = "customer_get";
$foxyData["customer_email"] = $email;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://" . $foxy_domain . "/api");
curl_setopt($ch, CURLOPT_POSTFIELDS, $foxyData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
// If you get SSL errors, you can uncomment the following, or ask your host to add the appropriate CA bundle
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = trim(curl_exec($ch));
// The following if block will print any CURL errors you might have
if ($response == false) {
print "CURL Error: \n" . curl_error($ch);
} else {
print $response;
}
curl_close($ch);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment