ruby_psigate 0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/CHANGELOG +2 -0
  2. data/Gemfile +12 -0
  3. data/LICENSE +0 -0
  4. data/Manifest +45 -0
  5. data/README.markdown +99 -0
  6. data/Rakefile +28 -0
  7. data/lib/certs/cacert.pem +2633 -0
  8. data/lib/ruby_psigate/account.rb +152 -0
  9. data/lib/ruby_psigate/account_manager_api.rb +137 -0
  10. data/lib/ruby_psigate/account_methods.rb +5 -0
  11. data/lib/ruby_psigate/address.rb +54 -0
  12. data/lib/ruby_psigate/connection.rb +96 -0
  13. data/lib/ruby_psigate/credit_card.rb +104 -0
  14. data/lib/ruby_psigate/credit_card_methods.rb +12 -0
  15. data/lib/ruby_psigate/error.rb +33 -0
  16. data/lib/ruby_psigate/gateway.rb +126 -0
  17. data/lib/ruby_psigate/hash_variables.rb +58 -0
  18. data/lib/ruby_psigate/item.rb +65 -0
  19. data/lib/ruby_psigate/item_option.rb +10 -0
  20. data/lib/ruby_psigate/number_validation_methods.rb +12 -0
  21. data/lib/ruby_psigate/order.rb +120 -0
  22. data/lib/ruby_psigate/recurring_charge.rb +53 -0
  23. data/lib/ruby_psigate/recurring_item.rb +26 -0
  24. data/lib/ruby_psigate/response.rb +109 -0
  25. data/lib/ruby_psigate/serializer.rb +59 -0
  26. data/lib/ruby_psigate/transaction_methods.rb +21 -0
  27. data/lib/ruby_psigate/utils.rb +18 -0
  28. data/lib/ruby_psigate.rb +57 -0
  29. data/ruby_psigate.gemspec +31 -0
  30. data/test/remote/remote_account_test.rb +33 -0
  31. data/test/remote/remote_gateway_test.rb +32 -0
  32. data/test/test_helper.rb +144 -0
  33. data/test/unit/account_manager_api_test.rb +96 -0
  34. data/test/unit/account_test.rb +388 -0
  35. data/test/unit/address_test.rb +99 -0
  36. data/test/unit/connection_test.rb +153 -0
  37. data/test/unit/credit_card_test.rb +152 -0
  38. data/test/unit/gateway_test.rb +112 -0
  39. data/test/unit/item_option_test.rb +19 -0
  40. data/test/unit/item_test.rb +106 -0
  41. data/test/unit/order_test.rb +491 -0
  42. data/test/unit/recurring_charge_test.rb +89 -0
  43. data/test/unit/recurring_item_test.rb +62 -0
  44. data/test/unit/response_test.rb +110 -0
  45. data/test/unit/serializer_test.rb +89 -0
  46. data/test/unit/xml_api_test.rb +25 -0
  47. metadata +154 -0
@@ -0,0 +1,110 @@
1
+ require 'test_helper'
2
+
3
+ module RubyPsigate
4
+ class ResponseTest < Test::Unit::TestCase
5
+
6
+ context "xml api response" do
7
+ setup do
8
+ @response = Response.new(xml_api_response)
9
+ end
10
+
11
+ should "return parsed result in a hash form" do
12
+ assert @response.hash.is_a? Hash
13
+ assert_not_nil @response.hash["Result"]
14
+ end
15
+
16
+ should "return parsed result of @response['Result']" do
17
+ assert_equal @response.parsed, @response.hash["Result"]
18
+ end
19
+ end
20
+
21
+ context "account manager api response" do
22
+ setup do
23
+ @response = Response.new(am_api_response)
24
+ end
25
+
26
+ should "return parsed result in a hash form" do
27
+ assert @response.hash.is_a? Hash
28
+ assert_not_nil @response.hash["Response"]
29
+ end
30
+
31
+ should "return parsed result of @response['Response']" do
32
+ assert_equal @response.parsed, @response.hash['Response']
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def xml_api_response
39
+ <<-EOF
40
+ <?xml version="1.0" encoding="UTF-8"?>
41
+ <Result>
42
+ <TransTime>Mon Nov 08 20:21:06 PST 2004</TransTime>
43
+ <OrderID>2004110820210605147</OrderID>
44
+ <Approved>APPROVED</Approved>
45
+ <ReturnCode>Y:TEST:TESTTRANS:M:X:YYY</ReturnCode>
46
+ <ErrMsg></ErrMsg>
47
+ <TaxTotal>5.00</TaxTotal>
48
+ <ShipTotal>15.00</ShipTotal>
49
+ <SubTotal>55.00</SubTotal>
50
+ <FullTotal>75.00</FullTotal>
51
+ <PaymentType>CC</PaymentType>
52
+ <CardNumber>411111...1111</CardNumber>
53
+ <CardExpMonth>05</CardExpMonth>
54
+ <CardExpYear>07</CardExpYear>
55
+ <TransRefNumber>1bd0082c392b7c5b</TransRefNumber>
56
+ <CardIDResult>M</CardIDResult>
57
+ <AVSResult>X</AVSResult>
58
+ <CardAuthNumber>TEST</CardAuthNumber>
59
+ <CardRefNumber>TESTTRANS</CardRefNumber>
60
+ <CardType>VISA</CardType>
61
+ <IPResult>YYY</IPResult>
62
+ <IPCountry>CA</IPCountry>
63
+ <IPRegion>Ontario</IPRegion>
64
+ <IPCity>Toronto</IPCity>
65
+ </Result>
66
+ EOF
67
+ end
68
+
69
+ def am_api_response
70
+ <<-EOF
71
+ <?xml version="1.0" encoding="UTF-8"?>
72
+ <Response>
73
+ <CID>1000001</CID>
74
+ <Action>REGISTER NEW PAYMENT ACCOUNTS</Action>
75
+ <ReturnCode>RPA-0000</ReturnCode>
76
+ <ReturnMessage>Register Payment Accounts completed successfully.</ReturnMessage>
77
+ <Account>
78
+ <ReturnCode>RPA-0010</ReturnCode>
79
+ <ReturnMessage>Register Payment Account completed successfully.</ReturnMessage>
80
+ <AccountID>2010090412944</AccountID>
81
+ <Status></Status>
82
+ <Name>John Smith</Name>
83
+ <Company>PSiGate Inc.</Company>
84
+ <Address1>145 King St.</Address1>
85
+ <Address2>2300</Address2>
86
+ <City>Toronto</City>
87
+ <Province>Ontario</Province>
88
+ <Postalcode>M5H 1J8</Postalcode>
89
+ <Country>Canada</Country>
90
+ <Phone>1-905-123-4567</Phone>
91
+ <Fax>1-905-123-4568</Fax>
92
+ <Email>support@psigate.com</Email>
93
+ <Comments>No Comment Today</Comments>
94
+ <CardInfo>
95
+ <Status></Status>
96
+ <SerialNo>1</SerialNo>
97
+ <AccountID>2010090412944</AccountID>
98
+ <CardHolder>John Smith</CardHolder>
99
+ <CardNumber>400555...0019</CardNumber>
100
+ <CardExpMonth>08</CardExpMonth>
101
+ <CardExpYear>11</CardExpYear>
102
+ <CardType>VISA</CardType>
103
+ </CardInfo>
104
+ </Account>
105
+ </Response>
106
+ EOF
107
+ end
108
+
109
+ end
110
+ end
@@ -0,0 +1,89 @@
1
+ require 'test_helper'
2
+
3
+ module RubyPsigate
4
+ class SerializerTest < Test::Unit::TestCase
5
+
6
+ should "raise error if initialized without a valid hash" do
7
+ fake_hash = ["Hello", "World"]
8
+ assert_raises InvalidHashError do
9
+ Serializer.new(fake_hash)
10
+ end
11
+ end
12
+
13
+ context "xml building functions" do
14
+ should "create a basic markup from a hash" do
15
+ valid_response = "<Something>Hello World</Something>"
16
+ input_hash = { :Something => "Hello World" }
17
+ @result = Serializer.new(input_hash)
18
+ assert_equal valid_response, @result.to_xml
19
+ end
20
+
21
+ should "create a 1-level nested markup from hash" do
22
+ valid_response = "<Family><Dad>Bob</Dad><Mom>Jane</Mom></Family>"
23
+ input_hash = { :Family => { :Dad => "Bob", :Mom => "Jane" } }
24
+ @result = Serializer.new(input_hash)
25
+ assert_equal valid_response, @result.to_xml
26
+ end
27
+
28
+ should "create a 2-level nested markup from hash" do
29
+ valid_response = "<Family><Dad>Bob</Dad><Mom>Jane</Mom><Children><Son>Mike</Son><Daughter>Ann</Daughter></Children></Family>"
30
+ input_hash = { :Family => { :Dad => "Bob", :Mom => "Jane", :Children => { :Son => "Mike", :Daughter => "Ann" } } }
31
+ @result = Serializer.new(input_hash)
32
+ assert_equal valid_response, @result.to_xml
33
+ end
34
+
35
+ should "include header" do
36
+ valid_response = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Something>Hello World</Something>"
37
+ input_hash = { :Something => "Hello World" }
38
+ @result = Serializer.new(input_hash, :header => true)
39
+ assert_equal valid_response, @result.to_xml
40
+ end
41
+
42
+ should "create a complicated markup from hash" do
43
+ @expectation = "<Order><StoreID>teststore</StoreID><Passphrase>test1234</Passphrase><Subtotal>10.00</Subtotal><PaymentType>CC</PaymentType><CardAction>0</CardAction><CardNumber>4111111111111111</CardNumber><CardExpMonth>02</CardExpMonth><CardExpYear>15</CardExpYear><CardIDNumber>3422</CardIDNumber></Order>"
44
+ @params = {
45
+ :Order => {
46
+ :StoreID => "teststore",
47
+ :Passphrase => "test1234",
48
+ :Subtotal => "10.00",
49
+ :PaymentType => "CC",
50
+ :CardAction => "0",
51
+ :CardNumber => "4111111111111111",
52
+ :CardExpMonth => "02",
53
+ :CardExpYear => "15",
54
+ :CardIDNumber => "3422"
55
+ }
56
+ }
57
+ @result = Serializer.new(@params).to_xml
58
+ assert_equal @expectation, @result
59
+ end
60
+
61
+ should "create a markup from an array of hash under the same parent element" do
62
+ @expectation = "<Item><Name>Mercedes Benz</Name><Price>30000.00</Price></Item><Item><Name>BMW</Name><Price>25000.00</Price></Item>"
63
+ @params = {
64
+ :Item => [
65
+ { :Name => "Mercedes Benz", :Price => "30000.00"},
66
+ { :Name => "BMW", :Price => "25000.00" }
67
+ ]
68
+ }
69
+
70
+ @result = Serializer.new(@params).to_xml
71
+ assert_equal @expectation, @result
72
+ end
73
+
74
+ should "create a markup from an array of hash, with each array element having its own embedded options" do
75
+ @expectation = "<Item><Name>Mercedes Benz</Name><Price>30000.00</Price><Option><model>sports</model><color>black</color></Option></Item><Item><Name>BMW</Name><Price>25000.00</Price><Option><model>luxury</model><color>red</color></Option></Item>"
76
+ @params = {
77
+ :Item => [
78
+ { :Name => "Mercedes Benz", :Price => "30000.00", :Option => { :model => "sports", :color => "black" } },
79
+ { :Name => "BMW", :Price => "25000.00", :Option => { :model => "luxury", :color => "red" } }
80
+ ]
81
+ }
82
+
83
+ @result = Serializer.new(@params).to_xml
84
+ assert_equal @expectation, @result
85
+ end
86
+ end
87
+
88
+ end
89
+ end
@@ -0,0 +1,25 @@
1
+ # require 'test_helper'
2
+ #
3
+ # module RubyPsigate
4
+ # class XmlApiTest < Test::Unit::TestCase
5
+ #
6
+ # context "class constants" do
7
+ # should "return TEST URL" do
8
+ # assert_equal XmlApi::TEST_URL, "https://dev.psigate.com:7989/Messenger/XMLMessenger"
9
+ # end
10
+ #
11
+ # should "return LIVE URL" do
12
+ # assert_equal XmlApi::LIVE_URL, "https://secure.psigate.com:7934/Messenger/XMLMessenger"
13
+ # end
14
+ # end
15
+ #
16
+ # context "a new instance" do
17
+ # setup do
18
+ # store_id = 'teststore'
19
+ # passphrase = 'psigate1234'
20
+ # @xml_api = XmlApi.new(store_id, passphrase)
21
+ # end
22
+ # end
23
+ #
24
+ # end
25
+ # end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_psigate
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 7
8
+ version: "0.7"
9
+ platform: ruby
10
+ authors:
11
+ - Simon Chiu
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-09-21 00:00:00 -04:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description: RubyPsigate parses and packages XML messages to/from Psigate's servers for transactions and recurring billing management.
21
+ email: skhchiu@gmail.com
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files:
27
+ - CHANGELOG
28
+ - LICENSE
29
+ - README.markdown
30
+ - lib/certs/cacert.pem
31
+ - lib/ruby_psigate.rb
32
+ - lib/ruby_psigate/account.rb
33
+ - lib/ruby_psigate/account_manager_api.rb
34
+ - lib/ruby_psigate/account_methods.rb
35
+ - lib/ruby_psigate/address.rb
36
+ - lib/ruby_psigate/connection.rb
37
+ - lib/ruby_psigate/credit_card.rb
38
+ - lib/ruby_psigate/credit_card_methods.rb
39
+ - lib/ruby_psigate/error.rb
40
+ - lib/ruby_psigate/gateway.rb
41
+ - lib/ruby_psigate/hash_variables.rb
42
+ - lib/ruby_psigate/item.rb
43
+ - lib/ruby_psigate/item_option.rb
44
+ - lib/ruby_psigate/number_validation_methods.rb
45
+ - lib/ruby_psigate/order.rb
46
+ - lib/ruby_psigate/recurring_charge.rb
47
+ - lib/ruby_psigate/recurring_item.rb
48
+ - lib/ruby_psigate/response.rb
49
+ - lib/ruby_psigate/serializer.rb
50
+ - lib/ruby_psigate/transaction_methods.rb
51
+ - lib/ruby_psigate/utils.rb
52
+ files:
53
+ - CHANGELOG
54
+ - Gemfile
55
+ - LICENSE
56
+ - Manifest
57
+ - README.markdown
58
+ - Rakefile
59
+ - lib/certs/cacert.pem
60
+ - lib/ruby_psigate.rb
61
+ - lib/ruby_psigate/account.rb
62
+ - lib/ruby_psigate/account_manager_api.rb
63
+ - lib/ruby_psigate/account_methods.rb
64
+ - lib/ruby_psigate/address.rb
65
+ - lib/ruby_psigate/connection.rb
66
+ - lib/ruby_psigate/credit_card.rb
67
+ - lib/ruby_psigate/credit_card_methods.rb
68
+ - lib/ruby_psigate/error.rb
69
+ - lib/ruby_psigate/gateway.rb
70
+ - lib/ruby_psigate/hash_variables.rb
71
+ - lib/ruby_psigate/item.rb
72
+ - lib/ruby_psigate/item_option.rb
73
+ - lib/ruby_psigate/number_validation_methods.rb
74
+ - lib/ruby_psigate/order.rb
75
+ - lib/ruby_psigate/recurring_charge.rb
76
+ - lib/ruby_psigate/recurring_item.rb
77
+ - lib/ruby_psigate/response.rb
78
+ - lib/ruby_psigate/serializer.rb
79
+ - lib/ruby_psigate/transaction_methods.rb
80
+ - lib/ruby_psigate/utils.rb
81
+ - test/remote/remote_account_test.rb
82
+ - test/remote/remote_gateway_test.rb
83
+ - test/test_helper.rb
84
+ - test/unit/account_manager_api_test.rb
85
+ - test/unit/account_test.rb
86
+ - test/unit/address_test.rb
87
+ - test/unit/connection_test.rb
88
+ - test/unit/credit_card_test.rb
89
+ - test/unit/gateway_test.rb
90
+ - test/unit/item_option_test.rb
91
+ - test/unit/item_test.rb
92
+ - test/unit/order_test.rb
93
+ - test/unit/recurring_charge_test.rb
94
+ - test/unit/recurring_item_test.rb
95
+ - test/unit/response_test.rb
96
+ - test/unit/serializer_test.rb
97
+ - test/unit/xml_api_test.rb
98
+ - ruby_psigate.gemspec
99
+ has_rdoc: true
100
+ homepage: http://oss.simonchiu.com
101
+ licenses: []
102
+
103
+ post_install_message:
104
+ rdoc_options:
105
+ - --line-numbers
106
+ - --inline-source
107
+ - --title
108
+ - Ruby_psigate
109
+ - --main
110
+ - README.markdown
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ segments:
127
+ - 1
128
+ - 2
129
+ version: "1.2"
130
+ requirements: []
131
+
132
+ rubyforge_project: ruby_psigate
133
+ rubygems_version: 1.3.7
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: A library to connect with the XML and Account interfaces of Psigate's servers
137
+ test_files:
138
+ - test/remote/remote_account_test.rb
139
+ - test/remote/remote_gateway_test.rb
140
+ - test/test_helper.rb
141
+ - test/unit/account_manager_api_test.rb
142
+ - test/unit/account_test.rb
143
+ - test/unit/address_test.rb
144
+ - test/unit/connection_test.rb
145
+ - test/unit/credit_card_test.rb
146
+ - test/unit/gateway_test.rb
147
+ - test/unit/item_option_test.rb
148
+ - test/unit/item_test.rb
149
+ - test/unit/order_test.rb
150
+ - test/unit/recurring_charge_test.rb
151
+ - test/unit/recurring_item_test.rb
152
+ - test/unit/response_test.rb
153
+ - test/unit/serializer_test.rb
154
+ - test/unit/xml_api_test.rb