sage_pay 0.2.13 → 1.0.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.
@@ -1,7 +1,8 @@
1
1
  module SagePay
2
2
  module Server
3
3
  class Response
4
- class_inheritable_hash :key_converter, :value_converter, :match_converter, :instance_writer => false
4
+
5
+ class_attribute :key_converter, :value_converter, :match_converter, :instance_writer => false
5
6
 
6
7
  self.key_converter = {
7
8
  "VPSProtocol" => :vps_protocol,
@@ -1,42 +1,8 @@
1
+ # Need to not fail when uri contains curly braces
2
+ # This overrides the DEFAULT_PARSER with the UNRESERVED key, including '{' and '}'
3
+ # DEFAULT_PARSER is used everywhere, so its better to override it once
1
4
  module URI
2
- module REGEXP
3
- module PATTERN
4
-
5
- # FIXME: SagePay insists that curly brackets in URLs is OK, so we have
6
- # to convince the URI parser that's the case. First we have to update
7
- # the constant in question.
8
- remove_const :UNRESERVED
9
- UNRESERVED = "-_.!~*'()#{ALNUM}\{\}"
10
-
11
- # FIXME: Then we have to update all the dependent constants we care
12
- # about.
13
- remove_const :URIC
14
- remove_const :QUERY
15
- remove_const :X_ABS_URI
16
- URIC = "(?:[#{UNRESERVED}#{RESERVED}]|#{ESCAPED})"
17
- QUERY = "#{URIC}*"
18
- X_ABS_URI = "
19
- (#{PATTERN::SCHEME}): (?# 1: scheme)
20
- (?:
21
- (#{PATTERN::OPAQUE_PART}) (?# 2: opaque)
22
- |
23
- (?:(?:
24
- //(?:
25
- (?:(?:(#{PATTERN::USERINFO})@)? (?# 3: userinfo)
26
- (?:(#{PATTERN::HOST})(?::(\\d*))?))?(?# 4: host, 5: port)
27
- |
28
- (#{PATTERN::REG_NAME}) (?# 6: registry)
29
- )
30
- |
31
- (?!//)) (?# XXX: '//' is the mark for hostport)
32
- (#{PATTERN::ABS_PATH})? (?# 7: path)
33
- )(?:\\?(#{PATTERN::QUERY}))? (?# 8: query)
34
- )
35
- (?:\\#(#{PATTERN::FRAGMENT}))? (?# 9: fragment)
36
- "
37
- end
38
- remove_const :ABS_URI
39
- ABS_URI = Regexp.new('^' + PATTERN::X_ABS_URI + '$', #'
40
- Regexp::EXTENDED, 'N').freeze
41
- end
5
+ remove_const :DEFAULT_PARSER
6
+ unreserved = REGEXP::PATTERN::UNRESERVED
7
+ DEFAULT_PARSER = Parser.new(:UNRESERVED => unreserved + "\{\}")
42
8
  end
@@ -0,0 +1,36 @@
1
+ module SagePay
2
+ module Validators
3
+ VENDOR_NAME_FORMAT = /\A[A-Za-z0-9\-_]*\z/.freeze
4
+ VENDOR_TX_CODE_FORMAT = /\A[A-Za-z0-9\-_\.{}]*\z/.freeze
5
+
6
+ # The following lack the requisite accented character matchers
7
+ NAME_FORMAT = /\A[[:alpha:] \\\/&'\.\-]*\z/.freeze
8
+ ADDRESS_FORMAT = /\A[[:alnum:][:space:]\+\\\/&'\.:,\(\)\-]*\z/.freeze
9
+
10
+ POST_CODE_FORMAT = /\A[[:alnum:] -]*\z/.freeze
11
+ PHONE_FORMAT = /\A[[:alnum:] \+\(\)-]*\z/.freeze
12
+
13
+ # Basic
14
+ EMAIL_FORMAT = /@/.freeze
15
+
16
+ COUNTRY_OPTIONS = %w{AF AX AL DZ AS AD AO AI AQ AG AR AM AW AU AT AZ BS BH
17
+ BD BB BY BE BZ BJ BM BT BO BQ BA BW BV BR IO BN BG BF
18
+ BI KH CM CA CV KY CF TD CL CN CX CC CO KM CG CD CK CR
19
+ CI HR CU CW CY CZ DK DJ DM DO EC EG SV GQ ER EE ET FK
20
+ FO FJ FI FR GF PF TF GA GM GE DE GH GI GR GL GD GP GU
21
+ GT GG GN GW GY HT HM VA HN HK HU IS IN ID IR IQ IE IM
22
+ IL IT JM JP JE JO KZ KE KI KP KR KW KG LA LV LB LS LR
23
+ LY LI LT LU MO MK MG MW MY MV ML MT MH MQ MR MU YT MX
24
+ FM MD MC MN ME MS MA MZ MM NA NR NP NL NC NZ NI NE NG
25
+ NU NF MP NO OM PK PW PS PA PG PY PE PH PN PL PT PR QA
26
+ RE RO RU RW BL SH KN LC MF PM VC WS SM ST SA SN RS SC
27
+ SL SG SX SK SI SB SO ZA GS SS ES LK SD SR SJ SZ SE CH
28
+ SY TW TJ TZ TH TL TG TK TO TT TN TR TM TC TV UG UA AE
29
+ GB US UM UY UZ VU VE VN VG VI WF EH YE ZM ZW}.freeze
30
+
31
+ US_STATE_OPTIONS = %w{AL AK AZ AR CA CO CT DE DC FL GA HI ID IL IN IA KS KY
32
+ LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH
33
+ OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY AS GU MP
34
+ PR VI FM MH PW AA AE AP}.freeze
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module SagePay
2
+ VERSION = '1.0.0'
3
+ end
@@ -1,63 +1,52 @@
1
+ $: << 'lib'
2
+ require 'sage_pay/version'
3
+
1
4
  Gem::Specification.new do |s|
2
5
  s.specification_version = 2 if s.respond_to? :specification_version=
6
+ s.required_ruby_version = '>= 1.9.2'
3
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
8
  s.rubygems_version = '1.3.6'
5
9
 
6
- ## Leave these as is they will be modified for you by the rake gemspec task.
7
- ## If your rubyforge_project name is different, then edit it and comment out
8
- ## the sub! line in the Rakefile
9
10
  s.name = 'sage_pay'
10
- s.version = '0.2.13'
11
- s.date = '2010-08-15'
11
+ s.version = SagePay::VERSION
12
+ s.date = '2012-07-21'
12
13
  s.rubyforge_project = 'sage_pay'
13
14
 
14
- ## Make sure your summary is short. The description may be as long
15
- ## as you like.
16
15
  s.summary = "Ruby implementation of the SagePay payment gateway protocol."
17
16
  s.description = <<-DESCRIPTION
18
17
  This is a Ruby library for integrating with SagePay. SagePay is a payment
19
18
  gateway for accepting credit card payments through your web app.
20
19
  DESCRIPTION
21
20
 
22
- ## List the primary authors. If there are a bunch of authors, it's probably
23
- ## better to set the email to an email list or something. If you don't have
24
- ## a custom homepage, consider using your GitHub URL or the like.
25
21
  s.authors = ["Graeme Mathieson"]
26
22
  s.email = 'mathie@woss.name'
27
23
  s.homepage = 'http://github.com/mathie/sage_pay'
28
24
 
29
- ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
30
- ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
31
25
  s.require_paths = %w[lib]
32
26
 
33
- ## Specify any RDoc options here. You'll want to add your README and
34
- ## LICENSE files to the extra_rdoc_files list.
35
27
  s.rdoc_options = ["--charset=UTF-8"]
36
28
  s.extra_rdoc_files = %w[README.md LICENSE]
37
29
 
38
- ## List your runtime dependencies here. Runtime dependencies are those
39
- ## that are needed for an end user to actually USE your code.
40
- s.add_dependency('activesupport', [">= 2.3.8"])
41
- s.add_dependency('validatable', [">= 1.6.7"])
30
+ s.add_dependency('activesupport', [">= 3.1.3"])
31
+ s.add_dependency('activemodel', [">= 3.1.0"])
42
32
  s.add_dependency('uuid', [">= 2.3.0"])
33
+ s.add_dependency('i18n', [">= 0.6.0"])
43
34
 
44
- ## List your development dependencies here. Development dependencies are
45
- ## those that are only needed during development
46
35
  s.add_development_dependency('rspec')
36
+ s.add_development_dependency('rake')
47
37
 
48
- ## Leave this section as-is. It will be automatically generated from the
49
- ## contents of your Git repository via the gemspec task. DO NOT REMOVE
50
- ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
51
- # = MANIFEST =
52
38
  s.files = %w[
39
+ .rbenv-version
40
+ .rspec
53
41
  CHANGELOG.md
54
42
  Gemfile
55
- Gemfile.lock
56
43
  LICENSE
57
44
  README.md
58
45
  Rakefile
59
46
  TODO
47
+ config/locales/en.yml
60
48
  lib/sage_pay.rb
49
+ lib/sage_pay/locale_initializer.rb
61
50
  lib/sage_pay/server.rb
62
51
  lib/sage_pay/server/abort.rb
63
52
  lib/sage_pay/server/address.rb
@@ -78,8 +67,8 @@ gateway for accepting credit card payments through your web app.
78
67
  lib/sage_pay/server/signature_verification_details.rb
79
68
  lib/sage_pay/server/transaction_code.rb
80
69
  lib/sage_pay/uri_fixups.rb
81
- lib/validatable-ext.rb
82
- lib/validations/validates_inclusion_of.rb
70
+ lib/sage_pay/validators.rb
71
+ lib/sage_pay/version.rb
83
72
  sage_pay.gemspec
84
73
  spec/integration/sage_pay/server_spec.rb
85
74
  spec/sage_pay/server/address_spec.rb
@@ -96,9 +85,6 @@ gateway for accepting credit card payments through your web app.
96
85
  spec/support/integration.rb
97
86
  spec/support/validation_matchers.rb
98
87
  ]
99
- # = MANIFEST =
100
88
 
101
- ## Test files will be grabbed from the file list. Make sure the path glob
102
- ## matches what you actually use.
103
89
  s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
104
90
  end
@@ -5,8 +5,8 @@ if run_integration_specs?
5
5
  before(:each) do
6
6
  SagePay::Server.default_registration_options = {
7
7
  :mode => :simulator,
8
- :vendor => "rubaidh",
9
- :notification_url => "http://test.host/notification"
8
+ :vendor => ENV["VENDOR_NAME"],
9
+ :notification_url => 'http://test.host/notification'
10
10
  }
11
11
  end
12
12
 
@@ -106,7 +106,7 @@ if run_integration_specs?
106
106
 
107
107
  describe ".deferred" do
108
108
  before(:each) do
109
- @payment = SagePay::Server.deferred(
109
+ @deferred = SagePay::Server.deferred(
110
110
  :description => "Demo payment",
111
111
  :amount => 12.34,
112
112
  :currency => "GBP",
@@ -115,21 +115,21 @@ if run_integration_specs?
115
115
  end
116
116
 
117
117
  it "should successfully register the deferred payment with SagePay" do
118
- @payment.run!.should_not be_nil
118
+ @deferred.run!.should_not be_nil
119
119
  end
120
120
 
121
121
  it "should be a valid deferred payment" do
122
- registration = @payment.run!
122
+ registration = @deferred.run!
123
123
  registration.should be_ok
124
124
  end
125
125
 
126
126
  it "should have a next URL" do
127
- registration = @payment.run!
127
+ registration = @deferred.run!
128
128
  registration.next_url.should_not be_nil
129
129
  end
130
130
 
131
131
  it "should allow us to follow the next URL and the response should be successful" do
132
- registration = @payment.run!
132
+ registration = @deferred.run!
133
133
  uri = URI.parse(registration.next_url)
134
134
  request = Net::HTTP::Get.new(uri.request_uri)
135
135
  http = Net::HTTP.new(uri.host, uri.port)
@@ -140,8 +140,8 @@ if run_integration_specs?
140
140
  end
141
141
 
142
142
  it "should allow us to retrieve signature verification details" do
143
- @payment.run!
144
- sig_details = @payment.signature_verification_details
143
+ @deferred.run!
144
+ sig_details = @deferred.signature_verification_details
145
145
 
146
146
  sig_details.should_not be_nil
147
147
  sig_details.security_key.should_not be_nil
@@ -103,21 +103,21 @@ describe SagePay::Server::Address do
103
103
  it "should require a US state to be present if the country is the US" do
104
104
  address = address_factory(:country => "US", :state => "")
105
105
  address.should_not be_valid
106
- address.errors.on(:state).should == "is required if the country is US"
106
+ address.errors[:state].should == ["is required if the country is US"]
107
107
  end
108
108
 
109
109
  it "should require the US state to be absent if the country is not in the US" do
110
110
  address = address_factory(:country => "GB", :state => "WY")
111
111
  address.should_not be_valid
112
- address.errors.on(:state).should == "is present but the country is not US"
112
+ address.errors[:state].should == ["is present but the country is not US"]
113
113
  end
114
114
 
115
115
  it "should validate the state against a list of US states" do
116
116
  address = address_factory(:country => "US", :state => "WY")
117
117
  address.should be_valid
118
- address = address_factory(:country => "US", :state => "AA")
118
+ address = address_factory(:country => "US", :state => "AB")
119
119
  address.should_not be_valid
120
- address.errors.on(:state).should == "is not a US state"
120
+ address.errors[:state].should == ["is not a US state"]
121
121
  end
122
122
 
123
123
  it "should validate the country against a list of ISO 3166-1 country codes" do
@@ -125,7 +125,7 @@ describe SagePay::Server::Address do
125
125
  address.should be_valid
126
126
  address = address_factory(:country => "AA")
127
127
  address.should_not be_valid
128
- address.errors.on(:country).should == "is not an ISO3166-1 country code"
128
+ address.errors[:country].should == ["is not an ISO3166-1 country code"]
129
129
  end
130
130
  end
131
131
  end
@@ -22,7 +22,7 @@ describe NotificationResponse do
22
22
 
23
23
  notification_response = notification_response_factory(:status => :invalid, :status_detail => "")
24
24
  notification_response.should_not be_valid
25
- notification_response.errors.on(:status_detail).should include("can't be empty")
25
+ notification_response.errors[:status_detail].should include("can't be empty")
26
26
  end
27
27
 
28
28
  it { validates_the_length_of(:notification_response, :redirect_url, :max => 255) }
@@ -40,7 +40,7 @@ describe NotificationResponse do
40
40
 
41
41
  notification_response = notification_response_factory(:status => :chickens)
42
42
  notification_response.should_not be_valid
43
- notification_response.errors.on(:status).should include("is not in the list")
43
+ notification_response.errors[:status].should include("is not in the list")
44
44
  end
45
45
  end
46
46
 
@@ -71,11 +71,11 @@ describe Registration do
71
71
 
72
72
  registration = registration_factory(:amount => "0.00")
73
73
  registration.should_not be_valid
74
- registration.errors.on(:amount).should include("is less than the minimum value (0.01)")
74
+ registration.errors[:amount].should include("is less than the minimum value (0.01)")
75
75
 
76
76
  registration = registration_factory(:amount => "-23")
77
77
  registration.should_not be_valid
78
- registration.errors.on(:amount).should include("is less than the minimum value (0.01)")
78
+ registration.errors[:amount].should include("is less than the minimum value (0.01)")
79
79
  end
80
80
 
81
81
  it "should allow the amount to be a maximum of 100,000.00" do
@@ -84,11 +84,11 @@ describe Registration do
84
84
 
85
85
  registration = registration_factory(:amount => "100000.01")
86
86
  registration.should_not be_valid
87
- registration.errors.on(:amount).should include("is greater than the maximum value (100,000.00)")
87
+ registration.errors[:amount].should include("is greater than the maximum value (100,000.00)")
88
88
 
89
89
  registration = registration_factory(:amount => "123456")
90
90
  registration.should_not be_valid
91
- registration.errors.on(:amount).should include("is greater than the maximum value (100,000.00)")
91
+ registration.errors[:amount].should include("is greater than the maximum value (100,000.00)")
92
92
  end
93
93
 
94
94
  it "should allow the transaction type to be one of :payment, :deferred or :authenticate" do
@@ -103,7 +103,7 @@ describe Registration do
103
103
 
104
104
  registration = registration_factory(:tx_type => :chickens)
105
105
  registration.should_not be_valid
106
- registration.errors.on(:tx_type).should include("is not in the list")
106
+ registration.errors[:tx_type].should include("is not in the list")
107
107
  end
108
108
 
109
109
  it "should allow the mode to be one of :simulator, :test or :live" do
@@ -118,7 +118,7 @@ describe Registration do
118
118
 
119
119
  registration = registration_factory(:mode => :chickens)
120
120
  registration.should_not be_valid
121
- registration.errors.on(:mode).should include("is not in the list")
121
+ registration.errors[:mode].should include("is not in the list")
122
122
  end
123
123
 
124
124
  it "should allow the gift aid setting to be true or false" do
@@ -130,7 +130,7 @@ describe Registration do
130
130
 
131
131
  registration = registration_factory(:allow_gift_aid => "chickens")
132
132
  registration.should_not be_valid
133
- registration.errors.on(:allow_gift_aid).should include("is not in the list")
133
+ registration.errors[:allow_gift_aid].should include("is not in the list")
134
134
  end
135
135
 
136
136
  it "should allow apply_avs_cv2 to be 0 through 3 (see docs for what that means)" do
@@ -148,7 +148,7 @@ describe Registration do
148
148
 
149
149
  registration = registration_factory(:apply_avs_cv2 => 4)
150
150
  registration.should_not be_valid
151
- registration.errors.on(:apply_avs_cv2).should include("is not in the list")
151
+ registration.errors[:apply_avs_cv2].should include("is not in the list")
152
152
  end
153
153
 
154
154
  it "should allow apply_3d_secure to be 0 through 3 (see docs for what that means)" do
@@ -166,7 +166,7 @@ describe Registration do
166
166
 
167
167
  registration = registration_factory(:apply_3d_secure => 4)
168
168
  registration.should_not be_valid
169
- registration.errors.on(:apply_3d_secure).should include("is not in the list")
169
+ registration.errors[:apply_3d_secure].should include("is not in the list")
170
170
  end
171
171
 
172
172
  it "should allow profile to be normal or low" do
@@ -178,7 +178,7 @@ describe Registration do
178
178
 
179
179
  registration = registration_factory(:profile => :chickens)
180
180
  registration.should_not be_valid
181
- registration.errors.on(:profile).should include("is not in the list")
181
+ registration.errors[:profile].should include("is not in the list")
182
182
  end
183
183
 
184
184
  it "should allow billing_agreement to be true or false" do
@@ -190,7 +190,7 @@ describe Registration do
190
190
 
191
191
  registration = registration_factory(:billing_agreement => "chickens")
192
192
  registration.should_not be_valid
193
- registration.errors.on(:billing_agreement).should include("is not in the list")
193
+ registration.errors[:billing_agreement].should include("is not in the list")
194
194
  end
195
195
 
196
196
  it "should allow the account type to be one of ecommerce, continuous authority or mail order" do
@@ -205,7 +205,7 @@ describe Registration do
205
205
 
206
206
  registration = registration_factory(:account_type => :chickens)
207
207
  registration.should_not be_valid
208
- registration.errors.on(:account_type).should include("is not in the list")
208
+ registration.errors[:account_type].should include("is not in the list")
209
209
  end
210
210
  end
211
211
 
@@ -512,7 +512,7 @@ describe Registration do
512
512
  it "should raise an exception to say that we couldn't talk to SagePay" do
513
513
  lambda {
514
514
  @registration.run!
515
- }.should raise_error RuntimeError, "I guess SagePay doesn't like us today."
515
+ }.should raise_error RuntimeError, /I guess SagePay doesn't like us today/
516
516
  end
517
517
  end
518
518
 
@@ -5,8 +5,8 @@ describe SagePay::Server do
5
5
  before(:each) do
6
6
  SagePay::Server.default_registration_options = {
7
7
  :mode => :test,
8
- :vendor => "rubaidh",
9
- :notification_url => "http://test.host/notification"
8
+ :vendor => 'dummyvendor',
9
+ :notification_url => 'http://test.host/notification'
10
10
  }
11
11
  end
12
12
 
@@ -18,8 +18,8 @@ describe SagePay::Server do
18
18
 
19
19
  payment = SagePay::Server.payment
20
20
  payment.mode.should == :test
21
- payment.vendor.should == "rubaidh"
22
- payment.notification_url.should == "http://test.host/notification"
21
+ payment.vendor.should == 'dummyvendor'
22
+ payment.notification_url.should == 'http://test.host/notification'
23
23
  end
24
24
 
25
25
  it "should generate a vendor transaction code automatically" do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SagePay do
4
- it "should be version 0.2.13" do
5
- SagePay::VERSION.should == '0.2.13'
4
+ it "should be version 1.0.0" do
5
+ SagePay::VERSION.should == '1.0.0'
6
6
  end
7
7
  end
@@ -1,5 +1,11 @@
1
1
  require 'rubygems'
2
- require 'spec/autorun'
2
+
3
+ if ENV['COVERAGE']
4
+ require 'simplecov'
5
+ SimpleCov.start do
6
+ add_filter '/spec/'
7
+ end
8
+ end
3
9
 
4
10
  $: << File.join(File.dirname(__FILE__), '..', 'lib')
5
11
  require 'sage_pay'
@@ -8,7 +14,7 @@ require 'sage_pay'
8
14
  # in ./support/ and its subdirectories.
9
15
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
16
 
11
- Spec::Runner.configure do |config|
17
+ RSpec.configure do |config|
12
18
  config.include(Factories)
13
19
  config.include(ValidationMatchers)
14
20
  end