nimbleshop_authorizedotnet 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/nimbleshop_authorizedotnet/authorizedotnets_controller.rb +9 -23
- data/app/controllers/nimbleshop_authorizedotnet/payments_controller.rb +10 -6
- data/app/models/nimbleshop_authorizedotnet/authorizedotnet.rb +6 -5
- data/app/views/nimbleshop_authorizedotnet/authorizedotnets/_edit.html.erb +60 -25
- data/app/views/nimbleshop_authorizedotnet/payments/_new.html.erb +7 -4
- data/lib/nimbleshop_authorizedotnet/gateway.rb +1 -1
- data/lib/nimbleshop_authorizedotnet/processor.rb +69 -52
- data/lib/tasks/nimbleshop_authorizedotnet_tasks.rake +3 -3
- data/test/test_helper.rb +3 -1
- data/test/unit/payment_method_test.rb +8 -13
- data/test/unit/processor_test.rb +42 -33
- metadata +4 -5
- data/app/views/nimbleshop_authorizedotnet/authorizedotnets/_form.html.erb +0 -67
@@ -8,37 +8,23 @@ module NimbleshopAuthorizedotnet
|
|
8
8
|
before_filter :load_payment_method
|
9
9
|
|
10
10
|
def update
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
msg = @payment_method.errors.full_messages.first
|
19
|
-
error = %Q[alert("#{msg}")]
|
20
|
-
format.js { render js: error }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
11
|
+
alert_msg = if @payment_method.update_attributes(post_params[:authorizedotnet])
|
12
|
+
msg = "Record has been updated"
|
13
|
+
%Q[alert("#{msg}")]
|
14
|
+
else
|
15
|
+
msg = @payment_method.errors.full_messages.first
|
16
|
+
%Q[alert("#{msg}")]
|
17
|
+
end
|
24
18
|
|
25
|
-
def destroy
|
26
19
|
respond_to do |format|
|
27
|
-
|
28
|
-
format.js {
|
29
|
-
flash[:notice] = 'Authorize.net record was successfully deleted'
|
30
|
-
render js: "window.location = '/admin/payment_methods'"
|
31
|
-
}
|
32
|
-
else
|
33
|
-
format.js { render js: 'Authorize.net record could not be deleted. Please try again later.' }
|
34
|
-
end
|
20
|
+
format.js { render js: alert_msg }
|
35
21
|
end
|
36
22
|
end
|
37
23
|
|
38
24
|
private
|
39
25
|
|
40
26
|
def post_params
|
41
|
-
params.permit(authorizedotnet: [:mode, :ssl, :
|
27
|
+
params.permit(authorizedotnet: [:mode, :ssl, :api_login_id, :transaction_key, :business_name])
|
42
28
|
end
|
43
29
|
|
44
30
|
def load_payment_method
|
@@ -3,19 +3,19 @@ module NimbleshopAuthorizedotnet
|
|
3
3
|
class PaymentsController < ::ActionController::Base
|
4
4
|
|
5
5
|
def create
|
6
|
-
order = Order.find_by_id!
|
6
|
+
order = Order.find_by_id! session[:order_id]
|
7
7
|
|
8
8
|
address_attrs = order.final_billing_address.to_credit_card_attributes
|
9
|
-
creditcard_attrs =
|
10
|
-
creditcard = Creditcard.new
|
9
|
+
creditcard_attrs = creditcard_params.merge address_attrs
|
10
|
+
creditcard = Creditcard.new creditcard_attrs
|
11
11
|
|
12
12
|
payment_method = NimbleshopAuthorizedotnet::Authorizedotnet.first
|
13
|
-
processor = NimbleshopAuthorizedotnet::Processor.new(
|
13
|
+
processor = NimbleshopAuthorizedotnet::Processor.new(order: order, payment_method: payment_method)
|
14
14
|
|
15
15
|
default_action = Shop.current.default_creditcard_action
|
16
16
|
|
17
17
|
if processor.send(default_action, creditcard: creditcard)
|
18
|
-
url = nimbleshop_simply.order_path
|
18
|
+
url = nimbleshop_simply.order_path order
|
19
19
|
@output = "window.location='#{url}'"
|
20
20
|
else
|
21
21
|
error = processor.errors.first
|
@@ -31,6 +31,10 @@ module NimbleshopAuthorizedotnet
|
|
31
31
|
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
private
|
35
35
|
|
36
|
+
def creditcard_params
|
37
|
+
params.require(:creditcard).permit(:number, :"expires_on(3i)", :"expires_on(2i)", :"expires_on(1i)", :cvv)
|
38
|
+
end
|
39
|
+
end
|
36
40
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
module NimbleshopAuthorizedotnet
|
2
2
|
class Authorizedotnet < PaymentMethod
|
3
3
|
|
4
|
-
store_accessor :metadata, :
|
4
|
+
store_accessor :metadata, :api_login_id, :transaction_key, :business_name, :mode, :ssl
|
5
5
|
|
6
6
|
before_save :set_mode, :set_ssl
|
7
7
|
|
8
|
-
validates_presence_of :
|
8
|
+
validates_presence_of :api_login_id, message: "^Api Login Id can't be blank"
|
9
|
+
validates_presence_of :transaction_key, :business_name
|
9
10
|
|
10
11
|
def credentials
|
11
|
-
{ login:
|
12
|
+
{ login: api_login_id, password: transaction_key }
|
12
13
|
end
|
13
14
|
|
14
15
|
def use_ssl?
|
@@ -18,8 +19,8 @@ module NimbleshopAuthorizedotnet
|
|
18
19
|
def kapture!(order, processor_klass = nil)
|
19
20
|
processor_klass ||= NimbleshopAuthorizedotnet::Processor
|
20
21
|
processor = processor_klass.new(order: order, payment_method: self)
|
21
|
-
|
22
|
-
order.
|
22
|
+
|
23
|
+
processor.kapture transaction_gid: order.payment_transactions.last.transaction_gid
|
23
24
|
end
|
24
25
|
|
25
26
|
private
|
@@ -1,31 +1,66 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
<% payment_method = NimbleshopAuthorizedotnet::Authorizedotnet.first %>
|
2
|
+
|
3
|
+
<%= content_tag :div, style: 'display:none', data: { behavior: "payment-method-form-#{payment_method.permalink}" } do %>
|
4
|
+
<div style="width:200px;margin-left:60px;"> <%= nimbleshop_authorizedotnet_picture_on_admin_payment_methods %> </div>
|
5
|
+
<br />
|
6
|
+
|
7
|
+
<%= form_for payment_method, url: '/nimbleshop_authorizedotnet/authorizedotnet',
|
8
|
+
remote: true,
|
9
|
+
html: { method: 'put',
|
10
|
+
id: 'nimbleshop-authorizedotnet-form',
|
11
|
+
class: 'nimbleshop-payment-method-form form-horizontal'} do |f| %>
|
12
12
|
|
13
|
-
|
13
|
+
<fieldset>
|
14
|
+
<div class='control-group'>
|
15
|
+
<%= f.label :api_login_id, 'Api Login Id', class: 'control-label' %>
|
16
|
+
<div class='controls'>
|
17
|
+
<%= f.text_field :api_login_id, class: 'span6' %>
|
18
|
+
</div>
|
19
|
+
</div>
|
14
20
|
|
15
|
-
|
16
|
-
|
21
|
+
<div class='control-group'>
|
22
|
+
<%= f.label :transaction_key, nil, class: 'control-label' %>
|
23
|
+
<div class='controls'>
|
24
|
+
<%= f.text_field :transaction_key, class: 'span6' %>
|
25
|
+
</div>
|
26
|
+
</div>
|
17
27
|
|
18
|
-
|
19
|
-
|
28
|
+
<div class='control-group'>
|
29
|
+
<%= f.label :business_name, nil, class: 'control-label' %>
|
30
|
+
<%= link_to '?', '#', 'data-content' => 'Please enter the name of the company as it would appear in the credit card statement. If are not sure what name would appear in the credit card statements then consult your merchant account provider.',
|
31
|
+
'data-original-title' => 'Business name' %>
|
32
|
+
<div class='controls'>
|
33
|
+
<%= f.text_field :business_name, class: 'span6' %>
|
34
|
+
</div>
|
35
|
+
</div>
|
20
36
|
|
21
|
-
<
|
22
|
-
|
37
|
+
<div class='control-group'>
|
38
|
+
<div class='controls'>
|
39
|
+
<label class='checkbox'>
|
40
|
+
<%= f.check_box :mode, {}, 'test', 'production' %> Enable test mode
|
41
|
+
<%= link_to '?', '#', class: 'help', 'data-content' => 'In the test mode real credit card numbers are not accepted.',
|
42
|
+
'data-original-title' => 'Test mode' %>
|
43
|
+
</label>
|
44
|
+
</div>
|
45
|
+
</div>
|
23
46
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
47
|
+
<div class='control-group'>
|
48
|
+
<div class='controls'>
|
49
|
+
<label class='checkbox'>
|
50
|
+
<%= f.check_box :ssl, {}, 'enabled', 'disabled' %> Enable SSL requirement
|
51
|
+
<%= link_to '?', '#', class: 'help', 'data-content' => 'Enabling SSL requirement will force the payment page to be on SSL.',
|
52
|
+
'data-original-title' => 'SSL requirement' %>
|
53
|
+
</label>
|
54
|
+
</div>
|
55
|
+
</div>
|
56
|
+
|
57
|
+
</fieldset>
|
58
|
+
|
59
|
+
<div class='form-actions'>
|
60
|
+
<%= f.submit('Submit', class: 'btn btn-primary') %>
|
61
|
+
|
62
|
+
<%= link_to 'Disable', main_app.disable_admin_payment_method_path(payment_method), class: 'disable-payment-method-link', method: :put %>
|
63
|
+
</div>
|
29
64
|
|
30
|
-
|
31
|
-
|
65
|
+
<% end %>
|
66
|
+
<% end %>
|
@@ -48,10 +48,10 @@
|
|
48
48
|
Expiration date
|
49
49
|
</p>
|
50
50
|
<div class='controls'>
|
51
|
-
<%= f.date_select :expires_on, discard_day: true,
|
52
|
-
start_year: Date.today.year,
|
53
|
-
end_year: (Date.today.year + 10),
|
54
|
-
add_month_numbers: true,
|
51
|
+
<%= f.date_select :expires_on, discard_day: true,
|
52
|
+
start_year: Date.today.year,
|
53
|
+
end_year: (Date.today.year + 10),
|
54
|
+
add_month_numbers: true,
|
55
55
|
order: [:day, :month, :year] %>
|
56
56
|
</div>
|
57
57
|
</div>
|
@@ -87,5 +87,8 @@ $(document).ready(function(){
|
|
87
87
|
var $btn = $('#authorizedotnet-payment-form').find('.btn-primary');
|
88
88
|
$btn.attr('value', 'Submit').removeAttr('disabled');
|
89
89
|
})
|
90
|
+
.bind("ajax:error", function(evt, xhr, status, error){
|
91
|
+
alert("Something has gone wrong")
|
92
|
+
})
|
90
93
|
});
|
91
94
|
</script>
|
@@ -3,7 +3,7 @@ module NimbleshopAuthorizedotnet
|
|
3
3
|
def self.instance(payment_method)
|
4
4
|
ActiveMerchant::Billing::Gateway.logger = Rails.logger if payment_method.mode.to_s == 'test'
|
5
5
|
|
6
|
-
ActiveMerchant::Billing::AuthorizeNetGateway.new
|
6
|
+
ActiveMerchant::Billing::AuthorizeNetGateway.new payment_method.credentials
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -4,10 +4,13 @@ module NimbleshopAuthorizedotnet
|
|
4
4
|
attr_reader :order, :payment_method, :errors, :gateway
|
5
5
|
|
6
6
|
def initialize(options)
|
7
|
+
options.symbolize_keys!
|
8
|
+
options.assert_valid_keys :order, :payment_method
|
9
|
+
|
7
10
|
@errors = []
|
8
|
-
@order = options.fetch
|
9
|
-
@payment_method = options.fetch
|
10
|
-
@gateway = ::NimbleshopAuthorizedotnet::Gateway.instance
|
11
|
+
@order = options.fetch :order
|
12
|
+
@payment_method = options.fetch :payment_method
|
13
|
+
@gateway = ::NimbleshopAuthorizedotnet::Gateway.instance payment_method
|
11
14
|
end
|
12
15
|
|
13
16
|
private
|
@@ -27,9 +30,9 @@ module NimbleshopAuthorizedotnet
|
|
27
30
|
#
|
28
31
|
def do_authorize(options = {})
|
29
32
|
options.symbolize_keys!
|
30
|
-
options.assert_valid_keys
|
33
|
+
options.assert_valid_keys :creditcard
|
31
34
|
|
32
|
-
creditcard = options
|
35
|
+
creditcard = options.fetch :creditcard
|
33
36
|
|
34
37
|
unless valid_card?(creditcard)
|
35
38
|
@errors.push(*creditcard.errors.full_messages)
|
@@ -37,17 +40,24 @@ module NimbleshopAuthorizedotnet
|
|
37
40
|
end
|
38
41
|
|
39
42
|
response = gateway.authorize(order.total_amount_in_cents, creditcard, ::Nimbleshop::PaymentUtil.activemerchant_options(order))
|
40
|
-
record_transaction(response, 'authorized', card_number: creditcard.display_number, cardtype: creditcard.cardtype)
|
41
43
|
|
42
44
|
if response.success?
|
45
|
+
recorder = ::Nimbleshop::PaymentTransactionRecorder.new(order: order,
|
46
|
+
response: response,
|
47
|
+
operation: :authorized,
|
48
|
+
transaction_gid: get_transaction_gid(response),
|
49
|
+
metadata: { card_number: creditcard.display_number, cardtype: creditcard.cardtype})
|
50
|
+
recorder.record
|
43
51
|
order.update_attributes(payment_method: payment_method)
|
44
52
|
order.authorize
|
45
53
|
else
|
46
54
|
@errors << 'Credit card was declined. Please try again!'
|
47
|
-
return false
|
48
55
|
end
|
56
|
+
|
57
|
+
response.success?
|
49
58
|
end
|
50
59
|
|
60
|
+
|
51
61
|
# Creates purchase for the order amount.
|
52
62
|
#
|
53
63
|
# === Options
|
@@ -59,9 +69,9 @@ module NimbleshopAuthorizedotnet
|
|
59
69
|
#
|
60
70
|
def do_purchase(options = {})
|
61
71
|
options.symbolize_keys!
|
62
|
-
options.assert_valid_keys
|
72
|
+
options.assert_valid_keys :creditcard
|
63
73
|
|
64
|
-
creditcard = options
|
74
|
+
creditcard = options.fetch :creditcard
|
65
75
|
|
66
76
|
unless valid_card?(creditcard)
|
67
77
|
@errors.push(*creditcard.errors.full_messages)
|
@@ -69,15 +79,22 @@ module NimbleshopAuthorizedotnet
|
|
69
79
|
end
|
70
80
|
|
71
81
|
response = gateway.purchase(order.total_amount_in_cents, creditcard)
|
72
|
-
record_transaction(response, 'purchased', card_number: creditcard.display_number, cardtype: creditcard.cardtype)
|
73
82
|
|
74
83
|
if response.success?
|
84
|
+
recorder = ::Nimbleshop::PaymentTransactionRecorder.new(order: order,
|
85
|
+
response: response,
|
86
|
+
operation: :purchased,
|
87
|
+
transaction_gid: get_transaction_gid(response),
|
88
|
+
metadata: { card_number: creditcard.display_number, cardtype: creditcard.cardtype})
|
89
|
+
recorder.record
|
90
|
+
|
75
91
|
order.update_attributes(payment_method: payment_method)
|
76
92
|
order.purchase
|
77
93
|
else
|
78
94
|
@errors << 'Credit card was declined. Please try again!'
|
79
|
-
return false
|
80
95
|
end
|
96
|
+
|
97
|
+
response.success?
|
81
98
|
end
|
82
99
|
|
83
100
|
# Captures the previously authorized transaction.
|
@@ -91,21 +108,26 @@ module NimbleshopAuthorizedotnet
|
|
91
108
|
#
|
92
109
|
def do_kapture(options = {})
|
93
110
|
options.symbolize_keys!
|
94
|
-
options.assert_valid_keys
|
95
|
-
|
111
|
+
options.assert_valid_keys :transaction_gid
|
112
|
+
transaction_gid = options.fetch :transaction_gid
|
113
|
+
payment_transaction = PaymentTransaction.find_by_transaction_gid! transaction_gid
|
96
114
|
|
97
|
-
response = gateway.capture(order.total_amount_in_cents,
|
98
|
-
|
99
|
-
pt = PaymentTransaction.find_by_transaction_gid! tsx_id
|
100
|
-
#record_transaction(response, 'captured')
|
101
|
-
record_transaction(response, 'captured', card_number: pt.metadata[:card_number], cardtype: pt.metadata[:cardtype])
|
115
|
+
response = gateway.capture(order.total_amount_in_cents, transaction_gid, {})
|
102
116
|
|
103
117
|
if response.success?
|
118
|
+
recorder = ::Nimbleshop::PaymentTransactionRecorder.new(order: order,
|
119
|
+
response: response,
|
120
|
+
operation: :captured,
|
121
|
+
transaction_gid: get_transaction_gid(response),
|
122
|
+
metadata: { card_number: payment_transaction.metadata[:card_number],
|
123
|
+
cardtype: payment_transaction.metadata[:cardtype]})
|
124
|
+
recorder.record
|
104
125
|
order.kapture
|
105
126
|
else
|
106
|
-
@errors << "Capture
|
107
|
-
false
|
127
|
+
@errors << "Capture operation failed"
|
108
128
|
end
|
129
|
+
|
130
|
+
response.success?
|
109
131
|
end
|
110
132
|
|
111
133
|
# Voids the previously authorized transaction.
|
@@ -119,18 +141,23 @@ module NimbleshopAuthorizedotnet
|
|
119
141
|
#
|
120
142
|
def do_void(options = {})
|
121
143
|
options.symbolize_keys!
|
122
|
-
options.assert_valid_keys
|
123
|
-
transaction_gid = options
|
144
|
+
options.assert_valid_keys :transaction_gid
|
145
|
+
transaction_gid = options.fetch :transaction_gid
|
124
146
|
|
125
147
|
response = gateway.void(transaction_gid, {})
|
126
|
-
record_transaction(response, 'voided')
|
127
148
|
|
128
149
|
if response.success?
|
150
|
+
recorder = ::Nimbleshop::PaymentTransactionRecorder.new(order: order,
|
151
|
+
response: response,
|
152
|
+
operation: :voided,
|
153
|
+
transaction_gid: get_transaction_gid(response))
|
154
|
+
recorder.record
|
129
155
|
order.void
|
130
156
|
else
|
131
157
|
@errors << "Void operation failed"
|
132
|
-
false
|
133
158
|
end
|
159
|
+
|
160
|
+
response.success?
|
134
161
|
end
|
135
162
|
|
136
163
|
# Refunds the given transaction.
|
@@ -144,49 +171,39 @@ module NimbleshopAuthorizedotnet
|
|
144
171
|
#
|
145
172
|
def do_refund(options = {})
|
146
173
|
options.symbolize_keys!
|
147
|
-
options.assert_valid_keys
|
174
|
+
options.assert_valid_keys :transaction_gid, :card_number
|
148
175
|
|
149
|
-
transaction_gid = options
|
150
|
-
card_number = options
|
176
|
+
transaction_gid = options.fetch :transaction_gid
|
177
|
+
card_number = options.fetch :card_number
|
151
178
|
|
152
179
|
response = gateway.refund(order.total_amount_in_cents, transaction_gid, card_number: card_number)
|
153
|
-
record_transaction(response, 'refunded')
|
154
180
|
|
155
181
|
if response.success?
|
182
|
+
recorder = ::Nimbleshop::PaymentTransactionRecorder.new(order: order,
|
183
|
+
response: response,
|
184
|
+
operation: :refunded,
|
185
|
+
transaction_gid: get_transaction_gid(response))
|
186
|
+
recorder.record
|
156
187
|
order.refund
|
157
188
|
else
|
158
189
|
@errors << "Refund failed"
|
159
|
-
false
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
def record_transaction(response, operation, additional_options = {}) # :nodoc:
|
165
|
-
#
|
166
|
-
# Following code invokes response.authorization to get transaction id. Note that this method can be called
|
167
|
-
# after capture or refund. And it feels weird to call +authorization+ when the operation was +capture+.
|
168
|
-
# However this is how ActiveMerchant works. It sets transaction id in +authorization+ key.
|
169
|
-
#
|
170
|
-
# https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net.rb#L283
|
171
|
-
#
|
172
|
-
transaction_gid = response.authorization
|
173
|
-
|
174
|
-
options = { operation: operation,
|
175
|
-
params: response.params,
|
176
|
-
success: response.success?,
|
177
|
-
metadata: additional_options,
|
178
|
-
transaction_gid: transaction_gid }
|
179
|
-
|
180
|
-
if response.success?
|
181
|
-
options.update(amount: order.total_amount_in_cents)
|
182
190
|
end
|
183
191
|
|
184
|
-
|
192
|
+
response.success?
|
185
193
|
end
|
186
194
|
|
187
195
|
def valid_card?(creditcard) # :nodoc:
|
188
196
|
creditcard && creditcard.valid?
|
189
197
|
end
|
190
198
|
|
199
|
+
# Following code invokes response.authorization to get transaction id. Note that this method can be called
|
200
|
+
# after capture or refund. And it feels weird to call +authorization+ when the operation was +capture+.
|
201
|
+
# However this is how ActiveMerchant works. It sets transaction id in +authorization+ key.
|
202
|
+
#
|
203
|
+
# https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net.rb#L283
|
204
|
+
def get_transaction_gid(response)
|
205
|
+
response.authorization
|
206
|
+
end
|
207
|
+
|
191
208
|
end
|
192
209
|
end
|
@@ -14,18 +14,18 @@ namespace :nimbleshop_authorizedotnet do
|
|
14
14
|
task :load_record => :environment do
|
15
15
|
|
16
16
|
if NimbleshopAuthorizedotnet::Authorizedotnet.find_by_permalink('authorizedotnet')
|
17
|
-
|
17
|
+
Rails.logger.debug 'Authorize.net record already exists'
|
18
18
|
else
|
19
19
|
NimbleshopAuthorizedotnet::Authorizedotnet.create!(
|
20
20
|
{
|
21
|
-
|
21
|
+
api_login_id: Nimbleshop.config.authorizedotnet.api_login_id,
|
22
22
|
transaction_key: Nimbleshop.config.authorizedotnet.transaction_key,
|
23
23
|
business_name: 'Nimbleshop LLC',
|
24
24
|
name: 'Authorize.net',
|
25
25
|
permalink: 'authorizedotnet',
|
26
26
|
description: %Q[<p> Authorize.Net is a payment gateway service provider allowing merchants to accept credit card and electronic checks paymentsn. Authorize.Net claims a user base of over 305,000 merchants, which would make them the Internet's largest payment gateway service provider. </p> <p> It also provides an instant test account which you can use while your application is being processed. </p>]
|
27
27
|
})
|
28
|
-
|
28
|
+
Rails.logger.debug 'Authorize.net record was successfuly created'
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/test/test_helper.rb
CHANGED
@@ -20,7 +20,9 @@ class ActiveSupport::TestCase
|
|
20
20
|
self.use_transactional_fixtures = false
|
21
21
|
setup do
|
22
22
|
DatabaseCleaner.start
|
23
|
-
ActiveRecord::Fixtures.create_fixtures("#{File.dirname(__FILE__)}/../../../nimbleshop_core/test/fixtures", ['shops',
|
23
|
+
ActiveRecord::Fixtures.create_fixtures("#{File.dirname(__FILE__)}/../../../nimbleshop_core/test/fixtures", ['shops',
|
24
|
+
'link_groups',
|
25
|
+
'payment_methods'])
|
24
26
|
end
|
25
27
|
teardown do
|
26
28
|
DatabaseCleaner.clean
|
@@ -5,33 +5,28 @@ class PaymentMethodAuthorizeNetTest < ActiveSupport::TestCase
|
|
5
5
|
test "validations" do
|
6
6
|
pm = NimbleshopAuthorizedotnet::Authorizedotnet.new(name: 'Authorize.net', description: 'this is description')
|
7
7
|
refute pm.valid?
|
8
|
-
expected = ["Business name can't be blank", "Login can't be blank", "Transaction key can't be blank"]
|
9
|
-
assert_equal expected, pm.errors.full_messages.sort
|
8
|
+
expected = ["Business name can't be blank", "Api Login Id can't be blank", "Transaction key can't be blank"]
|
9
|
+
assert_equal expected.sort, pm.errors.full_messages.sort
|
10
10
|
end
|
11
11
|
|
12
12
|
test "should save the record" do
|
13
13
|
pm = NimbleshopAuthorizedotnet::Authorizedotnet.new(name: 'Authorize.net', description: 'this is description')
|
14
|
-
pm.
|
14
|
+
pm.api_login_id = 'FWERSDEED093d'
|
15
15
|
pm.transaction_key = 'SDFSDFSFSF423433SDFSFSSFSFSF334'
|
16
16
|
pm.business_name = 'BigBinary LLC'
|
17
17
|
assert pm.save
|
18
18
|
assert_match /authorize-net/, pm.permalink
|
19
19
|
end
|
20
|
-
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
22
|
class PaymentMethodAuthorizeNetKaptureTest < ActiveSupport::TestCase
|
25
|
-
setup do
|
26
|
-
class HackedProcessor < NimbleshopAuthorizedotnet::Processor
|
27
|
-
def kapture(*args); end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
23
|
test '#kapture!' do
|
32
24
|
order = create :order_paid_using_authorizedotnet
|
33
|
-
|
34
|
-
|
25
|
+
|
26
|
+
playcasette('authorize.net/capture-success') do
|
27
|
+
NimbleshopAuthorizedotnet::Authorizedotnet.first.kapture!(order, NimbleshopAuthorizedotnet::Processor)
|
28
|
+
end
|
29
|
+
|
35
30
|
assert_equal 'purchased', order.payment_status
|
36
31
|
end
|
37
32
|
end
|
data/test/unit/processor_test.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
module Processor
|
4
|
+
|
4
5
|
class NimbleshopAuthorizeNetAuthorizeTest < ActiveRecord::TestCase
|
5
6
|
setup do
|
6
7
|
payment_method = NimbleshopAuthorizedotnet::Authorizedotnet.first
|
7
|
-
@order = create
|
8
|
+
@order = create :order
|
8
9
|
@order.stubs(:total_amount).returns(100.48)
|
9
10
|
@processor = NimbleshopAuthorizedotnet::Processor.new(order: @order, payment_method: payment_method)
|
10
11
|
end
|
11
12
|
|
12
13
|
test 'when authorization succeeds' do
|
13
|
-
creditcard = build
|
14
|
+
creditcard = build :creditcard
|
15
|
+
transactions_count = @order.payment_transactions.count
|
14
16
|
|
15
17
|
playcasette('authorize.net/authorize-success') do
|
16
18
|
assert_equal true, @processor.authorize(creditcard: creditcard)
|
@@ -20,13 +22,16 @@ module Processor
|
|
20
22
|
|
21
23
|
transaction = @order.payment_transactions.last
|
22
24
|
assert_equal 'authorized', transaction.operation
|
23
|
-
assert_equal true, transaction.success
|
24
25
|
assert_equal NimbleshopAuthorizedotnet::Authorizedotnet.first, @order.payment_method
|
25
26
|
assert @order.authorized?
|
27
|
+
assert_equal 'visa', transaction.metadata[:cardtype]
|
28
|
+
assert_equal transactions_count + 1, @order.payment_transactions.count
|
26
29
|
end
|
27
30
|
|
28
31
|
test 'authorization fails when credit card number is not entered' do
|
29
32
|
creditcard = build(:creditcard, number: nil)
|
33
|
+
transactions_count = @order.payment_transactions.count
|
34
|
+
|
30
35
|
assert_equal false, @processor.authorize(creditcard: creditcard)
|
31
36
|
assert_equal 'Please enter credit card number', @processor.errors.first
|
32
37
|
|
@@ -34,10 +39,12 @@ module Processor
|
|
34
39
|
|
35
40
|
assert_nil @order.payment_method
|
36
41
|
assert @order.abandoned?
|
42
|
+
assert_equal transactions_count, @order.payment_transactions.count
|
37
43
|
end
|
38
44
|
|
39
45
|
test 'authorization fails with invalid credit card number' do
|
40
46
|
creditcard = build(:creditcard, number: 2)
|
47
|
+
transactions_count = @order.payment_transactions.count
|
41
48
|
|
42
49
|
playcasette('authorize.net/authorize-failure') do
|
43
50
|
assert_equal false, @processor.authorize(creditcard: creditcard)
|
@@ -48,6 +55,7 @@ module Processor
|
|
48
55
|
|
49
56
|
assert_nil @order.payment_method
|
50
57
|
assert @order.abandoned?
|
58
|
+
assert_equal transactions_count, @order.payment_transactions.count
|
51
59
|
end
|
52
60
|
end
|
53
61
|
|
@@ -57,7 +65,7 @@ module Processor
|
|
57
65
|
@order = create(:order, payment_method: payment_method)
|
58
66
|
@order.stubs(:total_amount).returns(100.48)
|
59
67
|
@processor = NimbleshopAuthorizedotnet::Processor.new(order: @order, payment_method: payment_method)
|
60
|
-
creditcard = build
|
68
|
+
creditcard = build :creditcard
|
61
69
|
|
62
70
|
playcasette('authorize.net/authorize-success') do
|
63
71
|
@processor.authorize(creditcard: creditcard)
|
@@ -67,7 +75,8 @@ module Processor
|
|
67
75
|
end
|
68
76
|
|
69
77
|
test 'when capture succeeds' do
|
70
|
-
creditcard = build
|
78
|
+
creditcard = build :creditcard
|
79
|
+
transactions_count = @order.payment_transactions.count
|
71
80
|
|
72
81
|
playcasette('authorize.net/capture-success') do
|
73
82
|
assert_equal true, @processor.kapture(transaction_gid: @tsx_id)
|
@@ -76,27 +85,25 @@ module Processor
|
|
76
85
|
@order.reload
|
77
86
|
transaction = @order.payment_transactions.last
|
78
87
|
assert_equal 'captured', transaction.operation
|
79
|
-
assert_equal true, transaction.success
|
80
88
|
assert_equal "XXXX-XXXX-XXXX-0027", transaction.metadata[:card_number]
|
81
89
|
assert_equal 'visa', transaction.metadata[:cardtype]
|
82
90
|
assert @order.purchased?
|
91
|
+
assert_equal transactions_count + 1, @order.payment_transactions.count
|
83
92
|
end
|
84
93
|
|
85
94
|
test 'when capture fails' do
|
86
95
|
creditcard = build(:creditcard, number: 2)
|
96
|
+
transactions_count = @order.payment_transactions.count
|
87
97
|
|
88
98
|
playcasette('authorize.net/capture-failure') do
|
89
99
|
assert_equal false, @processor.kapture(transaction_gid: @tsx_id)
|
90
|
-
assert_equal 'Capture
|
100
|
+
assert_equal 'Capture operation failed', @processor.errors.first
|
91
101
|
end
|
92
102
|
|
93
103
|
@order.reload
|
94
104
|
|
95
|
-
transaction = @order.payment_transactions.last
|
96
|
-
|
97
|
-
assert_equal false, transaction.success
|
98
|
-
assert_equal 'captured', transaction.operation
|
99
105
|
assert @order.authorized?
|
106
|
+
assert_equal transactions_count, @order.payment_transactions.count
|
100
107
|
end
|
101
108
|
end
|
102
109
|
|
@@ -118,6 +125,7 @@ module Processor
|
|
118
125
|
end
|
119
126
|
|
120
127
|
test 'when refund succeeds' do
|
128
|
+
transactions_count = @order.payment_transactions.count
|
121
129
|
|
122
130
|
playcasette('authorize.net/refund-success') do
|
123
131
|
assert_equal true, @processor.refund(transaction_gid: @transaction.transaction_gid,
|
@@ -128,12 +136,13 @@ module Processor
|
|
128
136
|
transaction = @order.payment_transactions.last
|
129
137
|
|
130
138
|
assert_equal 'refunded', transaction.operation
|
131
|
-
assert_equal true, transaction.success
|
132
139
|
assert_equal NimbleshopAuthorizedotnet::Authorizedotnet.first, @order.payment_method
|
133
140
|
assert @order.refunded?
|
141
|
+
assert_equal transactions_count + 1, @order.payment_transactions.count
|
134
142
|
end
|
135
143
|
|
136
144
|
test 'when refund fails' do
|
145
|
+
transactions_count = @order.payment_transactions.count
|
137
146
|
|
138
147
|
playcasette('authorize.net/refund-failure') do
|
139
148
|
assert_equal false, @processor.refund(transaction_gid: @transaction.transaction_gid, card_number: '1234')
|
@@ -141,20 +150,18 @@ module Processor
|
|
141
150
|
|
142
151
|
@order.reload
|
143
152
|
|
144
|
-
|
145
|
-
|
146
|
-
assert_equal 'refunded', transaction.operation
|
147
|
-
assert_equal false, transaction.success
|
153
|
+
assert @order.purchased?
|
154
|
+
assert_equal transactions_count, @order.payment_transactions.count
|
148
155
|
end
|
149
156
|
end
|
150
157
|
|
151
158
|
class AuthorizeNetVoidTest < ActiveRecord::TestCase
|
152
159
|
setup do
|
153
160
|
payment_method = NimbleshopAuthorizedotnet::Authorizedotnet.first
|
154
|
-
@order = create
|
161
|
+
@order = create :order
|
155
162
|
@order.stubs(:total_amount).returns(100.48)
|
156
163
|
@processor = NimbleshopAuthorizedotnet::Processor.new(order: @order, payment_method: payment_method)
|
157
|
-
creditcard = build
|
164
|
+
creditcard = build :creditcard
|
158
165
|
|
159
166
|
playcasette('authorize.net/authorize-success') do
|
160
167
|
assert_equal true, @processor.authorize(creditcard: creditcard)
|
@@ -163,7 +170,9 @@ module Processor
|
|
163
170
|
@tsx_id = @order.payment_transactions.last.transaction_gid
|
164
171
|
end
|
165
172
|
|
166
|
-
test 'when
|
173
|
+
test 'when void succeeds' do
|
174
|
+
transactions_count = @order.payment_transactions.count
|
175
|
+
|
167
176
|
playcasette('authorize.net/void-success') do
|
168
177
|
assert_equal true, @processor.void(transaction_gid: @tsx_id)
|
169
178
|
end
|
@@ -172,35 +181,35 @@ module Processor
|
|
172
181
|
transaction = @order.payment_transactions.last
|
173
182
|
|
174
183
|
assert_equal 'voided', transaction.operation
|
175
|
-
assert_equal true, transaction.success
|
176
184
|
assert_equal NimbleshopAuthorizedotnet::Authorizedotnet.first, @order.payment_method
|
177
185
|
assert @order.voided?
|
186
|
+
assert_equal transactions_count + 1, @order.payment_transactions.count
|
178
187
|
end
|
179
188
|
|
180
|
-
test 'when
|
189
|
+
test 'when void fails' do
|
190
|
+
transactions_count = @order.payment_transactions.count
|
191
|
+
|
181
192
|
playcasette('authorize.net/void-failure') do
|
182
193
|
assert_equal false, @processor.void(transaction_gid: @tsx_id)
|
183
194
|
end
|
184
195
|
|
185
196
|
@order.reload
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
assert_equal 'voided', transaction.operation
|
190
|
-
assert_equal false, transaction.success
|
197
|
+
assert @order.authorized?
|
198
|
+
assert_equal transactions_count, @order.payment_transactions.count
|
191
199
|
end
|
192
200
|
end
|
193
201
|
|
194
202
|
class AuthorizeNetPurchaseTest < ActiveRecord::TestCase
|
195
203
|
setup do
|
196
204
|
payment_method = NimbleshopAuthorizedotnet::Authorizedotnet.first
|
197
|
-
@order = create
|
205
|
+
@order = create :order
|
198
206
|
@order.stubs(:total_amount).returns(100.48)
|
199
207
|
@processor = NimbleshopAuthorizedotnet::Processor.new(order: @order, payment_method: payment_method)
|
200
208
|
end
|
201
209
|
|
202
210
|
test 'when purchase succeeds' do
|
203
|
-
creditcard = build
|
211
|
+
creditcard = build :creditcard
|
212
|
+
transactions_count = @order.payment_transactions.count
|
204
213
|
|
205
214
|
playcasette('authorize.net/purchase-success') do
|
206
215
|
assert_equal true, @processor.purchase(creditcard: creditcard)
|
@@ -210,12 +219,13 @@ module Processor
|
|
210
219
|
|
211
220
|
transaction = @order.payment_transactions.last
|
212
221
|
assert_equal 'purchased', transaction.operation
|
213
|
-
assert_equal true, transaction.success
|
214
222
|
assert @order.purchased?
|
223
|
+
assert_equal transactions_count + 1, @order.payment_transactions.count
|
215
224
|
end
|
216
225
|
|
217
226
|
test 'purchase fails when credit card number is not entered ' do
|
218
227
|
creditcard = build(:creditcard, number: nil)
|
228
|
+
transactions_count = @order.payment_transactions.count
|
219
229
|
|
220
230
|
playcasette('authorize.net/purchase-failure') do
|
221
231
|
assert_equal false, @processor.purchase(creditcard: creditcard)
|
@@ -223,21 +233,20 @@ module Processor
|
|
223
233
|
end
|
224
234
|
|
225
235
|
assert @order.abandoned?
|
236
|
+
assert_equal transactions_count, @order.payment_transactions.count
|
226
237
|
end
|
227
238
|
|
228
239
|
test 'purchase fails when invalid credit card number is entered' do
|
229
240
|
creditcard = build(:creditcard, number: 2)
|
241
|
+
transactions_count = @order.payment_transactions.count
|
230
242
|
|
231
243
|
playcasette('authorize.net/purchase-failure') do
|
232
244
|
assert_equal false, @processor.purchase(creditcard: creditcard)
|
233
245
|
assert_equal 'Credit card was declined. Please try again!', @processor.errors.first
|
234
246
|
end
|
235
247
|
|
236
|
-
transaction = @order.payment_transactions.last
|
237
|
-
|
238
|
-
assert_equal false, transaction.success
|
239
|
-
assert_equal 'purchased', transaction.operation
|
240
248
|
assert @order.abandoned?
|
249
|
+
assert_equal transactions_count, @order.payment_transactions.count
|
241
250
|
end
|
242
251
|
end
|
243
252
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nimbleshop_authorizedotnet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemerchant
|
@@ -46,7 +46,6 @@ files:
|
|
46
46
|
- app/helpers/nimbleshop_authorizedotnet/exposed_helper.rb
|
47
47
|
- app/models/nimbleshop_authorizedotnet/authorizedotnet.rb
|
48
48
|
- app/views/nimbleshop_authorizedotnet/authorizedotnets/_edit.html.erb
|
49
|
-
- app/views/nimbleshop_authorizedotnet/authorizedotnets/_form.html.erb
|
50
49
|
- app/views/nimbleshop_authorizedotnet/payments/_authorize_net_instructions.html.erb
|
51
50
|
- app/views/nimbleshop_authorizedotnet/payments/_new.html.erb
|
52
51
|
- app/views/nimbleshop_authorizedotnet/payments/_order_show_extra_info.html.erb
|
@@ -87,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
86
|
version: '0'
|
88
87
|
segments:
|
89
88
|
- 0
|
90
|
-
hash:
|
89
|
+
hash: -3279639122130010380
|
91
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
91
|
none: false
|
93
92
|
requirements:
|
@@ -96,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
95
|
version: '0'
|
97
96
|
segments:
|
98
97
|
- 0
|
99
|
-
hash:
|
98
|
+
hash: -3279639122130010380
|
100
99
|
requirements: []
|
101
100
|
rubyforge_project:
|
102
101
|
rubygems_version: 1.8.24
|
@@ -1,67 +0,0 @@
|
|
1
|
-
<div class='well nimbleshop-payment-method-form-well' id='nimbleshop-authorizedotnet-form-well' style='display:none;'>
|
2
|
-
|
3
|
-
<%= form_for NimbleshopAuthorizedotnet::Authorizedotnet.first, url: '/nimbleshop_authorizedotnet/authorizedotnet',
|
4
|
-
remote: true,
|
5
|
-
html: { method: 'put',
|
6
|
-
id: 'nimbleshop-authorizedotnet-form',
|
7
|
-
class: 'nimbleshop-payment-method-form form-horizontal'} do |f| %>
|
8
|
-
|
9
|
-
<fieldset>
|
10
|
-
<div class='control-group'>
|
11
|
-
<%= f.label :login_id, nil, class: 'control-label' %>
|
12
|
-
<div class='controls'>
|
13
|
-
<%= f.text_field :login_id, class: 'span6' %>
|
14
|
-
</div>
|
15
|
-
</div>
|
16
|
-
<div class='control-group'>
|
17
|
-
<%= f.label :transaction_key, nil, class: 'control-label' %>
|
18
|
-
<div class='controls'>
|
19
|
-
<%= f.text_field :transaction_key, class: 'span6' %>
|
20
|
-
</div>
|
21
|
-
</div>
|
22
|
-
|
23
|
-
<div class='control-group'>
|
24
|
-
<%= f.label :business_name, nil, class: 'control-label' %>
|
25
|
-
<%= link_to '?', '#', 'data-content' => 'Please enter the name of the company as it would appear in the credit card statement. If are not sure what name would appear in the credit card statements then consult your merchant account provider.',
|
26
|
-
'data-original-title' => 'Business name' %>
|
27
|
-
<div class='controls'>
|
28
|
-
<%= f.text_field :business_name, class: 'span6' %>
|
29
|
-
</div>
|
30
|
-
</div>
|
31
|
-
|
32
|
-
<div class='control-group'>
|
33
|
-
<div class='controls'>
|
34
|
-
<label class='checkbox'>
|
35
|
-
<%= f.check_box :mode, {}, 'test', 'production' %> Enable test mode
|
36
|
-
<%= link_to '?', '#', class: 'help', 'data-content' => 'In the test mode real credit card numbers are not accepted.',
|
37
|
-
'data-original-title' => 'Test mode' %>
|
38
|
-
</label>
|
39
|
-
</div>
|
40
|
-
</div>
|
41
|
-
|
42
|
-
<div class='control-group'>
|
43
|
-
<div class='controls'>
|
44
|
-
<label class='checkbox'>
|
45
|
-
<%= f.check_box :ssl, {}, 'enabled', 'disabled' %> Enable SSL requirement
|
46
|
-
<%= link_to '?', '#', class: 'help', 'data-content' => 'Enabling SSL requirement will force the payment page to be on SSL.',
|
47
|
-
'data-original-title' => 'SSL requirement' %>
|
48
|
-
</label>
|
49
|
-
</div>
|
50
|
-
</div>
|
51
|
-
|
52
|
-
</fieldset>
|
53
|
-
|
54
|
-
<div class='form-actions'>
|
55
|
-
<%= f.submit('Submit', class: 'btn btn-primary') %>
|
56
|
-
|
57
|
-
<%= link_to t(:cancel), nimbleshop_authorizedotnet.authorizedotnet_path, class: 'cancel btn' %>
|
58
|
-
</div>
|
59
|
-
<% end %>
|
60
|
-
|
61
|
-
</div>
|
62
|
-
|
63
|
-
<style>
|
64
|
-
.control-group a.help {
|
65
|
-
float: none;
|
66
|
-
}
|
67
|
-
</style>
|