green_by_phone 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Russ Smith
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = green_by_phone
2
+
3
+ API for http://www.greenbyphone.com
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2009 Card Player. See LICENSE for details.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "green_by_phone"
8
+ gem.summary = "API for http://www.greenbyphone.com"
9
+ gem.description = "API for http://www.greenbyphone.com"
10
+ gem.email = "techteam@cardplayer.com"
11
+ gem.homepage = "http://github.com/cardplayer/green_by_phone"
12
+ gem.authors = ["Cardplayer"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "green_by_phone #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{green_by_phone}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Cardplayer"]
12
+ s.date = %q{2009-12-14}
13
+ s.description = %q{API for http://www.greenbyphone.com}
14
+ s.email = %q{techteam@cardplayer.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "green_by_phone.gemspec",
27
+ "lib/green_by_phone.rb",
28
+ "lib/green_by_phone/gateway.rb",
29
+ "lib/green_by_phone/response.rb",
30
+ "test/data.yml",
31
+ "test/helper.rb",
32
+ "test/test_gateway.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/cardplayer/green_by_phone}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{API for http://www.greenbyphone.com}
39
+ s.test_files = [
40
+ "test/helper.rb",
41
+ "test/test_gateway.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
55
+ end
56
+ end
57
+
@@ -0,0 +1,6 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'crack'
4
+
5
+ require 'lib/green_by_phone/gateway'
6
+ require 'lib/green_by_phone/response'
@@ -0,0 +1,76 @@
1
+ module GreenByPhone
2
+ class Gateway
3
+ API_URL = 'https://www.greenbyphone.com/eCheck.asmx'
4
+
5
+ def initialize(options = {})
6
+ @login = options[:login]
7
+ @password = options[:password]
8
+ end
9
+
10
+ def one_time_draft(options = {})
11
+ post = {}
12
+ add_customer(post, options)
13
+ add_check(post, options)
14
+ commit(options[:real_time] ? 'OneTimeDraftRTV' : 'OneTimeDraftBV', post)
15
+ end
16
+
17
+ def recurring_draft(options = {})
18
+ post = {}
19
+ add_customer(post, options)
20
+ add_check(post, options)
21
+ add_recurring(post, options)
22
+ commit(options[:real_time] ? 'RecurringDraftRTV' : 'RecurringDraftBV', post)
23
+ end
24
+
25
+ def verification_result(options = {})
26
+ post = { 'Check_ID' => options[:check_id] }
27
+ commit('VerificationResult', post)
28
+ end
29
+
30
+ private
31
+
32
+ def add_customer(post, options)
33
+ post['Name'] = options[:name]
34
+ post['EmailAddress'] = options[:email_address]
35
+ post['Phone'] = options[:phone]
36
+ post['PhoneExtension'] = options[:phone_extension]
37
+ post['address1'] = options[:address1]
38
+ post['address2'] = options[:address2]
39
+ post['city'] = options[:city]
40
+ post['state'] = options[:state]
41
+ post['Zip'] = options[:zip]
42
+ end
43
+
44
+ def add_check(post, options)
45
+ post['RoutingNumber'] = options[:routing_number]
46
+ post['AccountNumber'] = options[:account_number]
47
+ post['BankName'] = options[:bank_name]
48
+ post['CheckAmount'] = options[:check_amount]
49
+ post['CheckDate'] = options[:check_date]
50
+ post['CheckMemo'] = options[:check_memo]
51
+ end
52
+
53
+ def add_recurring(post, options)
54
+ post['RecurringType'] = options[:recurring_type]
55
+ post['RecurringOffset'] = options[:recurring_offset]
56
+ post['RecurringPayments'] = options[:recurring_payments]
57
+ end
58
+
59
+ def parse(response)
60
+ Crack::XML.parse(response)
61
+ end
62
+
63
+ def commit(action, post)
64
+ post['Client_ID'] = @login
65
+ post['ApiPassword'] = @password
66
+
67
+ uri = URI.parse(API_URL + "/#{action}")
68
+
69
+ request = Net::HTTP.new(uri.host, 443)
70
+ request.use_ssl = true
71
+ data = parse(request.post(uri.path, post.collect { |k,v| "#{k}=#{v}" }.join('&')).body)
72
+
73
+ Response.new_from_request(data['DraftResult'])
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,30 @@
1
+ module GreenByPhone
2
+ class Response
3
+ attr_reader :result, :result_description
4
+ attr_reader :verify_result, :verify_result_description
5
+ attr_reader :check_number, :check_id
6
+
7
+ def self.new_from_request(options = {})
8
+ self.new(
9
+ :result => options['Result'],
10
+ :result_description => options['ResultDescription'],
11
+ :verify_result => options['VerifyResult'],
12
+ :verify_result_description => options['VerifyResultDescription'],
13
+ :check_number => options['CheckNumber'],
14
+ :check_id => options['Check_ID'])
15
+ end
16
+
17
+ def initialize(options = {})
18
+ @result = options[:result]
19
+ @result_description = options[:result_escription]
20
+ @verify_result = options[:verify_result]
21
+ @verify_result_description = options[:verify_result_description]
22
+ @check_number = options[:check_number]
23
+ @check_id = options[:check_id]
24
+ end
25
+
26
+ def success?
27
+ @result == 0 && @verification_result == 0
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ credentials:
2
+ login: login
3
+ password: password
4
+
5
+ data:
6
+ name: Longbob Longson
7
+ email_address: longbob@longbob.com
8
+ phone: 702-123-1234
9
+ address: 11234 Dream Lane
10
+ address2: Suite 1234
11
+ city: Las Vegas
12
+ state: NV
13
+ zip: 89123
14
+ routing_number: 000000000
15
+ account_number: 1234567890
16
+ bank_name: Bank of USA
17
+ check_amount: <%= "#{rand(99)}.#{rand(99)}" %>
18
+ check_date: 12/01/09
19
+ check_memo: Testing
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'activesupport'
4
+ require 'shoulda'
5
+ require 'erb'
6
+ require 'fakeweb'
7
+
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+ require 'green_by_phone'
11
+
12
+ class Test::Unit::TestCase
13
+ FakeWeb.allow_net_connect = false
14
+
15
+ def fixture(key)
16
+ yaml_data = YAML.load(ERB.new(File.read(File.join(File.dirname(__FILE__), 'data.yml'))).result)
17
+ symbolize_keys(yaml_data)
18
+ yaml_data[key]
19
+ end
20
+
21
+ def symbolize_keys(hash)
22
+ return unless hash.is_a?(Hash)
23
+ hash.symbolize_keys!
24
+ hash.each { |k,v| symbolize_keys(v) }
25
+ end
26
+ end
@@ -0,0 +1,71 @@
1
+ require 'helper'
2
+
3
+ class TestGreenByPhone < Test::Unit::TestCase
4
+ context "Gateway" do
5
+ setup do
6
+ FakeWeb.register_uri(
7
+ :post, /#{GreenByPhone::Gateway::API_URL}*/,
8
+ :body => successful_post_response)
9
+
10
+ @gateway = GreenByPhone::Gateway.new(
11
+ :login => fixture(:credentials)[:login],
12
+ :password => fixture(:credentials)[:password])
13
+ end
14
+
15
+ should "one time draft bv" do
16
+ response = @gateway.one_time_draft(test_data)
17
+
18
+ assert true, response.success?
19
+ end
20
+
21
+ should "one time draft rtv" do
22
+ response = @gateway.one_time_draft(test_data(:real_time => true))
23
+
24
+ assert true, response.success?
25
+ end
26
+
27
+ should "recurring data bv" do
28
+ response = @gateway.recurring_draft(test_data(
29
+ :recurring_type => 'M',
30
+ :recurring_offset => '1',
31
+ :recurring_payments => '-1'))
32
+
33
+ assert true, response.success?
34
+ end
35
+
36
+ should "recurring data rtv" do
37
+ response = @gateway.recurring_draft(test_data(
38
+ :real_time => true,
39
+ :recurring_type => 'M',
40
+ :recurring_offset => '1',
41
+ :recurring_payments => '-1'))
42
+
43
+ assert true, response.success?
44
+ end
45
+
46
+ should "verification result" do
47
+ response = @gateway.recurring_draft(:check_id => 12345)
48
+
49
+ assert true, response.success?
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def test_data(options = {})
56
+ fixture(:data).merge(options)
57
+ end
58
+
59
+ def successful_post_response
60
+ <<-EOF
61
+ <DraftResult>
62
+ <Result>0</Result>
63
+ <ResultDescription>Data Accepted.</ResultDescription>
64
+ <VerifyResult>0</VerifyResult>
65
+ <VerifyResultDescription>Success</VerifyResultDescription>
66
+ <CheckNumber>1234567890</CheckNumber>
67
+ <Check_ID>1234567890</Check_ID>
68
+ </DraftResult>
69
+ EOF
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: green_by_phone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Cardplayer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-14 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: API for http://www.greenbyphone.com
26
+ email: techteam@cardplayer.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - green_by_phone.gemspec
42
+ - lib/green_by_phone.rb
43
+ - lib/green_by_phone/gateway.rb
44
+ - lib/green_by_phone/response.rb
45
+ - test/data.yml
46
+ - test/helper.rb
47
+ - test/test_gateway.rb
48
+ has_rdoc: true
49
+ homepage: http://github.com/cardplayer/green_by_phone
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --charset=UTF-8
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.3.5
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: API for http://www.greenbyphone.com
76
+ test_files:
77
+ - test/helper.rb
78
+ - test/test_gateway.rb