Table of Contents

type:
integration
system:
Ruby on Rails
name:
Datafeed Decryption Example
description:
A basic example of how to decrypt a foxycart v060 datafeed
tag:
datafeed, encryption
date:
2010-06-25
version:
1.0
developer:
http://obledesign.com

Datafeed Decryption Example

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 post in our forum, but if we cannot offer assistance (due to unfamiliarity with this particular system or language) we apologize in advance.

Description

A simple example of how to implement a datafeed listener in Ruby on Rails. It especially focuses on decrypting the RC4 encryption.

Installation

  1. Create a new Datafeeds controller with the code below or paste the method into your own controller.
  2. Edit the API_KEY with the API key from your own store.

Requirements

Gotchas

Code

class DatafeedsController < ApplicationController
 
  API_KEY = 'YOUR_API_KEY_GOES_HERE'
 
  # Parses Foxycart datafeed v060
  # see http://wiki.foxycart.com/docs/datafeed for details
  def create
 
    require 'rc4'
    require 'nokogiri'
 
    decryptor = RC4.new(API_KEY) 
    xml = decryptor.decrypt(CGI::unescape(params['FoxyData']))
 
    feed = Nokogiri::XML(xml)
    feed.xpath('.//transaction').each do |transaction|
 
      # PROCESS THE FEED AS YOU LIKE HERE
 
    end
 
    render :text => 'foxy'
 
    rescue Exception=>e
      render :text => e.to_s
 
  end
 
end