samurai 0.2.29 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/views/application/_transaction.html.erb +2 -2
- data/lib/samurai/message.rb +4 -1
- data/lib/samurai/processor.rb +13 -8
- data/lib/samurai/transaction.rb +13 -8
- data/lib/samurai/version.rb +1 -1
- data/spec/lib/payment_method_spec.rb +228 -78
- data/spec/lib/processor_spec.rb +179 -20
- data/spec/lib/transaction_spec.rb +143 -0
- data/spec/spec_helper.rb +3 -8
- data/spec/support/transparent_redirect_helper.rb +1 -1
- metadata +14 -15
- data/spec/lib/authorization_spec.rb +0 -52
- data/spec/lib/purchase_spec.rb +0 -82
@@ -17,7 +17,7 @@
|
|
17
17
|
|
18
18
|
<p><strong>Date / Time:</strong> <%= transaction.created_at %></p>
|
19
19
|
<p>
|
20
|
-
<strong>
|
20
|
+
<strong>Description:</strong> <%= transaction.description %><br>
|
21
21
|
<strong>Billing Reference:</strong> <%= transaction.billing_reference %><br>
|
22
22
|
<strong>Customer Reference: </strong> <%= transaction.customer_reference %><br>
|
23
23
|
<strong>Custom Data: </strong> <%= transaction.custom %><br>
|
@@ -26,4 +26,4 @@
|
|
26
26
|
<p>
|
27
27
|
<strong>AVS Response:</strong> <%= transaction.processor_response.try(:avs_result_code) || 'None' %>
|
28
28
|
</p>
|
29
|
-
<% end %>
|
29
|
+
<% end %>
|
data/lib/samurai/message.rb
CHANGED
@@ -29,7 +29,7 @@ class Samurai::Message < Samurai::Base
|
|
29
29
|
'error input.merchant_login invalid' => 'The merchant ID is not valid or active.',
|
30
30
|
'error input.store_number invalid' => 'Invalid Store Number.',
|
31
31
|
'error processor.bank_info invalid' => 'Invalid banking information.',
|
32
|
-
'error processor.transaction not_allowed' => '
|
32
|
+
'error processor.transaction not_allowed' => 'This transaction type is not allowed.',
|
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.',
|
@@ -59,14 +59,17 @@ class Samurai::Message < Samurai::Base
|
|
59
59
|
'error input.card_number too_short' => 'The card number was too short.',
|
60
60
|
'error input.card_number too_long' => 'The card number was too long.',
|
61
61
|
'error input.card_number failed_checksum' => 'The card number was invalid.',
|
62
|
+
'error input.card_number is_invalid' => 'The card number was invalid.',
|
62
63
|
'error input.cvv is_blank' => 'The CVV was blank.',
|
63
64
|
'error input.cvv not_numeric' => 'The CVV was invalid.',
|
64
65
|
'error input.cvv too_short' => 'The CVV was too short.',
|
65
66
|
'error input.cvv too_long' => 'The CVV was too long.',
|
66
67
|
'error input.expiry_month is_blank' => 'The expiration month was blank.',
|
67
68
|
'error input.expiry_month not_numeric' => 'The expiration month was invalid.',
|
69
|
+
'error input.expiry_month is_invalid' => 'The expiration month was invalid.',
|
68
70
|
'error input.expiry_year is_blank' => 'The expiration year was blank.',
|
69
71
|
'error input.expiry_year not_numeric' => 'The expiration year was invalid.',
|
72
|
+
'error input.expiry_year is_invalid' => 'The expiration year was invalid.',
|
70
73
|
}
|
71
74
|
|
72
75
|
def self.response_mappings
|
data/lib/samurai/processor.rb
CHANGED
@@ -4,12 +4,13 @@
|
|
4
4
|
# This class represents a Samurai Processor connection
|
5
5
|
# It can be used to create purchase & authorize transactions
|
6
6
|
class Samurai::Processor < Samurai::Base
|
7
|
-
|
7
|
+
alias_method :token, :id
|
8
|
+
|
8
9
|
# Returns the default processor specified by Samurai.processor_token if you passed it into Samurai.setup_site.
|
9
10
|
def self.the_processor
|
10
11
|
Samurai::Processor.new(:id => Samurai.processor_token)
|
11
12
|
end
|
12
|
-
|
13
|
+
|
13
14
|
# Convenience method that calls the purchase method on the default processor.
|
14
15
|
def self.purchase(*args)
|
15
16
|
the_processor.purchase(*args)
|
@@ -19,14 +20,16 @@ class Samurai::Processor < Samurai::Base
|
|
19
20
|
def self.authorize(*args)
|
20
21
|
the_processor.authorize(*args)
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
# Convenience method to authorize and capture a payment_method for a particular amount in one transaction.
|
24
25
|
# Parameters:
|
25
26
|
#
|
26
27
|
# * `payment_method_token`: token identifying the payment method to authorize
|
27
28
|
# * `amount`: amount to authorize
|
28
29
|
# * `options`: an optional has of additional values to pass in accepted values are:
|
29
|
-
# * `
|
30
|
+
# * `description`: description for the transaction
|
31
|
+
# * `descriptor_name`: dynamic descriptor name field
|
32
|
+
# * `descriptor_phone`: dynamic descriptor phone field
|
30
33
|
# * `custom`: custom data, this data does not get passed to the processor, it is stored within `api.samurai.feefighters.com` only
|
31
34
|
# * `customer_reference`: an identifier for the customer, this will appear in the processor if supported
|
32
35
|
# * `billing_reference`: an identifier for the purchase, this will appear in the processor if supported
|
@@ -43,7 +46,9 @@ class Samurai::Processor < Samurai::Base
|
|
43
46
|
# * `amount`: amount to authorize
|
44
47
|
#
|
45
48
|
# * options: an optional has of additional values to pass in accepted values are:
|
46
|
-
# * `
|
49
|
+
# * `description`: description for the transaction
|
50
|
+
# * `descriptor_name`: dynamic descriptor name field
|
51
|
+
# * `descriptor_phone`: dynamic descriptor phone field
|
47
52
|
# * `custom`: custom data, this data does not get passed to the processor, it is stored within api.samurai.feefighters.com only
|
48
53
|
# * `customer_reference`: an identifier for the customer, this will appear in the processor if supported
|
49
54
|
# * `billing_reference`: an identifier for the purchase, this will appear in the processor if supported
|
@@ -52,7 +57,7 @@ class Samurai::Processor < Samurai::Base
|
|
52
57
|
def authorize(payment_method_token, amount, options = {})
|
53
58
|
execute(:authorize, options.merge(:payment_method_token => payment_method_token, :amount => amount))
|
54
59
|
end
|
55
|
-
|
60
|
+
|
56
61
|
private
|
57
62
|
|
58
63
|
# Make the actual ActiveResource POST request, process the response
|
@@ -77,5 +82,5 @@ class Samurai::Processor < Samurai::Base
|
|
77
82
|
end
|
78
83
|
end
|
79
84
|
end
|
80
|
-
|
81
|
-
end
|
85
|
+
|
86
|
+
end
|
data/lib/samurai/transaction.rb
CHANGED
@@ -33,13 +33,14 @@ class Samurai::Transaction < Samurai::Base
|
|
33
33
|
|
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
|
-
def reverse(options = {})
|
36
|
+
def reverse(amount = nil, options = {})
|
37
37
|
execute(:reverse, {:amount => amount || self.amount}.reverse_merge(options))
|
38
38
|
end
|
39
39
|
|
40
40
|
def success?
|
41
41
|
respond_to?(:processor_response) && processor_response && processor_response.success
|
42
42
|
end
|
43
|
+
alias_method :success, :success?
|
43
44
|
def failed?
|
44
45
|
!success?
|
45
46
|
end
|
@@ -65,11 +66,12 @@ class Samurai::Transaction < Samurai::Base
|
|
65
66
|
# Override base error processing with specific Transaction behavior
|
66
67
|
# Examine the `<processor_response><messages>` array, and add an error to the Errors object for each `<message>`
|
67
68
|
def process_response_errors
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
_messages = []
|
70
|
+
_messages += processor_response.messages if respond_to?(:processor_response) && processor_response.respond_to?(:messages)
|
71
|
+
_messages += payment_method.messages if payment_method
|
72
|
+
_messages.each do |message|
|
73
|
+
if message.subclass == 'error'
|
74
|
+
self.errors.add message.context, message.description
|
73
75
|
end
|
74
76
|
end
|
75
77
|
end
|
@@ -82,7 +84,9 @@ class Samurai::Transaction < Samurai::Base
|
|
82
84
|
:type => options[:type],
|
83
85
|
:payment_method_token => options[:payment_method_token],
|
84
86
|
:currency_code => options[:currency_code] || (options[:payment_method_token] && 'USD'), # currency code is only required for payloads that include the PMT
|
85
|
-
:
|
87
|
+
:description => options[:description],
|
88
|
+
:descriptor_name => options[:descriptor_name],
|
89
|
+
:descriptor_phone => options[:descriptor_phone],
|
86
90
|
:custom => options[:custom],
|
87
91
|
:customer_reference => options[:customer_reference],
|
88
92
|
:billing_reference => options[:billing_reference]
|
@@ -94,7 +98,8 @@ class Samurai::Transaction < Samurai::Base
|
|
94
98
|
# Setup the Transaction schema for ActiveResource, so that new objects contain empty attributes
|
95
99
|
KNOWN_ATTRIBUTES = [
|
96
100
|
:amount, :type, :payment_method_token, :currency_code,
|
97
|
-
:
|
101
|
+
:description, :custom, :customer_reference, :billing_reference, :processor_response,
|
102
|
+
:descriptor_name, :descriptor_phone
|
98
103
|
]
|
99
104
|
if [ActiveResource::VERSION::MAJOR, ActiveResource::VERSION::MINOR].compact.join('.').to_f < 3.1
|
100
105
|
# If we're using ActiveResource pre-3.1, there's no schema class method, so we resort to some tricks...
|
data/lib/samurai/version.rb
CHANGED
@@ -1,97 +1,247 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "PaymentMethod
|
3
|
+
describe "PaymentMethod" do
|
4
|
+
before do
|
5
|
+
@params = {
|
6
|
+
:first_name => "FirstName",
|
7
|
+
:last_name => "LastName",
|
8
|
+
:address_1 => "123 Main St.",
|
9
|
+
:address_2 => "Apt #3",
|
10
|
+
:city => "Chicago",
|
11
|
+
:state => "IL",
|
12
|
+
:zip => "10101",
|
13
|
+
:card_number => "4111-1111-1111-1111",
|
14
|
+
:cvv => "123",
|
15
|
+
:expiry_month => '03',
|
16
|
+
:expiry_year => "2015",
|
17
|
+
}
|
18
|
+
end
|
4
19
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
20
|
+
describe 'S2S #create' do
|
21
|
+
it 'should be successful' do
|
22
|
+
pm = Samurai::PaymentMethod.create @params
|
23
|
+
Samurai::PaymentMethod.find(pm.token).tap do |pm|
|
24
|
+
pm.is_sensitive_data_valid.should be_true
|
25
|
+
pm.is_expiration_valid.should be_true
|
26
|
+
pm.first_name.should == @params[:first_name]
|
27
|
+
pm.last_name.should == @params[:last_name]
|
28
|
+
pm.address_1.should == @params[:address_1]
|
29
|
+
pm.address_2.should == @params[:address_2]
|
30
|
+
pm.city.should == @params[:city]
|
31
|
+
pm.state.should == @params[:state]
|
32
|
+
pm.zip.should == @params[:zip]
|
33
|
+
pm.last_four_digits.should == @params[:card_number][-4, 4]
|
34
|
+
pm.expiry_month.should == @params[:expiry_month].to_i
|
35
|
+
pm.expiry_year.should == @params[:expiry_year].to_i
|
36
|
+
end
|
37
|
+
end
|
38
|
+
describe 'fail on input.card_number' do
|
39
|
+
it 'should return is_blank' do
|
40
|
+
pm = Samurai::PaymentMethod.create @params.merge(:card_number => '')
|
41
|
+
pm.is_sensitive_data_valid.should be_false
|
42
|
+
pm.errors['input.card_number'].should == [ 'The card number was blank.' ]
|
43
|
+
end
|
44
|
+
it 'should return too_short' do
|
45
|
+
pm = Samurai::PaymentMethod.create @params.merge(:card_number => '4111-1')
|
46
|
+
pm.is_sensitive_data_valid.should be_false
|
47
|
+
pm.errors['input.card_number'].should == [ 'The card number was too short.' ]
|
48
|
+
end
|
49
|
+
it 'should return too_long' do
|
50
|
+
pm = Samurai::PaymentMethod.create @params.merge(:card_number => '4111-1111-1111-1111-11')
|
51
|
+
pm.is_sensitive_data_valid.should be_false
|
52
|
+
pm.errors['input.card_number'].should == [ 'The card number was too long.' ]
|
53
|
+
end
|
54
|
+
it 'should return failed_checksum' do
|
55
|
+
pm = Samurai::PaymentMethod.create @params.merge(:card_number => '4111-1111-1111-1234')
|
56
|
+
pm.is_sensitive_data_valid.should be_false
|
57
|
+
pm.errors['input.card_number'].should == [ 'The card number was invalid.' ]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
describe 'fail on input.cvv' do
|
61
|
+
it 'should return too_short' do
|
62
|
+
pm = Samurai::PaymentMethod.create @params.merge(:cvv => '1')
|
63
|
+
pm.is_sensitive_data_valid.should be_false
|
64
|
+
pm.errors['input.cvv'].should == [ 'The CVV was too short.' ]
|
65
|
+
end
|
66
|
+
it 'should return too_long' do
|
67
|
+
pm = Samurai::PaymentMethod.create @params.merge(:cvv => '111111')
|
68
|
+
pm.is_sensitive_data_valid.should be_false
|
69
|
+
pm.errors['input.cvv'].should == [ 'The CVV was too long.' ]
|
70
|
+
end
|
71
|
+
it 'should return not_numeric' do
|
72
|
+
pm = Samurai::PaymentMethod.create @params.merge(:cvv => 'abcd1')
|
73
|
+
pm.is_sensitive_data_valid.should be_false
|
74
|
+
pm.errors['input.cvv'].should == [ 'The CVV was invalid.' ]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
describe 'fail on input.expiry_month' do
|
78
|
+
it 'should return is_blank' do
|
79
|
+
pm = Samurai::PaymentMethod.create @params.merge(:expiry_month => '')
|
80
|
+
pm.is_sensitive_data_valid.should be_true
|
81
|
+
pm.is_expiration_valid.should be_false
|
82
|
+
pm.errors['input.expiry_month'].should == [ 'The expiration month was blank.' ]
|
83
|
+
end
|
84
|
+
it 'should return is_invalid' do
|
85
|
+
pm = Samurai::PaymentMethod.create @params.merge(:expiry_month => 'abcd')
|
86
|
+
pm.is_sensitive_data_valid.should be_true
|
87
|
+
pm.is_expiration_valid.should be_false
|
88
|
+
pm.errors['input.expiry_month'].should == [ 'The expiration month was invalid.' ]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
describe 'fail on input.expiry_year' do
|
92
|
+
it 'should return is_blank' do
|
93
|
+
pm = Samurai::PaymentMethod.create @params.merge(:expiry_year => '')
|
94
|
+
pm.is_sensitive_data_valid.should be_true
|
95
|
+
pm.is_expiration_valid.should be_false
|
96
|
+
pm.errors['input.expiry_year'].should == [ 'The expiration year was blank.' ]
|
97
|
+
end
|
98
|
+
it 'should return is_invalid' do
|
99
|
+
pm = Samurai::PaymentMethod.create @params.merge(:expiry_year => 'abcd')
|
100
|
+
pm.is_sensitive_data_valid.should be_true
|
101
|
+
pm.is_expiration_valid.should be_false
|
102
|
+
pm.errors['input.expiry_year'].should == [ 'The expiration year was invalid.' ]
|
103
|
+
end
|
104
|
+
end
|
18
105
|
end
|
19
106
|
|
20
|
-
describe '
|
21
|
-
before
|
107
|
+
describe 'S2S #update' do
|
108
|
+
before do
|
22
109
|
@params = {
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
110
|
+
:first_name => "FirstNameX",
|
111
|
+
:last_name => "LastNameX",
|
112
|
+
:address_1 => "123 Main St.X",
|
113
|
+
:address_2 => "Apt #3X",
|
114
|
+
:city => "ChicagoX",
|
115
|
+
:state => "IL",
|
116
|
+
:zip => "10101",
|
117
|
+
:card_number => "5454-5454-5454-5454",
|
118
|
+
:cvv => "456",
|
119
|
+
:expiry_month => '05',
|
120
|
+
:expiry_year => "2016",
|
34
121
|
}
|
122
|
+
@pm = Samurai::PaymentMethod.find create_payment_method(default_payment_method_params)[:payment_method_token]
|
35
123
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
124
|
+
it 'should be successful' do
|
125
|
+
@pm.update_attributes @params
|
126
|
+
Samurai::PaymentMethod.find(@pm.token).tap do |pm|
|
127
|
+
pm.is_sensitive_data_valid.should be_true
|
128
|
+
pm.is_expiration_valid.should be_true
|
129
|
+
pm.first_name.should == @params[:first_name]
|
130
|
+
pm.last_name.should == @params[:last_name]
|
131
|
+
pm.address_1.should == @params[:address_1]
|
132
|
+
pm.address_2.should == @params[:address_2]
|
133
|
+
pm.city.should == @params[:city]
|
134
|
+
pm.state.should == @params[:state]
|
135
|
+
pm.zip.should == @params[:zip]
|
136
|
+
pm.last_four_digits.should == @params[:card_number][-4, 4]
|
137
|
+
pm.expiry_month.should == @params[:expiry_month].to_i
|
138
|
+
pm.expiry_year.should == @params[:expiry_year].to_i
|
139
|
+
end
|
48
140
|
end
|
49
|
-
it 'should
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
141
|
+
it 'should be successful preserving sensitive data' do
|
142
|
+
_params = @params.merge({
|
143
|
+
:card_number => '****************',
|
144
|
+
:cvv => '***',
|
145
|
+
})
|
146
|
+
@pm.update_attributes _params
|
147
|
+
Samurai::PaymentMethod.find(@pm.token).tap do |pm|
|
148
|
+
pm.is_sensitive_data_valid.should be_true
|
149
|
+
pm.is_expiration_valid.should be_true
|
150
|
+
pm.first_name.should == @params[:first_name]
|
151
|
+
pm.last_name.should == @params[:last_name]
|
152
|
+
pm.address_1.should == @params[:address_1]
|
153
|
+
pm.address_2.should == @params[:address_2]
|
154
|
+
pm.city.should == @params[:city]
|
155
|
+
pm.state.should == @params[:state]
|
156
|
+
pm.zip.should == @params[:zip]
|
157
|
+
pm.last_four_digits.should == '1111'
|
158
|
+
pm.expiry_month.should == @params[:expiry_month].to_i
|
159
|
+
pm.expiry_year.should == @params[:expiry_year].to_i
|
160
|
+
end
|
54
161
|
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
162
|
+
describe 'fail on input.card_number' do
|
163
|
+
it 'should return too_short' do
|
164
|
+
@pm.update_attributes @params.merge(:card_number => '4111-1')
|
165
|
+
@pm.is_sensitive_data_valid.should be_false
|
166
|
+
@pm.errors['input.card_number'].should == [ 'The card number was too short.' ]
|
167
|
+
end
|
168
|
+
it 'should return too_long' do
|
169
|
+
@pm.update_attributes @params.merge(:card_number => '4111-1111-1111-1111-11')
|
170
|
+
@pm.is_sensitive_data_valid.should be_false
|
171
|
+
@pm.errors['input.card_number'].should == [ 'The card number was too long.' ]
|
172
|
+
end
|
173
|
+
it 'should return failed_checksum' do
|
174
|
+
@pm.update_attributes @params.merge(:card_number => '4111-1111-1111-1234')
|
175
|
+
@pm.is_sensitive_data_valid.should be_false
|
176
|
+
@pm.errors['input.card_number'].should == [ 'The card number was invalid.' ]
|
177
|
+
end
|
60
178
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
179
|
+
describe 'fail on input.cvv' do
|
180
|
+
it 'should return too_short' do
|
181
|
+
@pm.update_attributes @params.merge(:cvv => '1')
|
182
|
+
@pm.is_sensitive_data_valid.should be_false
|
183
|
+
@pm.errors['input.cvv'].should == [ 'The CVV was too short.' ]
|
184
|
+
end
|
185
|
+
it 'should return too_long' do
|
186
|
+
@pm.update_attributes @params.merge(:cvv => '111111')
|
187
|
+
@pm.is_sensitive_data_valid.should be_false
|
188
|
+
@pm.errors['input.cvv'].should == [ 'The CVV was too long.' ]
|
189
|
+
end
|
65
190
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
191
|
+
describe 'fail on input.expiry_month' do
|
192
|
+
it 'should return is_blank' do
|
193
|
+
@pm.update_attributes @params.merge(:expiry_month => '')
|
194
|
+
@pm.is_sensitive_data_valid.should be_true
|
195
|
+
@pm.is_expiration_valid.should be_false
|
196
|
+
@pm.errors['input.expiry_month'].should == [ 'The expiration month was blank.' ]
|
197
|
+
end
|
198
|
+
it 'should return is_invalid' do
|
199
|
+
@pm.update_attributes @params.merge(:expiry_month => 'abcd')
|
200
|
+
@pm.is_sensitive_data_valid.should be_true
|
201
|
+
@pm.is_expiration_valid.should be_false
|
202
|
+
@pm.errors['input.expiry_month'].should == [ 'The expiration month was invalid.' ]
|
203
|
+
end
|
71
204
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
205
|
+
describe 'fail on input.expiry_year' do
|
206
|
+
it 'should return is_blank' do
|
207
|
+
@pm.update_attributes @params.merge(:expiry_year => '')
|
208
|
+
@pm.is_sensitive_data_valid.should be_true
|
209
|
+
@pm.is_expiration_valid.should be_false
|
210
|
+
@pm.errors['input.expiry_year'].should == [ 'The expiration year was blank.' ]
|
211
|
+
end
|
212
|
+
it 'should return is_invalid' do
|
213
|
+
@pm.update_attributes @params.merge(:expiry_year => 'abcd')
|
214
|
+
@pm.is_sensitive_data_valid.should be_true
|
215
|
+
@pm.is_expiration_valid.should be_false
|
216
|
+
@pm.errors['input.expiry_year'].should == [ 'The expiration year was invalid.' ]
|
217
|
+
end
|
77
218
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
219
|
+
end
|
220
|
+
|
221
|
+
describe '#find' do
|
222
|
+
before do
|
223
|
+
@token = Samurai::PaymentMethod.create(@params).token
|
83
224
|
end
|
84
|
-
it 'should
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
225
|
+
it 'should be successful' do
|
226
|
+
Samurai::PaymentMethod.find(@token).tap do |pm|
|
227
|
+
pm.is_sensitive_data_valid.should be_true
|
228
|
+
pm.is_expiration_valid.should be_true
|
229
|
+
pm.first_name.should == @params[:first_name]
|
230
|
+
pm.last_name.should == @params[:last_name]
|
231
|
+
pm.address_1.should == @params[:address_1]
|
232
|
+
pm.address_2.should == @params[:address_2]
|
233
|
+
pm.city.should == @params[:city]
|
234
|
+
pm.state.should == @params[:state]
|
235
|
+
pm.zip.should == @params[:zip]
|
236
|
+
pm.last_four_digits.should == @params[:card_number][-4, 4]
|
237
|
+
pm.expiry_month.should == @params[:expiry_month].to_i
|
238
|
+
pm.expiry_year.should == @params[:expiry_year].to_i
|
239
|
+
end
|
89
240
|
end
|
90
|
-
it 'should
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
pm.errors['input.expiry_year'].should == [ 'The expiration year was blank.' ]
|
241
|
+
it 'should fail on an invalid token' do
|
242
|
+
lambda do
|
243
|
+
Samurai::PaymentMethod.find('abc123')
|
244
|
+
end.should raise_error(ActiveResource::ResourceNotFound)
|
95
245
|
end
|
96
246
|
end
|
97
247
|
|
data/spec/lib/processor_spec.rb
CHANGED
@@ -1,35 +1,194 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Processor
|
3
|
+
describe "Processor" do
|
4
4
|
before :each do
|
5
|
+
@rand = rand(1000)
|
5
6
|
@payment_method_token = create_payment_method(default_payment_method_params)[:payment_method_token]
|
6
7
|
end
|
7
8
|
|
8
|
-
|
9
|
-
processor
|
10
|
-
|
9
|
+
describe 'the_processor' do
|
10
|
+
it "should return the default processor" do
|
11
|
+
processor = Samurai::Processor.the_processor
|
12
|
+
processor.should_not be_nil
|
13
|
+
processor.token.should == DEFAULT_OPTIONS[:processor_token]
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
describe 'new processor' do
|
18
|
+
it "should return a processor" do
|
19
|
+
processor = Samurai::Processor.new(:id=>'abc123')
|
20
|
+
processor.should_not be_nil
|
21
|
+
processor.token.should == 'abc123'
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
describe 'purchase' do
|
26
|
+
it 'should be successful' do
|
27
|
+
purchase = Samurai::Processor.purchase(@payment_method_token, 100.0, {
|
28
|
+
:description => "description",
|
29
|
+
:descriptor_name => "descriptor_name",
|
30
|
+
:descriptor_phone => "descriptor_phone",
|
31
|
+
:custom => "custom_data",
|
32
|
+
:billing_reference => "ABC123#{@rand}",
|
33
|
+
:customer_reference => "Customer (123)",
|
34
|
+
})
|
35
|
+
purchase.success.should be_true
|
36
|
+
purchase.description.should == 'description'
|
37
|
+
purchase.descriptor_name.should == 'descriptor_name'
|
38
|
+
purchase.descriptor_phone.should == 'descriptor_phone'
|
39
|
+
purchase.custom.should == 'custom_data'
|
40
|
+
purchase.billing_reference.should == "ABC123#{@rand}"
|
41
|
+
purchase.customer_reference.should == "Customer (123)"
|
42
|
+
end
|
43
|
+
describe 'failures' do
|
44
|
+
it 'should return processor.transaction - declined' do
|
45
|
+
purchase = Samurai::Processor.purchase(@payment_method_token, 1.02, :billing_reference=>rand(1000))
|
46
|
+
purchase.success.should be_false
|
47
|
+
purchase.errors['processor.transaction'].should == [ 'The card was declined.' ]
|
48
|
+
end
|
49
|
+
it 'should return input.amount - invalid' do
|
50
|
+
purchase = Samurai::Processor.purchase(@payment_method_token, 1.10, :billing_reference=>rand(1000))
|
51
|
+
purchase.success.should be_false
|
52
|
+
purchase.errors['input.amount'].should == [ 'The transaction amount was invalid.' ]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
describe 'cvv responses' do
|
56
|
+
it 'should return processor.cvv_result_code = M' do
|
57
|
+
params = default_payment_method_params.merge('credit_card[cvv]'=>'111')
|
58
|
+
payment_method_token = create_payment_method(params)[:payment_method_token]
|
59
|
+
purchase = Samurai::Processor.purchase(payment_method_token, 1.00, :billing_reference=>rand(1000))
|
60
|
+
purchase.success.should be_true
|
61
|
+
purchase.processor_response.cvv_result_code.should == 'M'
|
62
|
+
end
|
63
|
+
it 'should return processor.cvv_result_code = N' do
|
64
|
+
params = default_payment_method_params.merge('credit_card[cvv]'=>'222')
|
65
|
+
payment_method_token = create_payment_method(params)[:payment_method_token]
|
66
|
+
purchase = Samurai::Processor.purchase(payment_method_token, 1.00, :billing_reference=>rand(1000))
|
67
|
+
purchase.success.should be_true
|
68
|
+
purchase.processor_response.cvv_result_code.should == 'N'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
describe 'avs responses' do
|
72
|
+
it 'should return processor.avs_result_code = Y' do
|
73
|
+
params = default_payment_method_params.merge({
|
74
|
+
'credit_card[address_1]' => '1000 1st Av',
|
75
|
+
'credit_card[address_2]' => '',
|
76
|
+
'credit_card[zip]' => '10101',
|
77
|
+
})
|
78
|
+
payment_method_token = create_payment_method(params)[:payment_method_token]
|
79
|
+
purchase = Samurai::Processor.purchase(payment_method_token, 1.00, :billing_reference=>rand(1000))
|
80
|
+
purchase.success.should be_true
|
81
|
+
purchase.processor_response.avs_result_code.should == 'Y'
|
82
|
+
end
|
83
|
+
it 'should return processor.avs_result_code = Z' do
|
84
|
+
params = default_payment_method_params.merge({
|
85
|
+
'credit_card[address_1]' => '',
|
86
|
+
'credit_card[address_2]' => '',
|
87
|
+
'credit_card[zip]' => '10101',
|
88
|
+
})
|
89
|
+
payment_method_token = create_payment_method(params)[:payment_method_token]
|
90
|
+
purchase = Samurai::Processor.purchase(payment_method_token, 1.00, :billing_reference=>rand(1000))
|
91
|
+
purchase.success.should be_true
|
92
|
+
purchase.processor_response.avs_result_code.should == 'Z'
|
93
|
+
end
|
94
|
+
it 'should return processor.avs_result_code = N' do
|
95
|
+
params = default_payment_method_params.merge({
|
96
|
+
'credit_card[address_1]' => '123 Main St',
|
97
|
+
'credit_card[address_2]' => '',
|
98
|
+
'credit_card[zip]' => '60610',
|
99
|
+
})
|
100
|
+
payment_method_token = create_payment_method(params)[:payment_method_token]
|
101
|
+
Samurai::PaymentMethod.find(payment_method_token)
|
102
|
+
purchase = Samurai::Processor.purchase(payment_method_token, 1.00, :billing_reference=>rand(1000))
|
103
|
+
purchase.success.should be_true
|
104
|
+
purchase.processor_response.avs_result_code.should == 'N'
|
105
|
+
end
|
106
|
+
end
|
28
107
|
end
|
29
108
|
|
30
|
-
|
31
|
-
|
32
|
-
|
109
|
+
describe 'authorize' do
|
110
|
+
it 'should be successful' do
|
111
|
+
purchase = Samurai::Processor.authorize(@payment_method_token, 100.0, {
|
112
|
+
:description => "description",
|
113
|
+
:descriptor_name => "descriptor_name",
|
114
|
+
:descriptor_phone => "descriptor_phone",
|
115
|
+
:custom => "custom_data",
|
116
|
+
:billing_reference => "ABC123#{@rand}",
|
117
|
+
:customer_reference => "Customer (123)",
|
118
|
+
})
|
119
|
+
purchase.success.should be_true
|
120
|
+
purchase.description.should == 'description'
|
121
|
+
purchase.descriptor_name.should == 'descriptor_name'
|
122
|
+
purchase.descriptor_phone.should == 'descriptor_phone'
|
123
|
+
purchase.custom.should == 'custom_data'
|
124
|
+
purchase.billing_reference.should == "ABC123#{@rand}"
|
125
|
+
purchase.customer_reference.should == "Customer (123)"
|
126
|
+
end
|
127
|
+
describe 'failures' do
|
128
|
+
it 'should return processor.transaction - declined' do
|
129
|
+
authorize = Samurai::Processor.authorize(@payment_method_token, 1.02, :billing_reference=>rand(1000))
|
130
|
+
authorize.success.should be_false
|
131
|
+
authorize.errors['processor.transaction'].should == [ 'The card was declined.' ]
|
132
|
+
end
|
133
|
+
it 'should return input.amount - invalid' do
|
134
|
+
authorize = Samurai::Processor.authorize(@payment_method_token, 1.10, :billing_reference=>rand(1000))
|
135
|
+
authorize.success.should be_false
|
136
|
+
authorize.errors['input.amount'].should == [ 'The transaction amount was invalid.' ]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
describe 'cvv responses' do
|
140
|
+
it 'should return processor.cvv_result_code = M' do
|
141
|
+
params = default_payment_method_params.merge('credit_card[cvv]'=>'111')
|
142
|
+
payment_method_token = create_payment_method(params)[:payment_method_token]
|
143
|
+
purchase = Samurai::Processor.authorize(payment_method_token, 1.00, :billing_reference=>rand(1000))
|
144
|
+
purchase.success.should be_true
|
145
|
+
purchase.processor_response.cvv_result_code.should == 'M'
|
146
|
+
end
|
147
|
+
it 'should return processor.cvv_result_code = N' do
|
148
|
+
params = default_payment_method_params.merge('credit_card[cvv]'=>'222')
|
149
|
+
payment_method_token = create_payment_method(params)[:payment_method_token]
|
150
|
+
purchase = Samurai::Processor.authorize(payment_method_token, 1.00, :billing_reference=>rand(1000))
|
151
|
+
purchase.success.should be_true
|
152
|
+
purchase.processor_response.cvv_result_code.should == 'N'
|
153
|
+
end
|
154
|
+
end
|
155
|
+
describe 'avs responses' do
|
156
|
+
it 'should return processor.avs_result_code = Y' do
|
157
|
+
params = default_payment_method_params.merge({
|
158
|
+
'credit_card[address_1]' => '1000 1st Av',
|
159
|
+
'credit_card[address_2]' => '',
|
160
|
+
'credit_card[zip]' => '10101',
|
161
|
+
})
|
162
|
+
payment_method_token = create_payment_method(params)[:payment_method_token]
|
163
|
+
purchase = Samurai::Processor.authorize(payment_method_token, 1.00, :billing_reference=>rand(1000))
|
164
|
+
purchase.success.should be_true
|
165
|
+
purchase.processor_response.avs_result_code.should == 'Y'
|
166
|
+
end
|
167
|
+
it 'should return processor.avs_result_code = Z' do
|
168
|
+
params = default_payment_method_params.merge({
|
169
|
+
'credit_card[address_1]' => '',
|
170
|
+
'credit_card[address_2]' => '',
|
171
|
+
'credit_card[zip]' => '10101',
|
172
|
+
})
|
173
|
+
payment_method_token = create_payment_method(params)[:payment_method_token]
|
174
|
+
purchase = Samurai::Processor.authorize(payment_method_token, 1.00, :billing_reference=>rand(1000))
|
175
|
+
purchase.success.should be_true
|
176
|
+
purchase.processor_response.avs_result_code.should == 'Z'
|
177
|
+
end
|
178
|
+
it 'should return processor.avs_result_code = N' do
|
179
|
+
params = default_payment_method_params.merge({
|
180
|
+
'credit_card[address_1]' => '123 Main St',
|
181
|
+
'credit_card[address_2]' => '',
|
182
|
+
'credit_card[zip]' => '60610',
|
183
|
+
})
|
184
|
+
payment_method_token = create_payment_method(params)[:payment_method_token]
|
185
|
+
Samurai::PaymentMethod.find(payment_method_token)
|
186
|
+
purchase = Samurai::Processor.authorize(payment_method_token, 1.00, :billing_reference=>rand(1000))
|
187
|
+
purchase.success.should be_true
|
188
|
+
purchase.processor_response.avs_result_code.should == 'N'
|
189
|
+
end
|
190
|
+
end
|
33
191
|
end
|
34
192
|
|
193
|
+
|
35
194
|
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Transaction" do
|
4
|
+
before do
|
5
|
+
@rand = rand(1000)
|
6
|
+
@payment_method_token = create_payment_method(default_payment_method_params)[:payment_method_token]
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'capture' do
|
10
|
+
describe 'success' do
|
11
|
+
before do
|
12
|
+
@auth = Samurai::Processor.authorize(@payment_method_token, 100.0)
|
13
|
+
end
|
14
|
+
it 'should be successful' do
|
15
|
+
capture = @auth.capture
|
16
|
+
capture.success.should be_true
|
17
|
+
end
|
18
|
+
it 'should be successful for full amount' do
|
19
|
+
capture = @auth.capture(100.0)
|
20
|
+
capture.success.should be_true
|
21
|
+
end
|
22
|
+
it 'should be successful for partial amount' do
|
23
|
+
capture = @auth.capture(50.0)
|
24
|
+
capture.success.should be_true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
describe 'failures' do
|
28
|
+
it 'should return processor.transaction - invalid with declined auth' do
|
29
|
+
auth = Samurai::Processor.authorize(@payment_method_token, 100.02) # declined auth
|
30
|
+
capture = auth.capture
|
31
|
+
capture.success.should be_false
|
32
|
+
capture.errors['processor.transaction'].should == [ 'This transaction type is not allowed.' ]
|
33
|
+
end
|
34
|
+
it 'should return processor.transaction - declined' do
|
35
|
+
auth = Samurai::Processor.authorize(@payment_method_token, 100.00)
|
36
|
+
capture = auth.capture(100.02)
|
37
|
+
capture.success.should be_false
|
38
|
+
capture.errors['processor.transaction'].should == [ 'The card was declined.' ]
|
39
|
+
end
|
40
|
+
it 'should return input.amount - invalid' do
|
41
|
+
auth = Samurai::Processor.authorize(@payment_method_token, 100.00)
|
42
|
+
capture = auth.capture(100.10)
|
43
|
+
capture.success.should be_false
|
44
|
+
capture.errors['input.amount'].should == [ 'The transaction amount was invalid.' ]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'reverse' do
|
50
|
+
describe 'on capture' do
|
51
|
+
before do
|
52
|
+
@purchase = Samurai::Processor.purchase(@payment_method_token, 100.0)
|
53
|
+
end
|
54
|
+
it 'should be successful' do
|
55
|
+
reverse = @purchase.reverse
|
56
|
+
reverse.success.should be_true
|
57
|
+
end
|
58
|
+
it 'should be successful for full amount' do
|
59
|
+
reverse = @purchase.reverse(100.0)
|
60
|
+
reverse.success.should be_true
|
61
|
+
end
|
62
|
+
it 'should be successful for partial amount' do
|
63
|
+
reverse = @purchase.reverse(50.0)
|
64
|
+
reverse.success.should be_true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
describe 'on authorize' do
|
68
|
+
before do
|
69
|
+
@authorize = Samurai::Processor.authorize(@payment_method_token, 100.0)
|
70
|
+
end
|
71
|
+
it 'should be successful' do
|
72
|
+
reverse = @authorize.reverse
|
73
|
+
reverse.success.should be_true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
describe 'failures' do
|
77
|
+
it 'should return input.amount - invalid' do
|
78
|
+
purchase = Samurai::Processor.purchase(@payment_method_token, 100.00)
|
79
|
+
reverse = purchase.reverse(100.10)
|
80
|
+
reverse.success.should be_false
|
81
|
+
reverse.errors['input.amount'].should == [ 'The transaction amount was invalid.' ]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'credit' do
|
87
|
+
describe 'on capture' do
|
88
|
+
before do
|
89
|
+
@purchase = Samurai::Processor.purchase(@payment_method_token, 100.0)
|
90
|
+
end
|
91
|
+
it 'should be successful' do
|
92
|
+
credit = @purchase.credit
|
93
|
+
credit.success.should be_true
|
94
|
+
end
|
95
|
+
it 'should be successful for full amount' do
|
96
|
+
credit = @purchase.credit(100.0)
|
97
|
+
credit.success.should be_true
|
98
|
+
end
|
99
|
+
it 'should be successful for partial amount' do
|
100
|
+
credit = @purchase.credit(50.0)
|
101
|
+
credit.success.should be_true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
describe 'on authorize' do
|
105
|
+
before do
|
106
|
+
@authorize = Samurai::Processor.authorize(@payment_method_token, 100.0)
|
107
|
+
end
|
108
|
+
it 'should be successful' do
|
109
|
+
credit = @authorize.credit
|
110
|
+
credit.success.should be_true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
describe 'failures' do
|
114
|
+
it 'should return input.amount - invalid' do
|
115
|
+
purchase = Samurai::Processor.purchase(@payment_method_token, 100.00)
|
116
|
+
credit = purchase.credit(100.10)
|
117
|
+
credit.success.should be_false
|
118
|
+
credit.errors['input.amount'].should == [ 'The transaction amount was invalid.' ]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe 'void' do
|
124
|
+
describe 'on authorized' do
|
125
|
+
before do
|
126
|
+
@authorize = Samurai::Processor.authorize(@payment_method_token, 100.0)
|
127
|
+
end
|
128
|
+
it 'should be successful' do
|
129
|
+
void = @authorize.void
|
130
|
+
void.success.should be_true
|
131
|
+
end
|
132
|
+
end
|
133
|
+
describe 'on captured' do
|
134
|
+
before do
|
135
|
+
@purchase = Samurai::Processor.purchase(@payment_method_token, 100.0)
|
136
|
+
end
|
137
|
+
it 'should be successful' do
|
138
|
+
void = @purchase.void
|
139
|
+
void.success.should be_true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
require 'rspec'
|
2
|
-
require 'ruby-debug'
|
3
2
|
require 'pp'
|
4
|
-
Debugger.start
|
5
|
-
Debugger.settings[:autoeval] = true
|
6
|
-
Debugger.settings[:autolist] = 5
|
7
|
-
Debugger.settings[:reload_source_on_change] = true
|
8
3
|
|
9
4
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
5
|
|
@@ -23,13 +18,13 @@ RSpec.configure do |c|
|
|
23
18
|
end
|
24
19
|
|
25
20
|
require 'samurai'
|
26
|
-
|
27
|
-
:site => SITE,
|
21
|
+
DEFAULT_OPTIONS = {
|
22
|
+
:site => SITE,
|
28
23
|
:merchant_key => ENV['merchant_key'] || 'a1ebafb6da5238fb8a3ac9f6',
|
29
24
|
:merchant_password => ENV['merchant_password'] || 'ae1aa640f6b735c4730fbb56',
|
30
25
|
:processor_token => ENV['processor_token'] || '5a0e1ca1e5a11a2997bbf912'
|
31
26
|
}
|
32
|
-
|
27
|
+
Samurai.options = DEFAULT_OPTIONS.clone
|
33
28
|
|
34
29
|
|
35
30
|
#
|
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.
|
4
|
+
version: 0.3.0
|
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-
|
13
|
+
date: 2011-12-22 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activeresource
|
17
|
-
requirement: &
|
17
|
+
requirement: &70265074098340 !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: *70265074098340
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bundler
|
28
|
-
requirement: &
|
28
|
+
requirement: &70265074097660 !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: *70265074097660
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70265074096960 !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: *70265074096960
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: fakeweb
|
50
|
-
requirement: &
|
50
|
+
requirement: &70265074096580 !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: *70265074096580
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: ruby-debug19
|
61
|
-
requirement: &
|
61
|
+
requirement: &70265074095780 !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: *70265074095780
|
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.
|
@@ -100,11 +100,10 @@ files:
|
|
100
100
|
- lib/samurai/transaction.rb
|
101
101
|
- lib/samurai/version.rb
|
102
102
|
- samurai.gemspec
|
103
|
-
- spec/lib/authorization_spec.rb
|
104
103
|
- spec/lib/message_spec.rb
|
105
104
|
- spec/lib/payment_method_spec.rb
|
106
105
|
- spec/lib/processor_spec.rb
|
107
|
-
- spec/lib/
|
106
|
+
- spec/lib/transaction_spec.rb
|
108
107
|
- spec/spec_helper.rb
|
109
108
|
- spec/support/transaction_seed.rb
|
110
109
|
- spec/support/transparent_redirect_helper.rb
|
@@ -128,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
127
|
version: 1.3.5
|
129
128
|
requirements: []
|
130
129
|
rubyforge_project:
|
131
|
-
rubygems_version: 1.8.
|
130
|
+
rubygems_version: 1.8.10
|
132
131
|
signing_key:
|
133
132
|
specification_version: 3
|
134
133
|
summary: Integration gem for samurai.feefighters.com
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "processing authorizations" do
|
4
|
-
|
5
|
-
before :each do
|
6
|
-
payment_method_token = create_payment_method(default_payment_method_params)[:payment_method_token]
|
7
|
-
@authorization = Samurai::Processor.authorize(payment_method_token, 1.0, :billing_reference=>rand(1000))
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should create a new authorization transaction" do
|
11
|
-
@authorization.processor_response.success.should be_true
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should find the authorization" do
|
15
|
-
transaction = Samurai::Transaction.find(@authorization.reference_id)
|
16
|
-
transaction.reference_id.should == @authorization.reference_id
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should successfully capture" do
|
20
|
-
capture = @authorization.capture(1.0)
|
21
|
-
capture.processor_response.success.should be_true
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should capture an authorization without specifying an amount" do
|
25
|
-
capture = @authorization.capture
|
26
|
-
capture.amount.should == "#{1.0}"
|
27
|
-
capture.processor_response.success.should be_true
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should partially capture an authorization" do
|
31
|
-
capture = @authorization.capture(BigDecimal('0.5'))
|
32
|
-
capture.amount.should == "#{BigDecimal('0.5')}"
|
33
|
-
capture.processor_response.success.should be_true
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should void an authorization" do
|
37
|
-
void = @authorization.void
|
38
|
-
void.processor_response.success.should be_true
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should credit an authorization for the full amount by default" do
|
42
|
-
credit = @authorization.credit
|
43
|
-
credit.amount.should == "#{BigDecimal('1.0')}"
|
44
|
-
credit.processor_response.success.should be_true
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should partially credit an authorization" do
|
48
|
-
credit = @authorization.credit(BigDecimal('0.5'))
|
49
|
-
credit.amount.should == "#{BigDecimal('0.5')}"
|
50
|
-
credit.processor_response.success.should be_true
|
51
|
-
end
|
52
|
-
end
|
data/spec/lib/purchase_spec.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "processing purchases" do
|
4
|
-
|
5
|
-
describe 'for a successful transaction' do
|
6
|
-
before :each do
|
7
|
-
@payment_method_token = create_payment_method(default_payment_method_params)[:payment_method_token]
|
8
|
-
@purchase = Samurai::Processor.purchase(@payment_method_token, 1.0, :billing_reference=>rand(1000))
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should process successfully" do
|
12
|
-
@purchase.processor_response.success.should be_true
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should be able to void a recent purchase" do
|
16
|
-
void = @purchase.void
|
17
|
-
void.processor_response.success.should be_true
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should be able to credit a recent purchase" do
|
21
|
-
credit = @purchase.credit
|
22
|
-
credit.processor_response.success.should be_true
|
23
|
-
credit.transaction_type.should == 'Credit'
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should be able to reverse a recent purchase" do
|
27
|
-
reverse = @purchase.reverse
|
28
|
-
reverse.processor_response.success.should be_true
|
29
|
-
reverse.transaction_type.should == 'Credit'
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should be able to reverse a settled purchase" do
|
33
|
-
reverse = @purchase.reverse
|
34
|
-
reverse.processor_response.success.should be_true
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should be able to credit a settled purchase" do
|
38
|
-
credit = @purchase.credit
|
39
|
-
credit.processor_response.success.should be_true
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe 'for a declined transaction' do
|
44
|
-
before :each do
|
45
|
-
@payment_method_token = create_payment_method(default_payment_method_params)[:payment_method_token]
|
46
|
-
@purchase = Samurai::Processor.purchase(@payment_method_token, 1.02)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should process" do
|
50
|
-
@purchase.processor_response.success.should be_false
|
51
|
-
[@purchase.errors['processor.transaction']].flatten.first.should == 'The card was declined.'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
describe 'for a invalid card number transaction' do
|
57
|
-
before :each do
|
58
|
-
@payment_method_token = create_payment_method(default_payment_method_params)[:payment_method_token]
|
59
|
-
@purchase = Samurai::Processor.purchase(@payment_method_token, 1.07)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should process" do
|
63
|
-
@purchase.processor_response.success.should be_false
|
64
|
-
[@purchase.errors['input.card_number']].flatten.first.should == 'The card number was invalid.'
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe 'for a expired card transaction' do
|
69
|
-
before :each do
|
70
|
-
@payment_method_token = create_payment_method(default_payment_method_params)[:payment_method_token]
|
71
|
-
@purchase = Samurai::Processor.purchase(@payment_method_token, 1.08)
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should process" do
|
75
|
-
@purchase.processor_response.success.should be_false
|
76
|
-
[@purchase.errors['input.expiry_month']].flatten.first.should == 'The expiration date month was invalid, or prior to today.'
|
77
|
-
[@purchase.errors['input.expiry_year']].flatten.first.should == 'The expiration date year was invalid, or prior to today.'
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
end
|