Last active
December 18, 2015 03:38
-
-
Save joshuaziering/5719175 to your computer and use it in GitHub Desktop.
Webhook To Bring Email Addresses From Shopify To Infusionsoft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
); | |
// 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