spree_purchase_order 2.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b9a8504276f0c6890041da69baa3711d5d1e919
4
+ data.tar.gz: 7b9f791ccf2ab1c9c743c4acc82a800aa80d2ba7
5
+ SHA512:
6
+ metadata.gz: 39f2e8b06c4be4e1e624ef0acb5fff39182e023a3e61cb9090f2bf9bdf275ae336bfa5b118e0e4a9a8488fbf9ff1731debfd50a3133ed824940fe9d67e18bf38
7
+ data.tar.gz: 9d1fe6b26136e116d9096759c7dd2a1149334b6139c62642c1084c5887232184f9cfc8814d1e3714e33fc1129eda2a91379ad302b3c715296d0655e288a0f039
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Deepak Mahakale
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Spree Purchase Order
2
+
3
+ Add Purchase Order payment method in Spree
4
+
5
+ ## Installation
6
+
7
+ 1. Add this line to your Gemfile:
8
+
9
+ gem 'spree_purchase_order'
10
+
11
+ 2. Install the gem using Bundler:
12
+
13
+ bundle install
14
+
15
+ 3. Copy & run migrations
16
+
17
+ bundle exec rails g spree_purchase_order:install
18
+
19
+ 3. Restart your server
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SpreePurchaseOrder'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+ task default: :test
@@ -0,0 +1 @@
1
+ //= require admin/spree_backend
@@ -0,0 +1 @@
1
+ //= require store/spree_frontend
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require admin/spree_backend
3
+ */
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require store/spree_frontend
3
+ */
@@ -0,0 +1,15 @@
1
+ Spree::Order.class_eval do
2
+ def authorize_digital?
3
+ return true if paid?
4
+ if pay_with_po?
5
+ payments.each do |payment|
6
+ return true if payment.po? && payment.source.attachment_file_name
7
+ end
8
+ return false
9
+ end
10
+ end
11
+
12
+ def pay_with_po?
13
+ payments.collect(&:po?).include?(true)
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ Spree::Payment::Processing.class_eval do
2
+ def purchase!
3
+ started_processing!
4
+ if source.class == Spree::PurchaseOrder
5
+ gateway_action(source, :authorize, :pend)
6
+ else
7
+ gateway_action(source, :purchase, :complete)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ Spree::Payment.class_eval do
2
+ attr_accessible :source, :source_type, :number, :contact_email, :contact_name, :invoice_date
3
+ has_one :purchase_order
4
+
5
+ def po?
6
+ payment_method.type == 'Spree::PaymentMethod::PurchaseOrder'
7
+ end
8
+ end
@@ -0,0 +1,39 @@
1
+ module Spree
2
+ class PaymentMethod::PurchaseOrder < PaymentMethod
3
+ def payment_source_class
4
+ Spree::PurchaseOrder
5
+ end
6
+
7
+ def actions
8
+ %w(complete void)
9
+ end
10
+
11
+ def can_complete?(payment)
12
+ %w(checkout pending).include?(payment.state)
13
+ end
14
+
15
+ def can_void?(payment)
16
+ payment.state != 'void'
17
+ end
18
+
19
+ def authorize(*args)
20
+ ActiveMerchant::Billing::Response.new(true, 'Purchase Order: Success', {}, {})
21
+ end
22
+
23
+ def complete(*)
24
+ ActiveMerchant::Billing::Response.new(true, 'Purchase Order: Success', {}, {})
25
+ end
26
+
27
+ def void(*args)
28
+ ActiveMerchant::Billing::Response.new(true, '', {}, {})
29
+ end
30
+
31
+ def source_required?
32
+ true
33
+ end
34
+
35
+ def auto_capture?
36
+ false
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,7 @@
1
+ module Spree
2
+ class PurchaseOrder < ActiveRecord::Base
3
+ has_one :payment, as: :source
4
+ attr_accessible :po_number, :organization_name
5
+ validates_presence_of :po_number, :organization_name
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ <div class='well clearfix'>
2
+ <% param_prefix = "payment_source[#{payment_method.id}]" %>
3
+ <p class='field'>
4
+ <%= label_tag :po_number do %>
5
+ PO Number<abbr class='required' title='required'>*</abbr>
6
+ <% end %>
7
+ <%= text_field_tag "#{param_prefix}[po_number]", '', id: :po_number, class: 'form-control required', size: 10, maxlength: 10, autocomplete: "off" %>
8
+ </p>
9
+ <p class='field'>
10
+ <%= label_tag :organization_name do %>
11
+ Organization Name<abbr class='required' title='required'>*</abbr>
12
+ <% end %>
13
+ <%= text_field_tag "#{param_prefix}[organization_name]", '', id: :organization_name, class: 'form-control required'%>
14
+ </p>
15
+ </div>
@@ -0,0 +1,26 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ activerecord:
24
+ attributes:
25
+ spree/purchase_order:
26
+ po_number: Purchase order number
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ # Add your extension routes here
3
+ end
@@ -0,0 +1,10 @@
1
+ class CreateSpreePurchaseOrders < ActiveRecord::Migration
2
+ def change
3
+ create_table :spree_purchase_orders do |t|
4
+ t.string :po_number
5
+ t.string :organization_name
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class AddPoNumberToSpreePayments < ActiveRecord::Migration
2
+ def change
3
+ add_column :spree_payments, :po_number, :string
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ module SpreePurchaseOrder
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ def add_javascripts
6
+ append_file 'app/assets/javascripts/store/all.js', "//= require store/spree_purchase_order\n"
7
+ append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_purchase_order\n"
8
+ end
9
+
10
+ def add_stylesheets
11
+ inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_purchase_order\n", before: /\*\//, verbose: true
12
+ inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/spree_purchase_order\n", before: /\*\//, verbose: true
13
+ end
14
+
15
+ def add_migrations
16
+ run 'bundle exec rake railties:install:migrations FROM=spree_purchase_order'
17
+ end
18
+
19
+ def run_migrations
20
+ res = ask 'Would you like to run the migrations now? [Y/n]'
21
+ if res == '' || res.downcase == 'y'
22
+ run 'bundle exec rake db:migrate'
23
+ else
24
+ puts "Skiping rake db:migrate, don't forget to run it!"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ module SpreePurchaseOrder
2
+ class Engine < ::Rails::Engine
3
+ require 'spree/core'
4
+ isolate_namespace Spree
5
+ engine_name 'spree_purchase_order'
6
+
7
+ config.autoload_paths << "#{config.root}/lib"
8
+
9
+ config.generators do |g|
10
+ g.test_framework :rspec
11
+ end
12
+
13
+ def self.activate
14
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
15
+ Rails.configuration.cache_classes ? require(c) : load(c)
16
+ end
17
+ end
18
+
19
+ config.to_prepare &method(:activate).to_proc
20
+
21
+ config.after_initialize do |app|
22
+ app.config.spree.payment_methods << Spree::PaymentMethod::PurchaseOrder
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module SpreePurchaseOrder
2
+ VERSION = '2.0.1'
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'spree_core'
2
+ require 'spree_purchase_order/engine'
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_purchase_order
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Deepak Mahakale
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: spree_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ description: Adds Purchase Order as a Payment Method to Spree Commerce
28
+ email: deepakmahakale@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - MIT-LICENSE
34
+ - README.md
35
+ - Rakefile
36
+ - app/assets/javascripts/admin/spree_purchase_order.js
37
+ - app/assets/javascripts/store/spree_purchase_order.js
38
+ - app/assets/stylesheets/admin/spree_purchase_order.css
39
+ - app/assets/stylesheets/store/spree_purchase_order.css
40
+ - app/models/spree/order_decorator.rb
41
+ - app/models/spree/payment/processing_decorator.rb
42
+ - app/models/spree/payment_decorator.rb
43
+ - app/models/spree/payment_method/purchase_order.rb
44
+ - app/models/spree/purchase_order.rb
45
+ - app/views/spree/checkout/payment/_purchaseorder.html.erb
46
+ - config/locales/en.yml
47
+ - config/routes.rb
48
+ - db/migrate/20160111123141_create_spree_purchase_orders.rb
49
+ - db/migrate/20160111163926_add_po_number_to_spree_payments.rb
50
+ - lib/generators/spree_purchase_order/install/install_generator.rb
51
+ - lib/spree_purchase_order.rb
52
+ - lib/spree_purchase_order/engine.rb
53
+ - lib/spree_purchase_order/version.rb
54
+ homepage: https://github.com/deepakmahakale/spree_purchase_order
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 1.9.3
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements:
73
+ - none
74
+ rubyforge_project:
75
+ rubygems_version: 2.5.1
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Adds Purchase Order as a Payment Method to Spree Commerce
79
+ test_files: []