Advertisement
sparkweb

Sample FoxyCart Datafeed

Feb 18th, 2012
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.53 KB | None | 0 0
  1. <?php
  2.  
  3. //Set Globals and Get Settings
  4. $apikey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  5.  
  6. //-----------------------------------------------------
  7. // TRANSACTION DATAFEED
  8. //-----------------------------------------------------
  9. if (isset($_POST["FoxyData"])) {
  10.  
  11.    
  12.     //DECRYPT (required)
  13.     //-----------------------------------------------------
  14.     $FoxyData_decrypted = foxycart_decrypt($_POST["FoxyData"]);
  15.     $xml = simplexml_load_string($FoxyData_decrypted, NULL, LIBXML_NOCDATA);
  16.  
  17.    
  18.     //For Each Transaction
  19.     foreach($xml->transactions->transaction as $transaction) {
  20.    
  21.         //This variable will tell us whether this is a multi-ship store or not
  22.         $is_multiship = 0;
  23.  
  24.         //Get FoxyCart Transaction Information
  25.         //Simply setting lots of helpful data to PHP variables so you can access it easily
  26.         //If you need to access more variables, you can see some sample XML here: http://wiki.foxycart.com/v/0.7.2/transaction_xml_datafeed
  27.         $transaction_id = (string)$transaction->id;
  28.         $transaction_date = (string)$transaction->transaction_date;
  29.         $customer_ip = (string)$transaction->customer_ip;
  30.         $customer_id = (string)$transaction->customer_id;
  31.         $customer_first_name = (string)$transaction->customer_first_name;
  32.         $customer_last_name = (string)$transaction->customer_last_name;
  33.         $customer_company = (string)$transaction->customer_company;
  34.         $customer_email = (string)$transaction->customer_email;
  35.         $customer_password = (string)$transaction->customer_password;
  36.         $customer_address1 = (string)$transaction->customer_address1;
  37.         $customer_address2 = (string)$transaction->customer_address2;
  38.         $customer_city = (string)$transaction->customer_city;
  39.         $customer_state = (string)$transaction->customer_state;
  40.         $customer_postal_code = (string)$transaction->customer_postal_code;
  41.         $customer_country = (string)$transaction->customer_country;
  42.         $customer_phone = (string)$transaction->customer_phone;
  43.        
  44.        
  45.         //This is for a multi-ship store. The shipping addresses will go in a $shipto array with the address name as the key
  46.         $shipto = array();
  47.         foreach($transaction->shipto_addresses->shipto_address as $shipto_address) {
  48.             $is_multiship = 1;
  49.             $shipto_name = (string)$shipto_address->address_name;
  50.             $shipto[$shipto_name] = array(
  51.                 'first_name' => (string)$shipto_address->shipto_first_name,
  52.                 'last_name' => (string)$shipto_address->shipto_last_name,
  53.                 'company' => (string)$shipto_address->shipto_company,
  54.                 'address1' => (string)$shipto_address->shipto_address1,
  55.                 'address2' => (string)$shipto_address->shipto_address2,
  56.                 'city' => (string)$shipto_address->shipto_city,
  57.                 'state' => (string)$shipto_address->shipto_state,
  58.                 'postal_code' => (string)$shipto_address->shipto_postal_code,
  59.                 'country' => (string)$shipto_address->shipto_country,
  60.                 'shipping_service_description' => (string)$shipto_address->shipto_shipping_service_description,
  61.                 'subtotal' => (string)$shipto_address->shipto_subtotal,
  62.                 'tax_total' => (string)$shipto_address->shipto_tax_total,
  63.                 'shipping_total' => (string)$shipto_address->shipto_shipping_total,
  64.                 'total' => (string)$shipto_address->shipto_,
  65.                 'custom_fields' => array()
  66.             );
  67.            
  68.             //Putting the Custom Fields in an array if they are there
  69.             if (!empty($shipto_address->custom_fields)) {
  70.                 foreach($shipto_address->custom_fields->custom_field as $custom_field) {
  71.                     $shipto[$shipto_name]['custom_fields'][(string)$custom_field->custom_field_name] = (string)$custom_field->custom_field_value;
  72.                 }
  73.             }
  74.         }
  75.        
  76.         //This is setup for a single ship store
  77.         if (!$is_multiship) {
  78.             $shipping_first_name = (string)$transaction->shipping_first_name ? (string)$transaction->shipping_first_name : $customer_first_name;
  79.             $shipping_last_name = (string)$transaction->shipping_last_name ? (string)$transaction->shipping_last_name : $customer_last_name;
  80.             $shipping_company = (string)$transaction->shipping_company ? (string)$transaction->shipping_company : $customer_company;
  81.             $shipping_address1 = (string)$transaction->shipping_address1 ? (string)$transaction->shipping_address1 : $customer_address1;
  82.             $shipping_address2 = (string)$transaction->shipping_address2 ? (string)$transaction->shipping_address2 : $customer_address2;
  83.             $shipping_city = (string)$transaction->shipping_city ? (string)$transaction->shipping_city : $customer_city;
  84.             $shipping_state = (string)$transaction->shipping_state ? (string)$transaction->shipping_state : $customer_state;
  85.             $shipping_postal_code = (string)$transaction->shipping_postal_code ? (string)$transaction->shipping_postal_code : $customer_postal_code;
  86.             $shipping_country = (string)$transaction->shipping_country ? (string)$transaction->shipping_country : $customer_country;
  87.             $shipping_phone = (string)$transaction->shipping_phone ? (string)$transaction->shipping_phone : $customer_phone;
  88.             $shipto_shipping_service_description = (string)$transaction->shipto_shipping_service_description;
  89.         }
  90.  
  91.         //Putting the Custom Fields in an array if they are there. These are on the top level and could be there for both single ship and multiship stores
  92.         $custom_fields = array();
  93.         if (!empty($transaction->custom_fields)) {
  94.             foreach($transaction->custom_fields->custom_field as $custom_field) {
  95.                 $custom_fields[(string)$custom_field->custom_field_name] = (string)$custom_field->custom_field_value;
  96.             }
  97.         }
  98.        
  99.  
  100.        
  101.  
  102.  
  103.  
  104.         //For Each Transaction Detail
  105.         foreach($transaction->transaction_details->transaction_detail as $transaction_detail) {
  106.             $product_name = (string)$transaction_detail->product_name;
  107.             $product_code = (string)$transaction_detail->product_code;
  108.             $product_quantity = (int)$transaction_detail->product_quantity;
  109.             $product_price = (double)$transaction_detail->product_price;
  110.             $product_shipto = (double)$transaction_detail->shipto;
  111.             $category_code = (string)$transaction_detail->category_code;
  112.             $product_delivery_type = (string)$transaction_detail->product_delivery_type;
  113.             $sub_token_url = (string)$transaction_detail->sub_token_url;
  114.             $subscription_frequency = (string)$transaction_detail->subscription_frequency;
  115.             $subscription_startdate = (string)$transaction_detail->subscription_startdate;
  116.             $subscription_nextdate = (string)$transaction_detail->subscription_nextdate;
  117.             $subscription_enddate = (string)$transaction_detail->subscription_enddate;
  118.            
  119.             //These are the options for the product
  120.             $transaction_detail_options = array();
  121.             foreach($transaction_detail->transaction_detail_options->transaction_detail_option as $transaction_detail_option) {
  122.                 $product_option_name = $transaction_detail_option->product_option_name;
  123.                 $product_option_value = (string)$transaction_detail_option->product_option_value;
  124.                 $price_mod = (double)$transaction_detail_option->price_mod;
  125.                 $weight_mod = (double)$transaction_detail_option->weight_mod;
  126.  
  127.  
  128.  
  129.  
  130.             }
  131.  
  132.  
  133.  
  134.  
  135.  
  136.             //If you have custom code to run for each product, put it here:
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.         }
  148.        
  149.         //If you have custom code to run for each order, put it here:
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.     }
  163.    
  164.     //All Done!
  165.     die("foxy");
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173. //-----------------------------------------------------
  174. // NO POST CONTENT SENT
  175. //-----------------------------------------------------
  176. } else {
  177.     die('No Content Received From Datafeed');
  178. }
  179.  
  180.  
  181.  
  182.  
  183. //Decrypt Data From Source
  184. function foxycart_decrypt($src) {
  185.         global $apikey;
  186.     return rc4crypt::decrypt($apikey,urldecode($src));
  187. }
  188.  
  189.  
  190. // ======================================================================================
  191. // RC4 ENCRYPTION CLASS
  192. // Do not modify.
  193. // ======================================================================================
  194. /**
  195.  * RC4Crypt 3.2
  196.  *
  197.  * RC4Crypt is a petite library that allows you to use RC4
  198.  * encryption easily in PHP. It's OO and can produce outputs
  199.  * in binary and hex.
  200.  *
  201.  * (C) Copyright 2006 Mukul Sabharwal [http://mjsabby.com]
  202.  *     All Rights Reserved
  203.  *
  204.  * @link http://rc4crypt.devhome.org
  205.  * @author Mukul Sabharwal <mjsabby@gmail.com>
  206.  * @version $Id: class.rc4crypt.php,v 3.2 2006/03/10 05:47:24 mukul Exp $
  207.  * @copyright Copyright &copy; 2006 Mukul Sabharwal
  208.  * @license http://www.gnu.org/copyleft/gpl.html
  209.  * @package RC4Crypt
  210.  */
  211. class rc4crypt {
  212.     /**
  213.      * The symmetric encryption function
  214.      *
  215.      * @param string $pwd Key to encrypt with (can be binary of hex)
  216.      * @param string $data Content to be encrypted
  217.      * @param bool $ispwdHex Key passed is in hexadecimal or not
  218.      * @access public
  219.      * @return string
  220.      */
  221.     function encrypt ($pwd, $data, $ispwdHex = 0) {
  222.         if ($ispwdHex) $pwd = @pack('H*', $pwd); // valid input, please!
  223.         $key[] = '';
  224.         $box[] = '';
  225.         $cipher = '';
  226.         $pwd_length = strlen($pwd);
  227.         $data_length = strlen($data);
  228.         for ($i = 0; $i < 256; $i++) {
  229.             $key[$i] = ord($pwd[$i % $pwd_length]);
  230.             $box[$i] = $i;
  231.         }
  232.         for ($j = $i = 0; $i < 256; $i++) {
  233.             $j = ($j + $box[$i] + $key[$i]) % 256;
  234.             $tmp = $box[$i];
  235.             $box[$i] = $box[$j];
  236.             $box[$j] = $tmp;
  237.         }
  238.         for ($a = $j = $i = 0; $i < $data_length; $i++) {
  239.             $a = ($a + 1) % 256;
  240.             $j = ($j + $box[$a]) % 256;
  241.             $tmp = $box[$a];
  242.             $box[$a] = $box[$j];
  243.             $box[$j] = $tmp;
  244.             $k = $box[(($box[$a] + $box[$j]) % 256)];
  245.             $cipher .= chr(ord($data[$i]) ^ $k);
  246.         }
  247.         return $cipher;
  248.     }
  249.     /**
  250.      * Decryption, recall encryption
  251.      *
  252.      * @param string $pwd Key to decrypt with (can be binary of hex)
  253.      * @param string $data Content to be decrypted
  254.      * @param bool $ispwdHex Key passed is in hexadecimal or not
  255.      * @access public
  256.      * @return string
  257.      */
  258.     function decrypt ($pwd, $data, $ispwdHex = 0) {
  259.         return rc4crypt::encrypt($pwd, $data, $ispwdHex);
  260.     }
  261. }
  262. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement