tb_checkout 1.0.7 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/tb_checkout/transactions_controller.rb +3 -27
- data/app/models/tb_checkout/transaction.rb +6 -18
- data/app/views/tb_checkout/transactions/new.html.erb +1 -1
- data/config/routes.rb +1 -4
- data/lib/tb_checkout/version.rb +1 -1
- data/spec/controllers/tb_checkout/transactions_controller_spec.rb +0 -14
- data/spec/dummy/db/migrate/20160523163605_add_requires_password_change_to_spud_users.tb_core.rb +6 -0
- data/spec/dummy/db/schema.rb +20 -19
- data/spec/factories/tb_checkout_transactions.rb +1 -4
- data/spec/models/tb_checkout/transaction_spec.rb +34 -0
- metadata +9 -8
- data/app/views/tb_checkout/transactions/confirm.html.erb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5d9b2cc2e634754b468bb4fd031d82d7f903332
|
4
|
+
data.tar.gz: 8e88348699acf8e4d8aa2ad27afb6f8f123969df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c776ebaa8d81fa3d82a1f13a58a1d2f1246442712ac55a59b527686bc3e6b1addf66dd519b78b312dfc515dea13b4cc4966886581bbf569169e5bfc9fc80966
|
7
|
+
data.tar.gz: cf4bb9f72a253f3430ac6ab3de8e7896dbee3591cab4743f44409882a836e4bb580708c5a6987cd78c7f5ab5bf6a1bdb06592abcb52f4a818cad4872ffbb95a5
|
@@ -26,8 +26,9 @@ class TbCheckout::TransactionsController < TbCheckout::ApplicationController
|
|
26
26
|
def create
|
27
27
|
@transaction = @cart.transactions.new(transaction_params)
|
28
28
|
@transaction.session_id = session.id
|
29
|
-
if @transaction.save() && @transaction.
|
30
|
-
|
29
|
+
if @transaction.save() && @transaction.capture!
|
30
|
+
flash[:notice] = 'Thanks! Your payment was collected successfully'
|
31
|
+
redirect_to tb_checkout_transaction_path(@transaction)
|
31
32
|
else
|
32
33
|
if @transaction.response
|
33
34
|
flash.now[:error] = @transaction.response.message
|
@@ -39,31 +40,6 @@ class TbCheckout::TransactionsController < TbCheckout::ApplicationController
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
def confirm
|
43
|
-
@transaction = @cart.transactions.authorized.where(:id => params[:id]).first
|
44
|
-
if @transaction.blank?
|
45
|
-
redirect_to new_tb_checkout_transaction_path
|
46
|
-
else
|
47
|
-
render 'confirm'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def capture
|
52
|
-
@transaction = @cart.transactions.authorized.where(:id => params[:id]).first
|
53
|
-
if @transaction.blank?
|
54
|
-
redirect_to new_tb_checkout_transaction_path
|
55
|
-
return false
|
56
|
-
else
|
57
|
-
if @transaction.capture!
|
58
|
-
flash[:notice] = 'Thanks! Your payment was collected successfully'
|
59
|
-
redirect_to tb_checkout_transaction_path(@transaction)
|
60
|
-
else
|
61
|
-
flash.now[:error] = @transaction.response.message if @transaction.response
|
62
|
-
render 'confirm'
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
43
|
def show
|
68
44
|
@transaction = TbCheckout::Transaction.captured.find_by(:id => params[:id])
|
69
45
|
if @transaction.present? && @transaction.belongs_to?(user_id:current_user_id, session_id:session.id)
|
@@ -48,20 +48,8 @@ module TbCheckout
|
|
48
48
|
#
|
49
49
|
# * The transaction must be in PENDING state in order ot take this action
|
50
50
|
def authorize!
|
51
|
-
|
52
|
-
|
53
|
-
raise StandardError, 'Payment must be in Pending state before authorization'
|
54
|
-
end
|
55
|
-
@response = TbCheckout.gateway.authorize(amount_in_cents, build_credit_card(), build_purchase_options())
|
56
|
-
if @response.success?
|
57
|
-
self.update_columns(:status => Status::AUTHORIZED, :gateway_transaction_id => @response.params['transaction_id'], :response_text => @response.to_json)
|
58
|
-
return true
|
59
|
-
else
|
60
|
-
self.update_columns(:status => Status::FAIL, :response_text => @response.to_json)
|
61
|
-
logger.fatal @response.inspect
|
62
|
-
return false
|
63
|
-
end
|
64
|
-
end
|
51
|
+
ActiveSupport::Deprecation.warn 'TbCheckout::Transaction#authorize! is deprecated and will be removed. Call capture! instead.', caller
|
52
|
+
return true
|
65
53
|
end
|
66
54
|
|
67
55
|
# Capture the funds from an authorized transaction through the payment gateway
|
@@ -69,11 +57,11 @@ module TbCheckout
|
|
69
57
|
# * The transaction must be in AUTHORIZED state in order ot take this action
|
70
58
|
def capture!
|
71
59
|
self.with_lock(true) do
|
72
|
-
if self.status != Status::
|
73
|
-
raise StandardError, 'Payment must be in
|
60
|
+
if self.status != Status::PENDING
|
61
|
+
raise StandardError, 'Payment must be in Pending state before capture'
|
74
62
|
end
|
75
|
-
@response = TbCheckout.gateway.
|
76
|
-
if @response.success?
|
63
|
+
@response = TbCheckout.gateway.purchase(amount_in_cents, build_credit_card(), build_purchase_options())
|
64
|
+
if @response.success?
|
77
65
|
self.update_columns(:status => Status::CAPTURED, :response_text => @response.to_json)
|
78
66
|
else
|
79
67
|
self.update_columns(:status => Status::FAIL, :response_text => @response.to_json)
|
@@ -80,7 +80,7 @@
|
|
80
80
|
|
81
81
|
<div class="form-group form-actions">
|
82
82
|
<div class="col-sm-offset-2 col-sm-10">
|
83
|
-
<%= f.submit 'Submit', :class => 'btn btn-primary' %>
|
83
|
+
<%= f.submit 'Submit', :class => 'btn btn-primary', :data => {:disable_with => 'Please wait...'} %>
|
84
84
|
<%= link_to 'Back', tb_checkout_cart_path, :class => 'btn btn-default' %>
|
85
85
|
</div>
|
86
86
|
</div>
|
data/config/routes.rb
CHANGED
@@ -6,10 +6,7 @@ Rails.application.routes.draw do
|
|
6
6
|
resources :cart_items, :only => [:create, :update, :destroy]
|
7
7
|
|
8
8
|
resources :transactions, :path => 'orders', :only => [:index, :show]
|
9
|
-
resources :transactions, :path => 'checkout', :only => [:new, :create], :path_names => {:new => '/'}
|
10
|
-
get :confirm, :on => :member
|
11
|
-
patch :capture, :on => :member
|
12
|
-
end
|
9
|
+
resources :transactions, :path => 'checkout', :only => [:new, :create], :path_names => {:new => '/'}
|
13
10
|
|
14
11
|
namespace :admin do
|
15
12
|
resources :carts, :only => [:index, :show]
|
data/lib/tb_checkout/version.rb
CHANGED
@@ -72,20 +72,6 @@ RSpec.describe TbCheckout::TransactionsController, :type => :controller do
|
|
72
72
|
post :create, :tb_checkout_transaction => FactoryGirl.attributes_for(:tb_checkout_transaction)
|
73
73
|
transaction = TbCheckout::Transaction.last
|
74
74
|
expect(transaction).to_not eq(nil)
|
75
|
-
expect(response).to redirect_to(confirm_tb_checkout_transaction_path(transaction))
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should render the confirmation page" do
|
79
|
-
transaction = FactoryGirl.create(:tb_checkout_transaction, :authorized, :cart => controller.tb_checkout_current_cart)
|
80
|
-
get :confirm, :id => transaction.id
|
81
|
-
expect(response).to be_success
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should capture the transaction and redirect to the detail page" do
|
85
|
-
transaction = FactoryGirl.create(:tb_checkout_transaction, :authorized, :cart => controller.tb_checkout_current_cart)
|
86
|
-
patch :capture, :id => transaction.id
|
87
|
-
transaction.reload()
|
88
|
-
expect(transaction.status).to eq(TbCheckout::Transaction::Status::CAPTURED)
|
89
75
|
expect(response).to redirect_to(tb_checkout_transaction_path(transaction))
|
90
76
|
end
|
91
77
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20160523163605) do
|
15
15
|
|
16
16
|
create_table "spud_permissions", force: :cascade do |t|
|
17
17
|
t.string "name", limit: 255, null: false
|
@@ -47,27 +47,28 @@ ActiveRecord::Schema.define(version: 20140915234534) do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
create_table "spud_users", force: :cascade do |t|
|
50
|
-
t.string "first_name",
|
51
|
-
t.string "last_name",
|
52
|
-
t.boolean "super_admin"
|
53
|
-
t.string "login",
|
54
|
-
t.string "email",
|
55
|
-
t.string "crypted_password",
|
56
|
-
t.string "password_salt",
|
57
|
-
t.string "persistence_token",
|
58
|
-
t.string "single_access_token",
|
59
|
-
t.string "perishable_token",
|
60
|
-
t.integer "login_count",
|
61
|
-
t.integer "failed_login_count",
|
50
|
+
t.string "first_name", limit: 255
|
51
|
+
t.string "last_name", limit: 255
|
52
|
+
t.boolean "super_admin"
|
53
|
+
t.string "login", limit: 255, null: false
|
54
|
+
t.string "email", limit: 255, null: false
|
55
|
+
t.string "crypted_password", limit: 255, null: false
|
56
|
+
t.string "password_salt", limit: 255, null: false
|
57
|
+
t.string "persistence_token", limit: 255, null: false
|
58
|
+
t.string "single_access_token", limit: 255, null: false
|
59
|
+
t.string "perishable_token", limit: 255, null: false
|
60
|
+
t.integer "login_count", limit: 4, default: 0, null: false
|
61
|
+
t.integer "failed_login_count", limit: 4, default: 0, null: false
|
62
62
|
t.datetime "last_request_at"
|
63
63
|
t.datetime "current_login_at"
|
64
64
|
t.datetime "last_login_at"
|
65
|
-
t.string "current_login_ip",
|
66
|
-
t.string "last_login_ip",
|
65
|
+
t.string "current_login_ip", limit: 255
|
66
|
+
t.string "last_login_ip", limit: 255
|
67
67
|
t.datetime "created_at"
|
68
68
|
t.datetime "updated_at"
|
69
|
-
t.string "time_zone",
|
70
|
-
t.integer "spud_role_id",
|
69
|
+
t.string "time_zone", limit: 255
|
70
|
+
t.integer "spud_role_id", limit: 4
|
71
|
+
t.boolean "requires_password_change", default: false
|
71
72
|
end
|
72
73
|
|
73
74
|
add_index "spud_users", ["email"], name: "index_spud_users_on_email", using: :btree
|
@@ -98,8 +99,8 @@ ActiveRecord::Schema.define(version: 20140915234534) do
|
|
98
99
|
create_table "tb_checkout_carts", force: :cascade do |t|
|
99
100
|
t.integer "spud_user_id", limit: 4
|
100
101
|
t.string "session_id", limit: 32
|
101
|
-
t.boolean "is_completed",
|
102
|
-
t.boolean "is_abandoned",
|
102
|
+
t.boolean "is_completed", default: false
|
103
|
+
t.boolean "is_abandoned", default: false
|
103
104
|
t.datetime "created_at"
|
104
105
|
t.datetime "updated_at"
|
105
106
|
end
|
@@ -29,11 +29,8 @@ FactoryGirl.define do
|
|
29
29
|
billing_state "IN"
|
30
30
|
billing_postal 46032
|
31
31
|
|
32
|
-
trait :authorized do
|
33
|
-
after(:create) { |t| t.authorize! }
|
34
|
-
end
|
35
32
|
trait :captured do
|
36
|
-
after(:create) { |t| t.
|
33
|
+
after(:create) { |t| t.capture! }
|
37
34
|
end
|
38
35
|
end
|
39
36
|
end
|
@@ -4,4 +4,38 @@ RSpec.describe TbCheckout::Transaction, :type => :model do
|
|
4
4
|
pending "add some examples to (or delete) #{__FILE__}"
|
5
5
|
|
6
6
|
it_behaves_like 'belongs_to_spud_user_session', :tb_checkout_transaction
|
7
|
+
|
8
|
+
let(:transaction) {
|
9
|
+
FactoryGirl.create(:tb_checkout_transaction)
|
10
|
+
}
|
11
|
+
|
12
|
+
describe '#capture' do
|
13
|
+
context 'when successful' do
|
14
|
+
it 'makes a purchase' do
|
15
|
+
expect {
|
16
|
+
transaction.capture!
|
17
|
+
}.to change(transaction, :status).to('captured')
|
18
|
+
end
|
19
|
+
it 'updates the cart' do
|
20
|
+
transaction.capture!
|
21
|
+
expect(transaction.cart.is_completed).to eq(true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#build_credit_card' do
|
27
|
+
it 'returns a credit card' do
|
28
|
+
result = transaction.send(:build_credit_card)
|
29
|
+
expect(result).to be_a(ActiveMerchant::Billing::CreditCard)
|
30
|
+
expect(result.first_name).to eq(transaction.billing_first_name)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#build_purchase_options' do
|
35
|
+
it 'returns some options' do
|
36
|
+
result = transaction.send(:build_purchase_options)
|
37
|
+
expect(result).to be_a(Hash)
|
38
|
+
expect(result[:email]).to eq(transaction.cart.spud_user.email)
|
39
|
+
end
|
40
|
+
end
|
7
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tb_checkout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Westlake Design
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tb_core
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
61
|
+
version: 3.4.2
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.
|
68
|
+
version: 3.4.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: factory_girl_rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,7 +111,7 @@ dependencies:
|
|
111
111
|
description: TB Checkout is a shopping cart and payments system designed for use with
|
112
112
|
Twice Baked and Active Merchant
|
113
113
|
email:
|
114
|
-
- greg@
|
114
|
+
- greg.woods@moserit.com
|
115
115
|
executables: []
|
116
116
|
extensions: []
|
117
117
|
extra_rdoc_files: []
|
@@ -161,7 +161,6 @@ files:
|
|
161
161
|
- app/views/tb_checkout/carts/_cart.html.erb
|
162
162
|
- app/views/tb_checkout/carts/show.html.erb
|
163
163
|
- app/views/tb_checkout/transactions/_details.html.erb
|
164
|
-
- app/views/tb_checkout/transactions/confirm.html.erb
|
165
164
|
- app/views/tb_checkout/transactions/index.html.erb
|
166
165
|
- app/views/tb_checkout/transactions/new.html.erb
|
167
166
|
- app/views/tb_checkout/transactions/show.html.erb
|
@@ -224,6 +223,7 @@ files:
|
|
224
223
|
- spec/dummy/db/migrate/20140915202270_create_tb_checkout_transactions.tb_checkout_engine.rb
|
225
224
|
- spec/dummy/db/migrate/20140915202271_create_tb_checkout_basic_products.tb_checkout_engine.rb
|
226
225
|
- spec/dummy/db/migrate/20140915234534_add_spud_user_and_session_id_to_transactions.tb_checkout_engine.rb
|
226
|
+
- spec/dummy/db/migrate/20160523163605_add_requires_password_change_to_spud_users.tb_core.rb
|
227
227
|
- spec/dummy/db/schema.rb
|
228
228
|
- spec/dummy/public/404.html
|
229
229
|
- spec/dummy/public/422.html
|
@@ -237,7 +237,7 @@ files:
|
|
237
237
|
- spec/models/tb_checkout/transaction_spec.rb
|
238
238
|
- spec/rails_helper.rb
|
239
239
|
- spec/spec_helper.rb
|
240
|
-
homepage: http://bitbucket.org/
|
240
|
+
homepage: http://bitbucket.org/moser-inc/tb_checkout
|
241
241
|
licenses:
|
242
242
|
- MIT
|
243
243
|
metadata: {}
|
@@ -257,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
257
|
version: '0'
|
258
258
|
requirements: []
|
259
259
|
rubyforge_project:
|
260
|
-
rubygems_version: 2.
|
260
|
+
rubygems_version: 2.5.1
|
261
261
|
signing_key:
|
262
262
|
specification_version: 4
|
263
263
|
summary: Simple shopping cart and checkout system for Twice Baked
|
@@ -306,6 +306,7 @@ test_files:
|
|
306
306
|
- spec/dummy/db/migrate/20140915202270_create_tb_checkout_transactions.tb_checkout_engine.rb
|
307
307
|
- spec/dummy/db/migrate/20140915202271_create_tb_checkout_basic_products.tb_checkout_engine.rb
|
308
308
|
- spec/dummy/db/migrate/20140915234534_add_spud_user_and_session_id_to_transactions.tb_checkout_engine.rb
|
309
|
+
- spec/dummy/db/migrate/20160523163605_add_requires_password_change_to_spud_users.tb_core.rb
|
309
310
|
- spec/dummy/db/schema.rb
|
310
311
|
- spec/dummy/public/404.html
|
311
312
|
- spec/dummy/public/422.html
|
@@ -1,11 +0,0 @@
|
|
1
|
-
<h1>Confirm Payment</h1>
|
2
|
-
|
3
|
-
<p>Click "Confirm" below to finish your transaction.</p>
|
4
|
-
|
5
|
-
<% cache [@transaction, 'details'] do %>
|
6
|
-
<%= render 'details' %>
|
7
|
-
<% end %>
|
8
|
-
|
9
|
-
<%= form_for [:capture, @transaction] do |f| %>
|
10
|
-
<%= f.submit 'Confirm', :class => 'btn btn-primary' %>
|
11
|
-
<% end %>
|