activemerchant-paymentech-orbital 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 John Corrigan
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,18 @@
1
+ = activemerchant-paymentech-orbital
2
+
3
+ A gem to provide a ruby interface for Chase Paymentech Orbital payment gateway.
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
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 John Corrigan. See LICENSE for details.
@@ -0,0 +1,55 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "activemerchant-paymentech-orbital"
7
+ gem.summary = "A gem to provide a ruby interface for Chase Paymentech Orbital payment gateway."
8
+ gem.description = "A gem to provide a ruby interface for Chase Paymentech Orbital payment gateway."
9
+ gem.email = "john@mintdigital.com"
10
+ gem.homepage = "http://github.com/johnideal/activemerchant-paymentech-orbital"
11
+ gem.authors = ["John Corrigan"]
12
+ gem.add_dependency("activemerchant", "= 1.4.2")
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ task :test => :check_dependencies
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ if File.exist?('VERSION')
46
+ version = File.read('VERSION')
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "activemerchant-paymentech-orbital #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,79 @@
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{activemerchant-paymentech-orbital}
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 = ["John Corrigan"]
12
+ s.date = %q{2009-12-03}
13
+ s.description = %q{A gem to provide a ruby interface for Chase Paymentech Orbital payment gateway.}
14
+ s.email = %q{john@mintdigital.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
+ "activemerchant-paymentech-orbital.gemspec",
27
+ "lib/active_merchant/billing/paymentech_orbital.rb",
28
+ "lib/active_merchant/billing/paymentech_orbital/request.rb",
29
+ "lib/active_merchant/billing/paymentech_orbital/request/end_of_day.rb",
30
+ "lib/active_merchant/billing/paymentech_orbital/request/new_order.rb",
31
+ "lib/active_merchant/billing/paymentech_orbital/request/profile_management.rb",
32
+ "lib/active_merchant/billing/paymentech_orbital/request/void.rb",
33
+ "lib/active_merchant/billing/paymentech_orbital/response.rb",
34
+ "lib/activemerchant-paymentech-orbital.rb",
35
+ "test/activemerchant-paymentech-orbital_test.rb",
36
+ "test/factories.rb",
37
+ "test/mocks/active_merchant/billing/gateway.rb",
38
+ "test/options.rb",
39
+ "test/payment_orbital/gateway_test.rb",
40
+ "test/payment_orbital/request/end_of_day_test.rb",
41
+ "test/payment_orbital/request/new_order_test.rb",
42
+ "test/payment_orbital/request/profile_management_test.rb",
43
+ "test/payment_orbital/request/void_test.rb",
44
+ "test/payment_orbital/request_test.rb",
45
+ "test/test_helper.rb"
46
+ ]
47
+ s.homepage = %q{http://github.com/johnideal/activemerchant-paymentech-orbital}
48
+ s.rdoc_options = ["--charset=UTF-8"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = %q{1.3.5}
51
+ s.summary = %q{A gem to provide a ruby interface for Chase Paymentech Orbital payment gateway.}
52
+ s.test_files = [
53
+ "test/activemerchant-paymentech-orbital_test.rb",
54
+ "test/factories.rb",
55
+ "test/mocks/active_merchant/billing/gateway.rb",
56
+ "test/options.rb",
57
+ "test/payment_orbital/gateway_test.rb",
58
+ "test/payment_orbital/request/end_of_day_test.rb",
59
+ "test/payment_orbital/request/new_order_test.rb",
60
+ "test/payment_orbital/request/profile_management_test.rb",
61
+ "test/payment_orbital/request/void_test.rb",
62
+ "test/payment_orbital/request_test.rb",
63
+ "test/test_helper.rb"
64
+ ]
65
+
66
+ if s.respond_to? :specification_version then
67
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
68
+ s.specification_version = 3
69
+
70
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
71
+ s.add_runtime_dependency(%q<activemerchant>, ["= 1.4.2"])
72
+ else
73
+ s.add_dependency(%q<activemerchant>, ["= 1.4.2"])
74
+ end
75
+ else
76
+ s.add_dependency(%q<activemerchant>, ["= 1.4.2"])
77
+ end
78
+ end
79
+
@@ -0,0 +1,113 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module PaymentechOrbital
4
+ class Gateway < ActiveMerchant::Billing::Gateway
5
+ cattr_accessor :currency_code, :currency_exponent, :headers, :urls
6
+
7
+ self.urls = {
8
+ :test => [
9
+ 'https://orbitalvar1.paymentech.net/authorize',
10
+ 'https://orbitalvar2.paymentech.net/authorize'
11
+ ],
12
+ :live => [
13
+ 'https://orbital1.paymentech.net/authorize',
14
+ 'https://orbital2.paymentech.net/authorize'
15
+ ]
16
+ }
17
+
18
+ # Currency information for the api.
19
+ self.currency_code = "840"
20
+ self.currency_exponent = "2"
21
+
22
+ # Money format
23
+ self.money_format = :cents
24
+
25
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
26
+ self.supported_countries = ['US']
27
+
28
+ # The card types supported by the payment gateway
29
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
30
+
31
+ # The homepage URL of the gateway
32
+ self.homepage_url = 'http://www.example.net/'
33
+
34
+ # The name of the gateway
35
+ self.display_name = 'Paymentect Orbital Gateway'
36
+
37
+ # Headers
38
+ self.headers = {
39
+ "MIME-Version" => "1.0",
40
+ "Content-Type" => "Application/PTI46",
41
+ "Content-transfer-encoding" => "text",
42
+ "Request-number" => "1",
43
+ "Document-type" => "Request"
44
+ }
45
+
46
+ attr_reader :request, :response
47
+
48
+ def initialize(options = {})
49
+ requires!(options, :login, :password, :merchant_id, :bin, :terminal_id)
50
+ @options = options.merge({
51
+ :currency_code => self.class.currency_code,
52
+ :currency_exponent => self.class.currency_exponent
53
+ })
54
+ super
55
+ end
56
+
57
+ def authorize(money, credit_card=nil, options = {})
58
+ @request = Request::NewOrder.new("A", money, credit_card, options.merge(@options))
59
+
60
+ commit('authonly', @request)
61
+ end
62
+
63
+ def purchase(money, credit_card=nil, options = {})
64
+ @request = Request::NewOrder.new("AC", money, credit_card, options.merge(@options))
65
+
66
+ commit('sale', @request)
67
+ end
68
+
69
+ def refund(money, credit_card=nil, options={})
70
+ @request = Request::NewOrder.new("R", money, credit_card, options.merge(@options))
71
+
72
+ commit('refund', @request)
73
+ end
74
+
75
+ def profile(action, credit_card=nil, options={})
76
+ @request = Request::ProfileManagement.new(action, credit_card, options.merge(@options))
77
+
78
+ commit("profile-#{action}", @request)
79
+ end
80
+
81
+ def void(tx_ref_num, tx_ref_idx, money=nil, options={})
82
+ @request = Request::Void.new(tx_ref_num, tx_ref_idx, money, options.merge(@options))
83
+
84
+ commit('void', @request)
85
+ end
86
+
87
+ def end_of_day(options={})
88
+ @request = Request::EndOfDay.new(options.merge(@options))
89
+
90
+ commit('end of day', @request)
91
+ end
92
+
93
+ private
94
+ def commit(action, request)
95
+ resp = ssl_post(endpoint_url, request.to_xml, headers)
96
+
97
+ @response ||= Response.new(resp, request.request_type, {
98
+ :test => test?
99
+ })
100
+ end
101
+
102
+ def headers
103
+ self.class.headers.merge(request.headers)
104
+ end
105
+
106
+ def endpoint_url
107
+ self.class.urls[Base.gateway_mode][0]
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+
@@ -0,0 +1,67 @@
1
+ require 'ostruct'
2
+
3
+ module ActiveMerchant
4
+ module Billing
5
+ module PaymentechOrbital
6
+ module Request
7
+ class Base
8
+ attr_reader :gateway, :options
9
+
10
+ def initialize(options={})
11
+ @options = OpenStruct.new(options)
12
+ end
13
+
14
+ def to_xml
15
+ @_xml ||= build_request
16
+ end
17
+ alias :xml :to_xml
18
+
19
+ def headers
20
+ @_headers ||= options.headers || {}
21
+ end
22
+
23
+ private
24
+ delegate :login, :password, :merchant_id,
25
+ :bin, :terminal_id, :currency_code,
26
+ :currency_exponent, :customer_ref_num,
27
+ :order_id, :to => :options
28
+
29
+ def address
30
+ @_address ||= options.billing_address || options.address || {}
31
+ end
32
+
33
+ def full_street_address
34
+ "#{address[:address1]} #{address[:address2]}".strip
35
+ end
36
+
37
+ # Implement me. I should be the parent tag for the request.
38
+ def request_type; "RequestType"; end
39
+
40
+ def build_request
41
+ xml = Builder::XmlMarkup.new(:indent => 2)
42
+
43
+ xml.instruct!(:xml, :version => '1.0', :encoding => 'UTF-8')
44
+ xml.tag! "Request" do
45
+ xml.tag! request_type do
46
+ add_authentication(xml)
47
+
48
+ request_body(xml)
49
+ end
50
+ end
51
+
52
+ xml.target!
53
+ end
54
+
55
+ # Implement me. I should take the provided
56
+ # xml builder and add tags to the request.
57
+ def request_body(xml); xml; end
58
+
59
+ def add_authentication(xml)
60
+ xml.tag! "OrbitalConnectionUsername", login
61
+ xml.tag! "OrbitalConnectionPassword", password
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,22 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ module PaymentechOrbital
4
+ module Request
5
+ class EndOfDay < PaymentechOrbital::Request::Base
6
+ def request_type; "EndOfDay"; end
7
+
8
+ private
9
+ def request_body(xml)
10
+ add_meta_info(xml)
11
+ end
12
+
13
+ def add_meta_info(xml)
14
+ xml.tag! "BIN", bin
15
+ xml.tag! "MerchantID", merchant_id
16
+ xml.tag! "TerminalID", terminal_id
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,121 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ module PaymentechOrbital
4
+ module Request
5
+ class NewOrder < PaymentechOrbital::Request::Base
6
+ attr_reader :message_type, :money, :credit_card
7
+
8
+ def initialize(message_type, money, credit_card, options)
9
+ @message_type = message_type
10
+ @money = money
11
+ @credit_card = credit_card
12
+ super(options)
13
+ end
14
+
15
+ delegate :industry_type, :mb_type, :recurring_start_date,
16
+ :recurring_end_date, :recurring_end_date_flag,
17
+ :recurring_max_billings, :recurring_frequency,
18
+ :deferred_bill_date, :soft_descriptors,
19
+ :to => :options
20
+
21
+ def request_type; "NewOrder"; end
22
+
23
+ def recurring?
24
+ industry_type == "RC"
25
+ end
26
+
27
+ private
28
+ def request_body(xml)
29
+ add_meta_info(xml)
30
+ add_credit_card(xml)
31
+ add_billing_address(xml)
32
+ add_profile_management_options(xml)
33
+ add_order_information(xml)
34
+ add_soft_descriptor_info(xml)
35
+ add_managed_billing_info(xml)
36
+ end
37
+
38
+ def add_meta_info(xml)
39
+ xml.tag! "IndustryType", industry_type || "EC"
40
+ xml.tag! "MessageType", message_type
41
+ xml.tag! "BIN", bin
42
+ xml.tag! "MerchantID", merchant_id
43
+ xml.tag! "TerminalID", terminal_id
44
+ end
45
+
46
+ def add_credit_card(xml)
47
+ if credit_card
48
+ xml.tag! "CardBrand", credit_card.respond_to?(:brand) ? credit_card.brand : credit_card.type
49
+ xml.tag! "AccountNum", credit_card.number
50
+ xml.tag! "Exp", "#{credit_card.month}#{credit_card.year}"
51
+ add_currency(xml)
52
+ xml.tag! "CardSecValInd", "1"
53
+ xml.tag! "CardSecVal", credit_card.verification_value
54
+ else
55
+ xml.tag! "AccountNum", nil
56
+ add_currency(xml)
57
+ end
58
+ end
59
+
60
+ def add_currency(xml)
61
+ xml.tag! "CurrencyCode", currency_code
62
+ xml.tag! "CurrencyExponent", currency_exponent
63
+ end
64
+
65
+ def add_billing_address(xml)
66
+ xml.tag! "AVSzip", address[:zip]
67
+ if full_street_address.length < 30
68
+ xml.tag! "AVSaddress1", full_street_address
69
+ else
70
+ xml.tag! "AVSaddress1", address[:address1]
71
+ xml.tag! "AVSaddress2", address[:address2]
72
+ end
73
+ xml.tag! "AVScity", address[:city]
74
+ xml.tag! "AVSstate", address[:state]
75
+ xml.tag! "AVSphoneNum" , address[:phone]
76
+ xml.tag! "AVSname", address[:name]
77
+ xml.tag! "AVScountryCode", address[:country]
78
+ end
79
+
80
+ def add_profile_management_options(xml)
81
+ if customer_ref_num
82
+ xml.tag! "CustomerRefNum", customer_ref_num
83
+ else
84
+ xml.tag! "CustomerProfileFromOrderInd", "A"
85
+ xml.tag! "CustomerProfileOrderOverrideInd", "NO"
86
+ end
87
+ end
88
+
89
+ def add_order_information(xml)
90
+ xml.tag! "OrderID", order_id
91
+ xml.tag! "Amount", money
92
+ end
93
+
94
+ def add_soft_descriptor_info(xml)
95
+ if soft_descriptors
96
+ xml.tag! "SDMerchantName", soft_descriptors[:merchant_name]
97
+ xml.tag! "SDProductDescription", soft_descriptors[:production_description]
98
+ xml.tag! "SDMerchantCity", soft_descriptors[:merchant_city]
99
+ xml.tag! "SDMerchantPhone", soft_descriptors[:merchant_phone]
100
+ xml.tag! "SDMerchantURL", soft_descriptors[:merchant_url]
101
+ xml.tag! "SDMerchantEmail", soft_descriptors[:merchant_email]
102
+ end
103
+ end
104
+
105
+ def add_managed_billing_info(xml)
106
+ if recurring?
107
+ xml.tag! "MBType", mb_type || "R"
108
+ xml.tag! "MBOrderIdGenerationMethod", "DI"
109
+ xml.tag! "MBRecurringStartDate", recurring_start_date || (Date.today + 1).strftime("%m%d%Y")
110
+ xml.tag! "MBRecurringEndDate", recurring_end_date
111
+ xml.tag! "MBRecurringNoEndDateFlag", recurring_end_date_flag || (recurring_end_date ? "N" : "Y")
112
+ xml.tag! "MBRecurringMaxBillings", recurring_max_billings
113
+ xml.tag! "MBRecurringFrequency", recurring_frequency
114
+ xml.tag! "MBDeferredBillDate", deferred_bill_date
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end