Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
integration:csharp-reading-xmldatafeed-with-xmlserializer [2012/08/22 09:12] babbleintegration:csharp-reading-xmldatafeed-with-xmlserializer [2019/10/18 03:15] (current) – [Data entry] adam
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 :     1.0 +supports-foxycart-version-from : 1.0  
-supports-foxycart-version-to   :     # Last FoxyCart version that supports this (leave empty if unknown) +supports-foxycart-version-to   : 1.0 # Last FoxyCart version that supports this (leave empty if unknown) 
-systems                       cSharp, .netasp.net +systems                        ASP.NetC\# #  
-name                          Reading the transaction feed using XmlSerializer in cSharp.net +name                           : Reading the transaction feed using XmlSerializer in cSharp.net  
-description                    +description                    Shows how to use the .net XmlSerializer object to easily read the FoxyCart transaction feed in cSharp.net #  
-tags_tags                     cSharp, .net, datafeed, xml +tags                           : cSharp, .net, datafeed, xml  
-date_dt                       2012-08-22 +date_dt                        : 2012-08-22  
-version                       v0.1 +version                        : v0.1  
-developer_url :                 # if you'd like a link back to your site, stick it here+developer_url                  http://www.babblebib.com # if you'd like a link back to your site, stick it here
 ---- ----
  
  
  
-====== csharp-reading-xmldatafeed-with-xmlserializer ======+ 
 +====== Reading the transaction datafeed with XmlSerializer class in c# ======
  
 <WRAP important round> <WRAP important round>
Line 23: Line 24:
 ===== Description ===== ===== Description =====
 This post outlines the most effective way of reading the FoxyCart transaction data feed in c#.net and asp.net. It is written in c#, but could apply to any .net language. This post outlines the most effective way of reading the FoxyCart transaction data feed in c#.net and asp.net. It is written in c#, but could apply to any .net language.
 +
 +The post is based on FoxyCart v1.0, but the logic works just as well for any version. However if you are using previous versions, you'll have to go through the entire article without skipping any steps.
  
 The post is based around the ''XmlSerializer'' class which can serialize an XML file and give you a very easy way to the data using code such as ''transaction.customer_name''. See here for details on XmlSerializer class [[http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx]] The post is based around the ''XmlSerializer'' class which can serialize an XML file and give you a very easy way to the data using code such as ''transaction.customer_name''. See here for details on XmlSerializer class [[http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx]]
Line 44: Line 47:
   * Enter the following command, this will generated a file called FoxyData_v1.xsd: ''xsd.exe FoxyData_v1.xml''   * Enter the following command, this will generated a file called FoxyData_v1.xsd: ''xsd.exe FoxyData_v1.xml''
   * Open FoxyData_v1.xsd in **Notepad**   * Open FoxyData_v1.xsd in **Notepad**
-  * **Find and replace** ''</xs:sequence>'' with ''</xs:sequence><xs:attribute name="tmp" type="xs:string" />''. Save the updated XSD file.+  * **Find and replace** ''</xs:sequence>'' with ''</xs:sequence><xs:attribute name="tmp" type="xs:string" />''. NOTE: You may experience problems wit the way the speech marks are copied and pasted, watch out for errors related to this in the next section, if you see them, just do another find and replace but re-type the speech marks. Save the updated XSD file.
   * In the **Visual Studio 2010 command prompt** enter the following command. This will generate a file called FoxyData_v1.cs: ''xsd.exe /c FoxyData_v1.xsd''    * In the **Visual Studio 2010 command prompt** enter the following command. This will generate a file called FoxyData_v1.cs: ''xsd.exe /c FoxyData_v1.xsd'' 
  
Line 107: Line 110:
 Visual Studio 2010 (or newer). Visual Studio 2010 (or newer).
  
-A Foxy Cart transaction feed XML file (v1.0). Decrypted and decoded. See other articles on how to decrypt and decode the FoxyCart transaction feed in .net.+A Foxy Cart transaction feed XML file (v1.0 - see description section for previous versions). Decrypted and decoded. See other articles on how to decrypt and decode the FoxyCart transaction feed in .net.
  
  
Line 151: Line 154:
 // <auto-generated> // <auto-generated>
 //     This code was generated by a tool. //     This code was generated by a tool.
-//     Runtime Version:4.0.30319.269+//     Runtime Version:4.0.30319.17929
 // //
 //     Changes to this file may cause incorrect behavior and will be lost if //     Changes to this file may cause incorrect behavior and will be lost if
Line 366: Line 369:
          
     private string customer_password_hash_configField;     private string customer_password_hash_configField;
-     
-    private string custom_fieldsField; 
          
     private string shipto_addressesField;     private string shipto_addressesField;
Line 376: Line 377:
          
     private foxydataTransactionsTransactionDiscounts[] discountsField;     private foxydataTransactionsTransactionDiscounts[] discountsField;
 +    
 +    private foxydataTransactionsTransactionCustom_fields[] custom_fieldsField;
          
     private foxydataTransactionsTransactionTransaction_details[] transaction_detailsField;     private foxydataTransactionsTransactionTransaction_details[] transaction_detailsField;
Line 983: Line 986:
         set {         set {
             this.customer_password_hash_configField = value;             this.customer_password_hash_configField = value;
-        } 
-    } 
-     
-    /// <remarks/> 
-    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] 
-    public string custom_fields { 
-        get { 
-            return this.custom_fieldsField; 
-        } 
-        set { 
-            this.custom_fieldsField = value; 
         }         }
     }     }
Line 1038: Line 1030:
         set {         set {
             this.discountsField = value;             this.discountsField = value;
 +        }
 +    }
 +    
 +    /// <remarks/>
 +    [System.Xml.Serialization.XmlElementAttribute("custom_fields", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
 +    public foxydataTransactionsTransactionCustom_fields[] custom_fields {
 +        get {
 +            return this.custom_fieldsField;
 +        }
 +        set {
 +            this.custom_fieldsField = value;
         }         }
     }     }
Line 1232: Line 1235:
         set {         set {
             this.coupon_discount_detailsField = value;             this.coupon_discount_detailsField = value;
 +        }
 +    }
 +    
 +    /// <remarks/>
 +    [System.Xml.Serialization.XmlAttributeAttribute()]
 +    public string tmp {
 +        get {
 +            return this.tmpField;
 +        }
 +        set {
 +            this.tmpField = value;
 +        }
 +    }
 +}
 +
 +/// <remarks/>
 +[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
 +[System.SerializableAttribute()]
 +[System.Diagnostics.DebuggerStepThroughAttribute()]
 +[System.ComponentModel.DesignerCategoryAttribute("code")]
 +[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
 +public partial class foxydataTransactionsTransactionCustom_fields {
 +    
 +    private foxydataTransactionsTransactionCustom_fieldsCustom_field[] custom_fieldField;
 +    
 +    private string tmpField;
 +    
 +    /// <remarks/>
 +    [System.Xml.Serialization.XmlElementAttribute("custom_field", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
 +    public foxydataTransactionsTransactionCustom_fieldsCustom_field[] custom_field {
 +        get {
 +            return this.custom_fieldField;
 +        }
 +        set {
 +            this.custom_fieldField = value;
 +        }
 +    }
 +    
 +    /// <remarks/>
 +    [System.Xml.Serialization.XmlAttributeAttribute()]
 +    public string tmp {
 +        get {
 +            return this.tmpField;
 +        }
 +        set {
 +            this.tmpField = value;
 +        }
 +    }
 +}
 +
 +/// <remarks/>
 +[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
 +[System.SerializableAttribute()]
 +[System.Diagnostics.DebuggerStepThroughAttribute()]
 +[System.ComponentModel.DesignerCategoryAttribute("code")]
 +[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
 +public partial class foxydataTransactionsTransactionCustom_fieldsCustom_field {
 +    
 +    private string custom_field_nameField;
 +    
 +    private string custom_field_valueField;
 +    
 +    private string custom_field_is_hiddenField;
 +    
 +    private string tmpField;
 +    
 +    /// <remarks/>
 +    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
 +    public string custom_field_name {
 +        get {
 +            return this.custom_field_nameField;
 +        }
 +        set {
 +            this.custom_field_nameField = value;
 +        }
 +    }
 +    
 +    /// <remarks/>
 +    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
 +    public string custom_field_value {
 +        get {
 +            return this.custom_field_valueField;
 +        }
 +        set {
 +            this.custom_field_valueField = value;
 +        }
 +    }
 +    
 +    /// <remarks/>
 +    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
 +    public string custom_field_is_hidden {
 +        get {
 +            return this.custom_field_is_hiddenField;
 +        }
 +        set {
 +            this.custom_field_is_hiddenField = value;
         }         }
     }     }
Line 1721: Line 1820:
     }     }
 } }
-</code> 
- 
-==== FoxyData_v1.xsd ==== 
-This is the XSD file that is used to create the FoxyData_v1.cs class. It has been updated to include the ''<xs:attribute name="tmp" type="xs:string" />''. This is based on v1.0 of the transaction feed, but may not be a complete file. Hopefully FoxyCart will provide a complete XSD at some point soon (nudge, nudge FoxyCart! ) 
- 
-<code> 
-<?xml version="1.0" encoding="utf-8"?> 
-<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
-  <xs:element name="foxydata"> 
-    <xs:complexType> 
-      <xs:sequence> 
-        <xs:element name="store_version" type="xs:string" minOccurs="0" /> 
-        <xs:element name="transactions" minOccurs="0" maxOccurs="unbounded"> 
-          <xs:complexType> 
-            <xs:sequence> 
-              <xs:element name="transaction" minOccurs="0" maxOccurs="unbounded"> 
-                <xs:complexType> 
-                  <xs:sequence> 
-                    <xs:element name="id" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="store_id" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="store_version" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="is_test" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="is_hidden" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="data_is_fed" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="transaction_date" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="payment_type" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="payment_gateway_type" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="processor_response" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="purchase_order" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="cc_number_masked" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="cc_type" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="cc_exp_month" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="cc_exp_year" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="cc_start_date_month" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="cc_start_date_year" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="cc_issue_number" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="minfraud_score" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="paypal_payer_id" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_id" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="is_anonymous" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_first_name" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_last_name" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_company" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_address1" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_address2" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_city" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_state" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_postal_code" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_country" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_phone" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_email" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_ip" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipping_first_name" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipping_last_name" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipping_company" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipping_address1" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipping_address2" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipping_city" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipping_state" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipping_postal_code" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipping_country" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipping_phone" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipto_shipping_service_description" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="product_total" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="tax_total" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipping_total" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="order_total" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="receipt_url" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="taxes" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_password" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_password_salt" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_password_hash_type" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="customer_password_hash_config" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="custom_fields" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="shipto_addresses" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="attributes" type="xs:string" minOccurs="0" /> 
-                    <xs:element name="processor_response_details" minOccurs="0" maxOccurs="unbounded"> 
-                      <xs:complexType> 
-                        <xs:sequence> 
-                          <xs:element name="PaymentType" type="xs:string" minOccurs="0" /> 
-                        </xs:sequence><xs:attribute name="tmp" type="xs:string" /> 
-                      </xs:complexType> 
-                    </xs:element> 
-                    <xs:element name="discounts" minOccurs="0" maxOccurs="unbounded"> 
-                      <xs:complexType> 
-                        <xs:sequence> 
-                          <xs:element name="discount" minOccurs="0" maxOccurs="unbounded"> 
-                            <xs:complexType> 
-                              <xs:sequence> 
-                                <xs:element name="code" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="valid_categories" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="name" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="amount" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="display" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="coupon_discount_type" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="coupon_discount_details" type="xs:string" minOccurs="0" /> 
-                              </xs:sequence><xs:attribute name="tmp" type="xs:string" /> 
-                            </xs:complexType> 
-                          </xs:element> 
-                        </xs:sequence><xs:attribute name="tmp" type="xs:string" /> 
-                      </xs:complexType> 
-                    </xs:element> 
-                    <xs:element name="transaction_details" minOccurs="0" maxOccurs="unbounded"> 
-                      <xs:complexType> 
-                        <xs:sequence> 
-                          <xs:element name="transaction_detail" minOccurs="0" maxOccurs="unbounded"> 
-                            <xs:complexType> 
-                              <xs:sequence> 
-                                <xs:element name="product_name" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="product_price" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="product_quantity" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="product_weight" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="product_code" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="image" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="url" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="length" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="width" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="height" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="downloadable_url" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="sub_token_url" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="subscription_frequency" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="subscription_startdate" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="subscription_nextdate" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="subscription_enddate" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="is_future_line_item" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="shipto" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="category_description" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="category_code" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="product_delivery_type" type="xs:string" minOccurs="0" /> 
-                                <xs:element name="transaction_detail_options" minOccurs="0" maxOccurs="unbounded"> 
-                                  <xs:complexType> 
-                                    <xs:sequence> 
-                                      <xs:element name="transaction_detail_option" minOccurs="0" maxOccurs="unbounded"> 
-                                        <xs:complexType> 
-                                          <xs:sequence> 
-                                            <xs:element name="product_option_name" type="xs:string" minOccurs="0" /> 
-                                            <xs:element name="product_option_value" type="xs:string" minOccurs="0" /> 
-                                            <xs:element name="price_mod" type="xs:string" minOccurs="0" /> 
-                                            <xs:element name="weight_mod" type="xs:string" minOccurs="0" /> 
-                                          </xs:sequence><xs:attribute name="tmp" type="xs:string" /> 
-                                        </xs:complexType> 
-                                      </xs:element> 
-                                    </xs:sequence><xs:attribute name="tmp" type="xs:string" /> 
-                                  </xs:complexType> 
-                                </xs:element> 
-                              </xs:sequence><xs:attribute name="tmp" type="xs:string" /> 
-                            </xs:complexType> 
-                          </xs:element> 
-                        </xs:sequence><xs:attribute name="tmp" type="xs:string" /> 
-                      </xs:complexType> 
-                    </xs:element> 
-                  </xs:sequence><xs:attribute name="tmp" type="xs:string" /> 
-                </xs:complexType> 
-              </xs:element> 
-            </xs:sequence><xs:attribute name="tmp" type="xs:string" /> 
-          </xs:complexType> 
-        </xs:element> 
-      </xs:sequence><xs:attribute name="tmp" type="xs:string" /> 
-    </xs:complexType> 
-  </xs:element> 
-  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"> 
-    <xs:complexType> 
-      <xs:choice minOccurs="0" maxOccurs="unbounded"> 
-        <xs:element ref="foxydata" /> 
-      </xs:choice> 
-    </xs:complexType> 
-  </xs:element> 
-</xs:schema> 
 </code> </code>

Site Tools