activemerchant-payway 0.0.1

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.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # ECI VALUES
2
+ * *CCT* Call Centre Transaction
3
+ * *IVR* IVR Transaction
4
+ * *MTO* MOTO Transaction
5
+ * *SSL* Channel Encrypted Transaction (SSL or other)
6
+ * *1* 3D Secure transaction. This is the value returned from your MPI (Merchant Plugin Interface) software for 3D Secure transactions
7
+
8
+ # Usage
9
+
10
+ gateway = ActiveMerchant::Billing::PayWayGateway.new(
11
+ :username => 'abcdefgh',
12
+ :password => '12345678',
13
+ :pem => '/location/of/certificate.pem',
14
+ :eci => 'SSL'
15
+ )
16
+
17
+ card = ActiveMerchant::Billing::CreditCard.new(
18
+ :number => 1234123412341234,
19
+ :month => 05,
20
+ :year => 2010,
21
+ :first_name => 'Joe',
22
+ :last_name => 'Bloggs',
23
+ :verification_value => 123,
24
+ :type => 'visa'
25
+ )
26
+
27
+ options = {
28
+ :order_number => 'abc',
29
+ :original_order_number => 'xyz' # used to call on past authentications
30
+ }
31
+
32
+ gateway.purchase(amount, card, options)
33
+
34
+ # Note When Testing
35
+
36
+ Since the merchant has to enable Diners and Amex on the Payway side,
37
+ To run the tests for these two cards simply run with the `PAYWAY_TEST_DINERS` and
38
+ `PAYWAY_TEST_AMEX` environment variables.
39
+
40
+ You also need to fill out `credentials.txt` and `payway.pem` in the config directory
41
+ with your api login and certificate generated at [http://www.payway.com.au](http://www.payway.com.au)
42
+
43
+ ## Contributors
44
+
45
+ Developed by [@dangalipo](http://twitter.com/dangalipo) and [@mlambie](http://twitter.com/mlambie), sponsored by [@frontiergroup](http://twitter.com/frontiergroup)
46
+
47
+ Released by [@dirkkelly](http://twitter.com/dirkkelly) so all of you can use it.
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "activemerchant-payway"
16
+ gem.homepage = "http://github.com/thefrontiergroup/activemerchant-payway"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{ActiveMerchant PayWay Plugin}
19
+ gem.description = %Q{ActiveMerchant PayWay Plugin}
20
+ gem.email = "dk@dirkkelly.com"
21
+ gem.authors = ["Matt Lambie", "Dan Galipo", "Dirk Kelly"]
22
+ gem.add_dependency 'activemerchant', '>= 1.9.1'
23
+ end
24
+ Jeweler::RubygemsDotOrgTasks.new
25
+
26
+ require 'rake/testtask'
27
+ Rake::TestTask.new(:test) do |test|
28
+ test.libs << 'lib' << 'test'
29
+ test.pattern = 'test/**/test_*.rb'
30
+ test.verbose = true
31
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{activemerchant-payway}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Matt Lambie", "Dan Galipo", "Dirk Kelly"]
12
+ s.date = %q{2010-12-01}
13
+ s.description = %q{ActiveMerchant PayWay Plugin}
14
+ s.email = %q{dk@dirkkelly.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "README.md",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "activemerchant-payway.gemspec",
23
+ "config/credentials.txt",
24
+ "config/payway.pem",
25
+ "init.rb",
26
+ "lib/active_merchant/billing/gateways/pay_way.rb",
27
+ "lib/activemerchant-payway.rb",
28
+ "test/remote/gateways/remote_pay_way_test.rb",
29
+ "test/test_helper.rb",
30
+ "test/unit/gateways/pay_way_test.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/thefrontiergroup/activemerchant-payway}
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.7}
36
+ s.summary = %q{ActiveMerchant PayWay Plugin}
37
+ s.test_files = [
38
+ "test/remote/gateways/remote_pay_way_test.rb",
39
+ "test/test_helper.rb",
40
+ "test/unit/gateways/pay_way_test.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<activemerchant>, [">= 1.9.1"])
49
+ else
50
+ s.add_dependency(%q<activemerchant>, [">= 1.9.1"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<activemerchant>, [">= 1.9.1"])
54
+ end
55
+ end
56
+
@@ -0,0 +1,2 @@
1
+ abcdefgh
2
+ 12345678
data/config/payway.pem ADDED
File without changes
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'activemerchant_pay_way'
@@ -0,0 +1,232 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+
4
+ class PayWayGateway < Gateway
5
+
6
+ URL = 'https://ccapi.client.qvalent.com/payway/ccapi'
7
+
8
+ SUMMARY_CODES = {
9
+ '0' => 'Approved',
10
+ '1' => 'Declined',
11
+ '2' => 'Erred',
12
+ '3' => 'Rejected'
13
+ }
14
+
15
+ RESPONSE_CODES= {
16
+ '00' => 'Completed Successfully',
17
+ '01' => 'Refer to card issuer',
18
+ '03' => 'Invalid merchant',
19
+ '04' => 'Pick-up card',
20
+ '05' => 'Do not honour',
21
+ '08' => 'Honour only with identification',
22
+ '12' => 'Invalid transaction',
23
+ '13' => 'Invalid amount',
24
+ '14' => 'Invalid card number (no such number)',
25
+ '30' => 'Format error',
26
+ '36' => 'Restricted card',
27
+ '41' => 'Lost card',
28
+ '42' => 'No universal card',
29
+ '43' => 'Stolen card',
30
+ '51' => 'Not sufficient funds',
31
+ '54' => 'Expired card',
32
+ '61' => 'Exceeds withdrawal amount limits',
33
+ '62' => 'Restricted card',
34
+ '65' => 'Exceeds withdrawal frequency limit',
35
+ '91' => 'Issuer or switch is inoperative',
36
+ '92' => 'Financial institution or intermediate network facility cannot be found for routing',
37
+ '94' => 'Duplicate transmission',
38
+ 'Q1' => 'Unknown Buyer',
39
+ 'Q2' => 'Transaction Pending',
40
+ 'Q3' => 'Payment Gateway Connection Error',
41
+ 'Q4' => 'Payment Gateway Unavailable',
42
+ 'Q5' => 'Invalid Transaction',
43
+ 'Q6' => 'Duplicate Transaction – requery to determine status',
44
+ 'QA' => 'Invalid parameters or Initialisation failed',
45
+ 'QB' => 'Order type not currently supported',
46
+ 'QC' => 'Invalid Order Type',
47
+ 'QD' => 'Invalid Payment Amount - Payment amount less than minimum/exceeds maximum allowed limit',
48
+ 'QE' => 'Internal Error',
49
+ 'QF' => 'Transaction Failed',
50
+ 'QG' => 'Unknown Customer Order Number',
51
+ 'QH' => 'Unknown Customer Username or Password',
52
+ 'QI' => 'Transaction incomplete - contact Westpac to confirm reconciliation',
53
+ 'QJ' => 'Invalid Client Certificate',
54
+ 'QK' => 'Unknown Customer Merchant',
55
+ 'QL' => 'Business Group not configured for customer',
56
+ 'QM' => 'Payment Instrument not configured for customer',
57
+ 'QN' => 'Configuration Error',
58
+ 'QO' => 'Missing Payment Instrument',
59
+ 'QP' => 'Missing Supplier Account',
60
+ 'QQ' => 'Invalid Credit Card Verification Number',
61
+ 'QR' => 'Transaction Retry',
62
+ 'QS' => 'Transaction Successful',
63
+ 'QT' => 'Invalid currency',
64
+ 'QU' => 'Unknown Customer IP Address',
65
+ 'QV' => 'Invalid Original Order Number specified for Refund, Refund amount exceeds capture amount, or Previous capture was not approved',
66
+ 'QW' => 'Invalid Reference Number',
67
+ 'QX' => 'Network Error has occurred',
68
+ 'QY' => 'Card Type Not Accepted',
69
+ 'QZ' => 'Zero value transaction'
70
+ }
71
+
72
+ TRANSACTIONS = {
73
+ :authorization => 'preauth',
74
+ :purchase => 'capture',
75
+ :capture => 'captureWithoutAuth',
76
+ :status => 'query',
77
+ :credit => 'refund'
78
+ }
79
+
80
+ self.supported_countries = [ 'AU' ]
81
+ self.supported_cardtypes = [ :visa, :master, :diners_club, :american_express, :bankcard ]
82
+ self.display_name = 'Pay Way'
83
+ self.homepage_url = 'http://www.payway.com.au'
84
+ self.default_currency = 'AUD'
85
+ self.money_format = :cents
86
+
87
+ # Create a new Payway gateway.
88
+ def initialize(options = {})
89
+ requires!(options, :username, :password, :pem)
90
+ @options = options
91
+
92
+ @options[:eci] ||= 'SSL'
93
+ @options[:currency] ||= default_currency
94
+ @options[:merchant] ||= 'TEST'
95
+ @options[:pem] = File.read(options[:pem])
96
+
97
+ @post = {}
98
+ @transaction = {}
99
+
100
+ super
101
+ end
102
+
103
+ # Build the string and send it
104
+ def process(action, amount, credit_card)
105
+ @transaction.merge!({
106
+ :type => action,
107
+ :amount => amount,
108
+ :credit_card => credit_card
109
+ })
110
+
111
+ build_card
112
+ build_order
113
+ build_customer
114
+
115
+ send_post
116
+ end
117
+
118
+ def authorize(amount, credit_card, options = {})
119
+ requires!(options, :order_number)
120
+
121
+ @transaction.merge!({ :order_number => options[:order_number] })
122
+
123
+ process(:authorize, amount, credit_card)
124
+ end
125
+
126
+ def capture(amount, credit_card, options = {})
127
+ requires!(options, :order_number, :original_order_number)
128
+
129
+ @transaction.merge!({
130
+ :order_number => options[:order_number],
131
+ :original_order_number => options[:original_order_number]
132
+ })
133
+
134
+ process(:capture, amount, credit_card)
135
+ end
136
+
137
+ def purchase(amount, credit_card, options = {})
138
+ requires!(options, :order_number)
139
+
140
+ @transaction.merge!({ :order_number => options[:order_number] })
141
+
142
+ process(:purchase, amount, credit_card)
143
+ end
144
+
145
+ def credit(amount, credit_card, options = {})
146
+ requires!(options, :order_number, :original_order_number)
147
+
148
+
149
+ @transaction.merge!({
150
+ :order_number => options[:order_number],
151
+ :original_order_number => options[:original_order_number]
152
+ })
153
+
154
+ process(:credit, amount, credit_card)
155
+ end
156
+
157
+ def status(options = {})
158
+ requires!(options, :order_number)
159
+ @transaction = transaction
160
+ @transaction[:type] = TRANSACTIONS[:status]
161
+
162
+ build_order
163
+
164
+ send_post
165
+ end
166
+
167
+ private
168
+
169
+ # Adds credit card details to the post hash
170
+ def build_card
171
+ card = @transaction[:credit_card]
172
+ @post.merge!({
173
+ 'card.cardHolderName' => "#{card.first_name} #{card.last_name}",
174
+ 'card.PAN' => card.number,
175
+ 'card.CVN' => card.verification_value,
176
+ 'card.expiryYear' => card.year.to_s[-2,2],
177
+ 'card.expiryMonth' => sprintf('%02d', card.month),
178
+ 'card.currency' => @options[:currency]
179
+ })
180
+ end
181
+
182
+ # Adds the order arguments to the post hash
183
+ def build_order
184
+ @post.merge!({
185
+ 'order.ECI' => @options[:eci],
186
+ 'order.amount' => @transaction[:amount],
187
+ 'order.type' => TRANSACTIONS[@transaction[:type]]
188
+ })
189
+
190
+ if @transaction[:original_order_number].present?
191
+ @post['order.originalOrderNumber'] = @transaction[:original_order_number]
192
+ end
193
+ end
194
+
195
+ # Adds the customer arguments to the post hash
196
+ def build_customer
197
+ @post.merge!({
198
+ 'customer.username' => @options[:username],
199
+ 'customer.password' => @options[:password],
200
+ 'customer.merchant' => @options[:merchant],
201
+ 'customer.orderNumber'=> "#{@transaction[:order_number]} - #{Time.new.to_i.to_s}",
202
+ })
203
+ end
204
+
205
+ # Creates the request and returns the sumarised result
206
+ def send_post
207
+ @request = URI.encode(@post.map {|k,v| "#{k}=#{v}"}.join('&'))
208
+
209
+ @response = ssl_post(URL, @request)
210
+
211
+ result = process_response
212
+ end
213
+
214
+ def process_response
215
+ params = {}
216
+
217
+ @response.split("&").each do |items|
218
+ key, value = items.split("=")
219
+ key = key.split('.')[1]
220
+ params[key.underscore.to_sym] = value
221
+ end
222
+
223
+ msg = "#{SUMMARY_CODES[params[:summary_code]]} - #{RESPONSE_CODES[params[:response_code]]}"
224
+
225
+ success = params[:summary_code].to_s == "0"
226
+ options = { :test => @options[:merchant].to_s == "TEST" }
227
+
228
+ result = Response.new(success, msg, params, options)
229
+ end
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,2 @@
1
+ require 'active_merchant'
2
+ require 'active_merchant/billing/gateways/pay_way'
@@ -0,0 +1,212 @@
1
+ require 'test/test_helper'
2
+ require 'activemerchant_pay_way'
3
+
4
+ USERNAME = File.new('config/credentials.txt').readlines[0].gsub("\n","")
5
+ PASSWORD = File.new('config/credentials.txt').readlines[1].gsub("\n","")
6
+ PEM_FILE = 'config/payway.pem'
7
+
8
+ class RemotePayWayTest < Test::Unit::TestCase
9
+
10
+ def setup
11
+ @amount = 1100
12
+
13
+ @options = {
14
+ :order_number => (Time.now.to_f * 1000).round,
15
+ :original_order_number => 'xyz'
16
+ }
17
+
18
+ @gateway = ActiveMerchant::Billing::PayWayGateway.new(
19
+ :username => USERNAME,
20
+ :password => PASSWORD,
21
+ :merchant => 'TEST',
22
+ :pem => PEM_FILE
23
+ )
24
+
25
+ @visa = ActiveMerchant::Billing::CreditCard.new(
26
+ :number => 4564710000000004,
27
+ :month => 2,
28
+ :year => 2019,
29
+ :first_name => 'Bob',
30
+ :last_name => 'Smith',
31
+ :verification_value => 847,
32
+ :type => 'visa'
33
+ )
34
+
35
+ @mastercard = ActiveMerchant::Billing::CreditCard.new(
36
+ :number => 5163200000000008,
37
+ :month => 8,
38
+ :year => 2020,
39
+ :first_name => 'Bob',
40
+ :last_name => 'Smith',
41
+ :verification_value => '070',
42
+ :type => 'master'
43
+ )
44
+
45
+ @amex = ActiveMerchant::Billing::CreditCard.new(
46
+ :number => 376000000000006,
47
+ :month => 6,
48
+ :year => 2020,
49
+ :first_name => 'Bob',
50
+ :last_name => 'Smith',
51
+ :verification_value => 2349,
52
+ :type => 'american_express'
53
+ )
54
+
55
+ @diners = ActiveMerchant::Billing::CreditCard.new(
56
+ :number => 36430000000007,
57
+ :month => 6,
58
+ :year => 2022,
59
+ :first_name => 'Bob',
60
+ :last_name => 'Smith',
61
+ :verification_value => 348,
62
+ :type => 'diners_club'
63
+ )
64
+
65
+ @expired = ActiveMerchant::Billing::CreditCard.new(
66
+ :number => 4564710000000012,
67
+ :month => 2,
68
+ :year => 2005,
69
+ :first_name => 'Bob',
70
+ :last_name => 'Smith',
71
+ :verification_value => 963,
72
+ :type => 'visa'
73
+ )
74
+
75
+ @low = ActiveMerchant::Billing::CreditCard.new(
76
+ :number => 4564710000000020,
77
+ :month => 5,
78
+ :year => 2020,
79
+ :first_name => 'Bob',
80
+ :last_name => 'Smith',
81
+ :verification_value => 234,
82
+ :type => 'visa'
83
+ )
84
+
85
+ @stolen_mastercard = ActiveMerchant::Billing::CreditCard.new(
86
+ :number => 5163200000000016,
87
+ :month => 12,
88
+ :year => 2019,
89
+ :first_name => 'Bob',
90
+ :last_name => 'Smith',
91
+ :verification_value => 728,
92
+ :type => 'master'
93
+ )
94
+
95
+ @invalid = ActiveMerchant::Billing::CreditCard.new(
96
+ :number => 4564720000000037,
97
+ :month => 9,
98
+ :year => 2019,
99
+ :first_name => 'Bob',
100
+ :last_name => 'Smith',
101
+ :verification_value => '030',
102
+ :type => 'visa'
103
+ )
104
+
105
+ @restricted = ActiveMerchant::Billing::CreditCard.new(
106
+ :number => 343400000000016,
107
+ :month => 1,
108
+ :year => 2019,
109
+ :first_name => 'Bob',
110
+ :last_name => 'Smith',
111
+ :verification_value => 9023,
112
+ :type => 'american_express'
113
+ )
114
+
115
+ @stolen_diners = ActiveMerchant::Billing::CreditCard.new(
116
+ :number => 36430000000015,
117
+ :month => 8,
118
+ :year => 2021,
119
+ :first_name => 'Bob',
120
+ :last_name => 'Smith',
121
+ :verification_value => 988,
122
+ :type => 'diners_club'
123
+ )
124
+ end
125
+
126
+ def test_successful_visa
127
+ assert response = @gateway.purchase(@amount, @visa, @options)
128
+ assert_success response
129
+ assert_response_message_prefix 'Approved', response
130
+ end
131
+
132
+ def test_successful_mastercard
133
+ assert response = @gateway.purchase(@amount, @mastercard, @options)
134
+ assert_success response
135
+ assert_response_message_prefix 'Approved', response
136
+ end
137
+
138
+ if ENV['PAYWAY_TEST_AMEX'].present?
139
+ def test_successful_amex
140
+ assert response = @gateway.purchase(@amount, @amex, @options)
141
+ assert_success response
142
+ assert_response_message_prefix 'Approved', response
143
+ end
144
+ end
145
+
146
+ if ENV['PAYWAY_TEST_DINERS'].present?
147
+ def test_successful_diners
148
+ assert response = @gateway.purchase(@amount, @diners, @options)
149
+ assert_success response
150
+ assert_response_message_prefix 'Approved', response
151
+ end
152
+ end
153
+
154
+ def test_expired_visa
155
+ assert response = @gateway.purchase(@amount, @expired, @options)
156
+ assert_failure response
157
+ assert_equal 'Declined - Expired card', response.message
158
+ end
159
+
160
+ def test_low_visa
161
+ assert response = @gateway.purchase(@amount, @low, @options)
162
+ assert_failure response
163
+ assert_equal 'Declined - Not sufficient funds', response.message
164
+ end
165
+
166
+ def test_stolen_mastercard
167
+ assert response = @gateway.purchase(@amount, @stolen_mastercard, @options)
168
+ assert_failure response
169
+ assert_equal 'Declined - Pick-up card', response.message
170
+ end
171
+
172
+ def test_invalid_visa
173
+ assert response = @gateway.purchase(@amount, @invalid, @options)
174
+ assert_failure response
175
+ assert_equal 'Declined - Do not honour', response.message
176
+ end
177
+
178
+ if ENV['PAYWAY_TEST_AMEX'].present?
179
+ def test_restricted_amex
180
+ assert response = @gateway.purchase(@amount, @restricted, @options)
181
+ assert_failure response
182
+ assert_equal 'Rejected - Restricted card', response.message
183
+ end
184
+ end
185
+
186
+ if ENV['PAYWAY_TEST_DINERS'].present?
187
+ def test_stolen_diners
188
+ assert response = @gateway.purchase(@amount, @stolen_diners, @options)
189
+ assert_failure response
190
+ assert_equal 'Declined - Pick-up card', response.message
191
+ end
192
+ end
193
+
194
+ def test_invalid_login
195
+ gateway = ActiveMerchant::Billing::PayWayGateway.new(
196
+ :username => '',
197
+ :password => '',
198
+ :merchant => 'TEST',
199
+ :pem => PEM_FILE
200
+ )
201
+ assert response = gateway.purchase(@amount, @visa, @options)
202
+ assert_failure response
203
+ assert_equal 'Rejected - Unknown Customer Username or Password', response.message
204
+ end
205
+
206
+ protected
207
+
208
+ def assert_response_message_prefix(prefix, response)
209
+ assert_equal prefix, response.message.split(' - ', 2).first
210
+ end
211
+
212
+ end
@@ -0,0 +1,197 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'money'
7
+ require 'mocha'
8
+ require 'yaml'
9
+ require 'active_merchant'
10
+
11
+ require 'active_support/core_ext/integer/time'
12
+ require 'active_support/core_ext/numeric/time'
13
+
14
+ begin
15
+ require 'active_support/core_ext/time/acts_like'
16
+ rescue LoadError
17
+ end
18
+
19
+ begin
20
+ gem 'actionpack'
21
+ rescue LoadError
22
+ raise StandardError, "The view tests need ActionPack installed as gem to run"
23
+ end
24
+
25
+ require 'action_controller'
26
+ require "action_view/template"
27
+ begin
28
+ require 'action_dispatch/testing/test_process'
29
+ rescue LoadError
30
+ require 'action_controller/test_process'
31
+ end
32
+ require 'active_merchant/billing/integrations/action_view_helper'
33
+
34
+ ActiveMerchant::Billing::Base.mode = :test
35
+
36
+ # Test gateways
37
+ class SimpleTestGateway < ActiveMerchant::Billing::Gateway
38
+ end
39
+
40
+ class SubclassGateway < SimpleTestGateway
41
+ end
42
+
43
+
44
+ module ActiveMerchant
45
+ module Assertions
46
+ AssertionClass = RUBY_VERSION > '1.9' ? MiniTest::Assertion : Test::Unit::AssertionFailedError
47
+
48
+ def assert_field(field, value)
49
+ clean_backtrace do
50
+ assert_equal value, @helper.fields[field]
51
+ end
52
+ end
53
+
54
+ # Allows the testing of you to check for negative assertions:
55
+ #
56
+ # # Instead of
57
+ # assert !something_that_is_false
58
+ #
59
+ # # Do this
60
+ # assert_false something_that_should_be_false
61
+ #
62
+ # An optional +msg+ parameter is available to help you debug.
63
+ def assert_false(boolean, message = nil)
64
+ message = build_message message, '<?> is not false or nil.', boolean
65
+
66
+ clean_backtrace do
67
+ assert_block message do
68
+ not boolean
69
+ end
70
+ end
71
+ end
72
+
73
+ # A handy little assertion to check for a successful response:
74
+ #
75
+ # # Instead of
76
+ # assert_success response
77
+ #
78
+ # # DRY that up with
79
+ # assert_success response
80
+ #
81
+ # A message will automatically show the inspection of the response
82
+ # object if things go afoul.
83
+ def assert_success(response)
84
+ clean_backtrace do
85
+ assert response.success?, "Response failed: #{response.inspect}"
86
+ end
87
+ end
88
+
89
+ # The negative of +assert_success+
90
+ def assert_failure(response)
91
+ clean_backtrace do
92
+ assert_false response.success?, "Response expected to fail: #{response.inspect}"
93
+ end
94
+ end
95
+
96
+ def assert_valid(validateable)
97
+ clean_backtrace do
98
+ assert validateable.valid?, "Expected to be valid"
99
+ end
100
+ end
101
+
102
+ def assert_not_valid(validateable)
103
+ clean_backtrace do
104
+ assert_false validateable.valid?, "Expected to not be valid"
105
+ end
106
+ end
107
+
108
+ private
109
+ def clean_backtrace(&block)
110
+ yield
111
+ rescue AssertionClass => e
112
+ path = File.expand_path(__FILE__)
113
+ raise AssertionClass, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ }
114
+ end
115
+ end
116
+
117
+ module Fixtures
118
+ HOME_DIR = RUBY_PLATFORM =~ /mswin32/ ? ENV['HOMEPATH'] : ENV['HOME'] unless defined?(HOME_DIR)
119
+ LOCAL_CREDENTIALS = File.join(HOME_DIR.to_s, '.active_merchant/fixtures.yml') unless defined?(LOCAL_CREDENTIALS)
120
+ DEFAULT_CREDENTIALS = File.join(File.dirname(__FILE__), 'fixtures.yml') unless defined?(DEFAULT_CREDENTIALS)
121
+
122
+ private
123
+ def credit_card(number = '4242424242424242', options = {})
124
+ defaults = {
125
+ :number => number,
126
+ :month => 9,
127
+ :year => Time.now.year + 1,
128
+ :first_name => 'Longbob',
129
+ :last_name => 'Longsen',
130
+ :verification_value => '123',
131
+ :type => 'visa'
132
+ }.update(options)
133
+
134
+ Billing::CreditCard.new(defaults)
135
+ end
136
+
137
+ def check(options = {})
138
+ defaults = {
139
+ :name => 'Jim Smith',
140
+ :routing_number => '244183602',
141
+ :account_number => '15378535',
142
+ :account_holder_type => 'personal',
143
+ :account_type => 'checking',
144
+ :number => '1'
145
+ }.update(options)
146
+
147
+ Billing::Check.new(defaults)
148
+ end
149
+
150
+ def address(options = {})
151
+ {
152
+ :name => 'Jim Smith',
153
+ :address1 => '1234 My Street',
154
+ :address2 => 'Apt 1',
155
+ :company => 'Widgets Inc',
156
+ :city => 'Ottawa',
157
+ :state => 'ON',
158
+ :zip => 'K1C2N6',
159
+ :country => 'CA',
160
+ :phone => '(555)555-5555',
161
+ :fax => '(555)555-6666'
162
+ }.update(options)
163
+ end
164
+
165
+ def all_fixtures
166
+ @@fixtures ||= load_fixtures
167
+ end
168
+
169
+ def fixtures(key)
170
+ data = all_fixtures[key] || raise(StandardError, "No fixture data was found for '#{key}'")
171
+
172
+ data.dup
173
+ end
174
+
175
+ def load_fixtures
176
+ file = File.exists?(LOCAL_CREDENTIALS) ? LOCAL_CREDENTIALS : DEFAULT_CREDENTIALS
177
+ yaml_data = YAML.load(File.read(file))
178
+ symbolize_keys(yaml_data)
179
+
180
+ yaml_data
181
+ end
182
+
183
+ def symbolize_keys(hash)
184
+ return unless hash.is_a?(Hash)
185
+
186
+ hash.symbolize_keys!
187
+ hash.each{|k,v| symbolize_keys(v)}
188
+ end
189
+ end
190
+ end
191
+
192
+ Test::Unit::TestCase.class_eval do
193
+ include ActiveMerchant::Billing
194
+ include ActiveMerchant::Assertions
195
+ include ActiveMerchant::Utils
196
+ include ActiveMerchant::Fixtures
197
+ end
@@ -0,0 +1,227 @@
1
+ require 'test/test_helper'
2
+ require 'active_merchant/billing/gateways/pay_way'
3
+
4
+ class PayWayTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @gateway = ActiveMerchant::Billing::PayWayGateway.new(
8
+ :username => '12341234',
9
+ :password => 'abcdabcd',
10
+ :pem => 'config/payway.pem'
11
+ )
12
+
13
+ @amount = 1000
14
+
15
+ @credit_card = ActiveMerchant::Billing::CreditCard.new(
16
+ :number => 4564710000000004,
17
+ :month => 2,
18
+ :year => 2019,
19
+ :first_name => 'Bob',
20
+ :last_name => 'Smith',
21
+ :verification_value => '847',
22
+ :type => 'visa'
23
+ )
24
+
25
+ @options = {
26
+ :order_number => 'abc',
27
+ :orginal_order_number => 'xyz'
28
+ }
29
+ end
30
+
31
+ def test_successful_purchase_visa
32
+ @gateway.stubs(:ssl_post).returns(successful_response_visa)
33
+
34
+ response = @gateway.purchase(@amount, @credit_card, @options)
35
+
36
+ assert_instance_of Response, response
37
+ assert_success response
38
+
39
+ assert_match '0', response.params['summary_code']
40
+ assert_match '08', response.params['response_code']
41
+ assert_match 'VISA', response.params['card_scheme_name']
42
+ end
43
+
44
+ def test_successful_purchase_master_card
45
+ @gateway.stubs(:ssl_post).returns(successful_response_master_card)
46
+
47
+ response = @gateway.purchase(@amount, @credit_card, @options)
48
+
49
+ assert_instance_of Response, response
50
+ assert_success response
51
+
52
+ assert_match '0', response.params['summary_code']
53
+ assert_match '08', response.params['response_code']
54
+ assert_match 'MASTERCARD', response.params['card_scheme_name']
55
+ end
56
+
57
+ def test_successful_authorize_visa
58
+ @gateway.stubs(:ssl_post).returns(successful_response_visa)
59
+
60
+ response = @gateway.purchase(@amount, @credit_card, @options)
61
+
62
+ assert_instance_of Response, response
63
+ assert_success response
64
+
65
+ assert_match '0', response.params['summary_code']
66
+ assert_match '08', response.params['response_code']
67
+ assert_match 'VISA', response.params['card_scheme_name']
68
+ end
69
+
70
+ def test_successful_authorize_master_card
71
+ @gateway.stubs(:ssl_post).returns(successful_response_master_card)
72
+
73
+ response = @gateway.purchase(@amount, @credit_card, @options)
74
+
75
+ assert_instance_of Response, response
76
+ assert_success response
77
+
78
+ assert_match '0', response.params['summary_code']
79
+ assert_match '08', response.params['response_code']
80
+ assert_match 'MASTERCARD', response.params['card_scheme_name']
81
+ end
82
+
83
+ def test_successful_capture_visa
84
+ @gateway.stubs(:ssl_post).returns(successful_response_visa)
85
+
86
+ response = @gateway.purchase(@amount, @credit_card, @options)
87
+
88
+ assert_instance_of Response, response
89
+ assert_success response
90
+
91
+ assert_match '0', response.params['summary_code']
92
+ assert_match '08', response.params['response_code']
93
+ assert_match 'VISA', response.params['card_scheme_name']
94
+ end
95
+
96
+ def test_successful_capture_master_card
97
+ @gateway.stubs(:ssl_post).returns(successful_response_master_card)
98
+
99
+ response = @gateway.purchase(@amount, @credit_card, @options)
100
+
101
+ assert_instance_of Response, response
102
+ assert_success response
103
+
104
+ assert_match '0', response.params['summary_code']
105
+ assert_match '08', response.params['response_code']
106
+ assert_match 'MASTERCARD', response.params['card_scheme_name']
107
+ end
108
+
109
+ def test_successful_credit_visa
110
+ @gateway.stubs(:ssl_post).returns(successful_response_visa)
111
+
112
+ response = @gateway.purchase(@amount, @credit_card, @options)
113
+
114
+ assert_instance_of Response, response
115
+ assert_success response
116
+
117
+ assert_match '0', response.params['summary_code']
118
+ assert_match '08', response.params['response_code']
119
+ assert_match 'VISA', response.params['card_scheme_name']
120
+ end
121
+
122
+ def test_successful_credit_master_card
123
+ @gateway.stubs(:ssl_post).returns(successful_response_master_card)
124
+
125
+ response = @gateway.purchase(@amount, @credit_card, @options)
126
+
127
+ assert_instance_of Response, response
128
+ assert_success response
129
+
130
+ assert_match '0', response.params['summary_code']
131
+ assert_match '08', response.params['response_code']
132
+ assert_match 'MASTERCARD', response.params['card_scheme_name']
133
+ end
134
+
135
+ def test_purchase_with_invalid_credit_card
136
+ @gateway.stubs(:ssl_post).returns(purchase_with_invalid_credit_card_response)
137
+
138
+ credit_card.number = 4444333322221111
139
+
140
+ response = @gateway.purchase(@amount, @credit_card, @options)
141
+
142
+ assert_instance_of Response, response
143
+ assert_failure response
144
+
145
+ assert_match '1', response.params['summary_code']
146
+ assert_match '14', response.params['response_code']
147
+ end
148
+
149
+ def test_purchase_with_expired_credit_card
150
+ @gateway.stubs(:ssl_post).returns(purchase_with_expired_credit_card_response)
151
+
152
+ response = @gateway.purchase(@amount, @credit_card, @options)
153
+
154
+ assert_instance_of Response, response
155
+ assert_failure response
156
+
157
+ assert_match '1', response.params['summary_code']
158
+ assert_match '54', response.params['response_code']
159
+ end
160
+
161
+ def test_purchase_with_invalid_month
162
+ @gateway.stubs(:ssl_post).returns(purchase_with_invalid_month_response)
163
+ @credit_card.month = 13
164
+
165
+ response = @gateway.purchase(@amount, @credit_card, @options)
166
+
167
+ assert_instance_of Response, response
168
+ assert_failure response
169
+
170
+ assert_match '3', response.params['summary_code']
171
+ assert_match 'QA', response.params['response_code']
172
+ end
173
+
174
+ def test_bad_login
175
+ @gateway.stubs(:ssl_post).returns(bad_login_response)
176
+
177
+ response = @gateway.purchase(@amount, @credit_card, @options)
178
+
179
+ assert_instance_of Response, response
180
+ assert_failure response
181
+
182
+ assert_match '3', response.params['summary_code']
183
+ assert_match 'QH', response.params['response_code']
184
+ end
185
+
186
+ def test_bad_merchant
187
+ @gateway.stubs(:ssl_post).returns(bad_merchant_response)
188
+
189
+ response = @gateway.purchase(@amount, @credit_card, @options)
190
+
191
+ assert_instance_of Response, response
192
+ assert_failure response
193
+
194
+ assert_match '3', response.params['summary_code']
195
+ assert_match 'QK', response.params['response_code']
196
+ end
197
+
198
+ private
199
+
200
+ def successful_response_visa
201
+ "response.summaryCode=0&response.responseCode=08&response.cardSchemeName=VISA"
202
+ end
203
+
204
+ def successful_response_master_card
205
+ "response.summaryCode=0&response.responseCode=08&response.cardSchemeName=MASTERCARD"
206
+ end
207
+
208
+ def purchase_with_invalid_credit_card_response
209
+ "response.summaryCode=1&response.responseCode=14"
210
+ end
211
+
212
+ def purchase_with_expired_credit_card_response
213
+ "response.summaryCode=1&response.responseCode=54"
214
+ end
215
+
216
+ def purchase_with_invalid_month_response
217
+ "response.summaryCode=3&response.responseCode=QA"
218
+ end
219
+
220
+ def bad_login_response
221
+ "response.summaryCode=3&response.responseCode=QH"
222
+ end
223
+
224
+ def bad_merchant_response
225
+ "response.summaryCode=3&response.responseCode=QK"
226
+ end
227
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activemerchant-payway
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Matt Lambie
14
+ - Dan Galipo
15
+ - Dirk Kelly
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2010-12-01 00:00:00 +08:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ hash: 49
32
+ segments:
33
+ - 1
34
+ - 9
35
+ - 1
36
+ version: 1.9.1
37
+ name: activemerchant
38
+ requirement: *id001
39
+ description: ActiveMerchant PayWay Plugin
40
+ email: dk@dirkkelly.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files:
46
+ - README.md
47
+ files:
48
+ - README.md
49
+ - Rakefile
50
+ - VERSION
51
+ - activemerchant-payway.gemspec
52
+ - config/credentials.txt
53
+ - config/payway.pem
54
+ - init.rb
55
+ - lib/active_merchant/billing/gateways/pay_way.rb
56
+ - lib/activemerchant-payway.rb
57
+ - test/remote/gateways/remote_pay_way_test.rb
58
+ - test/test_helper.rb
59
+ - test/unit/gateways/pay_way_test.rb
60
+ has_rdoc: true
61
+ homepage: http://github.com/thefrontiergroup/activemerchant-payway
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.7
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: ActiveMerchant PayWay Plugin
94
+ test_files:
95
+ - test/remote/gateways/remote_pay_way_test.rb
96
+ - test/test_helper.rb
97
+ - test/unit/gateways/pay_way_test.rb