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,28 @@
|
|
1
|
+
<h1>Unified Payment Transactions</h1>
|
2
|
+
<% if @card_transactions.present? %>
|
3
|
+
<table class="order-summary" cellspacing="0" cellpadding="0" border="0">
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Transaction Status</th>
|
7
|
+
<th>Transaction Number</th>
|
8
|
+
<th><%= Spree.t(:amount) %></th>
|
9
|
+
<th>Response(Code:Description)</th>
|
10
|
+
<th>Date</th>
|
11
|
+
</tr>
|
12
|
+
</thead>
|
13
|
+
<tbody>
|
14
|
+
<% @card_transactions.each do |card_transaction| %>
|
15
|
+
<tr class="<%= cycle('even', 'odd') %>">
|
16
|
+
<td><%= card_transaction.status.try(:capitalize) %></td>
|
17
|
+
<td><%= card_transaction.payment_transaction_id %></td>
|
18
|
+
<td><%= number_to_currency(card_transaction.amount) %></td>
|
19
|
+
<td>ApprovalCode:<%= card_transaction.approval_code %><br>ResponseCode:<%= card_transaction.response_status %><br>Description:<%= card_transaction.response_description%><br>Status:<%= card_transaction.gateway_order_status.capitalize %></td>
|
20
|
+
<td><%= card_transaction.created_at.strftime("%d %b %Y, %I:%M%p") %></td>
|
21
|
+
</tr>
|
22
|
+
<% end %>
|
23
|
+
</tbody>
|
24
|
+
</table>
|
25
|
+
<%= paginate @card_transactions %>
|
26
|
+
<% else %>
|
27
|
+
No Transactions
|
28
|
+
<% end %>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<div class="unified_message">
|
2
|
+
Transaction Reference : <span><%= session[:transaction_id] %></span><br>
|
3
|
+
Please note this unique key as it would be needed for further payment reference.</div>
|
4
|
+
<table id="personal_details">
|
5
|
+
<tr>
|
6
|
+
<td align="left" valign="top" width="100"><strong>Email</strong></td>
|
7
|
+
<td align="left" valign="top"><%= @order.email %></td>
|
8
|
+
</tr>
|
9
|
+
<% if current_spree_user %>
|
10
|
+
<% if current_spree_user.respond_to?(:full_name) %>
|
11
|
+
<tr>
|
12
|
+
<td align="left" valign="top"><strong>Name</strong></td>
|
13
|
+
<td align="left" valign="top"><%= current_spree_user.full_name %></td>
|
14
|
+
</tr>
|
15
|
+
<% end %>
|
16
|
+
<% if current_spree_user.respond_to?(:phone) %>
|
17
|
+
<tr>
|
18
|
+
<td align="left" valign="top"><strong>Phone</strong></td>
|
19
|
+
<td align="left" valign="top"><%= current_spree_user.phone %></td>
|
20
|
+
</tr>
|
21
|
+
<% end %>
|
22
|
+
<% end %>
|
23
|
+
<tr>
|
24
|
+
<td align="left" valign="top"><strong>Amount</strong></td>
|
25
|
+
<td align="left" valign="top"><%= @order.total %></td>
|
26
|
+
</tr>
|
27
|
+
<tr>
|
28
|
+
<td align="left" valign="top"><strong>Currency</strong></td>
|
29
|
+
<td align="left" valign="top"><%= Spree::Config[:currency] %></td>
|
30
|
+
</tr>
|
31
|
+
</table>
|
32
|
+
|
33
|
+
<div class="rows pt20"><%= link_to 'Cancel', checkout_state_path('payment'), :id => 'back-to-payment', :method => 'get', :class => 'button' %>
|
34
|
+
<%= button_to "Proceed To Payment", create_unified_transaction_path, :remote => true, :disable_with => "Please wait...", :id => 'confirm_payment' %>
|
35
|
+
</div>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
UNIFIED_XML_CONTENT_MAPPING = { :masked_pan => 'PAN', :customer_name => 'Name',
|
2
|
+
:transaction_date_and_time => 'TranDateTime', :transaction_amount => 'PurchaseAmountScr',
|
3
|
+
:transaction_currency => 'CurrencyScr', :approval_code => 'ApprovalCode'
|
4
|
+
}
|
5
|
+
TRANSACTION_LIFETIME = 5
|
6
|
+
ADMIN_EMAIL = "admin@#{Spree::Config[:site_name]}"
|
7
|
+
MERCHANT_NAME = "#{Spree::Config[:site_name]}"
|
8
|
+
MERCHANT_URL = "#{Spree::Config[:site_name]}"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Spree::Core::Engine.routes.prepend do
|
2
|
+
get '/unified_payments', :to => "unified_payments#index", :as => :unified_payments
|
3
|
+
get '/unified_payments/new', :to => "unified_payments#new", :as => :new_unified_transaction
|
4
|
+
post '/unified_payments/create', :to => "unified_payments#create", :as => :create_unified_transaction
|
5
|
+
post '/unified_payments/canceled', :to => "unified_payments#canceled", :as => :canceled_unified_payments
|
6
|
+
post '/unified_payments/declined', :to => "unified_payments#declined", :as => :declined_unified_payments
|
7
|
+
post '/unified_payments/approved', :to => "unified_payments#approved", :as => :approved_unified_payments
|
8
|
+
get '/unified_payments/declined', :to => redirect{ |p, request| '/' }
|
9
|
+
|
10
|
+
namespace :admin do
|
11
|
+
get '/unified_payments', :to => "unified_payments#index"
|
12
|
+
get '/unified_payments/receipt/:transaction_id', :to => "unified_payments#receipt", :as => :unified_payments_receipt
|
13
|
+
post '/unified_payments/query_gateway', :to => "unified_payments#query_gateway", :as => :unified_payments_query_gateway
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class AddTransactionFieldsToUnifiedPaymentTransactions < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
change_table :unified_payment_transactions do |t|
|
4
|
+
t.references :order
|
5
|
+
t.references :user
|
6
|
+
t.string :payment_transaction_id
|
7
|
+
t.datetime :expired_at
|
8
|
+
t.string :status
|
9
|
+
t.index :payment_transaction_id
|
10
|
+
t.index :order_id
|
11
|
+
t.index :user_id
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SpreeUnifiedPayment
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
def add_javascripts
|
6
|
+
append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_unified_payment\n"
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_stylesheets
|
10
|
+
inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_unified_payment\n", :before => /\*\//, :verbose => true
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_migrations
|
14
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_unified_payment'
|
15
|
+
end
|
16
|
+
|
17
|
+
def run_migrations
|
18
|
+
res = ask "Would you like to run the migrations now? [Y/n]"
|
19
|
+
if res == "" || res.downcase == "y"
|
20
|
+
run 'bundle exec rake db:migrate'
|
21
|
+
else
|
22
|
+
puts "Skiping rake db:migrate, don't forget to run it!"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SpreeUnifiedGateway
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_unified_payment'
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
8
|
+
|
9
|
+
# use rspec for tests
|
10
|
+
config.generators do |g|
|
11
|
+
g.test_framework :rspec
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.activate
|
15
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
16
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
initializer "spree.register.payment_methods" do |app|
|
21
|
+
app.config.spree.payment_methods << Spree::PaymentMethod::UnifiedPaymentMethod
|
22
|
+
end
|
23
|
+
|
24
|
+
config.to_prepare &method(:activate).to_proc
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Constants' do
|
4
|
+
it { UNIFIED_XML_CONTENT_MAPPING.should eq({ :masked_pan => 'PAN', :customer_name => 'Name',
|
5
|
+
:transaction_date_and_time => 'TranDateTime', :transaction_amount => 'PurchaseAmountScr',
|
6
|
+
:transaction_currency => 'CurrencyScr', :approval_code => 'ApprovalCode'}) }
|
7
|
+
it { TRANSACTION_LIFETIME.should eq 5 }
|
8
|
+
it { ADMIN_EMAIL.should eq "admin@#{Spree::Config[:site_name]}" }
|
9
|
+
it { MERCHANT_NAME.should eq "#{Spree::Config[:site_name]}" }
|
10
|
+
it { MERCHANT_URL.should eq "#{Spree::Config[:site_name]}" }
|
11
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Admin::UnifiedPaymentsController do
|
4
|
+
let(:user) { mock_model(Spree::User) }
|
5
|
+
let(:role) { mock_model(Spree::Role) }
|
6
|
+
let(:card_transaction) { UnifiedPayment::Transaction.new( :gateway_order_id => '123213', :gateway_session_id => '1212', :payment_transaction_id => '123456', :xml_response => '<Message>123</Message>') }
|
7
|
+
let(:order) { mock_model(Spree::Order) }
|
8
|
+
let(:roles) { [role] }
|
9
|
+
|
10
|
+
before do
|
11
|
+
controller.stub(:spree_current_user).and_return(user)
|
12
|
+
controller.stub(:authorize_admin).and_return(true)
|
13
|
+
controller.stub(:authorize!).and_return(true)
|
14
|
+
user.stub(:generate_spree_api_key!).and_return(true)
|
15
|
+
user.stub(:roles).and_return(roles)
|
16
|
+
roles.stub(:includes).and_return(roles)
|
17
|
+
role.stub(:ability).and_return(true)
|
18
|
+
card_transaction.stub(:order).and_return(order)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#index' do
|
22
|
+
def send_request(params = {})
|
23
|
+
get :index, params.merge!(:use_route => 'spree', :page => 0)
|
24
|
+
end
|
25
|
+
|
26
|
+
before do
|
27
|
+
UnifiedPayment::Transaction.stub(:order).with('updated_at desc').and_return(UnifiedPayment::Transaction)
|
28
|
+
UnifiedPayment::Transaction.stub(:ransack).with({}).and_return(UnifiedPayment::Transaction)
|
29
|
+
UnifiedPayment::Transaction.stub_chain(:result, :page, :per).with().with(0).with(20).and_return([card_transaction])
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'method calls' do
|
33
|
+
it { UnifiedPayment::Transaction.should_receive(:order).with('updated_at desc').and_return(UnifiedPayment::Transaction) }
|
34
|
+
it { UnifiedPayment::Transaction.should_receive(:ransack).with({}).and_return(UnifiedPayment::Transaction) }
|
35
|
+
it { UnifiedPayment::Transaction.should_receive(:result) }
|
36
|
+
it { UnifiedPayment::Transaction.result.page(0).per(20).should eq([card_transaction]) }
|
37
|
+
|
38
|
+
after do
|
39
|
+
send_request
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'assigns' do
|
44
|
+
it 'card_transactions' do
|
45
|
+
send_request
|
46
|
+
assigns(:card_transactions).should eq([card_transaction])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#receipt' do
|
52
|
+
def send_request(params = {})
|
53
|
+
get :receipt, params.merge!(:use_route => 'spree')
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'Transaction present' do
|
57
|
+
before do
|
58
|
+
UnifiedPayment::Transaction.stub(:where).with(:payment_transaction_id => '123456').and_return([card_transaction])
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'method calls' do
|
62
|
+
it { UnifiedPayment::Transaction.should_receive(:where).with(:payment_transaction_id => '123456').and_return([card_transaction]) }
|
63
|
+
it { card_transaction.should_receive(:order).and_return(order)}
|
64
|
+
|
65
|
+
after do
|
66
|
+
send_request(:transaction_id => '123456')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should render no layout' do
|
71
|
+
send_request(:transaction_id => '123456')
|
72
|
+
response.should render_template(:layout => false)
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'assigns' do
|
76
|
+
before do
|
77
|
+
send_request(:transaction_id => '123456')
|
78
|
+
end
|
79
|
+
|
80
|
+
it { assigns(:message).should eq('123') }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'No transaction present' do
|
85
|
+
before do
|
86
|
+
UnifiedPayment::Transaction.stub(:where).with(:payment_transaction_id => '123456').and_return([])
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'method calls' do
|
90
|
+
it { UnifiedPayment::Transaction.should_receive(:where).with(:payment_transaction_id => '123456').and_return([]) }
|
91
|
+
it { card_transaction.should_not_receive(:order) }
|
92
|
+
|
93
|
+
after do
|
94
|
+
send_request(:transaction_id => '123456')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'renders js' do
|
99
|
+
send_request(:transaction_id => '123456')
|
100
|
+
response.body.should eq("alert('Could not find transaction')")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#query_gateway' do
|
106
|
+
def send_request(params = {})
|
107
|
+
get :query_gateway, params.merge!(:use_route => 'spree', :format => 'js')
|
108
|
+
end
|
109
|
+
|
110
|
+
before do
|
111
|
+
card_transaction.stub(:update_transaction_on_query).with("MyStatus").and_return(true)
|
112
|
+
UnifiedPayment::Transaction.stub(:where).with(:payment_transaction_id => '123456').and_return([card_transaction])
|
113
|
+
UnifiedPayment::Client.stub(:get_order_status).with(card_transaction.gateway_order_id, card_transaction.gateway_session_id).and_return({"orderStatus" => 'MyStatus'})
|
114
|
+
end
|
115
|
+
|
116
|
+
describe 'method calls' do
|
117
|
+
it { UnifiedPayment::Client.should_receive(:get_order_status).with(card_transaction.gateway_order_id, card_transaction.gateway_session_id).and_return({"orderStatus" => 'MyStatus'}) }
|
118
|
+
it { card_transaction.should_receive(:update_transaction_on_query).with('MyStatus').and_return(true) }
|
119
|
+
after do
|
120
|
+
send_request(:transaction_id => '123456')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe 'before filters' do
|
125
|
+
describe 'load_transactions' do
|
126
|
+
it { UnifiedPayment::Transaction.should_receive(:where).with(:payment_transaction_id => '123456').and_return([card_transaction]) }
|
127
|
+
|
128
|
+
after do
|
129
|
+
send_request(:transaction_id => '123456')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'approved status fetched' do
|
135
|
+
before do
|
136
|
+
UnifiedPayment::Client.stub(:get_order_status).with(card_transaction.gateway_order_id, card_transaction.gateway_session_id).and_return({"orderStatus" => 'APPROVED'})
|
137
|
+
card_transaction.stub(:update_transaction_on_query).with('APPROVED').and_return(true)
|
138
|
+
end
|
139
|
+
|
140
|
+
it { card_transaction.should_receive(:update_transaction_on_query).with('APPROVED').and_return(true) }
|
141
|
+
|
142
|
+
after do
|
143
|
+
send_request(:transaction_id => '123456')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'approved status not fetched' do
|
148
|
+
it { card_transaction.should_receive(:update_transaction_on_query).with('MyStatus') }
|
149
|
+
|
150
|
+
after do
|
151
|
+
send_request(:transaction_id => '123456')
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::CheckoutController do
|
4
|
+
let(:user) { mock_model(Spree.user_class) }
|
5
|
+
let(:role) { mock_model(Spree::Role) }
|
6
|
+
let(:roles) { [role] }
|
7
|
+
let(:order) { mock_model(Spree::Order) }
|
8
|
+
let(:payment) { mock_model(Spree::Payment) }
|
9
|
+
let(:variant) { mock_model(Spree::Variant, :name => 'test-variant') }
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
controller.stub(:spree_current_user).and_return(user)
|
13
|
+
user.stub(:generate_spree_api_key!).and_return(true)
|
14
|
+
controller.stub(:authenticate_spree_user!).and_return(true)
|
15
|
+
user.stub(:roles).and_return(roles)
|
16
|
+
controller.stub(:authorize!).and_return(true)
|
17
|
+
roles.stub(:includes).and_return(roles)
|
18
|
+
role.stub(:ability).and_return(true)
|
19
|
+
user.stub(:last_incomplete_spree_order).and_return(nil)
|
20
|
+
controller.stub(:load_order).and_return(true)
|
21
|
+
|
22
|
+
controller.stub(:ensure_order_not_completed).and_return(true)
|
23
|
+
controller.stub(:ensure_checkout_allowed).and_return(true)
|
24
|
+
controller.stub(:ensure_sufficient_stock_lines).and_return(true)
|
25
|
+
controller.stub(:ensure_valid_state).and_return(true)
|
26
|
+
controller.stub(:ensure_active_variants).and_return(true)
|
27
|
+
|
28
|
+
controller.stub(:associate_user).and_return(true)
|
29
|
+
controller.stub(:check_authorization).and_return(true)
|
30
|
+
controller.stub(:object_params).and_return('object_params')
|
31
|
+
controller.stub(:after_update_attributes).and_return(false)
|
32
|
+
controller.instance_variable_set(:@order, order)
|
33
|
+
order.stub(:has_checkout_step?).with('payment').and_return(true)
|
34
|
+
order.stub(:payment?).and_return(false)
|
35
|
+
order.stub(:update_attributes).and_return(false)
|
36
|
+
order.stub(:update_attributes).with('object_params').and_return(false)
|
37
|
+
@payments = [payment]
|
38
|
+
@payments.stub(:reload).and_return(true)
|
39
|
+
order.stub(:payments).and_return(@payments)
|
40
|
+
order.stub(:next).and_return(true)
|
41
|
+
order.stub(:completed?).and_return(false)
|
42
|
+
order.stub(:state).and_return('payment')
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#redirect_for_card_payment' do
|
46
|
+
def send_request(params = {})
|
47
|
+
put :update, params.merge!({:use_route => 'spree'})
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'if payment state' do
|
51
|
+
before do
|
52
|
+
@payment_method = mock_model(Spree::PaymentMethod, :type => 'Spree::PaymentMethod::UnifiedPaymentMethod')
|
53
|
+
@payment_method.stub(:is_a?).with(Spree::PaymentMethod::UnifiedPaymentMethod).and_return(true)
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when params[:order].present?' do
|
57
|
+
before { Spree::PaymentMethod.stub(:where).with(:id => '1').and_return([@payment_method]) }
|
58
|
+
|
59
|
+
describe 'method calls' do
|
60
|
+
it { order.should_receive(:update_attributes).with('object_params').and_return(false) }
|
61
|
+
it { @payment_method.should_receive(:is_a?).with(Spree::PaymentMethod::UnifiedPaymentMethod).and_return(true) }
|
62
|
+
it { Spree::PaymentMethod.should_receive(:where).with(:id => '1').and_return([@payment_method]) }
|
63
|
+
it { order.should_not_receive(:update) }
|
64
|
+
after { send_request({"order"=>{"payments_attributes"=>[{"payment_method_id"=>"1"}]}, "state"=>"payment"}) }
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should redirect to unified_payment#new' do
|
68
|
+
send_request({"order"=>{"payments_attributes"=>[{"payment_method_id"=>"1"}]}, "state"=>"payment"})
|
69
|
+
response.should redirect_to(new_unified_transaction_path)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when !params[:order].present?' do
|
74
|
+
it 'should not redirect to unified_payment#new' do
|
75
|
+
send_request({"state" => "payment"})
|
76
|
+
response.should_not redirect_to(new_unified_transaction_path)
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'method calls' do
|
80
|
+
it { order.should_receive(:update_attributes).with('object_params').exactly(1).times.and_return(true) }
|
81
|
+
it { Spree::PaymentMethod.should_receive(:where).with(:id => nil).and_return([]) }
|
82
|
+
after do
|
83
|
+
send_request({"state" => "payment"})
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when !params[:order][:payments_attributes].present?' do
|
89
|
+
it 'should not redirect to pay_by_card#new' do
|
90
|
+
send_request({"state" => "payment"})
|
91
|
+
response.should_not redirect_to(new_unified_transaction_path)
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'method calls' do
|
95
|
+
it { order.should_not_receive(:update) }
|
96
|
+
it { order.should_receive(:update_attributes).with('object_params').exactly(1).times.and_return(true) }
|
97
|
+
it { Spree::PaymentMethod.should_receive(:where).with(:id => nil).and_return([]) }
|
98
|
+
after do
|
99
|
+
send_request({"order"=>{"payments_attributes"=>[{}]}, "state"=>"payment"})
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'if not payment state' do
|
106
|
+
it { Spree::PaymentMethod.should_not_receive(:where).with(:id => '1') }
|
107
|
+
it { controller.should_not_receive(:redirect_for_card_payment) }
|
108
|
+
|
109
|
+
after do
|
110
|
+
send_request({"order"=>{"payments_attributes"=>[{"payment_method_id"=>"1"}]}, "state"=>"delivery"})
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|