samurai 0.2.26 → 0.2.27
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/Gemfile.lock +1 -1
- data/lib/samurai/base.rb +1 -1
- data/lib/samurai/message.rb +16 -2
- data/lib/samurai/payment_method.rb +4 -2
- data/lib/samurai/version.rb +1 -1
- data/spec/lib/payment_method_spec.rb +89 -11
- metadata +12 -12
data/Gemfile.lock
CHANGED
data/lib/samurai/base.rb
CHANGED
data/lib/samurai/message.rb
CHANGED
@@ -33,7 +33,7 @@ class Samurai::Message < Samurai::Base
|
|
33
33
|
'error processor.transaction type_invalid' => 'Requested transaction type is not allowed for this card/merchant.',
|
34
34
|
'error processor.transaction method_invalid' => 'The requested transaction could not be performed for this merchant.',
|
35
35
|
'error input.amount exceeds_limit' => 'The maximum transaction amount was exceeded.',
|
36
|
-
'error input.cvv invalid' => 'The CVV
|
36
|
+
'error input.cvv invalid' => 'The CVV code was not correct.',
|
37
37
|
'error processor.network_gateway communication_error' => 'There was a fatal communication error.',
|
38
38
|
'error processor.network_gateway unresponsive' => 'The processing network is temporarily unavailable.',
|
39
39
|
'error processor.network_gateway merchant_invalid' => 'The merchant number is not on file.',
|
@@ -52,7 +52,21 @@ class Samurai::Message < Samurai::Base
|
|
52
52
|
|
53
53
|
# CVV Responses
|
54
54
|
'error input.cvv declined' => 'The CVV code was not correct.',
|
55
|
-
|
55
|
+
|
56
|
+
# Input validations
|
57
|
+
'error input.card_number is_blank' => 'The card number was blank.',
|
58
|
+
'error input.card_number not_numeric' => 'The card number was invalid.',
|
59
|
+
'error input.card_number too_short' => 'The card number was too short.',
|
60
|
+
'error input.card_number too_long' => 'The card number was too long.',
|
61
|
+
'error input.card_number failed_checksum' => 'The card number was invalid.',
|
62
|
+
'error input.cvv is_blank' => 'The CVV was blank.',
|
63
|
+
'error input.cvv not_numeric' => 'The CVV was invalid.',
|
64
|
+
'error input.cvv too_short' => 'The CVV was too short.',
|
65
|
+
'error input.cvv too_long' => 'The CVV was too long.',
|
66
|
+
'error input.expiry_month is_blank' => 'The expiration month was blank.',
|
67
|
+
'error input.expiry_month not_numeric' => 'The expiration month was invalid.',
|
68
|
+
'error input.expiry_year is_blank' => 'The expiration year was blank.',
|
69
|
+
'error input.expiry_year not_numeric' => 'The expiration year was invalid.',
|
56
70
|
}
|
57
71
|
|
58
72
|
def self.response_mappings
|
@@ -37,8 +37,10 @@ class Samurai::PaymentMethod < Samurai::Base
|
|
37
37
|
# Examine the `<messages>` array, and add an error to the Errors object for each `<message>`
|
38
38
|
def process_response_errors
|
39
39
|
if respond_to?(:messages) && self.messages
|
40
|
-
|
41
|
-
|
40
|
+
# Sort the messages so that more-critical/relevant ones appear first, since only the first error is added to a field
|
41
|
+
sorted_messages = self.messages.sort_by {|m| ['is_blank', 'not_numeric', 'too_short', 'too_long', 'failed_checksum'].index(m.key) || 0 }
|
42
|
+
sorted_messages.each do |message|
|
43
|
+
self.errors.add message.context, message.description if self.errors[message.context].blank?
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
data/lib/samurai/version.rb
CHANGED
@@ -3,18 +3,96 @@ require 'spec_helper'
|
|
3
3
|
describe "PaymentMethod actions" do
|
4
4
|
|
5
5
|
it "should create a new PaymentMethod using S2S endpoint" do
|
6
|
-
|
7
|
-
:city => "Chicago",
|
8
|
-
:zip => "53211",
|
9
|
-
:expiry_month => 03,
|
10
|
-
:cvv => "123",
|
11
|
-
:card_number => "4111111111111111",
|
12
|
-
:address_1 => "1240 W Monroe #1",
|
13
|
-
:address_2 => "",
|
14
|
-
:last_name => "harper",
|
15
|
-
:expiry_year => "2015",
|
16
|
-
:first_name => "sean",
|
6
|
+
Samurai::PaymentMethod.create(
|
7
|
+
:city => "Chicago",
|
8
|
+
:zip => "53211",
|
9
|
+
:expiry_month => 03,
|
10
|
+
:cvv => "123",
|
11
|
+
:card_number => "4111111111111111",
|
12
|
+
:address_1 => "1240 W Monroe #1",
|
13
|
+
:address_2 => "",
|
14
|
+
:last_name => "harper",
|
15
|
+
:expiry_year => "2015",
|
16
|
+
:first_name => "sean",
|
17
17
|
:state => "IL")
|
18
18
|
end
|
19
19
|
|
20
|
+
describe 'with errors' do
|
21
|
+
before(:each) do
|
22
|
+
@params = {
|
23
|
+
:city => "Chicago",
|
24
|
+
:zip => "53211",
|
25
|
+
:expiry_month => 03,
|
26
|
+
:cvv => "123",
|
27
|
+
:card_number => "4111111111111111",
|
28
|
+
:address_1 => "1240 W Monroe #1",
|
29
|
+
:address_2 => "",
|
30
|
+
:last_name => "harper",
|
31
|
+
:expiry_year => "2015",
|
32
|
+
:first_name => "sean",
|
33
|
+
:state => "IL",
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should validate blank card number' do
|
38
|
+
pm = Samurai::PaymentMethod.create @params.merge(:card_number=>'')
|
39
|
+
pm.has_errors?.should be_true
|
40
|
+
pm.errors.count.should == 1
|
41
|
+
pm.errors['input.card_number'].should == [ 'The card number was blank.' ]
|
42
|
+
end
|
43
|
+
it 'should validate invalid card number' do
|
44
|
+
pm = Samurai::PaymentMethod.create @params.merge(:card_number=>'abc123')
|
45
|
+
pm.has_errors?.should be_true
|
46
|
+
pm.errors.count.should == 1
|
47
|
+
pm.errors['input.card_number'].should == [ 'The card number was invalid.' ]
|
48
|
+
end
|
49
|
+
it 'should validate short card number' do
|
50
|
+
pm = Samurai::PaymentMethod.create @params.merge(:card_number=>'1234')
|
51
|
+
pm.has_errors?.should be_true
|
52
|
+
pm.errors.count.should == 1
|
53
|
+
pm.errors['input.card_number'].should == [ 'The card number was too short.' ]
|
54
|
+
end
|
55
|
+
it 'should validate long card number' do
|
56
|
+
pm = Samurai::PaymentMethod.create @params.merge(:card_number=>'41111111111111111')
|
57
|
+
pm.has_errors?.should be_true
|
58
|
+
pm.errors.count.should == 1
|
59
|
+
pm.errors['input.card_number'].should == [ 'The card number was too long.' ]
|
60
|
+
end
|
61
|
+
it 'should not validate blank cvv' do
|
62
|
+
pm = Samurai::PaymentMethod.create @params.merge(:cvv=>'')
|
63
|
+
pm.has_errors?.should be_false
|
64
|
+
pm.errors.count.should == 0
|
65
|
+
end
|
66
|
+
it 'should validate invalid cvv' do
|
67
|
+
pm = Samurai::PaymentMethod.create @params.merge(:cvv=>'abc')
|
68
|
+
pm.has_errors?.should be_true
|
69
|
+
pm.errors.count.should == 1
|
70
|
+
pm.errors['input.cvv'].should == [ 'The CVV was invalid.' ]
|
71
|
+
end
|
72
|
+
it 'should validate short cvv' do
|
73
|
+
pm = Samurai::PaymentMethod.create @params.merge(:cvv=>'1')
|
74
|
+
pm.has_errors?.should be_true
|
75
|
+
pm.errors.count.should == 1
|
76
|
+
pm.errors['input.cvv'].should == [ 'The CVV was too short.' ]
|
77
|
+
end
|
78
|
+
it 'should validate long cvv' do
|
79
|
+
pm = Samurai::PaymentMethod.create @params.merge(:cvv=>'11111')
|
80
|
+
pm.has_errors?.should be_true
|
81
|
+
pm.errors.count.should == 1
|
82
|
+
pm.errors['input.cvv'].should == [ 'The CVV was too long.' ]
|
83
|
+
end
|
84
|
+
it 'should validate blank expiry_month' do
|
85
|
+
pm = Samurai::PaymentMethod.create @params.merge(:expiry_month=>'')
|
86
|
+
pm.has_errors?.should be_true
|
87
|
+
pm.errors.count.should == 1
|
88
|
+
pm.errors['input.expiry_month'].should == [ 'The expiration month was blank.' ]
|
89
|
+
end
|
90
|
+
it 'should validate blank expiry_year' do
|
91
|
+
pm = Samurai::PaymentMethod.create @params.merge(:expiry_year=>'')
|
92
|
+
pm.has_errors?.should be_true
|
93
|
+
pm.errors.count.should == 1
|
94
|
+
pm.errors['input.expiry_year'].should == [ 'The expiration year was blank.' ]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
20
98
|
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.
|
4
|
+
version: 0.2.27
|
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-
|
13
|
+
date: 2011-11-20 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activeresource
|
17
|
-
requirement: &
|
17
|
+
requirement: &70263286980460 !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: *
|
25
|
+
version_requirements: *70263286980460
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bundler
|
28
|
-
requirement: &
|
28
|
+
requirement: &70263286980000 !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: *
|
36
|
+
version_requirements: *70263286980000
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70263286979520 !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: *
|
47
|
+
version_requirements: *70263286979520
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: fakeweb
|
50
|
-
requirement: &
|
50
|
+
requirement: &70263286978900 !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: *
|
58
|
+
version_requirements: *70263286978900
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: ruby-debug19
|
61
|
-
requirement: &
|
61
|
+
requirement: &70263286969400 !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: *
|
69
|
+
version_requirements: *70263286969400
|
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.
|