tb_checkout 1.0.7 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb3fc1ae37d51e94af4338396c822e2d1392a17e
4
- data.tar.gz: 99c1376aef1929a46b5164a870d3b2b84e560236
3
+ metadata.gz: c5d9b2cc2e634754b468bb4fd031d82d7f903332
4
+ data.tar.gz: 8e88348699acf8e4d8aa2ad27afb6f8f123969df
5
5
  SHA512:
6
- metadata.gz: 6f7d66476d2a23b70f1a0feaa2671ce1f6c25138509da0eb54c0a4de9a8811353d58dfc3cdccabfc6463dbd901d345b94dfff94a5a18a744822b8c0abba2a628
7
- data.tar.gz: 1cfe8609867ef781b1bb6894f4a476bba0991c828cffbce5208964a1f63b2a95b0e5ad46ec3294c15e8fff70776620d22cc6b46e66255dddba61b69a55520b10
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.authorize!
30
- redirect_to confirm_tb_checkout_transaction_path(@transaction)
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
- self.with_lock(true) do
52
- if self.status != Status::PENDING
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::AUTHORIZED
73
- raise StandardError, 'Payment must be in Authorized state before capture'
60
+ if self.status != Status::PENDING
61
+ raise StandardError, 'Payment must be in Pending state before capture'
74
62
  end
75
- @response = TbCheckout.gateway.capture(amount_in_cents, self.gateway_transaction_id.to_s)
76
- if @response.success? || @response.params['action'] == 'PRIOR_AUTH_CAPTURE'
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 => '/'} do
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]
@@ -1,3 +1,3 @@
1
1
  module TbCheckout
2
- VERSION = "1.0.7"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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
@@ -0,0 +1,6 @@
1
+ # This migration comes from tb_core (originally 20150610143438)
2
+ class AddRequiresPasswordChangeToSpudUsers < ActiveRecord::Migration
3
+ def change
4
+ add_column :spud_users, :requires_password_change, :boolean, :default => false
5
+ end
6
+ end
@@ -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: 20140915234534) do
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", limit: 255
51
- t.string "last_name", limit: 255
52
- t.boolean "super_admin", limit: 1
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
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", limit: 255
66
- t.string "last_login_ip", limit: 255
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", limit: 255
70
- t.integer "spud_role_id", limit: 4
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", limit: 1, default: false
102
- t.boolean "is_abandoned", limit: 1, default: false
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.authorize! && t.capture! }
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.7
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: 2015-10-05 00:00:00.000000000 Z
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.1.0
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.1.0
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@westlakedesign.com
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/westlakedesign/tb_checkout
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.4.6
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 %>