Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
integration:foxycart:datafeed_with_csharp [2012/08/15 03:05]
95.144.180.128 [Requirements]
integration:foxycart:datafeed_with_csharp [2015/10/29 10:05] (current)
foxyluke [Data entry]
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 :  # 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 ​      ​ ASP.Net, C\#,                ​# the system(s) that the integration is for, separated with commas if more than one +systems ​                       : ASP.Net, C\# # the system(s) that the integration is for, separated with commas if more than one 
-name          : ASP.NET C\# API + Datafeed Code                 ​# the name of the integration +name                           ​: ASP.NET C\# API + Datafeed Code # the name of the integration 
-description ​  ​: Functions to interact with the FoxyCart API and XML Datafeed ​                +description ​                   : Functions to interact with the FoxyCart API and XML Datafeed ​ 
-tags_tags ​    : api, datafeed, xml, c\#, csharp, integration ​               # tags, separated by commas. don't include the "​system"​ here. +tags                           : api, datafeed, xml, c\#, csharp, integration # tags, separated by commas. don't include the "​system"​ here. 
-date_dt ​      ​: 2011-06-01 ​               # the date in YYYY-MM-DD format +date_dt ​                       : 2011-06-01 # the date in YYYY-MM-DD format 
-version ​      ​: 1.0                ​# if you have a version for your code, enter it here +version ​                       : 1.# 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 ​                  # if you'd like a link back to your site, stick it here
 ---- ----
  
  
-====== ASP.NET with C\# XML Datafeed E-Commerce Integration ======+ 
 +====== ASP.NET with C# XML Datafeed E-Commerce Integration ======
  
 <WRAP important round> <WRAP important round>
Line 49: Line 50:
         try         try
         {         {
-            ​string ​foxyFeed = Request.Form["​FoxyData"​];​ +            ​var foxyFeed = Request.Form["​FoxyData"​];​ 
-            ​byte[] ​ffBytes = Encoding.ASCII.GetBytes(foxyFeed);​ +            ​//Changed from ASCII to UTF8. Not sure why you'd get ASCII bytes on UTF-8 encoded data 
-            ​string ​unencodedFeed = HttpUtility.UrlDecode(ffBytes,​ Encoding.GetEncoding(1252));​ +            var ffBytes = Encoding.UTF8.GetBytes(foxyFeed);​ 
-            ​string transaction ​= RC4.Decrypt(API_KEY, ​unencodedFeed, false); +            ​//This takes the UTF-8 encoded bytes and decodes them to Latin-1. If the decoded data is not Latin-1, the RC4.Decrypt,​ doesn'​t seem to function properly. 
- +            var unencodedFeed = HttpUtility.UrlDecode(ffBytes,​ Encoding.GetEncoding(1252)); ​    ​ 
-            //Process ​the XML string "​transaction"​ as desired. +            ​var decryptedTransaction ​= RC4.Decrypt(API_KEY, ​unecodedUTF8Feed, false); 
 +            //At this point, we've decrypted UTF-8 data using the Latin-1 encoding, which functions properly, unless there are special characters in your data.  
 +            //​http://​www.weblogism.com/​item/​270/​why-does-e-become-a 
 +            //In order to fix the special characters, you need to turn the string back into Latin-1 bytes, and convert it to a UTF-8 string.  
 +            var transaction = Encoding.UTF8.GetString(Encoding.GetEncoding(1252).GetBytes(decryptedTransaction));​ 
 +                        ​ 
 +            //Now you can process ​the XML string "​transaction"​ as desired. 
 +     ​
             Response.Write("​foxy"​);​             Response.Write("​foxy"​);​
         }         }
         catch (Exception) { }   //​Just eat all exceptions. ​ You can log this internally if you'd like.         catch (Exception) { }   //​Just eat all exceptions. ​ You can log this internally if you'd like.
     }     }
- 
  
     /**     /**

Site Tools