Skip to content

Instantly share code, notes, and snippets.

@joshuaziering
Last active February 28, 2017 05:54
Show Gist options
  • Save joshuaziering/5710377 to your computer and use it in GitHub Desktop.
Save joshuaziering/5710377 to your computer and use it in GitHub Desktop.
A handler to take new customers from Shopify and put them into your Infusionsoft database.
<?php
/**
* Webhook Handler For Shopify To Infusionsoft
*
* @author Joshua Ziering <[email protected]>
*/
// Include and instantiate Infusionsoft Libraries
include('isdk.php');
$ifsapp = new iSDK;
// Here's a sample set of data like the Shopify API posts to this application that you can use for testing.
/*
$customer_information = '{
"customer": {
"first_name": "Steve",
"last_name": "Lastnameson",
"email": "[email protected]",
"verified_email": true,
"addresses": [
{
"address1": "123 Oak St",
"city": "Ottawa",
"country": "CA",
"first_name": "Mother",
"last_name": "Lastnameson",
"phone": "555-1212",
"province": "ON",
"zip": "123 ABC"
}
]
}
}';
*/
//$raw = file_get_contents('php://input');
$customer_information = json_decode(file_get_contents('php://input'));
//file_put_contents("jsonoutput.txt", $raw);
if (!$ifsapp->cfgCon("YourEndpointName","YourAPIKey1234567890")) {
echo "There was a problem connecting to Infusionsoft.";
}
// If they've input their email...
if ( ! empty($customer_information->customer->email))
{
global $ifsapp;
// First check to see if this email exists in our Infusionsoft database.
$contact = array(
'Email' => $customer_information->customer->email,
'FirstName' => $customer_information->customer->first_name,
'LastName' => $customer_information->customer->last_name
);
//print_r($contact);
// Check for existing contact
$returnFields = array('Id');
$duplicates = $ifsapp->findByEmail($contact['Email'], $returnFields);
if (!$duplicates)
{
// Add a new contact
//echo "Adding new email.";
$newCon = $ifsapp->addCon($contact);
}
}
header('HTTP/1.0 200 OK');
exit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment