====== Transaction XML Datafeeds: Instant Transaction Notification ======
===== An Overview of FoxyCart's Transaction XML Datafeed =====
In order to allow the flexibility and integration options that you need, FoxyCart can be configured to send encrypted XML to a URL of your choosing. This allows you to integrate FoxyCart without duplicating data across applications.
When you configure it for your store, it will send you an encrypted XML data via a ''POST'' of your new transactions immediately upon a successful transaction. You can use this to update inventory, create users or manage user permissions for a paid subscription site, or add users to your mailing list on a 3rd party email service provider's system. There are [[:integration|many examples]].
Please note that FoxyCart's XML datafeeds do //not// include credit card information (number, CSC, date, etc.).
===== DETAILS, BEST PRACTICES and TESTING Recommendations =====
==== Details ====
* When the datafeed is sent it **REQUIRES A RESPONSE OF ''foxy''** in order to indicate success. If anything other than ''foxy'' is returned by your datafeed processing script, FoxyCart will assume that your script errored, and you will be alerted.
* The Transaction XML Datafeed is sent immediately, in between the checkout and the receipt during your customers' transactions.
==== Testing ====
When you're testing your custom XML integration, don't run transactions through FoxyCart. This is both time consuming (as you have to add-to-cart and checkout), but it also doesn't give you any indication of what's actually going wrong.
A much better method is to use the [[:integration:foxycart:test_xml_post|XML Test Post]] script or [[:integration:foxycart:test_xml_post_with_csharp|application (C#)]]. This effectively mimics what FoxyCart is actually doing when sending the XML to your server in the first place. **Make sure you update the test XML** in the script to the appropriate version (below).
If you'd like to test using real data from your store, you can run a test transaction and [[:integration:foxycart:test_xml_write_to_file|write the datafeed to a file]], then copy it out and put it in the Test Post script.
If you're struggling to just get started with //reading// the feed, try this: on your script page, capture all the POST data and write it to a file. Test it by posting a simple form to this page just to ensure that it works, and then you can run a //single// FoxyCart transaction to capture its data. You should end up with an array with a key of 'FoxyData' and pages of url-encrypted data, e.g. "%EBrV%8C%E9...". After you've saved this to a file, you can work out the other details of your script, e.g. decoding the XML and routing it to your database or 3rd party applications (e.g. MailChimp).
==== Best Practices ====
* Test according to the above method.
* If you're doing complicated stuff, you may want to [[:integration:mysql|backup the XML to a database]]. This allows you to re-process things at a later date (like if you change mailing list service providers, add a new member functionality, etc.).
* Don't make assumptions about the data structure. Rather than just accessing a node and assuming the value is there, test first. This can prevent errors down the road.
==== Creating / Synching Users from the Datafeed ====
It might not be immediately obvious, but the instant transaction datafeed does indeed contain all the customer's information, so you can create new customers or update existing customer records via the datafeed. If you're using [[.:api|the API]] or [[.:sso|Single Sign-On]], make sure you understand the [[.:sso#best_practices|SSO Best Practices]] for this type of integration.
===== Notes =====
* The transaction XML datafeed comes with a ''POST'' name of ''FoxyData''. This is different than the [[subscription_xml_datafeed|Subscription XML Datafeeds]], which has a ''POST'' name of ''FoxySubscriptionData''.
=== Country Codes ===
For compatibility, FoxyCart uses ISO country codes in our XML:
* [[http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm|ISO.org]]
* [[wp>ISO_3166-1_alpha-2#Decoding_table|Wikipedia]]
===== Example XML =====
==== Non-MultiShip Store ====
0
==== MultiShip Store ====
0