spree_unified_payment 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +9 -0
- data/.travis.yml +6 -0
- data/Gemfile +20 -0
- data/LICENSE +26 -0
- data/README.md +61 -0
- data/Versionfile +12 -0
- data/app/assets/javascripts/admin/spree_unified_payment.js +39 -0
- data/app/assets/stylesheets/store/spree_unified_payment.css +7 -0
- data/app/controllers/application_controller.rb +2 -0
- data/app/controllers/spree/admin/unified_payments_controller.rb +34 -0
- data/app/controllers/spree/checkout_controller_decorator.rb +19 -0
- data/app/controllers/spree/unified_payments_controller.rb +151 -0
- data/app/helpers/transaction_notification_mail_helper.rb +12 -0
- data/app/helpers/unified_transaction_helper.rb +18 -0
- data/app/mailers/spree/transaction_notification_mailer.rb +16 -0
- data/app/models/spree/order_decorator.rb +67 -0
- data/app/models/spree/payment_method/unified_payment_method.rb +34 -0
- data/app/models/spree/store_credit_decorator.rb +4 -0
- data/app/models/spree/user_decorator.rb +7 -0
- data/app/models/unified_payment/transaction_decorator.rb +102 -0
- data/app/overrides/add_unified_tabs_to_admin_menu.rb +6 -0
- data/app/views/spree/admin/unified_payments/index.html.erb +98 -0
- data/app/views/spree/admin/unified_payments/query_gateway.js.erb +10 -0
- data/app/views/spree/admin/unified_payments/receipt.html.erb +20 -0
- data/app/views/spree/checkout/payment/_unifiedpaymentmethod.html.erb +24 -0
- data/app/views/spree/transaction_notification_mailer/send_mail.html.erb +20 -0
- data/app/views/spree/unified_payments/approved.html.erb +25 -0
- data/app/views/spree/unified_payments/canceled.html.erb +1 -0
- data/app/views/spree/unified_payments/create.html.erb +8 -0
- data/app/views/spree/unified_payments/create.js.erb +3 -0
- data/app/views/spree/unified_payments/declined.html.erb +4 -0
- data/app/views/spree/unified_payments/index.html.erb +28 -0
- data/app/views/spree/unified_payments/new.html.erb +35 -0
- data/app/views/spree/unified_payments/new.js.erb +3 -0
- data/config/initializers/constants.rb +8 -0
- data/config/routes.rb +15 -0
- data/db/migrate/20140120075553_add_transaction_fields_to_unified_payment_transactions.rb +14 -0
- data/db/migrate/20140120081453_add_unified_transaction_id_to_spree_store_credits.rb +6 -0
- data/lib/generators/spree_unified_payment/install/install_generator.rb +27 -0
- data/lib/spree_unified_payment/engine.rb +26 -0
- data/lib/spree_unified_payment.rb +2 -0
- data/lib/transaction_expiration.rb +9 -0
- data/spec/constants_spec.rb +11 -0
- data/spec/controllers/spree/admin/unified_payments_controller_spec.rb +155 -0
- data/spec/controllers/spree/checkout_controller_decorator_spec.rb +114 -0
- data/spec/controllers/spree/unified_payments_controller_spec.rb +509 -0
- data/spec/mailers/transaction_notification_mailer_spec.rb +48 -0
- data/spec/models/spree/order_decorator_spec.rb +206 -0
- data/spec/models/spree/payment_method/unified_payment_spec.rb +25 -0
- data/spec/models/spree/store_credit_decorator_spec.rb +11 -0
- data/spec/models/spree/user_decorator_spec.rb +12 -0
- data/spec/models/unified_payment/transaction_decorator_spec.rb +483 -0
- data/spec/spec_helper.rb +66 -0
- data/spree_unified_payment.gemspec +23 -0
- metadata +184 -0
@@ -0,0 +1,509 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::UnifiedPaymentsController do
|
4
|
+
|
5
|
+
let(:user) { mock_model(Spree.user_class) }
|
6
|
+
let(:order) { mock_model(Spree::Order, :total => '12') }
|
7
|
+
let(:variant) { mock_model(Spree::Variant, :name => 'test-variant') }
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
user.stub(:generate_spree_api_key!).and_return(true)
|
11
|
+
user.stub(:last_incomplete_spree_order).and_return(order)
|
12
|
+
Spree::Config[:site_name] = "MyTestSite"
|
13
|
+
controller.stub(:spree_current_user).and_return(user)
|
14
|
+
controller.stub(:current_order).and_return(order)
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'before going to gateway' do
|
18
|
+
before do
|
19
|
+
order.stub(:user).and_return(user)
|
20
|
+
order.stub(:completed?).and_return(false)
|
21
|
+
order.stub(:insufficient_stock_lines).and_return([])
|
22
|
+
order.stub(:pending_card_transaction).and_return(nil)
|
23
|
+
order.stub(:inactive_variants).and_return([])
|
24
|
+
order.stub(:reason_if_cant_pay_by_card).and_return(nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#ensure_and_load_order' do
|
28
|
+
def send_request(params = {})
|
29
|
+
get :new, params.merge!({:use_route => 'spree'})
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when current order does not exist' do
|
33
|
+
before do
|
34
|
+
controller.stub(:current_order).and_return(nil)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'does not call for reason_if_cant_pay_by_card on order' do
|
38
|
+
order.should_not_receive(:reason_if_cant_pay_by_card)
|
39
|
+
send_request
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'response should redirect to cart' do
|
43
|
+
send_request
|
44
|
+
response.should redirect_to '/cart'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'sets flash message' do
|
48
|
+
send_request
|
49
|
+
flash[:error].should eq('Order not found')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when current order exists with no errors' do
|
54
|
+
before { order.stub(:reason_if_cant_pay_by_card).and_return(nil) }
|
55
|
+
|
56
|
+
it 'calls for reason_if_cant_pay_by_card on order' do
|
57
|
+
order.should_receive(:reason_if_cant_pay_by_card).and_return(nil)
|
58
|
+
send_request
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'loads order' do
|
62
|
+
send_request
|
63
|
+
assigns(:order).should eq(order)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'sets no error message' do
|
67
|
+
flash[:error].should be_nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'order exists but no valid' do
|
72
|
+
before do
|
73
|
+
order.stub(:reason_if_cant_pay_by_card).and_return('Order is already completed.')
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'calls for reason_if_cant_pay_by_card on order' do
|
77
|
+
order.should_receive(:reason_if_cant_pay_by_card).and_return('Order is already completed.')
|
78
|
+
send_request
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'sets the flash message' do
|
82
|
+
send_request
|
83
|
+
flash[:error].should eq('Order is already completed.')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'gives a js response to redirect to cart' do
|
87
|
+
send_request
|
88
|
+
response.should redirect_to '/cart'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#index' do
|
94
|
+
before do
|
95
|
+
@unified_payment = mock_model(UnifiedPayment::Transaction)
|
96
|
+
@unified_payments = [@unified_payment]
|
97
|
+
@unified_payments.stub(:order).with('updated_at desc').and_return(@unified_payments)
|
98
|
+
@unified_payments.stub(:page).with('1').and_return(@unified_payments)
|
99
|
+
@unified_payments.stub(:per).with(20).and_return(@unified_payments)
|
100
|
+
user.stub(:unified_payments).and_return(@unified_payments)
|
101
|
+
end
|
102
|
+
|
103
|
+
def send_request(params = {})
|
104
|
+
get :index, params.merge!({:use_route => 'spree'})
|
105
|
+
end
|
106
|
+
|
107
|
+
it { user.should_receive(:unified_payments).and_return(@unified_payments) }
|
108
|
+
it { @unified_payments.should_receive(:order).with('updated_at desc').and_return(@unified_payments) }
|
109
|
+
it { @unified_payments.should_receive(:page).with('1').and_return(@unified_payments) }
|
110
|
+
it { @unified_payments.should_receive(:per).with(20).and_return(@unified_payments) }
|
111
|
+
after { send_request(:page => '1') }
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
describe '#new' do
|
116
|
+
|
117
|
+
def send_request(params = {})
|
118
|
+
get :new, params.merge!({:use_route => 'spree'})
|
119
|
+
end
|
120
|
+
|
121
|
+
before { controller.stub(:generate_transaction_id).and_return(12345678910121) }
|
122
|
+
|
123
|
+
describe 'method calls' do
|
124
|
+
it { controller.should_receive(:generate_transaction_id).and_return(12345678910121) }
|
125
|
+
|
126
|
+
after { send_request }
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'assigns' do
|
130
|
+
before { send_request }
|
131
|
+
|
132
|
+
it { session[:transaction_id].should eq(12345678910121) }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#create' do
|
137
|
+
|
138
|
+
def send_request(params = {})
|
139
|
+
post :create, params.merge!({:use_route => 'spree'})
|
140
|
+
end
|
141
|
+
|
142
|
+
before do
|
143
|
+
session[:transaction_id] = '12345678910121'
|
144
|
+
@gateway_response = Object.new
|
145
|
+
UnifiedPayment::Transaction.stub(:create_order_at_unified).with(order.total, {:approve_url=>"http://test.host/unified_payments/approved", :cancel_url=>"http://test.host/unified_payments/canceled", :decline_url=>"http://test.host/unified_payments/declined", :description=>"Purchasing items from MyTestSite"}).and_return(@gateway_response)
|
146
|
+
UnifiedPayment::Transaction.stub(:extract_url_for_unified_payment).with(@gateway_response).and_return('www.MyTestSite.com')
|
147
|
+
controller.stub(:tasks_on_gateway_create_response).with(@gateway_response, '12345678910121').and_return(true)
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'with a pending card transaction' do
|
151
|
+
before do
|
152
|
+
@pending_card_transaction = mock_model(UnifiedPayment::Transaction, :payment_transaction_id => '98765432110112')
|
153
|
+
@pending_card_transaction.stub(:abort!).and_return(true)
|
154
|
+
order.stub(:pending_card_transaction).and_return(@pending_card_transaction)
|
155
|
+
end
|
156
|
+
|
157
|
+
describe 'method calls' do
|
158
|
+
it { order.should_receive(:pending_card_transaction).and_return(@pending_card_transaction) }
|
159
|
+
it { @pending_card_transaction.should_receive(:abort!).and_return(true) }
|
160
|
+
|
161
|
+
after { send_request }
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'with no card transaction' do
|
166
|
+
before { order.stub(:pending_card_transaction).and_return(nil) }
|
167
|
+
|
168
|
+
describe 'method calls' do
|
169
|
+
it { order.should_receive(:pending_card_transaction).and_return(nil) }
|
170
|
+
|
171
|
+
after { send_request }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'when an order is successfully created at gateway' do
|
176
|
+
|
177
|
+
describe 'method calls' do
|
178
|
+
it { UnifiedPayment::Transaction.should_receive(:create_order_at_unified).with(order.total, {:approve_url=>"http://test.host/unified_payments/approved", :cancel_url=>"http://test.host/unified_payments/canceled", :decline_url=>"http://test.host/unified_payments/declined", :description=>"Purchasing items from MyTestSite"}).and_return(@gateway_response) }
|
179
|
+
it { UnifiedPayment::Transaction.should_receive(:extract_url_for_unified_payment).with(@gateway_response).and_return('www.MyTestSite.com') }
|
180
|
+
it { controller.should_receive(:tasks_on_gateway_create_response).with(@gateway_response, '12345678910121').and_return(true) }
|
181
|
+
|
182
|
+
after { send_request }
|
183
|
+
end
|
184
|
+
|
185
|
+
describe 'assigns' do
|
186
|
+
it 'payment_url' do
|
187
|
+
send_request
|
188
|
+
assigns(:payment_url).should eq("www.MyTestSite.com")
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context 'when order not created at gateway' do
|
194
|
+
|
195
|
+
before { UnifiedPayment::Transaction.stub(:create_order_at_unified).with(order.total, {:approve_url=>"http://test.host/unified_payments/approved", :cancel_url=>"http://test.host/unified_payments/canceled", :decline_url=>"http://test.host/unified_payments/declined", :description=>"Purchasing items from MyTestSite"}).and_return(false) }
|
196
|
+
|
197
|
+
describe 'method calls' do
|
198
|
+
it { UnifiedPayment::Transaction.should_receive(:create_order_at_unified).with(order.total, {:approve_url=>"http://test.host/unified_payments/approved", :cancel_url=>"http://test.host/unified_payments/canceled", :decline_url=>"http://test.host/unified_payments/declined", :description=>"Purchasing items from MyTestSite"}).and_return(false) }
|
199
|
+
it { UnifiedPayment::Transaction.should_not_receive(:extract_url_for_unified_payment) }
|
200
|
+
it { controller.should_not_receive(:tasks_on_gateway_create_response) }
|
201
|
+
|
202
|
+
after { send_request }
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'before filter' do
|
207
|
+
describe '#ensure_session_transaction_id' do
|
208
|
+
context 'when no session transaction id' do
|
209
|
+
before do
|
210
|
+
session[:transaction_id] = nil
|
211
|
+
send_request
|
212
|
+
end
|
213
|
+
|
214
|
+
it { flash[:error].should eq('No transaction id found, please try again') }
|
215
|
+
it { response.body.should eq("top.location.href = 'http://test.host/checkout/payment'") }
|
216
|
+
end
|
217
|
+
|
218
|
+
context 'when session transaction_id present' do
|
219
|
+
before { send_request }
|
220
|
+
|
221
|
+
it { flash[:error].should be_nil }
|
222
|
+
it { response.body.should eq("$('#confirm_payment').hide();top.location.href = 'www.MyTestSite.com'") }
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
describe '#tasks_on_gateway_create_response' do
|
229
|
+
def send_request(params = {})
|
230
|
+
post :create, params.merge!({:use_route => 'spree'})
|
231
|
+
end
|
232
|
+
|
233
|
+
before do
|
234
|
+
session[:transaction_id] = '12345678910121'
|
235
|
+
order.stub(:reserve_stock).and_return(true)
|
236
|
+
order.stub(:next).and_return(true)
|
237
|
+
@gateway_response = {'Status' => 'status', 'Order' => { 'SessionID' => '12312', 'OrderID' => '123121', 'URL' => 'MyResponse'}}
|
238
|
+
@transaction = UnifiedPayment::Transaction.new
|
239
|
+
UnifiedPayment::Transaction.stub(:create_order_at_unified).with(order.total, {:approve_url=>"http://test.host/unified_payments/approved", :cancel_url=>"http://test.host/unified_payments/canceled", :decline_url=>"http://test.host/unified_payments/declined", :description=>"Purchasing items from MyTestSite"}).and_return(@gateway_response)
|
240
|
+
UnifiedPayment::Transaction.stub(:extract_url_for_unified_payment).with(@gateway_response).and_return('www.MyTestSite.com')
|
241
|
+
UnifiedPayment::Transaction.stub(:where).with(:gateway_session_id => '12312', :gateway_order_id => '123121', :url => 'MyResponse').and_return([@transaction])
|
242
|
+
@transaction.stub(:save!).and_return(true)
|
243
|
+
end
|
244
|
+
|
245
|
+
describe 'method calls' do
|
246
|
+
context 'when order state is payment' do
|
247
|
+
before { order.stub(:state).and_return('payment') }
|
248
|
+
it { order.should_receive(:reserve_stock).and_return(true) }
|
249
|
+
it { order.should_receive(:next).and_return(true) }
|
250
|
+
|
251
|
+
after { send_request }
|
252
|
+
end
|
253
|
+
|
254
|
+
context 'when order state is not payment' do
|
255
|
+
it { order.should_receive(:reserve_stock).and_return(true) }
|
256
|
+
it { order.should_not_receive(:next) }
|
257
|
+
it { UnifiedPayment::Transaction.should_receive(:where).with(:gateway_session_id => '12312', :gateway_order_id => '123121', :url => 'MyResponse').and_return([@transaction]) }
|
258
|
+
it { @transaction.should_receive(:assign_attributes).with({:user_id => order.user.try(:id), :payment_transaction_id => '12345678910121', :order_id => order.id, :gateway_order_status => 'CREATED', :amount => order.total, :currency => Spree::Config[:currency], :response_status => 'status', :status => 'pending'}, :without_protection => true).and_return(true) }
|
259
|
+
it { @transaction.should_receive(:save!).and_return(true) }
|
260
|
+
after { send_request }
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe 'assigns' do
|
265
|
+
before { send_request }
|
266
|
+
|
267
|
+
it { session[:transaction_id].should be_nil }
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
context 'on return from gateway' do
|
273
|
+
before do
|
274
|
+
@card_transaction = mock_model(UnifiedPayment::Transaction)
|
275
|
+
@card_transaction.stub(:approved_at_gateway?).and_return(false)
|
276
|
+
@card_transaction.stub(:order).and_return(order)
|
277
|
+
UnifiedPayment::Transaction.stub_chain(:where, :first).and_return(@card_transaction)
|
278
|
+
end
|
279
|
+
|
280
|
+
context 'as declined' do
|
281
|
+
describe '#declined' do
|
282
|
+
|
283
|
+
def send_request(params = {})
|
284
|
+
post :declined, params.merge!({:use_route => 'spree'})
|
285
|
+
end
|
286
|
+
|
287
|
+
before do
|
288
|
+
@card_transaction.stub(:assign_attributes).with(:status => 'unsuccessful', :xml_response => '<Message><Hash>Mymessage</Hash><ResponseDescription>Reason</ResponseDescription></Message>').and_return(true)
|
289
|
+
@card_transaction.stub(:save).with(:validate => false).and_return(true)
|
290
|
+
end
|
291
|
+
|
292
|
+
describe 'method calls' do
|
293
|
+
|
294
|
+
it { @card_transaction.should_receive(:order).and_return(order) }
|
295
|
+
it { @card_transaction.should_receive(:assign_attributes).with(:status => 'unsuccessful', :xml_response => '<Message><Hash>Mymessage</Hash><ResponseDescription>Reason</ResponseDescription></Message>').and_return(true) }
|
296
|
+
it { @card_transaction.should_receive(:save).with(:validate => false).and_return(true) }
|
297
|
+
|
298
|
+
after { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><ResponseDescription>Reason</ResponseDescription></Message>'}) }
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'renders without layout' do
|
302
|
+
send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><ResponseDescription>Reason</ResponseDescription></Message>'})
|
303
|
+
response.should render_template(:declined, :layout => false)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
context 'as canceled' do
|
309
|
+
def send_request(params = {})
|
310
|
+
post :canceled, params.merge!({:use_route => 'spree'})
|
311
|
+
end
|
312
|
+
|
313
|
+
before do
|
314
|
+
@card_transaction.stub(:assign_attributes).with(:status => 'unsuccessful', :xml_response => '<Message><Hash>Mymessage</Hash></Message>').and_return(true)
|
315
|
+
@card_transaction.stub(:save).with(:validate => false).and_return(true)
|
316
|
+
end
|
317
|
+
|
318
|
+
context 'before filter' do
|
319
|
+
describe '#load_on_redirect' do
|
320
|
+
|
321
|
+
context 'there is a card transaction for the response' do
|
322
|
+
before { UnifiedPayment::Transaction.stub_chain(:where, :first).and_return(@card_transaction) }
|
323
|
+
|
324
|
+
describe 'method calls' do
|
325
|
+
it { @card_transaction.should_receive(:order).and_return(order) }
|
326
|
+
it { controller.should_not_receive(:verify_authenticity_token) }
|
327
|
+
|
328
|
+
after { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash></Message>'}) }
|
329
|
+
end
|
330
|
+
|
331
|
+
describe 'assigns' do
|
332
|
+
it 'card_transaction' do
|
333
|
+
send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash></Message>'})
|
334
|
+
assigns(:card_transaction).should eq(@card_transaction)
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
context 'there is no card transaction for the response' do
|
340
|
+
before do
|
341
|
+
UnifiedPayment::Transaction.stub_chain(:where, :first).and_return(nil)
|
342
|
+
send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash></Message>'})
|
343
|
+
end
|
344
|
+
|
345
|
+
describe 'method calls' do
|
346
|
+
it { flash[:error].should eq('No transaction. Please contact our support team.') }
|
347
|
+
it { response.should redirect_to('/') }
|
348
|
+
|
349
|
+
after { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash></Message>'}) }
|
350
|
+
end
|
351
|
+
|
352
|
+
describe 'assigns' do
|
353
|
+
it 'card_transaction' do
|
354
|
+
send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash></Message>'})
|
355
|
+
assigns(:card_transaction).should be_nil
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
describe '#canceled' do
|
363
|
+
|
364
|
+
describe 'method calls' do
|
365
|
+
it { @card_transaction.should_receive(:assign_attributes).with(:status => 'unsuccessful', :xml_response => '<Message><Hash>Mymessage</Hash></Message>').and_return(true) }
|
366
|
+
it { @card_transaction.should_receive(:save).with(:validate => false).and_return(true) }
|
367
|
+
it { controller.should_not_receive(:verify_authenticity_token) }
|
368
|
+
|
369
|
+
after { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash></Message>'}) }
|
370
|
+
end
|
371
|
+
|
372
|
+
it 'renders without layout' do
|
373
|
+
send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash></Message>'})
|
374
|
+
response.should render_template(:canceled, :layout => false)
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
describe '#approved' do
|
380
|
+
|
381
|
+
def send_request(params = {})
|
382
|
+
post :approved, params.merge!({:use_route => 'spree'})
|
383
|
+
end
|
384
|
+
|
385
|
+
before do
|
386
|
+
@card_transaction.stub(:expired_at?).and_return(false)
|
387
|
+
@card_transaction.stub(:xml_response=).with('<Message><Hash>Mymessage</Hash><PurchaseAmountScr>200</PurchaseAmountScr></Message>').and_return(true)
|
388
|
+
@card_transaction.stub(:status=).with("successful").and_return(true)
|
389
|
+
@card_transaction.stub(:status=).with("unsuccessful").and_return(true)
|
390
|
+
@card_transaction.stub(:save).with(:validate => false).and_return(true)
|
391
|
+
order.stub(:paid?).and_return(true)
|
392
|
+
end
|
393
|
+
|
394
|
+
describe 'method calls' do
|
395
|
+
it { @card_transaction.should_receive(:order).and_return(order) }
|
396
|
+
it { controller.should_not_receive(:verify_authenticity_token) }
|
397
|
+
|
398
|
+
after { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><PurchaseAmountScr>200</PurchaseAmountScr></Message>'}) }
|
399
|
+
end
|
400
|
+
|
401
|
+
context 'approved at gateway' do
|
402
|
+
before { @card_transaction.stub(:approved_at_gateway?).and_return(true) }
|
403
|
+
|
404
|
+
context 'payment made at gateway is not as in card transaction' do
|
405
|
+
before { @card_transaction.stub(:amount).and_return(100) }
|
406
|
+
it { controller.should_receive(:add_error).with("Payment made was not same as requested to gateway. Please contact administrator for queries.").and_return(true) }
|
407
|
+
it { @card_transaction.should_receive(:status=).with('unsuccessful').and_return(true) }
|
408
|
+
|
409
|
+
after { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><PurchaseAmountScr>200</PurchaseAmountScr></Message>'}) }
|
410
|
+
end
|
411
|
+
|
412
|
+
context 'payment made at gateway is same as in card transaction' do
|
413
|
+
before { @card_transaction.stub(:amount).and_return(200) }
|
414
|
+
context 'transaction has expired' do
|
415
|
+
before { @card_transaction.stub(:expired_at?).and_return(true) }
|
416
|
+
|
417
|
+
describe 'assigns' do
|
418
|
+
before { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><PurchaseAmountScr>200</PurchaseAmountScr></Message>'}) }
|
419
|
+
|
420
|
+
it { assigns(:transaction_expired).should be_true }
|
421
|
+
it { assigns(:payment_made).should eq(200) }
|
422
|
+
end
|
423
|
+
|
424
|
+
describe 'method_calls' do
|
425
|
+
it { controller.should_receive(:add_error).with('Payment was successful but transaction has expired. The payment made has been walleted in your account. Please contact administrator to help you further.').and_return(true) }
|
426
|
+
it { @card_transaction.should_receive(:status=).with('successful').and_return(true) }
|
427
|
+
|
428
|
+
after { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><PurchaseAmountScr>200</PurchaseAmountScr></Message>'}) }
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
context 'transaction has not expired' do
|
433
|
+
|
434
|
+
describe 'assigns' do
|
435
|
+
before { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><PurchaseAmountScr>200</PurchaseAmountScr></Message>'}) }
|
436
|
+
|
437
|
+
it { assigns(:transaction_expired).should be_false }
|
438
|
+
end
|
439
|
+
|
440
|
+
context 'order has not been paid or completed' do
|
441
|
+
before do
|
442
|
+
order.stub(:completed?).and_return(false)
|
443
|
+
order.stub(:paid?).and_return(false)
|
444
|
+
end
|
445
|
+
|
446
|
+
it { @card_transaction.should_receive(:status=).with('successful').and_return(true) }
|
447
|
+
|
448
|
+
after { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><PurchaseAmountScr>200</PurchaseAmountScr></Message>'}) }
|
449
|
+
end
|
450
|
+
|
451
|
+
context 'order already completed' do
|
452
|
+
before do
|
453
|
+
order.stub(:completed?).and_return(true)
|
454
|
+
order.stub(:paid?).and_return(false)
|
455
|
+
end
|
456
|
+
|
457
|
+
it { @card_transaction.should_receive(:status=).with('successful').and_return(true) }
|
458
|
+
it { controller.should_receive(:add_error).with('Order Already Paid Or Completed').and_return(true) }
|
459
|
+
|
460
|
+
after { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><PurchaseAmountScr>200</PurchaseAmountScr></Message>'}) }
|
461
|
+
end
|
462
|
+
|
463
|
+
context 'order already paid' do
|
464
|
+
it { controller.should_receive(:add_error).with('Order Already Paid Or Completed').and_return(true) }
|
465
|
+
it { @card_transaction.should_receive(:status=).with('successful').and_return(true) }
|
466
|
+
|
467
|
+
after { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><PurchaseAmountScr>200</PurchaseAmountScr></Message>'}) }
|
468
|
+
end
|
469
|
+
|
470
|
+
context 'order total is not same as card total' do
|
471
|
+
before do
|
472
|
+
order.stub(:completed?).and_return(false)
|
473
|
+
order.stub(:paid?).and_return(false)
|
474
|
+
order.stub(:total).and_return(100)
|
475
|
+
@card_transaction.stub(:amount).and_return(200)
|
476
|
+
end
|
477
|
+
it { controller.should_receive(:add_error).with("Payment made is different from order total. Payment made has been walleted to your account.").and_return(true) }
|
478
|
+
it { @card_transaction.should_receive(:status=).with('successful').and_return(true) }
|
479
|
+
it { @card_transaction.should_receive(:save).with(:validate => false).and_return(true) }
|
480
|
+
|
481
|
+
after { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><PurchaseAmountScr>200</PurchaseAmountScr></Message>'}) }
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
context 'not approved at gateway' do
|
488
|
+
before do
|
489
|
+
@card_transaction.stub(:approved_at_gateway?).and_return(false)
|
490
|
+
end
|
491
|
+
|
492
|
+
describe 'method calls' do
|
493
|
+
it { controller.should_receive(:add_error).with('Not Approved At Gateway').and_return(true) }
|
494
|
+
it { @card_transaction.should_not_receive(:amount) }
|
495
|
+
it { @card_transaction.should_not_receive(:status=) }
|
496
|
+
it { order.should_not_receive(:paid?) }
|
497
|
+
it { order.should_not_receive(:completed?) }
|
498
|
+
|
499
|
+
after { send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><PurchaseAmountScr>200</PurchaseAmountScr></Message>'}) }
|
500
|
+
end
|
501
|
+
|
502
|
+
it 'renders without layout' do
|
503
|
+
send_request({:xmlmsg => '<Message><Hash>Mymessage</Hash><PurchaseAmountScr>200</PurchaseAmountScr></Message>'})
|
504
|
+
response.should render_template(:approved, :layout => false)
|
505
|
+
end
|
506
|
+
end
|
507
|
+
end
|
508
|
+
end
|
509
|
+
end
|