ruby_psigate 0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Gemfile +12 -0
- data/LICENSE +0 -0
- data/Manifest +45 -0
- data/README.markdown +99 -0
- data/Rakefile +28 -0
- data/lib/certs/cacert.pem +2633 -0
- data/lib/ruby_psigate/account.rb +152 -0
- data/lib/ruby_psigate/account_manager_api.rb +137 -0
- data/lib/ruby_psigate/account_methods.rb +5 -0
- data/lib/ruby_psigate/address.rb +54 -0
- data/lib/ruby_psigate/connection.rb +96 -0
- data/lib/ruby_psigate/credit_card.rb +104 -0
- data/lib/ruby_psigate/credit_card_methods.rb +12 -0
- data/lib/ruby_psigate/error.rb +33 -0
- data/lib/ruby_psigate/gateway.rb +126 -0
- data/lib/ruby_psigate/hash_variables.rb +58 -0
- data/lib/ruby_psigate/item.rb +65 -0
- data/lib/ruby_psigate/item_option.rb +10 -0
- data/lib/ruby_psigate/number_validation_methods.rb +12 -0
- data/lib/ruby_psigate/order.rb +120 -0
- data/lib/ruby_psigate/recurring_charge.rb +53 -0
- data/lib/ruby_psigate/recurring_item.rb +26 -0
- data/lib/ruby_psigate/response.rb +109 -0
- data/lib/ruby_psigate/serializer.rb +59 -0
- data/lib/ruby_psigate/transaction_methods.rb +21 -0
- data/lib/ruby_psigate/utils.rb +18 -0
- data/lib/ruby_psigate.rb +57 -0
- data/ruby_psigate.gemspec +31 -0
- data/test/remote/remote_account_test.rb +33 -0
- data/test/remote/remote_gateway_test.rb +32 -0
- data/test/test_helper.rb +144 -0
- data/test/unit/account_manager_api_test.rb +96 -0
- data/test/unit/account_test.rb +388 -0
- data/test/unit/address_test.rb +99 -0
- data/test/unit/connection_test.rb +153 -0
- data/test/unit/credit_card_test.rb +152 -0
- data/test/unit/gateway_test.rb +112 -0
- data/test/unit/item_option_test.rb +19 -0
- data/test/unit/item_test.rb +106 -0
- data/test/unit/order_test.rb +491 -0
- data/test/unit/recurring_charge_test.rb +89 -0
- data/test/unit/recurring_item_test.rb +62 -0
- data/test/unit/response_test.rb +110 -0
- data/test/unit/serializer_test.rb +89 -0
- data/test/unit/xml_api_test.rb +25 -0
- metadata +154 -0
@@ -0,0 +1,152 @@
|
|
1
|
+
module RubyPsigate
|
2
|
+
class CreditCardTest < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def setup
|
5
|
+
@valid_attributes = {
|
6
|
+
:number => "4111111111111111",
|
7
|
+
:month => "12",
|
8
|
+
:year => "2020",
|
9
|
+
:verification_value => "123",
|
10
|
+
:name => "Bob John"
|
11
|
+
}
|
12
|
+
@cc = CreditCard.new(@valid_attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
should "respond to number" do
|
16
|
+
assert @cc.respond_to?(:number)
|
17
|
+
assert @cc.respond_to?(:number=)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "respond to month" do
|
21
|
+
assert @cc.respond_to?(:month)
|
22
|
+
assert @cc.respond_to?(:month=)
|
23
|
+
end
|
24
|
+
|
25
|
+
should "respond to year" do
|
26
|
+
assert @cc.respond_to?(:year)
|
27
|
+
assert @cc.respond_to?(:year=)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "respond to verification_value" do
|
31
|
+
assert @cc.respond_to?(:verification_value)
|
32
|
+
assert @cc.respond_to?(:verification_value=)
|
33
|
+
end
|
34
|
+
|
35
|
+
should "respond to type" do
|
36
|
+
assert @cc.respond_to?(:type)
|
37
|
+
end
|
38
|
+
|
39
|
+
should "respond_to name" do
|
40
|
+
assert @cc.respond_to?(:name)
|
41
|
+
assert @cc.respond_to?(:name=)
|
42
|
+
end
|
43
|
+
|
44
|
+
%w( number month year name ).each do |p|
|
45
|
+
should "raise error if #{p} is not included" do
|
46
|
+
@valid_attributes.delete(p.to_sym)
|
47
|
+
assert_raises(ArgumentError) { CreditCard.new(@valid_attributes) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "cc numbers" do
|
52
|
+
%w( 4111111111111111 ).each do |n|
|
53
|
+
should "#{n} be a valid" do
|
54
|
+
@valid_attributes[:number] = n
|
55
|
+
assert_nothing_raised { CreditCard.new(@valid_attributes) }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
%w( 1234567890123456 ).each do |n|
|
60
|
+
should "#{n} not be valid" do
|
61
|
+
@valid_attributes[:number] = n
|
62
|
+
assert_raises(CreditCardNumberInvalid) { CreditCard.new(@valid_attributes) }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "cc type" do
|
68
|
+
%w( visa mastercard american_express ).each do |type|
|
69
|
+
should "support #{type}" do
|
70
|
+
String.any_instance.expects(:creditcard_type).returns(type)
|
71
|
+
assert_nothing_raised { CreditCard.new(@valid_attributes) }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
%w( diners_club bankcard jcb enroute switch ).each do |type|
|
76
|
+
should "not support #{type}" do
|
77
|
+
String.any_instance.expects(:creditcard_type).returns(type)
|
78
|
+
assert_raises(CreditCardNotSupported) { CreditCard.new(@valid_attributes) }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
should "raise error if name is blank" do
|
84
|
+
@valid_attributes[:name] = nil
|
85
|
+
assert_raises(CreditCardOwnerNameMissing) { CreditCard.new(@valid_attributes) }
|
86
|
+
end
|
87
|
+
|
88
|
+
context "expiry date" do
|
89
|
+
%w( 13 14 15 16 ).each do |month|
|
90
|
+
should "raise CreditCardExpiryInvalid when the month is #{month}" do
|
91
|
+
@valid_attributes[:month] = month
|
92
|
+
assert_raises(CreditCardExpiryInvalid) { CreditCard.new(@valid_attributes) }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
%w( 1990 1999 2008 2009 ).each do |year|
|
97
|
+
should "raise CreditCardExpiryInvalid when month is #{year}" do
|
98
|
+
@valid_attributes[:year] = year
|
99
|
+
assert_raises(CreditCardExpiryInvalid) { CreditCard.new(@valid_attributes) }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
should "raise CreditCardExpired when expiry is #{Time.now.month-1}/#{Time.now.year}" do
|
104
|
+
@valid_attributes[:month] = ((Time.now.month)-1)
|
105
|
+
@valid_attributes[:year] = Time.now.year
|
106
|
+
assert_raises(CreditCardExpired) { CreditCard.new(@valid_attributes) }
|
107
|
+
end
|
108
|
+
|
109
|
+
%w( 1 2 3 4 5 6 7 8 9 10 11 12 ).each do |month|
|
110
|
+
should "not raise CreditCardExpired when expiry is #{month}/2010 and today's date is the last day of the same month" do
|
111
|
+
@valid_attributes[:month] = month
|
112
|
+
@valid_attributes[:year] = 2010
|
113
|
+
last_day = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month.to_i]
|
114
|
+
mock_today = Time.new(2010, month, last_day)
|
115
|
+
Time.stubs(:now).returns(mock_today)
|
116
|
+
assert_nothing_raised { CreditCard.new(@valid_attributes) }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
should "not raise CreditCardExpired when expiry is 2/2012 and today's date is 2/29/2010 (leap year)" do
|
121
|
+
@valid_attributes[:month] = 2
|
122
|
+
@valid_attributes[:year] = 2012
|
123
|
+
mock_today = Time.new(2010, 2, 29)
|
124
|
+
Time.stubs(:now).returns(mock_today)
|
125
|
+
assert_nothing_raised { CreditCard.new(@valid_attributes) }
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
should "return a hash" do
|
130
|
+
@expectation = {
|
131
|
+
:PaymentType => "CC",
|
132
|
+
:CardNumber => @cc.number,
|
133
|
+
:CardExpMonth => @cc.month,
|
134
|
+
:CardExpYear => @cc.year[2..3],
|
135
|
+
:CardIDNumber => @cc.verification_value
|
136
|
+
}
|
137
|
+
assert_equal @expectation, @cc.to_hash
|
138
|
+
end
|
139
|
+
|
140
|
+
should "return a hash for CardInfo hash (used in the account manager API)" do
|
141
|
+
@expectation = {
|
142
|
+
:CardHolder => "Bob John",
|
143
|
+
:CardNumber => "4111111111111111",
|
144
|
+
:CardExpMonth => "12",
|
145
|
+
:CardExpYear => "20"
|
146
|
+
}
|
147
|
+
|
148
|
+
assert_equal @expectation, @cc.to_hash(:card_info)
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module RubyPsigate
|
4
|
+
class GatewayTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
should "default to TEST environment" do
|
7
|
+
assert_equal :test, Gateway.env
|
8
|
+
end
|
9
|
+
|
10
|
+
should "set Gateway.env to :live" do
|
11
|
+
Gateway.live!
|
12
|
+
assert_equal :live, Gateway.env
|
13
|
+
end
|
14
|
+
|
15
|
+
should "set Gateway.env to :test" do
|
16
|
+
Gateway.test!
|
17
|
+
assert_equal :test, Gateway.env
|
18
|
+
end
|
19
|
+
|
20
|
+
should "set mode based on information passed to object instantiation" do
|
21
|
+
@gateway = Gateway.new(:store_id => "teststore", :passphrase => "psigate1234")
|
22
|
+
assert_equal :transaction, @gateway.mode
|
23
|
+
end
|
24
|
+
|
25
|
+
should "manually set mode" do
|
26
|
+
@gateway = Gateway.new
|
27
|
+
@gateway.mode = :account_manager
|
28
|
+
assert_equal :account_manager, @gateway.mode
|
29
|
+
end
|
30
|
+
|
31
|
+
should "set mode when parameter entered is a string" do
|
32
|
+
@gateway = Gateway.new
|
33
|
+
@gateway.mode = "account_manager"
|
34
|
+
assert_equal :account_manager, @gateway.mode
|
35
|
+
end
|
36
|
+
|
37
|
+
should "raise error if mode is invalid" do
|
38
|
+
@gateway = Gateway.new
|
39
|
+
assert_raises(InvalidGatewayMode) do
|
40
|
+
@gateway.mode = :unsupported
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "transaction interface" do
|
45
|
+
setup do
|
46
|
+
@gateway = Gateway.new(:store_id => "teststore", :passphrase => "psigate1234")
|
47
|
+
end
|
48
|
+
|
49
|
+
should "be set to transaction mode" do
|
50
|
+
assert_equal :transaction, @gateway.mode
|
51
|
+
end
|
52
|
+
|
53
|
+
should "respond to order getter/setter" do
|
54
|
+
assert @gateway.respond_to?(:order)
|
55
|
+
assert @gateway.respond_to?(:order=)
|
56
|
+
end
|
57
|
+
|
58
|
+
should "set the order" do
|
59
|
+
order = RubyPsigate::Order.new
|
60
|
+
assert @gateway.order.nil?
|
61
|
+
@gateway.order = order
|
62
|
+
assert_equal order, @gateway.order
|
63
|
+
end
|
64
|
+
|
65
|
+
should "raise error if mode not set before post" do
|
66
|
+
@gateway = Gateway.new
|
67
|
+
assert_nil @gateway.mode
|
68
|
+
assert_raises(InvalidGatewayMode) { @gateway.commit! }
|
69
|
+
end
|
70
|
+
|
71
|
+
should "raise error if mode is :transaction and passphrase is missing" do
|
72
|
+
@gateway = Gateway.new(:store_id => "teststore", :passphrase => nil)
|
73
|
+
@gateway.mode = :transaction
|
74
|
+
assert_raises(InvalidCredentials) { @gateway.commit! }
|
75
|
+
end
|
76
|
+
|
77
|
+
should "raise error if mode is :transaction and store_id is missing" do
|
78
|
+
@gateway = Gateway.new(:store_id => nil, :passphrase => "password")
|
79
|
+
@gateway.mode = :transaction
|
80
|
+
assert_raises(InvalidCredentials) { @gateway.commit! }
|
81
|
+
end
|
82
|
+
|
83
|
+
should "raise error if order not valid" do
|
84
|
+
@order = Order.new
|
85
|
+
@order.expects(:valid?).returns(false)
|
86
|
+
@gateway.order = @order
|
87
|
+
assert_raises(InvalidOrder) { @gateway.commit! }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "account manager" do
|
92
|
+
should "raise error if mode is :account_manager and cid is missing" do
|
93
|
+
@gateway = Gateway.new(:cid => nil, :user_id => "teststore", :password => "password")
|
94
|
+
@gateway.mode = :account_manager
|
95
|
+
assert_raises(InvalidCredentials) { @gateway.commit! }
|
96
|
+
end
|
97
|
+
|
98
|
+
should "raise error if mode is :account_manager and user_id is missing" do
|
99
|
+
@gateway = Gateway.new(:cid => "1000001", :user_id => nil, :password => "password")
|
100
|
+
@gateway.mode = :account_manager
|
101
|
+
assert_raises(InvalidCredentials) { @gateway.commit! }
|
102
|
+
end
|
103
|
+
|
104
|
+
should "raise error if mode is :account_manager and password is missing" do
|
105
|
+
@gateway = Gateway.new(:cid => "1000001", :user_id => "teststore", :password => nil)
|
106
|
+
@gateway.mode = :account_manager
|
107
|
+
assert_raises(InvalidCredentials) { @gateway.commit! }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module RubyPsigate
|
4
|
+
class ItemOptionTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
should "return a key-value hash pair" do
|
7
|
+
hash = { :colour => "Pink" }
|
8
|
+
@item_option = ItemOption.new(hash)
|
9
|
+
assert_equal hash, @item_option.instance_variable_get(:@option)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "accept multiple option parameters" do
|
13
|
+
hash = { :color => "Black", :size => "Large", :style => "modern" }
|
14
|
+
@item_option = ItemOption.new(hash)
|
15
|
+
assert_equal hash, @item_option.instance_variable_get(:@option)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module RubyPsigate
|
4
|
+
class ItemTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@item = Item.new
|
8
|
+
end
|
9
|
+
|
10
|
+
%w( unique_id desc qty price ).each do |field|
|
11
|
+
should "respond to #{field}" do
|
12
|
+
assert @item.respond_to?(field.downcase.to_sym)
|
13
|
+
setter = field.downcase + "="
|
14
|
+
assert @item.respond_to?(setter.to_sym)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
should "raise error if qty is less than 0" do
|
19
|
+
assert_raises(NumberLessThanZero) do
|
20
|
+
@item.qty = -3
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
should "not raise error if qty is 0" do
|
25
|
+
assert_nothing_raised do
|
26
|
+
@item.qty = 0
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
should "not raise error if qty above 0" do
|
31
|
+
assert_nothing_raised do
|
32
|
+
@item.qty = 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
should "set a whole number for qty" do
|
37
|
+
@item.qty = "1.33"
|
38
|
+
assert_equal "1.33".to_i, @item.qty
|
39
|
+
end
|
40
|
+
|
41
|
+
should "respond to price getter/setter" do
|
42
|
+
assert @item.respond_to?(:price)
|
43
|
+
assert @item.respond_to?(:price=)
|
44
|
+
end
|
45
|
+
|
46
|
+
should "set the amount to 100.00" do
|
47
|
+
@item.price = "100.00"
|
48
|
+
assert_equal Money.new(100.00*100), @item.price
|
49
|
+
end
|
50
|
+
|
51
|
+
should "respond to options" do
|
52
|
+
assert @item.respond_to?(:options)
|
53
|
+
end
|
54
|
+
|
55
|
+
should "add options via << method" do
|
56
|
+
assert_equal 0, @item.options.count
|
57
|
+
@item << ItemOption.new(:color => "pink")
|
58
|
+
assert_equal [{ :color => "pink"}], @item.options
|
59
|
+
end
|
60
|
+
|
61
|
+
should "raise an error unless added option is a ItemOption class" do
|
62
|
+
assert_raises(InvalidItemOption) do
|
63
|
+
@item << { :color => "pink" }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
should "return a simple item hash" do
|
68
|
+
@item.unique_id = "PSI-BOOK"
|
69
|
+
@item.desc = "XML Interface Doc"
|
70
|
+
@item.qty = 2
|
71
|
+
@item.price = 10.00
|
72
|
+
|
73
|
+
@expectation = {
|
74
|
+
:ItemID => "PSI-BOOK",
|
75
|
+
:ItemDescription => "XML Interface Doc",
|
76
|
+
:ItemQty => 2,
|
77
|
+
:ItemPrice => 10.00
|
78
|
+
}
|
79
|
+
|
80
|
+
assert_equal @expectation, @item.to_hash
|
81
|
+
end
|
82
|
+
|
83
|
+
should "return a nested item hash (with options)" do
|
84
|
+
@item.unique_id = "PSI-BOOK"
|
85
|
+
@item.desc = "XML Interface Doc"
|
86
|
+
@item.qty = 2
|
87
|
+
@item.price = 10.00
|
88
|
+
@item << ItemOption.new(:color => "pink")
|
89
|
+
@item << ItemOption.new(:size => "Extra Large")
|
90
|
+
|
91
|
+
@expectation = {
|
92
|
+
:ItemID => "PSI-BOOK",
|
93
|
+
:ItemDescription => "XML Interface Doc",
|
94
|
+
:ItemQty => 2,
|
95
|
+
:ItemPrice => 10.00,
|
96
|
+
:Option => {
|
97
|
+
:color => "pink",
|
98
|
+
:size => "Extra Large"
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
assert_equal @expectation, @item.to_hash
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|