Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

gem user can:

- create a gateway
- create a payment method
- fetch an existing payment method given a token
- (no error handling yet)
  • Loading branch information...
commit cead11390df97e81f2a6a657ecd400c956035812 1 parent 692a3bc
Lee Byrd & Rachel Heaton authored
View
6 Gemfile
@@ -0,0 +1,6 @@
+source :gemcutter
+
+# Specify your gem's dependencies in samurai.gemspec
+gemspec
+
+gem 'rspec_junit_formatter', :git=>'git://github.com/jkrall/rspec_junit_formatter.git'
View
54 Gemfile.lock
@@ -0,0 +1,54 @@
+GIT
+ remote: git://github.com/jkrall/rspec_junit_formatter.git
+ revision: a40f6008cfd085bddb801047760c406d6ea2ed83
+ specs:
+ rspec_junit_formatter (0.1.0)
+ builder
+ rspec (~> 2.0)
+
+PATH
+ remote: .
+ specs:
+ ronin (0.1)
+ activesupport
+ httparty
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activesupport (3.1.3)
+ multi_json (~> 1.0)
+ builder (3.0.0)
+ columnize (0.3.6)
+ diff-lcs (1.1.3)
+ httparty (0.8.1)
+ multi_json
+ multi_xml
+ linecache (0.46)
+ rbx-require-relative (> 0.0.4)
+ multi_json (1.0.4)
+ multi_xml (0.4.1)
+ rbx-require-relative (0.0.5)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.7.0)
+ ruby-debug (0.10.4)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.4.0)
+ ruby-debug-base (0.10.4)
+ linecache (>= 0.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bundler (>= 1.0.0)
+ ronin!
+ rspec (>= 2.6.0)
+ rspec_junit_formatter!
+ ruby-debug
View
3  lib/ronin.rb
@@ -0,0 +1,3 @@
+module Ronin; end
+require 'ronin/gateway'
+require 'ronin/models/payment_method'
View
56 lib/ronin/gateway.rb
@@ -0,0 +1,56 @@
+require 'httparty'
+require 'active_support/core_ext/hash'
+
+class Ronin::Gateway
+ def initialize(options={})
+ @site = options[:site]
+
+ @merchant_auth = {
+ :username =>options[:merchant_key],
+ :password => options[:merchant_password]
+ }
+
+ @processor_token = options[:processor_token]
+ end
+
+ def create_payment_method(params={})
+ response = post('payment_methods', :payment_method => params)
+ from_xml(Ronin::PaymentMethod, 'payment_method', response.body)
+ end
+
+ def find_payment_method(token)
+ response = get('payment_methods', token)
+ from_xml(Ronin::PaymentMethod, 'payment_method', response.body)
+ end
+
+ private
+
+ def get(uri, id)
+ request = HTTParty::Request.new(Net::HTTP::Get, "#{@site}#{uri}/#{id}.xml", :format => :xml, :basic_auth => @merchant_auth)
+ request.perform
+ end
+
+ def post(uri, params)
+ request = HTTParty::Request.new(Net::HTTP::Post, "#{@site}#{uri}.xml", :body => params, :format => :xml, :basic_auth => @merchant_auth)
+ request.perform
+ end
+
+ def from_xml(klass, key, attributes)
+ attributes = Hash.from_xml(attributes)[key]
+ obj = klass.new
+ obj.attributes = attributes
+ mod = Module.new do
+ obj.attributes.keys.each do |k|
+ define_method(k) do
+ return self.attributes[k]
+ end
+
+ define_method("#{k}=") do |val|
+ self.attributes[k] = val
+ end
+ end
+ end
+ obj.send(:extend, mod)
+ obj
+ end
+end
View
12 lib/ronin/models/payment_method.rb
@@ -0,0 +1,12 @@
+class Ronin::PaymentMethod
+ attr_accessor :attributes
+
+ def id
+ self.token
+ end
+
+ # Alias for `payment_method_token`
+ def token
+ self.attributes["payment_method_token"]
+ end
+end
View
30 ronin.gemspec
@@ -0,0 +1,30 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = "ronin"
+ s.version = "0.1"
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Ticket Evolution"]
+ s.email = ["dev@ticketevolution.com"]
+ s.homepage = "http://rubygems.org/gems/samurai"
+ s.summary = "Integration gem for samurai.feefighters.com"
+ s.description = "If you are an online merchant and using samurai.feefighters.com, this gem will make your life easy. Integrate with the samurai.feefighters.com portal and process transaction."
+
+ s.required_rubygems_version = ">= 1.3.5"
+
+ s.add_dependency 'activesupport'
+ s.add_dependency 'httparty'
+
+ s.add_development_dependency "bundler", ">= 1.0.0"
+ s.add_development_dependency "rspec", ">= 2.6.0"
+
+ if RUBY_VERSION =~ /^1\.9/
+ s.add_development_dependency 'ruby-debug19'
+ else
+ s.add_development_dependency 'ruby-debug'
+ end
+
+ s.files = `git ls-files`.split("\n")
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
+ s.require_path = 'lib'
+end
View
42 spec/integration/payment_method_spec.rb
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+describe "PaymentMethod" do
+ let(:gateway) { Ronin::Gateway.new(DEFAULT_OPTIONS.clone) }
+
+ before do
+ @params = {
+ :first_name => "FirstName",
+ :last_name => "LastName",
+ :address_1 => "123 Main St.",
+ :address_2 => "Apt #3",
+ :city => "Chicago",
+ :state => "IL",
+ :zip => "10101",
+ :card_number => "4111-1111-1111-1111",
+ :cvv => "123",
+ :expiry_month => '03',
+ :expiry_year => "2015",
+ }
+ end
+
+ describe 'S2S #create' do
+ it 'should be successful' do
+ payment_method = gateway.create_payment_method(@params)
+
+ gateway.find_payment_method(payment_method.token).tap do |pm|
+ pm.is_sensitive_data_valid.should be_true
+ pm.is_expiration_valid.should be_true
+ pm.first_name.should == @params[:first_name]
+ pm.last_name.should == @params[:last_name]
+ pm.address_1.should == @params[:address_1]
+ pm.address_2.should == @params[:address_2]
+ pm.city.should == @params[:city]
+ pm.state.should == @params[:state]
+ pm.zip.should == @params[:zip]
+ pm.last_four_digits.should == @params[:card_number][-4, 4]
+ pm.expiry_month.should == @params[:expiry_month].to_i
+ pm.expiry_year.should == @params[:expiry_year].to_i
+ end
+ end
+ end
+ end
View
11 spec/lib/gateway_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Ronin::Gateway do
+ describe "initialize" do
+ it "accepts options" do
+ lambda do
+ Ronin::Gateway.new({})
+ end.should_not raise_error
+ end
+ end
+end
View
29 spec/lib/models/payment_method_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe Ronin::PaymentMethod do
+ let(:payment_method) {Ronin::PaymentMethod.new}
+ it "has attributes" do
+ payment_method.attributes = {"foo" => "bar"}
+ payment_method.attributes.should == {"foo" => "bar"}
+ end
+
+ describe "#id" do
+ before do
+ payment_method.attributes = {"payment_method_token" => "t0k3n"}
+ end
+
+ it "returns token" do
+ payment_method.id.should == payment_method.token
+ end
+ end
+
+ describe "#token" do
+ before do
+ payment_method.attributes = {"payment_method_token" => "t0k3n"}
+ end
+
+ it "returns attributes['payment_method_token']" do
+ payment_method.token.should == "t0k3n"
+ end
+ end
+end
View
20 spec/spec_helper.rb
@@ -0,0 +1,20 @@
+require 'rspec'
+require 'pp'
+
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+
+SITE = ENV['site'] || 'https://api.samurai.feefighters.com/v1/'
+USE_MOCK = !ENV['site']
+
+RSpec.configure do |c|
+ c.before :each do
+ end
+end
+
+require 'ronin'
+DEFAULT_OPTIONS = {
+ :site => SITE,
+ :merchant_key => ENV['merchant_key'] || 'a1ebafb6da5238fb8a3ac9f6',
+ :merchant_password => ENV['merchant_password'] || 'ae1aa640f6b735c4730fbb56',
+ :processor_token => ENV['processor_token'] || '5a0e1ca1e5a11a2997bbf912'
+}
Please sign in to comment.
Something went wrong with that request. Please try again.