sage_pay 0.2.9 → 0.2.10

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,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.10
4
+
5
+ * Authorise support, I hope, which, again I hope, will make repeat actually work.
6
+
3
7
  ## 0.2.9
4
8
 
5
9
  * Repeat transaction implementation.
@@ -7,7 +7,7 @@ require 'md5'
7
7
  require 'uuid'
8
8
 
9
9
  module SagePay
10
- VERSION = '0.2.9'
10
+ VERSION = '0.2.10'
11
11
  end
12
12
 
13
13
  require 'validatable-ext'
@@ -29,4 +29,5 @@ require 'sage_pay/server/refund'
29
29
  require 'sage_pay/server/refund_response'
30
30
  require 'sage_pay/server/repeat'
31
31
  require 'sage_pay/server/repeat_response'
32
+ require 'sage_pay/server/authorise'
32
33
  require 'sage_pay/server'
@@ -68,6 +68,14 @@ module SagePay
68
68
  SagePay::Server::Refund.new(defaults.merge(attributes))
69
69
  end
70
70
 
71
+ def self.authorise(attributes = {})
72
+ defaults = {
73
+ :vendor_tx_code => TransactionCode.random,
74
+ }.merge(default_options)
75
+
76
+ SagePay::Server::Authorise.new(defaults.merge(attributes))
77
+ end
78
+
71
79
  def self.repeat(attributes = {})
72
80
  defaults = {
73
81
  :vendor_tx_code => TransactionCode.random,
@@ -1,6 +1,8 @@
1
1
  module SagePay
2
2
  module Server
3
3
  class Abort < Command
4
+ self.tx_type = :abort
5
+
4
6
  attr_accessor :vps_tx_id, :security_key, :tx_auth_no
5
7
 
6
8
  validates_presence_of :vps_tx_id, :security_key, :tx_auth_no
@@ -8,13 +10,6 @@ module SagePay
8
10
  validates_length_of :vps_tx_id, :is => 38
9
11
  validates_length_of :security_key, :is => 10
10
12
 
11
- validates_inclusion_of :tx_type, :allow_blank => true, :in => [ :abort ]
12
-
13
- def initialize(attributes = {})
14
- @tx_type = :abort
15
- super
16
- end
17
-
18
13
  def post_params
19
14
  super.merge({
20
15
  "VPSTxId" => vps_tx_id,
@@ -0,0 +1,44 @@
1
+ module SagePay
2
+ module Server
3
+ class Authorise < Command
4
+ self.tx_type = :authorise
5
+
6
+ attr_accessor :description, :related_transaction, :apply_avs_cv2
7
+ decimal_accessor :amount
8
+
9
+ validates_presence_of :amount, :description, :related_transaction
10
+
11
+ validates_length_of :description, :maximum => 100
12
+
13
+ validates_inclusion_of :apply_avs_cv2, :allow_blank => true, :in => (0..3).to_a
14
+
15
+ validates_true_for :amount, :key => :amount_minimum_value, :logic => lambda { amount.nil? || amount >= BigDecimal.new("0.01") }, :message => "is less than the minimum value (0.01)"
16
+ validates_true_for :amount, :key => :amount_maximum_value, :logic => lambda { amount.nil? || amount <= BigDecimal.new("100000") }, :message => "is greater than the maximum value (100,000.00)"
17
+
18
+ def post_params
19
+ params = super.merge({
20
+ "Amount" => ("%.2f" % amount),
21
+ "Description" => description
22
+ }).merge(related_transaction.post_params)
23
+
24
+ params['ApplyAVSCV2'] = apply_avs_cv2.to_s if apply_avs_cv2.present?
25
+
26
+ params
27
+ end
28
+
29
+ def response_from_response_body(response_body)
30
+ # FIXME: Since RepeatResponse is being shared for repeats and
31
+ # authorisations, it should probably be renamed.
32
+ RepeatResponse.from_response_body(response_body)
33
+ end
34
+
35
+ def live_service
36
+ "authorise"
37
+ end
38
+
39
+ def simulator_service
40
+ "VendorAuthoriseTx"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -3,8 +3,10 @@ module SagePay
3
3
  class Command
4
4
  include Validatable
5
5
 
6
- attr_reader :vps_protocol
7
- attr_accessor :mode, :tx_type, :vendor, :vendor_tx_code
6
+ class_inheritable_accessor :tx_type, :vps_protocol
7
+ self.vps_protocol = "2.23"
8
+
9
+ attr_accessor :mode, :vendor, :vendor_tx_code
8
10
 
9
11
  validates_presence_of :vps_protocol, :mode, :tx_type, :vendor,
10
12
  :vendor_tx_code
@@ -15,9 +17,16 @@ module SagePay
15
17
 
16
18
  validates_inclusion_of :mode, :allow_blank => true, :in => [ :simulator, :test, :live ]
17
19
 
18
- def initialize(attributes = {})
19
- @vps_protocol = "2.23"
20
+ def self.decimal_accessor(*attrs)
21
+ attrs.each do |attr|
22
+ attr_reader attr
23
+ define_method("#{attr}=") do |value|
24
+ instance_variable_set("@#{attr}", value.blank? ? nil : BigDecimal.new(value.to_s))
25
+ end
26
+ end
27
+ end
20
28
 
29
+ def initialize(attributes = {})
21
30
  attributes.each do |k, v|
22
31
  send("#{k}=", v)
23
32
  end
@@ -85,14 +94,6 @@ module SagePay
85
94
  raise RuntimeError, "I guess SagePay doesn't like us today."
86
95
  end
87
96
  end
88
-
89
- def present?(value)
90
- !blank?(value)
91
- end
92
-
93
- def blank?(value)
94
- value.nil? || (value.respond_to?(:empty?) && value.empty?)
95
- end
96
97
  end
97
98
  end
98
99
  end
@@ -43,20 +43,11 @@ module SagePay
43
43
  ]
44
44
 
45
45
  # Optional parameters that are only inserted if they are present
46
- params << ['StatusDetail', status_detail] if present?(status_detail)
46
+ params << ['StatusDetail', status_detail] if status_detail.present?
47
47
 
48
48
  # And return the completed hash
49
49
  params
50
50
  end
51
-
52
- private
53
- def present?(value)
54
- !blank?(value)
55
- end
56
-
57
- def blank?(value)
58
- value.nil? || (value.respond_to?(:empty?) && value.empty?)
59
- end
60
51
  end
61
52
  end
62
53
  end
@@ -1,23 +1,20 @@
1
1
  module SagePay
2
2
  module Server
3
3
  class Refund < Command
4
- attr_accessor :amount, :currency, :description, :related_transaction
4
+ self.tx_type = :refund
5
+
6
+ attr_accessor :currency, :description, :related_transaction
7
+ decimal_accessor :amount
5
8
 
6
9
  validates_presence_of :amount, :currency, :description, :related_transaction
7
10
 
8
11
  validates_length_of :currency, :is => 3
9
12
  validates_length_of :description, :maximum => 100
10
13
 
11
- validates_inclusion_of :tx_type, :allow_blank => true, :in => [ :refund ]
12
14
 
13
15
  validates_true_for :amount, :key => :amount_minimum_value, :logic => lambda { amount.nil? || amount >= BigDecimal.new("0.01") }, :message => "is less than the minimum value (0.01)"
14
16
  validates_true_for :amount, :key => :amount_maximum_value, :logic => lambda { amount.nil? || amount <= BigDecimal.new("100000") }, :message => "is greater than the maximum value (100,000.00)"
15
17
 
16
- def initialize(attributes = {})
17
- @tx_type = :refund
18
- super
19
- end
20
-
21
18
  def post_params
22
19
  super.merge({
23
20
  "Amount" => ("%.2f" % amount),
@@ -26,10 +23,6 @@ module SagePay
26
23
  }).merge(related_transaction.post_params)
27
24
  end
28
25
 
29
- def amount=(value)
30
- @amount = blank?(value) ? nil : BigDecimal.new(value.to_s)
31
- end
32
-
33
26
  def response_from_response_body(response_body)
34
27
  RefundResponse.from_response_body(response_body)
35
28
  end
@@ -1,10 +1,11 @@
1
1
  module SagePay
2
2
  module Server
3
3
  class Registration < Command
4
- attr_accessor :amount, :currency, :description, :notification_url,
4
+ attr_accessor :currency, :description, :notification_url,
5
5
  :billing_address, :delivery_address, :customer_email, :basket,
6
6
  :allow_gift_aid, :apply_avs_cv2, :apply_3d_secure, :profile,
7
7
  :billing_agreement, :account_type
8
+ decimal_accessor :amount
8
9
 
9
10
  validates_presence_of :amount, :currency, :description,
10
11
  :notification_url, :billing_address, :delivery_address
@@ -74,20 +75,20 @@ module SagePay
74
75
  })
75
76
 
76
77
  # Optional parameters that are only inserted if they are present
77
- params['BillingAddress2'] = billing_address.address_2 if present?(billing_address.address_2)
78
- params['BillingState'] = billing_address.state if present?(billing_address.state)
79
- params['BillingPhone'] = billing_address.phone if present?(billing_address.phone)
80
- params['DeliveryAddress2'] = delivery_address.address_2 if present?(delivery_address.address_2)
81
- params['DeliveryState'] = delivery_address.state if present?(delivery_address.state)
82
- params['DeliveryPhone'] = delivery_address.phone if present?(delivery_address.phone)
83
- params['CustomerEmail'] = customer_email if present?(customer_email)
84
- params['Basket'] = basket if present?(basket)
85
- params['AllowGiftAid'] = allow_gift_aid ? "1" : "0" if present?(allow_gift_aid)
86
- params['ApplyAVSCV2'] = apply_avs_cv2.to_s if present?(apply_avs_cv2)
87
- params['Apply3DSecure'] = apply_3d_secure.to_s if present?(apply_3d_secure)
88
- params['Profile'] = profile.to_s.upcase if present?(profile)
89
- params['BillingAgreement'] = billing_agreement ? "1" : "0" if present?(billing_agreement)
90
- params['AccountType'] = account_type_param if present?(account_type)
78
+ params['BillingAddress2'] = billing_address.address_2 if billing_address.address_2.present?
79
+ params['BillingState'] = billing_address.state if billing_address.state.present?
80
+ params['BillingPhone'] = billing_address.phone if billing_address.phone.present?
81
+ params['DeliveryAddress2'] = delivery_address.address_2 if delivery_address.address_2.present?
82
+ params['DeliveryState'] = delivery_address.state if delivery_address.state.present?
83
+ params['DeliveryPhone'] = delivery_address.phone if delivery_address.phone.present?
84
+ params['CustomerEmail'] = customer_email if customer_email.present?
85
+ params['Basket'] = basket if basket.present?
86
+ params['AllowGiftAid'] = allow_gift_aid ? "1" : "0" if allow_gift_aid.present? || allow_gift_aid == false
87
+ params['ApplyAVSCV2'] = apply_avs_cv2.to_s if apply_avs_cv2.present?
88
+ params['Apply3DSecure'] = apply_3d_secure.to_s if apply_3d_secure.present?
89
+ params['Profile'] = profile.to_s.upcase if profile.present?
90
+ params['BillingAgreement'] = billing_agreement ? "1" : "0" if billing_agreement.present? || billing_agreement == false
91
+ params['AccountType'] = account_type_param if account_type.present?
91
92
 
92
93
  # And return the completed hash
93
94
  params
@@ -97,10 +98,6 @@ module SagePay
97
98
  RegistrationResponse.from_response_body(response_body)
98
99
  end
99
100
 
100
- def amount=(value)
101
- @amount = blank?(value) ? nil : BigDecimal.new(value.to_s)
102
- end
103
-
104
101
  private
105
102
  def account_type_param
106
103
  case account_type
@@ -1,7 +1,10 @@
1
1
  module SagePay
2
2
  module Server
3
3
  class Release < Command
4
- attr_accessor :vps_tx_id, :security_key, :tx_auth_no, :release_amount
4
+ self.tx_type = :release
5
+
6
+ attr_accessor :vps_tx_id, :security_key, :tx_auth_no
7
+ decimal_accessor :release_amount
5
8
 
6
9
  validates_presence_of :vps_tx_id, :security_key, :tx_auth_no,
7
10
  :release_amount
@@ -9,16 +12,10 @@ module SagePay
9
12
  validates_length_of :vps_tx_id, :is => 38
10
13
  validates_length_of :security_key, :is => 10
11
14
 
12
- validates_inclusion_of :tx_type, :allow_blank => true, :in => [ :release ]
13
15
 
14
16
  validates_true_for :release_amount, :key => :release_amount_minimum_value, :logic => lambda { release_amount.nil? || release_amount >= BigDecimal.new("0.01") }, :message => "is less than the minimum value (0.01)"
15
17
  validates_true_for :release_amount, :key => :release_amount_maximum_value, :logic => lambda { release_amount.nil? || release_amount <= BigDecimal.new("100000") }, :message => "is greater than the maximum value (100,000.00)"
16
18
 
17
- def initialize(attributes = {})
18
- @tx_type = :release
19
- super
20
- end
21
-
22
19
  def post_params
23
20
  super.merge({
24
21
  "VPSTxId" => vps_tx_id,
@@ -28,10 +25,6 @@ module SagePay
28
25
  })
29
26
  end
30
27
 
31
- def release_amount=(value)
32
- @release_amount = blank?(value) ? nil : BigDecimal.new(value.to_s)
33
- end
34
-
35
28
  def live_service
36
29
  "release"
37
30
  end
@@ -1,23 +1,19 @@
1
1
  module SagePay
2
2
  module Server
3
3
  class Repeat < Command
4
- attr_accessor :amount, :currency, :description, :related_transaction, :cv2
4
+ self.tx_type = :repeat
5
+
6
+ attr_accessor :currency, :description, :related_transaction, :cv2
7
+ decimal_accessor :amount
5
8
 
6
9
  validates_presence_of :amount, :currency, :description, :related_transaction
7
10
 
8
11
  validates_length_of :currency, :is => 3
9
12
  validates_length_of :description, :maximum => 100
10
13
 
11
- validates_inclusion_of :tx_type, :allow_blank => true, :in => [ :repeat ]
12
-
13
14
  validates_true_for :amount, :key => :amount_minimum_value, :logic => lambda { amount.nil? || amount >= BigDecimal.new("0.01") }, :message => "is less than the minimum value (0.01)"
14
15
  validates_true_for :amount, :key => :amount_maximum_value, :logic => lambda { amount.nil? || amount <= BigDecimal.new("100000") }, :message => "is greater than the maximum value (100,000.00)"
15
16
 
16
- def initialize(attributes = {})
17
- @tx_type = :repeat
18
- super
19
- end
20
-
21
17
  def post_params
22
18
  params = super.merge({
23
19
  "Amount" => ("%.2f" % amount),
@@ -30,10 +26,6 @@ module SagePay
30
26
  params
31
27
  end
32
28
 
33
- def amount=(value)
34
- @amount = blank?(value) ? nil : BigDecimal.new(value.to_s)
35
- end
36
-
37
29
  def response_from_response_body(response_body)
38
30
  RepeatResponse.from_response_body(response_body)
39
31
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  ## If your rubyforge_project name is different, then edit it and comment out
8
8
  ## the sub! line in the Rakefile
9
9
  s.name = 'sage_pay'
10
- s.version = '0.2.9'
10
+ s.version = '0.2.10'
11
11
  s.date = '2010-04-25'
12
12
  s.rubyforge_project = 'sage_pay'
13
13
 
@@ -58,6 +58,7 @@ gateway for accepting credit card payments through your web app.
58
58
  lib/sage_pay/server.rb
59
59
  lib/sage_pay/server/abort.rb
60
60
  lib/sage_pay/server/address.rb
61
+ lib/sage_pay/server/authorise.rb
61
62
  lib/sage_pay/server/command.rb
62
63
  lib/sage_pay/server/notification.rb
63
64
  lib/sage_pay/server/notification_response.rb
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SagePay do
4
- it "should be version 0.2.9" do
5
- SagePay::VERSION.should == '0.2.9'
4
+ it "should be version 0.2.10" do
5
+ SagePay::VERSION.should == '0.2.10'
6
6
  end
7
7
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 9
9
- version: 0.2.9
8
+ - 10
9
+ version: 0.2.10
10
10
  platform: ruby
11
11
  authors:
12
12
  - Graeme Mathieson
@@ -79,6 +79,7 @@ files:
79
79
  - lib/sage_pay/server.rb
80
80
  - lib/sage_pay/server/abort.rb
81
81
  - lib/sage_pay/server/address.rb
82
+ - lib/sage_pay/server/authorise.rb
82
83
  - lib/sage_pay/server/command.rb
83
84
  - lib/sage_pay/server/notification.rb
84
85
  - lib/sage_pay/server/notification_response.rb