Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
integration:zapier-datafeed [2014/10/07 15:28] – created foxybrettintegration:zapier-datafeed [2018/11/26 20:27] (current) – [Zapier] marija
Line 1: Line 1:
 ---- dataentry integration ---- ---- dataentry integration ----
 type          : integration     # do not change this line type          : integration     # do not change this line
-supports-foxycart-version-from :     # Minimum required FoxyCart version for this to work+supports-foxycart-version-from :  1.1   # Minimum required FoxyCart version for this to work
 supports-foxycart-version-to   :     # Last FoxyCart version that supports this (leave empty if unknown) supports-foxycart-version-to   :     # Last FoxyCart version that supports this (leave empty if unknown)
-systems       :                 # the system(s) that the integration is for, separated with commas if more than one +systems       :   Zapier              # the system(s) that the integration is for, separated with commas if more than one 
-name          :                 # the name of the integration +name          :   Zapier Datafeed              # the name of the integration 
-description   :                  +description   :  Set your datafeed to push orders to Zapier                
-tags_tags     :                 # tags, separated by commas. don't include the "system" here. +tags_tags     :  zapier, api               # tags, separated by commas. don't include the "system" here. 
-date_dt       :                 # the date in YYYY-MM-DD format +date_dt       :   2014-10-07              # the date in YYYY-MM-DD format 
-version       :                 # if you have a version for your code, enter it here +version       :   1.0              # if you have a version for your code, enter it here 
-developer_url :                 # if you'd like a link back to your site, stick it here+developer_url :  http://www.sparkweb.net/               # if you'd like a link back to your site, stick it here
 ---- ----
  
  
  
-====== zapier-datafeed ======+====== Zapier ======
  
-<WRAP important round>+<WRAP center round important 90%> 
 +**We have implemented a different approach for Zapier.** In place of the following snippet, we now have [[v:2.0:webhooks|webhooks for Zapier (beta)]] feature in FoxyCart that allows you to pass the data from FoxyCart onto a whole stack of other services quickly and easily. Please see the "Zapier" section [[v:2.0:webhooks|here]]. This page will remain for reference.</WRAP> 
 + 
 + 
 +<WRAP center round important 90%>
 //**Please note:**// //**Please note:**//
 The code on this page is submitted by members of the FoxyCart community, and may not verified by FoxyCart.com LLC in any way, shape, or form. Please double check the code before installing. If you need help with it please [[http://forum.foxycart.com/|post in our forum]], but if we cannot offer assistance (due to unfamiliarity with this particular system or language) we apologize in advance. The code on this page is submitted by members of the FoxyCart community, and may not verified by FoxyCart.com LLC in any way, shape, or form. Please double check the code before installing. If you need help with it please [[http://forum.foxycart.com/|post in our forum]], but if we cannot offer assistance (due to unfamiliarity with this particular system or language) we apologize in advance.
Line 22: Line 26:
  
 ===== Description ===== ===== Description =====
 +Use the FoxyCart datafeed to push your orders to Zapier for processing and submitting to third-party API's.
  
 +===== Requirements =====
 +PHP, cURL
  
-===== Installation =====+===== Code ===== 
 +<code php><?php 
 +//Zapier Webhook Script by David Hollander, www.sparkweb.net 
 +//Version 1.0, 2014-10-07
  
 +//Setup Instructions
 +//-------------------------------------------------------------------------------------------------------------------
  
-===== Requirements =====+//Go to this url to enable the Zapier app: https://zapier.com/developer/invite/6466/2e388f1a688ec8ed2976c539d9ab71c4/
  
 +//Get this field from the FoxyCart > Advanced Settings page
 +$foxycart_api_key = "";
  
-===== Code ===== +//You'll be presented with a url when setting up your Zapier integration. Enter it here: 
-<code html+$zapier_static_webhook_url ""; 
-insert your code here, or upload zip file+ 
 +//This file needs to be saved on your webserver. Then go to Advanced Settings and check the box to enable store datafeed. 
 +//Put the url for this file in the datafeed box. 
 + 
 +//When Zapier asks you to create a brand new transaction in FoxyCart, just refeed a transaction. 
 +//You can do this by expanding the transaction on the FoxyCart transactions page. 
 + 
 +//------------------------------------------------------------------------------------------------------------------- 
 + 
 + 
 + 
 + 
 +//Processing The Datafeed 
 +if (isset($_POST["FoxyData"])) { 
 + 
 + //Make sure we have everything we need 
 + if (!$foxycart_api_key) { 
 + die("Please enter your FoxyCart API key."); 
 + } elseif (!$zapier_static_webhook_url) { 
 + die("Please enter your static webhook url from Zapier."); 
 +
 + 
 + //Decrypt the Datafeed 
 + $decrypted foxycart_decrypt($_POST["FoxyData"]); 
 + $xml_string simplexml_load_string($decrypted, NULL, LIBXML_NOCDATA); 
 + $json json_encode($xml_string); 
 + 
 + //Send to Zapier 
 + $ch curl_init(); 
 + curl_setopt_array($ch, array( 
 + CURLOPT_URL => $zapier_static_webhook_url, 
 + CURLOPT_FAILONERROR => 1, 
 + CURLOPT_RETURNTRANSFER => 1, 
 + CURLOPT_TIMEOUT => 5, 
 + CURLOPT_POSTFIELDS => $json, 
 + CURLOPT_POST => true, 
 + )); 
 + $result = curl_exec($ch); 
 + curl_close($ch); 
 + 
 + //Process Response 
 + $json = json_decode($result, 1); 
 + 
 + //No JSON Returned 
 + if (!is_array($json)) { 
 + die("Invalid Response: $result"); 
 + 
 + //Failure 
 + } elseif ($json['status'] != "success") { 
 + die("Unsuccessful Status: $result"); 
 + 
 + //All Good! 
 + } else { 
 + die("foxy"); 
 +
 + 
 +} else { 
 + die('No Content Received From Datafeed'); 
 +
 + 
 + 
 + 
 + 
 +//Decrypt Data From Source 
 +function foxycart_decrypt($src) { 
 +    global $foxycart_api_key; 
 + return rc4crypt::decrypt($foxycart_api_key, urldecode($src)); 
 +
 + 
 + 
 +// ====================================================================================== 
 +// RC4 ENCRYPTION CLASS 
 +// Do not modify. 
 +// ====================================================================================== 
 +/** 
 + * RC4Crypt 3.2 
 + * 
 + * RC4Crypt is a petite library that allows you to use RC4 
 + * encryption easily in PHP. It's OO and can produce outputs 
 + * in binary and hex. 
 + * 
 + * (C) Copyright 2006 Mukul Sabharwal [http://mjsabby.com] 
 +     All Rights Reserved 
 + * 
 + * @link http://rc4crypt.devhome.org 
 + * @author Mukul Sabharwal <mjsabby@gmail.com
 + * @version $Id: class.rc4crypt.php,v 3.2 2006/03/10 05:47:24 mukul Exp $ 
 + * @copyright Copyright &copy; 2006 Mukul Sabharwal 
 + * @license http://www.gnu.org/copyleft/gpl.html 
 + * @package RC4Crypt 
 + */ 
 +class rc4crypt { 
 + /** 
 + * The symmetric encryption function 
 +
 + * @param string $pwd Key to encrypt with (can be binary of hex) 
 + * @param string $data Content to be encrypted 
 + * @param bool $ispwdHex Key passed is in hexadecimal or not 
 + * @access public 
 + * @return string 
 + */ 
 + public static function encrypt ($pwd, $data, $ispwdHex = 0) { 
 + if ($ispwdHex) $pwd = @pack('H*', $pwd); // valid input, please! 
 +  $key[] = ''; 
 + $box[] = ''; 
 + $cipher = ''; 
 + $pwd_length = strlen($pwd); 
 + $data_length = strlen($data); 
 + for ($i = 0; $i < 256; $i++) { 
 + $key[$i] = ord($pwd[$i % $pwd_length]); 
 + $box[$i] = $i; 
 +
 + for ($j = $i = 0; $i < 256; $i++) { 
 + $j = ($j + $box[$i] + $key[$i]) % 256; 
 + $tmp = $box[$i]; 
 + $box[$i] = $box[$j]; 
 + $box[$j] = $tmp; 
 +
 + for ($= $j = $i = 0; $i < $data_length; $i++) { 
 + $a = ($a + 1) % 256; 
 + $j = ($j + $box[$a]) % 256; 
 + $tmp = $box[$a]; 
 + $box[$a] = $box[$j]; 
 + $box[$j] = $tmp; 
 + $k = $box[(($box[$a] + $box[$j]) % 256)]; 
 + $cipher .= chr(ord($data[$i]) ^ $k); 
 +
 + return $cipher; 
 +
 + /** 
 + * Decryption, recall encryption 
 +
 + * @param string $pwd Key to decrypt with (can be binary of hex) 
 + * @param string $data Content to be decrypted 
 + * @param bool $ispwdHex Key passed is in hexadecimal or not 
 + * @access public 
 + * @return string 
 + */ 
 + public static function decrypt ($pwd, $data, $ispwdHex = 0) { 
 + return rc4crypt::encrypt($pwd, $data, $ispwdHex); 
 +
 +}
 </code> </code>
  
  

Site Tools