sage_pay 0.2.7.1 → 0.2.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.8
4
+
5
+ * Refund implementation
6
+
3
7
  ## 0.2.7
4
8
 
5
9
  * Is abort now implemented?
@@ -0,0 +1,42 @@
1
+ module SagePay
2
+ module Server
3
+ class Refund < Command
4
+ attr_accessor :amount, :currency, :description, :related_transaction
5
+
6
+ validates_presence_of :amount, :currency, :description, :related_transaction
7
+
8
+ validates_length_of :currency, :is => 3
9
+ validates_length_of :description, :maximum => 100
10
+
11
+ validates_inclusion_of :tx_type, :allow_blank => true, :in => [ :refund ]
12
+
13
+ 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
+ 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
+ def initialize(attributes = {})
17
+ @tx_type = :refund
18
+ super
19
+ end
20
+
21
+ def post_params
22
+ super.merge({
23
+ "Amount" => ("%.2f" % amount),
24
+ "Currency" => currency,
25
+ "Description" => description
26
+ }).merge(related_transaction.post_params)
27
+ end
28
+
29
+ def amount=(value)
30
+ @amount = blank?(value) ? nil : BigDecimal.new(value.to_s)
31
+ end
32
+
33
+ def live_service
34
+ "refund"
35
+ end
36
+
37
+ def simulator_service
38
+ "VendorRefundTx"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,30 @@
1
+ module SagePay
2
+ module Server
3
+ class RelatedTransaction
4
+ include Validatable
5
+
6
+ attr_accessor :vps_tx_id, :vendor_tx_code, :security_key, :tx_auth_no
7
+
8
+ validates_presence_of :vps_tx_id, :vendor_tx_code, :security_key, :tx_auth_no
9
+
10
+ validates_length_of :vps_tx_id, :is => 38
11
+ validates_length_of :vendor_tx_code, :maximum => 40
12
+ validates_length_of :security_key, :is => 10
13
+
14
+ def initialize(attributes = {})
15
+ attributes.each do |k, v|
16
+ send("#{k}=", v)
17
+ end
18
+ end
19
+
20
+ def post_params
21
+ {
22
+ "RelatedVPSTxId" => vps_tx_id,
23
+ "RelatedVendorTxCode" => vendor_tx_code,
24
+ "RelatedSecurityKey" => security_key,
25
+ "RelatedTxAuthNo" => tx_auth_no,
26
+ }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -21,6 +21,10 @@ module SagePay
21
21
  @default_options ||= default_registration_options.except(:notification_url)
22
22
  end
23
23
 
24
+ def self.related_transaction(attributes = {})
25
+ SagePay::Server::RelatedTransaction.new(attributes)
26
+ end
27
+
24
28
  def self.payment(attributes = {})
25
29
  registration({ :tx_type => :payment }.merge(attributes))
26
30
  end
@@ -55,5 +59,12 @@ module SagePay
55
59
 
56
60
  SagePay::Server::Abort.new(defaults.merge(attributes))
57
61
  end
62
+
63
+ def self.refund(attributes = {})
64
+ defaults = {
65
+ }.merge(default_options)
66
+
67
+ SagePay::Server::Refund.new(defaults.merge(attributes))
68
+ end
58
69
  end
59
70
  end
data/lib/sage_pay.rb CHANGED
@@ -7,7 +7,7 @@ require 'md5'
7
7
  require 'uuid'
8
8
 
9
9
  module SagePay
10
- VERSION = '0.2.7.1'
10
+ VERSION = '0.2.8'
11
11
  end
12
12
 
13
13
  require 'validatable-ext'
@@ -16,6 +16,7 @@ require 'sage_pay/uri_fixups'
16
16
  require 'sage_pay/server/address'
17
17
  require 'sage_pay/server/transaction_code'
18
18
  require 'sage_pay/server/signature_verification_details'
19
+ require 'sage_pay/server/related_transaction'
19
20
  require 'sage_pay/server/command'
20
21
  require 'sage_pay/server/response'
21
22
  require 'sage_pay/server/registration'
@@ -24,4 +25,5 @@ require 'sage_pay/server/notification'
24
25
  require 'sage_pay/server/notification_response'
25
26
  require 'sage_pay/server/release'
26
27
  require 'sage_pay/server/abort'
28
+ require 'sage_pay/server/refund'
27
29
  require 'sage_pay/server'
data/sage_pay.gemspec CHANGED
@@ -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.7.1'
10
+ s.version = '0.2.8'
11
11
  s.date = '2010-04-25'
12
12
  s.rubyforge_project = 'sage_pay'
13
13
 
@@ -60,8 +60,10 @@ gateway for accepting credit card payments through your web app.
60
60
  lib/sage_pay/server/command.rb
61
61
  lib/sage_pay/server/notification.rb
62
62
  lib/sage_pay/server/notification_response.rb
63
+ lib/sage_pay/server/refund.rb
63
64
  lib/sage_pay/server/registration.rb
64
65
  lib/sage_pay/server/registration_response.rb
66
+ lib/sage_pay/server/related_transaction.rb
65
67
  lib/sage_pay/server/release.rb
66
68
  lib/sage_pay/server/response.rb
67
69
  lib/sage_pay/server/signature_verification_details.rb
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SagePay do
4
- it "should be version 0.2.7" do
5
- SagePay::VERSION.should == '0.2.7'
4
+ it "should be version 0.2.8" do
5
+ SagePay::VERSION.should == '0.2.8'
6
6
  end
7
7
  end
metadata CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 7
9
- - 1
10
- version: 0.2.7.1
8
+ - 8
9
+ version: 0.2.8
11
10
  platform: ruby
12
11
  authors:
13
12
  - Graeme Mathieson
@@ -82,8 +81,10 @@ files:
82
81
  - lib/sage_pay/server/command.rb
83
82
  - lib/sage_pay/server/notification.rb
84
83
  - lib/sage_pay/server/notification_response.rb
84
+ - lib/sage_pay/server/refund.rb
85
85
  - lib/sage_pay/server/registration.rb
86
86
  - lib/sage_pay/server/registration_response.rb
87
+ - lib/sage_pay/server/related_transaction.rb
87
88
  - lib/sage_pay/server/release.rb
88
89
  - lib/sage_pay/server/response.rb
89
90
  - lib/sage_pay/server/signature_verification_details.rb