spree_cod_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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1e108c2072c150d4010dae6a8ec22b019b298b35c3257d27220c580e653b91e7
4
+ data.tar.gz: ab31c2451b46759b045e70e706faf7771037958be6229bc6ed9d7fb43bc9a256
5
+ SHA512:
6
+ metadata.gz: 74ea27e29d5686ee85cdfd7346322d7895a9c09bc374517a319e20f3ad18c228fc531f58205fc288db47214dbd6fc03cb8e46a420e8703d56ef5e268d05de901
7
+ data.tar.gz: 59f1cfa09909a6e9bf12e6d4446872987d773c8db7b1561e2c9a1d4b9b0975712d9b0f958875553715f80c6266472bcaf7477bbbbac792d438f8762d42e39883
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .localeapp/locales
7
+ .project
8
+ .vscode
9
+ coverage
10
+ default
11
+ Gemfile.lock
12
+ tmp
13
+ nbproject
14
+ pkg
15
+ *.sw?
16
+ spec/dummy
17
+ .rvmrc
18
+ .sass-cache
19
+ public/spree
20
+ .ruby-version
21
+ .ruby-gemset
22
+ *.gem
23
+ */*.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ -r spec_helper
3
+ -f documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ TargetRubyVersion: 2.5
4
+ Include:
5
+ - '**/Gemfile'
6
+ - '**/Rakefile'
7
+ - '**/Appraisals'
8
+ Exclude:
9
+ - 'spec/dummy/**/*'
10
+ - 'lib/generators/**/*'
11
+
12
+ Rails:
13
+ Enabled: true
14
+
15
+ Metrics/LineLength:
16
+ Max: 150
17
+
18
+ # DISABLED
19
+
20
+ Style/Documentation:
21
+ Enabled: false
22
+
23
+ Style/FrozenStringLiteralComment:
24
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,37 @@
1
+ os: linux
2
+ dist: bionic
3
+
4
+ addons:
5
+ apt:
6
+ sources:
7
+ - google-chrome
8
+ packages:
9
+ - google-chrome-stable
10
+
11
+ services:
12
+ - mysql
13
+ - postgresql
14
+
15
+ language: ruby
16
+
17
+ rvm:
18
+ - 2.7
19
+ - 3.0
20
+
21
+ env:
22
+ - DB=mysql
23
+ - DB=postgres
24
+
25
+ before_install:
26
+ - mysql -u root -e "GRANT ALL ON *.* TO 'travis'@'%';"
27
+
28
+ before_script:
29
+ - CHROME_MAIN_VERSION=`google-chrome-stable --version | sed -E 's/(^Google Chrome |\.[0-9]+ )//g'`
30
+ - CHROMEDRIVER_VERSION=`curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_MAIN_VERSION"`
31
+ - curl "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" -O
32
+ - unzip chromedriver_linux64.zip -d ~/bin
33
+ - nvm install 14
34
+
35
+ script:
36
+ - bundle exec rake test_app
37
+ - bundle exec rspec
data/CONTRIBUTING.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) do |repo_name|
4
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
5
+ "https://github.com/#{repo_name}.git"
6
+ end
7
+
8
+ spree_opts = '~> 4.3.2'
9
+ gem 'spree', spree_opts
10
+ gem 'spree_backend', spree_opts
11
+ gem 'rails-controller-testing'
12
+
13
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 OlympusOne
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # SpreeCodPayment
2
+
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/2d267f05a2c5bc404d1f/maintainability)](https://codeclimate.com/github/olympusone/spree_cod_payment/maintainability)
4
+
5
+ Spree Cash On Delivery Payment extension allows web store administrator to ship order before payment is done.
6
+
7
+ ## Installation
8
+
9
+ 1. Add this extension to your Gemfile with this line:
10
+
11
+ ```ruby
12
+ gem 'spree_cod_payment'
13
+ ```
14
+
15
+ 2. Install the gem using Bundler
16
+
17
+ ```ruby
18
+ bundle install
19
+ ```
20
+
21
+ 3. Restart your server
22
+
23
+ If your server was running, restart it so that it can find the assets properly.
24
+
25
+ ## Testing
26
+
27
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`.
28
+
29
+ ```shell
30
+ bundle
31
+ bundle exec rake
32
+ ```
33
+
34
+ When testing your applications integration with this extension you may use it's factories.
35
+ Simply add this require statement to your spec_helper:
36
+
37
+ ```ruby
38
+ require 'spree_cod_payment/factories'
39
+ ```
40
+
41
+ ## Releasing
42
+
43
+ ```shell
44
+ bundle exec gem bump -p -t
45
+ bundle exec gem release
46
+ ```
47
+
48
+ For more options please see [gem-release REAMDE](https://github.com/svenfuchs/gem-release)
49
+
50
+ ## Contributing
51
+
52
+ If you'd like to contribute, please take a look at the
53
+ [instructions](CONTRIBUTING.md) for installing dependencies and crafting a good
54
+ pull request.
55
+
56
+ Copyright (c) 2022 OlympusOne, released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/extension_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default do
10
+ if Dir['spec/dummy'].empty?
11
+ Rake::Task[:test_app].invoke
12
+ Dir.chdir('../../')
13
+ end
14
+ Rake::Task[:spec].invoke
15
+ end
16
+
17
+ desc 'Generates a dummy app for testing'
18
+ task :test_app do
19
+ ENV['LIB_NAME'] = 'spree_cod_payment'
20
+ Rake::Task['extension:test_app'].invoke
21
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+ module Spree::OrderDecorator
2
+ def self.prepended(base)
3
+ base.has_many :payment_adjustments, through: :payments, source: :adjustments
4
+ end
5
+
6
+ def cod_payment?
7
+ return false unless ship_address.country_iso == 'GR'
8
+
9
+ payments.where.not(state: ['failed', 'void'])
10
+ .map { |m| m.payment_method.type }
11
+ .include?("Spree::PaymentMethod::CodPayment")
12
+ end
13
+ end
14
+
15
+ ::Spree::Order.prepend(Spree::OrderDecorator)
@@ -0,0 +1,46 @@
1
+ module Spree::PaymentDecorator
2
+ def self.prepended(base)
3
+ base.has_one :adjustment, as: :source, dependent: :destroy
4
+
5
+ base.after_create :set_adjustment
6
+ base.before_update :update_adjustment
7
+ end
8
+
9
+ private
10
+
11
+ def set_adjustment
12
+ if payment_method.type == "Spree::PaymentMethod::CodPayment" && payment_method.charge && order.ship_address.country_iso == 'GR'
13
+ label = I18n.t('cod_payment.charge_label')
14
+
15
+ build_adjustment(
16
+ amount: payment_method.charge,
17
+ label: label,
18
+ order: order,
19
+ included: false,
20
+ state: 'closed',
21
+ adjustable: order
22
+ )
23
+
24
+ adjustment.save
25
+
26
+ order.update_totals
27
+ order.persist_totals
28
+
29
+ update_columns(
30
+ amount: order.total,
31
+ updated_at: Time.current
32
+ )
33
+ end
34
+ end
35
+
36
+ def update_adjustment
37
+ if payment_method.type == "Spree::PaymentMethod::CodPayment" && (void? || invalid?) && adjustment && order.ship_address.country_iso == 'GR'
38
+ adjustment.update(eligible: false)
39
+
40
+ order.update_totals
41
+ order.persist_totals
42
+ end
43
+ end
44
+ end
45
+
46
+ ::Spree::Payment.prepend(Spree::PaymentDecorator)
@@ -0,0 +1,50 @@
1
+ module Spree
2
+ class PaymentMethod::CodPayment < ::Spree::PaymentMethod
3
+ def payment_profiles_supported?
4
+ false # we do not want to show the confirm step
5
+ end
6
+
7
+ def actions
8
+ %w{capture void}
9
+ end
10
+
11
+ # Indicates whether its possible to capture the payment
12
+ def can_capture?(payment)
13
+ return false if payment.completed?
14
+
15
+ payment.order.shipments.all?{|shipment|shipment.state == 'shipped'} \
16
+ && ['checkout', 'pending'].include?(payment.state)
17
+ end
18
+
19
+ # Indicates whether its possible to void the payment.
20
+ def can_void?(payment)
21
+ payment.state != 'void'
22
+ end
23
+
24
+ def capture(*args)
25
+ ActiveMerchant::Billing::Response.new(true, "", {}, {})
26
+ end
27
+
28
+ def cancel(response); end
29
+
30
+ def void(*args)
31
+ ActiveMerchant::Billing::Response.new(true, "", {}, {})
32
+ end
33
+
34
+ def source_required?
35
+ false
36
+ end
37
+
38
+ def payment_source_class
39
+ nil
40
+ end
41
+
42
+ def method_type
43
+ 'cod_payment'
44
+ end
45
+
46
+ def cod_payment?
47
+ true
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ module Spree::PaymentMethodDecorator
2
+ def self.prepended(base)
3
+ base.preference :charge, :string
4
+ end
5
+
6
+ def charge
7
+ preferences[:charge].to_f
8
+ end
9
+ end
10
+
11
+ ::Spree::PaymentMethod.prepend(Spree::PaymentMethodDecorator)
@@ -0,0 +1,23 @@
1
+ module Spree::ShipmentDecorator
2
+ def determine_state(order)
3
+ return 'ready' if cod_payment? && !shipped?
4
+
5
+ return 'canceled' if order.canceled?
6
+ return 'pending' unless order.can_ship?
7
+ return 'pending' if inventory_units.any? &:backordered?
8
+ return 'shipped' if shipped?
9
+
10
+ return order.paid? || Spree::Config[:auto_capture_on_dispatch] ? 'ready' : 'pending'
11
+ end
12
+
13
+ private
14
+ def cod_payment?
15
+ return false unless order.ship_address.country_iso == 'GR'
16
+
17
+ order.payments.any? do |payment|
18
+ payment.payment_method.type == "Spree::PaymentMethod::CodPayment" && !payment.void?
19
+ end
20
+ end
21
+ end
22
+
23
+ ::Spree::Shipment.prepend(Spree::ShipmentDecorator)
@@ -0,0 +1,8 @@
1
+ module SpreeCodPayment
2
+ class Configuration < Spree::Preferences::Configuration
3
+ # Some example preferences are shown below, for more information visit:
4
+ # https://guides.spreecommerce.org/developer/core/preferences.html
5
+
6
+ # preference :cod_payment_charge, :decimal
7
+ end
8
+ end
File without changes
File without changes
data/bin/rails ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" from the root of your extension
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/spree_cod_payment/engine', __FILE__)
6
+
7
+ require 'rails/all'
8
+ require 'rails/engine/commands'
@@ -0,0 +1,5 @@
1
+ el:
2
+ spree:
3
+ charge: Χρέωση
4
+ cod_payment:
5
+ charge_label: Έξοδα αντικαταβολής
@@ -0,0 +1,3 @@
1
+ en:
2
+ cod_payment:
3
+ charge_label: Cash on delivery charge
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Spree::Core::Engine.add_routes do
2
+ # Add your extension routes here
3
+ end
@@ -0,0 +1,20 @@
1
+ module SpreeCodPayment
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ class_option :migrate, type: :boolean, default: true
5
+
6
+ def add_migrations
7
+ run 'bundle exec rake railties:install:migrations FROM=spree_cod_payment'
8
+ end
9
+
10
+ def run_migrations
11
+ run_migrations = options[:migrate] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
12
+ if run_migrations
13
+ run 'bundle exec rails db:migrate'
14
+ else
15
+ puts 'Skipping rails db:migrate, don\'t forget to run it!'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ module SpreeCodPayment
2
+ class Engine < Rails::Engine
3
+ require 'spree/core'
4
+ isolate_namespace Spree
5
+ engine_name 'spree_cod_payment'
6
+
7
+ # use rspec for tests
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ end
11
+
12
+ initializer 'spree.register.payment_methods', after: :after_initialize do |_app|
13
+ _app.config.spree.payment_methods << Spree::PaymentMethod::CodPayment
14
+ end
15
+
16
+ initializer 'spree_cod_payment.environment', before: :load_config_initializers do |_app|
17
+ SpreeCodPayment::Config = SpreeCodPayment::Configuration.new
18
+ end
19
+
20
+ def self.activate
21
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/spree/*_decorator*.rb')) do |c|
22
+ Rails.application.config.cache_classes ? require(c) : load(c)
23
+ end
24
+ end
25
+
26
+ config.to_prepare(&method(:activate).to_proc)
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
3
+ #
4
+ # Example adding this to your spec_helper will load these Factories for use:
5
+ # require 'spree_cod_payment/factories'
6
+ end
@@ -0,0 +1,11 @@
1
+ module SpreeCodPayment
2
+ VERSION = '1.0.0'.freeze
3
+
4
+ module_function
5
+
6
+ # Returns the version of the currently loaded SpreeCodPayment as a
7
+ # <tt>Gem::Version</tt>.
8
+ def version
9
+ Gem::Version.new VERSION
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ require 'spree_core'
2
+ require 'spree_api'
3
+ require 'spree_backend'
4
+ require 'spree_extension'
5
+ require 'spree_cod_payment/engine'
6
+ require 'spree_cod_payment/version'
@@ -0,0 +1,30 @@
1
+ # encoding: UTF-8
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'spree_cod_payment/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.platform = Gem::Platform::RUBY
9
+ s.name = 'spree_cod_payment'
10
+ s.version = SpreeCodPayment.version
11
+ s.summary = 'Spree Cash On Delivery Payment'
12
+ s.description = ''
13
+ s.required_ruby_version = '>= 2.5'
14
+
15
+ s.author = 'OlympusOne'
16
+ s.email = 'info@olympusone.com'
17
+ s.homepage = 'https://github.com/olympusone/spree_cod_payment'
18
+ s.license = 'MIT'
19
+
20
+ s.files = `git ls-files`.split("\n").reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }
21
+ s.require_path = 'lib'
22
+ s.requirements << 'none'
23
+
24
+ spree_version = '>= 4.3.2'
25
+ s.add_dependency 'spree', spree_version
26
+ s.add_dependency 'spree_backend', spree_version
27
+ s.add_dependency 'spree_extension'
28
+
29
+ s.add_development_dependency 'spree_dev_tools'
30
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_cod_payment
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - OlympusOne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: spree
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.3.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.3.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: spree_backend
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.3.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.3.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: spree_extension
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: spree_dev_tools
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ''
70
+ email: info@olympusone.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - ".rspec"
77
+ - ".rubocop.yml"
78
+ - ".travis.yml"
79
+ - CONTRIBUTING.md
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - app/assets/.gitkeep
85
+ - app/controllers/.gitkeep
86
+ - app/helpers/.gitkeep
87
+ - app/models/spree/order_decorator.rb
88
+ - app/models/spree/payment_decorator.rb
89
+ - app/models/spree/payment_method/cod_payment.rb
90
+ - app/models/spree/payment_method_decorator.rb
91
+ - app/models/spree/shipment_decorator.rb
92
+ - app/models/spree_cod_payment/configuration.rb
93
+ - app/serializers/.gitkeep
94
+ - app/services/.gitkeep
95
+ - app/views/spree/admin/payments/source_views/_cod_payment.html.erb
96
+ - bin/rails
97
+ - config/locales/el.yml
98
+ - config/locales/en.yml
99
+ - config/routes.rb
100
+ - lib/generators/spree_cod_payment/install/install_generator.rb
101
+ - lib/spree_cod_payment.rb
102
+ - lib/spree_cod_payment/engine.rb
103
+ - lib/spree_cod_payment/factories.rb
104
+ - lib/spree_cod_payment/version.rb
105
+ - spree_cod_payment.gemspec
106
+ homepage: https://github.com/olympusone/spree_cod_payment
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '2.5'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements:
125
+ - none
126
+ rubygems_version: 3.5.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Spree Cash On Delivery Payment
130
+ test_files: []