samurai 0.2.22 → 0.2.23
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/samurai/message.rb +54 -0
- data/lib/samurai/version.rb +1 -1
- data/spec/lib/authorization_spec.rb +5 -5
- data/spec/lib/message_spec.rb +42 -0
- data/spec/lib/purchase_spec.rb +3 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/support/transparent_redirect_helper.rb +5 -4
- metadata +13 -15
- data/spec/lib/generate_docs_spec.rb.bak +0 -178
- data/spec/support/http_proxy.rb +0 -40
- data/spec/support/response_logger.rb +0 -71
data/Gemfile.lock
CHANGED
data/lib/samurai/message.rb
CHANGED
@@ -13,4 +13,58 @@ class Samurai::Message < Samurai::Base
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
DEFAULT_RESPONSE_MAPPINGS = {
|
17
|
+
# Transaction Responses
|
18
|
+
'info processor.transaction success' => 'The transaction was successful.',
|
19
|
+
'error processor.transaction declined' => 'The card was declined.',
|
20
|
+
'error processor.issuer call' => 'Call the card issuer for further instructions.',
|
21
|
+
'error processor.issuer unavailable' => 'The authorization did not respond within the alloted time.',
|
22
|
+
'error input.card_number invalid' => 'The card number was invalid.',
|
23
|
+
'error input.expiry_month invalid' => 'The expiration date month was invalid, or prior to today.',
|
24
|
+
'error input.expiry_year invalid' => 'The expiration date year was invalid, or prior to today.',
|
25
|
+
'error processor.pin invalid' => 'The PIN number is incorrect.',
|
26
|
+
'error input.amount invalid' => 'The transaction amount was invalid.',
|
27
|
+
'error processor.transaction declined_insufficient_funds' => 'The transaction was declined due to insufficient funds.',
|
28
|
+
'error processor.network_gateway merchant_invalid' => 'The Merchant Number is incorrect.',
|
29
|
+
'error input.merchant_login invalid' => 'The merchant ID is not valid or active.',
|
30
|
+
'error input.store_number invalid' => 'Invalid Store Number.',
|
31
|
+
'error processor.bank_info invalid' => 'Invalid banking information.',
|
32
|
+
'error processor.transaction not_allowed' => 'Merchant can not accept this card.',
|
33
|
+
'error processor.transaction type_invalid' => 'Requested transaction type is not allowed for this card/merchant.',
|
34
|
+
'error processor.transaction method_invalid' => 'The requested transaction could not be performed for this merchant.',
|
35
|
+
'error input.amount exceeds_limit' => 'The maximum transaction amount was exceeded.',
|
36
|
+
'error input.cvv invalid' => 'The CVV data entered is not correct.',
|
37
|
+
'error processor.network_gateway communication_error' => 'There was a fatal communication error.',
|
38
|
+
'error processor.network_gateway unresponsive' => 'The processing network is temporarily unavailable.',
|
39
|
+
'error processor.network_gateway merchant_invalid' => 'The merchant number is not on file.',
|
40
|
+
|
41
|
+
# AVS Responses
|
42
|
+
'info processor.avs_result_code 0' => 'No response.',
|
43
|
+
'info processor.avs_result_code Y' => 'The address and 5-digit ZIP match.',
|
44
|
+
'info processor.avs_result_code Z' => 'The 5-digit ZIP matches, the address does not.',
|
45
|
+
'info processor.avs_result_code X' => 'The address and 9-digit ZIP match.',
|
46
|
+
'info processor.avs_result_code A' => 'The address matches, the ZIP does not.',
|
47
|
+
'info processor.avs_result_code E' => 'There was an AVS error, or the data was illegible.',
|
48
|
+
'info processor.avs_result_code R' => 'The AVS request timed out.',
|
49
|
+
'info processor.avs_result_code S' => 'The issuer does not support AVS.',
|
50
|
+
'info processor.avs_result_code F' => 'The street addresses and postal codes match.',
|
51
|
+
'info processor.avs_result_code N' => 'The address and ZIP do not match.',
|
52
|
+
|
53
|
+
# CVV Responses
|
54
|
+
'error input.cvv declined' => 'The CVV code was not correct.',
|
55
|
+
'error input.cvv declined' => 'The CVV code was invalid.',
|
56
|
+
}
|
57
|
+
|
58
|
+
def self.response_mappings
|
59
|
+
@@response_mappings ||= DEFAULT_RESPONSE_MAPPINGS
|
60
|
+
end
|
61
|
+
def self.response_mappings=(_mappings)
|
62
|
+
@@response_mappings = DEFAULT_RESPONSE_MAPPINGS.merge(_mappings)
|
63
|
+
end
|
64
|
+
|
65
|
+
def description
|
66
|
+
_key = [subclass, context, key].join(' ')
|
67
|
+
self.class.response_mappings[_key] || ''
|
68
|
+
end
|
69
|
+
|
16
70
|
end
|
data/lib/samurai/version.rb
CHANGED
@@ -13,7 +13,7 @@ describe "processing authorizations" do
|
|
13
13
|
|
14
14
|
it "should find the authorization" do
|
15
15
|
transaction = Samurai::Transaction.find(@authorization.reference_id)
|
16
|
-
transaction.reference_id.
|
16
|
+
transaction.reference_id.should == @authorization.reference_id
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should successfully capture" do
|
@@ -23,13 +23,13 @@ describe "processing authorizations" do
|
|
23
23
|
|
24
24
|
it "should capture an authorization without specifying an amount" do
|
25
25
|
capture = @authorization.capture
|
26
|
-
capture.amount.
|
26
|
+
capture.amount.should == "#{1.0}"
|
27
27
|
capture.processor_response.success.should be_true
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should partially capture an authorization" do
|
31
31
|
capture = @authorization.capture(1.0 - BigDecimal('0.5'))
|
32
|
-
capture.amount.
|
32
|
+
capture.amount.should == "#{1.0 - BigDecimal('0.5')}"
|
33
33
|
capture.processor_response.success.should be_true
|
34
34
|
end
|
35
35
|
|
@@ -40,7 +40,7 @@ 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.
|
43
|
+
credit.amount.should == "#{1.0}"
|
44
44
|
pending "the response is not successful since the authorization hasn't settled" do
|
45
45
|
credit.processor_response.success.should be_true
|
46
46
|
end
|
@@ -48,7 +48,7 @@ describe "processing authorizations" do
|
|
48
48
|
|
49
49
|
it "should partially credit an authorization" do
|
50
50
|
credit = @authorization.credit(1.0 - BigDecimal('0.5'))
|
51
|
-
credit.amount.
|
51
|
+
credit.amount.should == "#{1.0 - BigDecimal('0.5')}"
|
52
52
|
pending "the response is not successful since the authorization hasn't settled" do
|
53
53
|
credit.processor_response.success.should be_true
|
54
54
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "message responses" do
|
4
|
+
|
5
|
+
it 'should display processor_transaction_success' do
|
6
|
+
message = Samurai::Message.new(:subclass=>'info', :context=>'processor.transaction', :key=>'success')
|
7
|
+
message.description.should == 'The transaction was successful.'
|
8
|
+
end
|
9
|
+
it 'should display processor_transaction_declined' do
|
10
|
+
message = Samurai::Message.new(:subclass=>'error', :context=>'processor.transaction', :key=>'declined')
|
11
|
+
message.description.should == 'The card was declined.'
|
12
|
+
end
|
13
|
+
it 'should display processor_issuer_call' do
|
14
|
+
message = Samurai::Message.new(:subclass=>'error', :context=>'processor.issuer', :key=>'call')
|
15
|
+
message.description.should == 'Call the card issuer for further instructions.'
|
16
|
+
end
|
17
|
+
it 'should display processor_issuer_unavailable' do
|
18
|
+
message = Samurai::Message.new(:subclass=>'error', :context=>'processor.issuer', :key=>'unavailable')
|
19
|
+
message.description.should == 'The authorization did not respond within the alloted time.'
|
20
|
+
end
|
21
|
+
it 'should display input_card_number_invalid' do
|
22
|
+
message = Samurai::Message.new(:subclass=>'error', :context=>'input.card_number', :key=>'invalid')
|
23
|
+
message.description.should == 'The card number was invalid.'
|
24
|
+
end
|
25
|
+
it 'should display input_expiry_month_invalid' do
|
26
|
+
message = Samurai::Message.new(:subclass=>'error', :context=>'input.expiry_month', :key=>'invalid')
|
27
|
+
message.description.should == 'The expiration date month was invalid, or prior to today.'
|
28
|
+
end
|
29
|
+
it 'should display input_expiry_year_invalid' do
|
30
|
+
message = Samurai::Message.new(:subclass=>'error', :context=>'input.expiry_year', :key=>'invalid')
|
31
|
+
message.description.should == 'The expiration date year was invalid, or prior to today.'
|
32
|
+
end
|
33
|
+
it 'should display input_amount_invalid' do
|
34
|
+
message = Samurai::Message.new(:subclass=>'error', :context=>'input.amount', :key=>'invalid')
|
35
|
+
message.description.should == 'The transaction amount was invalid.'
|
36
|
+
end
|
37
|
+
it 'should display processor_transaction_declined_insufficient_funds' do
|
38
|
+
message = Samurai::Message.new(:subclass=>'error', :context=>'processor.transaction', :key=>'declined_insufficient_funds')
|
39
|
+
message.description.should == 'The transaction was declined due to insufficient funds.'
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/spec/lib/purchase_spec.rb
CHANGED
@@ -33,9 +33,8 @@ describe "processing purchases" do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should be able to credit a settled purchase" do
|
36
|
-
pending "currently we cannot force settle a purchase, so can't test this properly"
|
37
|
-
|
38
|
-
|
39
|
-
end
|
36
|
+
pending "currently we cannot force settle a purchase, so can't test this properly"
|
37
|
+
credit = @purchase.credit
|
38
|
+
credit.processor_response.success.should be_true
|
40
39
|
end
|
41
40
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -27,7 +27,7 @@ Samurai.options = {
|
|
27
27
|
:site => SITE,
|
28
28
|
:merchant_key => ENV['merchant_key'] || 'a1ebafb6da5238fb8a3ac9f6',
|
29
29
|
:merchant_password => ENV['merchant_password'] || 'ae1aa640f6b735c4730fbb56',
|
30
|
-
:processor_token => ENV['processor_token'] || '
|
30
|
+
:processor_token => ENV['processor_token'] || '5a0e1ca1e5a11a2997bbf912'
|
31
31
|
}
|
32
32
|
|
33
33
|
|
@@ -25,18 +25,19 @@ module TransparentRedirectHelper
|
|
25
25
|
|
26
26
|
def default_payment_method_params
|
27
27
|
{
|
28
|
+
'sandbox' => true,
|
28
29
|
'redirect_url' => 'http://test.host',
|
29
30
|
'merchant_key' => Samurai.merchant_key,
|
30
31
|
'custom' => 'custom',
|
31
32
|
'credit_card[first_name]' => 'FirstName',
|
32
33
|
'credit_card[last_name]' => 'LastName',
|
33
|
-
'credit_card[address_1]' => '
|
34
|
+
'credit_card[address_1]' => '1000 1st Av',
|
34
35
|
'credit_card[address_2]' => '',
|
35
36
|
'credit_card[city]' => 'Chicago',
|
36
37
|
'credit_card[state]' => 'IL',
|
37
|
-
'credit_card[zip]' => '
|
38
|
-
'credit_card[card_number]' => '
|
39
|
-
'credit_card[cvv]' => '
|
38
|
+
'credit_card[zip]' => '10101',
|
39
|
+
'credit_card[card_number]' => '4111111111111111',
|
40
|
+
'credit_card[cvv]' => '111',
|
40
41
|
'credit_card[expiry_month]' => '05',
|
41
42
|
'credit_card[expiry_year]' => '2014',
|
42
43
|
}
|
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.23
|
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-11-04 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activeresource
|
17
|
-
requirement: &
|
17
|
+
requirement: &70268836094780 !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: *70268836094780
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bundler
|
28
|
-
requirement: &
|
28
|
+
requirement: &70268836094280 !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: *70268836094280
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70268836093800 !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: *70268836093800
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: fakeweb
|
50
|
-
requirement: &
|
50
|
+
requirement: &70268836093420 !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: *70268836093420
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: ruby-debug19
|
61
|
-
requirement: &
|
61
|
+
requirement: &70268836092920 !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: *70268836092920
|
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.
|
@@ -102,13 +102,11 @@ files:
|
|
102
102
|
- lib/samurai/version.rb
|
103
103
|
- samurai.gemspec
|
104
104
|
- spec/lib/authorization_spec.rb
|
105
|
-
- spec/lib/
|
105
|
+
- spec/lib/message_spec.rb
|
106
106
|
- spec/lib/payment_method_spec.rb
|
107
107
|
- spec/lib/processor_spec.rb
|
108
108
|
- spec/lib/purchase_spec.rb
|
109
109
|
- spec/spec_helper.rb
|
110
|
-
- spec/support/http_proxy.rb
|
111
|
-
- spec/support/response_logger.rb
|
112
110
|
- spec/support/transaction_seed.rb
|
113
111
|
- spec/support/transparent_redirect_helper.rb
|
114
112
|
homepage: http://rubygems.org/gems/samurai
|
@@ -1,178 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "generate documentation" do
|
4
|
-
include ResponseLoggerHelper
|
5
|
-
|
6
|
-
before(:all) do
|
7
|
-
@logger = ResponseLogger.new(File.open('response_log.html', 'w'))
|
8
|
-
end
|
9
|
-
after(:all) do
|
10
|
-
@logger.close!
|
11
|
-
end
|
12
|
-
|
13
|
-
before do
|
14
|
-
@logger.begin_section example.full_description.sub(/generate documentation/, '').titleize
|
15
|
-
|
16
|
-
@params = {
|
17
|
-
'redirect_url' => 'http://test.host',
|
18
|
-
'merchant_key' => Samurai.merchant_key,
|
19
|
-
'custom' => 'custom',
|
20
|
-
'credit_card[first_name]' => 'FirstName',
|
21
|
-
'credit_card[last_name]' => 'LastName',
|
22
|
-
'credit_card[address_1]' => '123 Main St',
|
23
|
-
'credit_card[address_2]' => '',
|
24
|
-
'credit_card[city]' => 'Chicago',
|
25
|
-
'credit_card[state]' => 'IL',
|
26
|
-
'credit_card[zip]' => '60610',
|
27
|
-
'credit_card[card_number]' => '4222222222222',
|
28
|
-
'credit_card[cvv]' => '123',
|
29
|
-
'credit_card[expiry_month]' => '05',
|
30
|
-
'credit_card[expiry_year]' => '2014',
|
31
|
-
}
|
32
|
-
|
33
|
-
Samurai::Base.instance_eval do
|
34
|
-
def connection(refresh = false)
|
35
|
-
if defined?(@connection) || superclass == ActiveResource::Base
|
36
|
-
@connection ||= begin
|
37
|
-
c = HttpProxyConnection.new(site, format)
|
38
|
-
c.proxy = proxy if proxy
|
39
|
-
c.user = user if user
|
40
|
-
c.password = password if password
|
41
|
-
c.auth_type = auth_type if auth_type
|
42
|
-
c.timeout = timeout if timeout
|
43
|
-
c.ssl_options = ssl_options if ssl_options
|
44
|
-
c
|
45
|
-
end
|
46
|
-
else
|
47
|
-
superclass.connection
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
Samurai::Base.connection
|
52
|
-
end
|
53
|
-
|
54
|
-
after do
|
55
|
-
@logger.end_section
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'with an invalid payment method' do
|
59
|
-
it 'should not create the payment method with missing card_number' do
|
60
|
-
@params.delete 'credit_card[card_number]'
|
61
|
-
data = create_payment_method(@params)
|
62
|
-
log_request_response! data[:request], data[:response]
|
63
|
-
data[:payment_method_token].should =~ /^[0-9a-z]{24}$/
|
64
|
-
Samurai::PaymentMethod.find data[:payment_method_token]
|
65
|
-
log_http!
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should create the payment method with invalid card_number format' do
|
69
|
-
@params['credit_card[card_number]'] = '12345'
|
70
|
-
data = create_payment_method(@params)
|
71
|
-
log_request_response! data[:request], data[:response]
|
72
|
-
data[:payment_method_token].should =~ /^[0-9a-z]{24}$/
|
73
|
-
Samurai::PaymentMethod.find data[:payment_method_token]
|
74
|
-
log_http!
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should create the payment method with blank cvv' do
|
78
|
-
@params['credit_card[cvv]'] = ''
|
79
|
-
data = create_payment_method(@params)
|
80
|
-
log_request_response! data[:request], data[:response]
|
81
|
-
data[:payment_method_token].should =~ /^[0-9a-z]{24}$/
|
82
|
-
Samurai::PaymentMethod.find data[:payment_method_token]
|
83
|
-
log_http!
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe 'with a valid payment method' do
|
88
|
-
before do
|
89
|
-
@amount = '1.00' # response code: card number is declined
|
90
|
-
@data = create_payment_method(@params)
|
91
|
-
end
|
92
|
-
it 'should create the payment method' do
|
93
|
-
log_request_response! @data[:request], @data[:response]
|
94
|
-
@data[:payment_method_token].should =~ /^[0-9a-z]{24}$/
|
95
|
-
Samurai::PaymentMethod.find @data[:payment_method_token]
|
96
|
-
log_http!
|
97
|
-
end
|
98
|
-
it 'should create a valid transaction' do
|
99
|
-
purchase = Samurai::Processor.purchase(@data[:payment_method_token], @amount)
|
100
|
-
log_http!
|
101
|
-
purchase.processor_response.success.should be_true
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe 'with a declined card' do
|
106
|
-
before do
|
107
|
-
@amount = '3.00' # response code: card number is declined
|
108
|
-
@data = create_payment_method(@params)
|
109
|
-
end
|
110
|
-
it 'should create the payment method' do
|
111
|
-
log_request_response! @data[:request], @data[:response]
|
112
|
-
@data[:payment_method_token].should =~ /^[0-9a-z]{24}$/
|
113
|
-
Samurai::PaymentMethod.find @data[:payment_method_token]
|
114
|
-
log_http!
|
115
|
-
end
|
116
|
-
it 'should create a valid transaction' do
|
117
|
-
purchase = Samurai::Processor.purchase(@data[:payment_method_token], @amount)
|
118
|
-
log_http!
|
119
|
-
purchase.processor_response.success.should be_false
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe 'with an expired card' do
|
124
|
-
before do
|
125
|
-
@amount = '8.00' # response code: card is expired
|
126
|
-
@data = create_payment_method(@params)
|
127
|
-
end
|
128
|
-
it 'should create the payment method' do
|
129
|
-
log_request_response! @data[:request], @data[:response]
|
130
|
-
@data[:payment_method_token].should =~ /^[0-9a-z]{24}$/
|
131
|
-
Samurai::PaymentMethod.find @data[:payment_method_token]
|
132
|
-
log_http!
|
133
|
-
end
|
134
|
-
it 'should create a valid transaction' do
|
135
|
-
purchase = Samurai::Processor.purchase(@data[:payment_method_token], @amount)
|
136
|
-
log_http!
|
137
|
-
purchase.processor_response.success.should be_false
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe 'with a card with incorrect cvv' do
|
142
|
-
before do
|
143
|
-
@amount = '6.00' # response code: card number is invalid
|
144
|
-
@data = create_payment_method(@params)
|
145
|
-
end
|
146
|
-
it 'should create the payment method' do
|
147
|
-
log_request_response! @data[:request], @data[:response]
|
148
|
-
@data[:payment_method_token].should =~ /^[0-9a-z]{24}$/
|
149
|
-
Samurai::PaymentMethod.find @data[:payment_method_token]
|
150
|
-
log_http!
|
151
|
-
end
|
152
|
-
it 'should create a valid transaction' do
|
153
|
-
purchase = Samurai::Processor.purchase(@data[:payment_method_token], @amount)
|
154
|
-
log_http!
|
155
|
-
purchase.processor_response.success.should be_false
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
describe 'with an nonexistant card' do
|
160
|
-
before do
|
161
|
-
@params['credit_card[card_number]'] = '4222222222222'
|
162
|
-
@amount = '6.00' # response code: card number is invalid
|
163
|
-
@data = create_payment_method(@params)
|
164
|
-
end
|
165
|
-
it 'should create the payment method' do
|
166
|
-
log_request_response! @data[:request], @data[:response]
|
167
|
-
@data[:payment_method_token].should =~ /^[0-9a-z]{24}$/
|
168
|
-
Samurai::PaymentMethod.find @data[:payment_method_token]
|
169
|
-
log_http!
|
170
|
-
end
|
171
|
-
it 'should create a valid transaction' do
|
172
|
-
purchase = Samurai::Processor.purchase(@data[:payment_method_token], @amount)
|
173
|
-
log_http!
|
174
|
-
purchase.processor_response.success.should be_false
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
end
|
data/spec/support/http_proxy.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'active_resource/connection'
|
2
|
-
|
3
|
-
class HttpProxy
|
4
|
-
attr_accessor :request, :response
|
5
|
-
|
6
|
-
def initialize(http, options={})
|
7
|
-
@http = http
|
8
|
-
@response = nil
|
9
|
-
@request = {}
|
10
|
-
end
|
11
|
-
|
12
|
-
def method_missing(meth, *args, &block)
|
13
|
-
case meth
|
14
|
-
when :post, :put
|
15
|
-
@request = {
|
16
|
-
:method => meth,
|
17
|
-
:path => args[0],
|
18
|
-
:body => args[1],
|
19
|
-
:headers => args[2],
|
20
|
-
}
|
21
|
-
when :get, :delete
|
22
|
-
@request = {
|
23
|
-
:method => meth,
|
24
|
-
:path => args[0],
|
25
|
-
:headers => args[1],
|
26
|
-
}
|
27
|
-
end
|
28
|
-
@response = @http.send(meth, *args, &block)
|
29
|
-
end
|
30
|
-
|
31
|
-
def respond_to?(meth)
|
32
|
-
super || @http.respond_to?(meth)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class HttpProxyConnection < ActiveResource::Connection
|
37
|
-
def http
|
38
|
-
@http ||= HttpProxy.new(configure_http(new_http))
|
39
|
-
end
|
40
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require "erb"
|
2
|
-
|
3
|
-
class ResponseLogger
|
4
|
-
include ERB::Util
|
5
|
-
|
6
|
-
def initialize(io)
|
7
|
-
@sections = []
|
8
|
-
@io = io
|
9
|
-
@io.puts '<div class="wrapper">'
|
10
|
-
end
|
11
|
-
|
12
|
-
def close!
|
13
|
-
@io.puts '</div>'
|
14
|
-
@sections.each do |section|
|
15
|
-
@io.puts "<a href='##{section[:id]}'>#{section[:name]}</a><br>"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def begin_section(name)
|
20
|
-
@sections << {:name=>name, :id=>h(name.parameterize)}
|
21
|
-
@io.puts "<article class='example span-8' id='#{h name.parameterize}'>"
|
22
|
-
@io.puts " <h3>#{h name}</h3>"
|
23
|
-
end
|
24
|
-
|
25
|
-
def end_section
|
26
|
-
@io.puts "</article>"
|
27
|
-
@io.puts "<hr>"
|
28
|
-
end
|
29
|
-
|
30
|
-
def log(request, response, options={})
|
31
|
-
@io.puts ' <div class="code http-request"><em class="lang">HTTP Request</em>'
|
32
|
-
@io.puts " <pre><strong>#{h request[:method].to_s.upcase} #{h request[:path]}</strong><br>"
|
33
|
-
@io.puts "Headers: #{h request[:headers].inject({}) {|h, (k,v)| h[k] = (v.is_a?(Array) ? v.first : v); h }}</pre>"
|
34
|
-
@io.puts ' </div>'
|
35
|
-
if request[:body]
|
36
|
-
@io.puts ' <div class="code xml">'
|
37
|
-
@io.puts ' <em class="lang">XML Payload</em>'
|
38
|
-
@io.puts " <pre class='prettyprint lang-xml'>#{h request[:body]}</pre>"
|
39
|
-
@io.puts ' </div>'
|
40
|
-
end
|
41
|
-
@io.puts ' <div class="code http-response">'
|
42
|
-
@io.puts " <em class='lang'>HTTP Response: #{h response.code}</em>"
|
43
|
-
@io.puts " <pre class='prettyprint lang-xml'><code>#{h response.body}</code></pre>"
|
44
|
-
@io.puts " </div>"
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
module ResponseLoggerHelper
|
50
|
-
def log_http! options={}
|
51
|
-
@logger.log Samurai::Base.connection.send(:http).request,
|
52
|
-
Samurai::Base.connection.send(:http).response,
|
53
|
-
options
|
54
|
-
end
|
55
|
-
|
56
|
-
def log_request_response! request, response, options={}
|
57
|
-
def request.[](v)
|
58
|
-
case v
|
59
|
-
when :method
|
60
|
-
return self.method
|
61
|
-
when :path
|
62
|
-
return self.path
|
63
|
-
when :headers
|
64
|
-
return self.to_hash
|
65
|
-
else
|
66
|
-
super
|
67
|
-
end
|
68
|
-
end
|
69
|
-
@logger.log request, response, options
|
70
|
-
end
|
71
|
-
end
|