samurai 0.2.24 → 0.2.25

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,4 +10,10 @@ class Samurai::ProcessorResponse < Samurai::Base
10
10
  avs_result_code_message && avs_result_code_message.key
11
11
  end
12
12
 
13
+ # Helper method for accessing the CVV result code from the response messages
14
+ def cvv_result_code
15
+ cvv_result_code_message = self.messages.find {|m| m.context=='processor.cvv_result_code' || m.context=='gateway.cvv_result_code' }
16
+ cvv_result_code_message && cvv_result_code_message.key
17
+ end
18
+
13
19
  end
@@ -5,25 +5,25 @@
5
5
  # It can be used to query Transactions & capture/void/credit/reverse
6
6
  class Samurai::Transaction < Samurai::Base
7
7
  include Samurai::CacheableByToken
8
-
8
+
9
9
  # Alias for `transaction_token`
10
10
  def id
11
11
  transaction_token
12
12
  end
13
13
  alias_method :token, :id
14
-
14
+
15
15
  # Captures an authorization. Optionally specify an `amount` to do a partial capture of the initial
16
16
  # authorization. The default is to capture the full amount of the authorization.
17
17
  def capture(amount = nil, options = {})
18
18
  execute(:capture, {:amount => amount || self.amount}.reverse_merge(options))
19
19
  end
20
-
21
- # Void this transaction. If the transaction has not yet been captured and settled it can be voided to
20
+
21
+ # Void this transaction. If the transaction has not yet been captured and settled it can be voided to
22
22
  # prevent any funds from transferring.
23
23
  def void(options = {})
24
24
  execute(:void, options)
25
25
  end
26
-
26
+
27
27
  # Create a credit or refund against the original transaction.
28
28
  # Optionally accepts an `amount` to credit, the default is to credit the full
29
29
  # value of the original amount
@@ -34,9 +34,7 @@ class Samurai::Transaction < Samurai::Base
34
34
  # Reverse this transaction. First, tries a void.
35
35
  # If a void is unsuccessful, (because the transaction has already settled) perform a credit for the full amount.
36
36
  def reverse(options = {})
37
- transaction = void(options)
38
- return transaction if transaction.processor_response.success
39
- return credit(nil, options)
37
+ execute(:reverse, {:amount => amount || self.amount}.reverse_merge(options))
40
38
  end
41
39
 
42
40
  def success?
@@ -1,3 +1,3 @@
1
1
  module Samurai
2
- VERSION = "0.2.24".freeze
2
+ VERSION = "0.2.25".freeze
3
3
  end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "processing authorizations" do
4
-
4
+
5
5
  before :each do
6
6
  payment_method_token = create_payment_method(default_payment_method_params)[:payment_method_token]
7
7
  @authorization = Samurai::Processor.authorize(payment_method_token, 1.0, :billing_reference=>rand(1000))
8
8
  end
9
-
9
+
10
10
  it "should create a new authorization transaction" do
11
11
  @authorization.processor_response.success.should be_true
12
12
  end
@@ -20,7 +20,7 @@ describe "processing authorizations" do
20
20
  capture = @authorization.capture(1.0)
21
21
  capture.processor_response.success.should be_true
22
22
  end
23
-
23
+
24
24
  it "should capture an authorization without specifying an amount" do
25
25
  capture = @authorization.capture
26
26
  capture.amount.should == "#{1.0}"
@@ -28,8 +28,8 @@ describe "processing authorizations" do
28
28
  end
29
29
 
30
30
  it "should partially capture an authorization" do
31
- capture = @authorization.capture(1.0 - BigDecimal('0.5'))
32
- capture.amount.should == "#{1.0 - BigDecimal('0.5')}"
31
+ capture = @authorization.capture(BigDecimal('0.5'))
32
+ capture.amount.should == "#{BigDecimal('0.5')}"
33
33
  capture.processor_response.success.should be_true
34
34
  end
35
35
 
@@ -40,17 +40,13 @@ describe "processing authorizations" do
40
40
 
41
41
  it "should credit an authorization for the full amount by default" do
42
42
  credit = @authorization.credit
43
- credit.amount.should == "#{1.0}"
44
- pending "the response is not successful since the authorization hasn't settled" do
45
- credit.processor_response.success.should be_true
46
- end
43
+ credit.amount.should == "#{BigDecimal('0.5')}"
44
+ credit.processor_response.success.should be_true
47
45
  end
48
46
 
49
47
  it "should partially credit an authorization" do
50
- credit = @authorization.credit(1.0 - BigDecimal('0.5'))
51
- credit.amount.should == "#{1.0 - BigDecimal('0.5')}"
52
- pending "the response is not successful since the authorization hasn't settled" do
53
- credit.processor_response.success.should be_true
54
- end
48
+ credit = @authorization.credit(BigDecimal('0.5'))
49
+ credit.amount.should == "#{BigDecimal('0.5')}"
50
+ credit.processor_response.success.should be_true
55
51
  end
56
52
  end
@@ -9,16 +9,16 @@ describe "Processor actions" do
9
9
  processor = Samurai::Processor.the_processor
10
10
  processor.should_not be_nil
11
11
  end
12
-
12
+
13
13
  it "should create a new purchase" do
14
- purchase = Samurai::Processor.purchase(@payment_method_token, @seed)
14
+ purchase = Samurai::Processor.purchase(@payment_method_token, 1.0, :billing_reference=>rand(1000))
15
15
  purchase.processor_response.success.should be_true
16
16
  # FakeWeb.last_request
17
17
  end
18
18
 
19
19
  it "should create a new purchase with tracking data" do
20
- purchase = Samurai::Processor.purchase(@payment_method_token, @seed, {
21
- :descriptor => "A test purchase",
20
+ purchase = Samurai::Processor.purchase(@payment_method_token, 1.0, {
21
+ :descriptor => "A test purchase",
22
22
  :custom => "some optional custom data",
23
23
  :billing_reference => "ABC123",
24
24
  :customer_reference => "Customer (123)"
@@ -26,10 +26,10 @@ describe "Processor actions" do
26
26
  purchase.processor_response.success.should be_true
27
27
  # FakeWeb.last_request
28
28
  end
29
-
29
+
30
30
  it "should create a non-new authorization" do
31
- authorization = Samurai::Processor.authorize(@payment_method_token, @seed)
31
+ authorization = Samurai::Processor.authorize(@payment_method_token, 1.0)
32
32
  authorization.processor_response.success.should be_true
33
33
  end
34
-
34
+
35
35
  end
@@ -17,24 +17,24 @@ describe "processing purchases" do
17
17
  void.processor_response.success.should be_true
18
18
  end
19
19
 
20
- it "should not be able to credit a recent purchase" do
20
+ it "should be able to credit a recent purchase" do
21
21
  credit = @purchase.credit
22
- credit.processor_response.success.should be_false
22
+ credit.processor_response.success.should be_true
23
+ credit.transaction_type.should == 'Credit'
23
24
  end
24
25
 
25
26
  it "should be able to reverse a recent purchase" do
26
27
  reverse = @purchase.reverse
27
28
  reverse.processor_response.success.should be_true
29
+ reverse.transaction_type.should == 'Credit'
28
30
  end
29
31
 
30
32
  it "should be able to reverse a settled purchase" do
31
- pending "currently we cannot force settle a purchase, so can't test this properly"
32
33
  reverse = @purchase.reverse
33
34
  reverse.processor_response.success.should be_true
34
35
  end
35
36
 
36
37
  it "should be able to credit a settled purchase" do
37
- pending "currently we cannot force settle a purchase, so can't test this properly"
38
38
  credit = @purchase.credit
39
39
  credit.processor_response.success.should be_true
40
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samurai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.24
4
+ version: 0.2.25
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-11-04 00:00:00.000000000Z
13
+ date: 2011-11-11 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activeresource
17
- requirement: &70345403388140 !ruby/object:Gem::Requirement
17
+ requirement: &70107049098300 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.2.2
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70345403388140
25
+ version_requirements: *70107049098300
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: bundler
28
- requirement: &70345403387640 !ruby/object:Gem::Requirement
28
+ requirement: &70107049097080 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.0.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70345403387640
36
+ version_requirements: *70107049097080
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &70345403387140 !ruby/object:Gem::Requirement
39
+ requirement: &70107049095700 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 2.6.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70345403387140
47
+ version_requirements: *70107049095700
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: fakeweb
50
- requirement: &70345403386760 !ruby/object:Gem::Requirement
50
+ requirement: &70107049094120 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70345403386760
58
+ version_requirements: *70107049094120
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: ruby-debug19
61
- requirement: &70345403386220 !ruby/object:Gem::Requirement
61
+ requirement: &70107049093040 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70345403386220
69
+ version_requirements: *70107049093040
70
70
  description: If you are an online merchant and using samurai.feefighters.com, this
71
71
  gem will make your life easy. Integrate with the samurai.feefighters.com portal
72
72
  and process transaction.