spree_komoju 0.0.2 → 0.0.3

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +16 -0
  5. data/Gemfile +8 -0
  6. data/LICENSE +26 -0
  7. data/README.md +39 -0
  8. data/Rakefile +21 -0
  9. data/app/assets/javascripts/spree/backend/spree_komoju.js +2 -0
  10. data/app/assets/javascripts/spree/frontend/spree_komoju.js +2 -0
  11. data/app/assets/stylesheets/spree/backend/spree_komoju.css +4 -0
  12. data/app/assets/stylesheets/spree/frontend/spree_komoju.css +4 -0
  13. data/app/controllers/spree/checkout_controller_decorator.rb +18 -0
  14. data/app/models/spree/bank_transfer.rb +26 -0
  15. data/app/models/spree/gateway/komoju_bank_transfer.rb +25 -0
  16. data/app/models/spree/gateway/komoju_credit_card.rb +40 -0
  17. data/app/models/spree/gateway/komoju_konbini.rb +23 -0
  18. data/app/models/spree/komoju_gateway.rb +51 -0
  19. data/app/models/spree/konbini.rb +32 -0
  20. data/app/overrides/add_instruction_to_order_show.rb +8 -0
  21. data/app/views/spree/admin/payments/source_views/_komoju_credit_card.html.erb +1 -0
  22. data/app/views/spree/admin/payments/source_views/_komoju_konbini.html.erb +25 -0
  23. data/app/views/spree/checkout/payment/_komoju_bank_transfer.html.erb +35 -0
  24. data/app/views/spree/checkout/payment/_komoju_credit_card.html.erb +1 -0
  25. data/app/views/spree/checkout/payment/_komoju_konbini.html.erb +11 -0
  26. data/app/views/spree/orders/_bank_transfer.html.erb +10 -0
  27. data/app/views/spree/orders/_konbini.html.erb +17 -0
  28. data/bin/rails +7 -0
  29. data/config/locales/en.yml +16 -0
  30. data/config/routes.rb +2 -0
  31. data/db/migrate/20150331051027_create_spree_konbinis.rb +18 -0
  32. data/db/migrate/20150401074721_create_spree_bank_transfers.rb +22 -0
  33. data/db/migrate/20151126050103_add_gateway_profile_ids_to_spree_konbinis.rb +6 -0
  34. data/lib/active_merchant/billing/gateways/komoju.rb +135 -0
  35. data/lib/generators/spree_komoju/install/images/circle-k.png +0 -0
  36. data/lib/generators/spree_komoju/install/images/daily-yamazaki.png +0 -0
  37. data/lib/generators/spree_komoju/install/images/family-mart.png +0 -0
  38. data/lib/generators/spree_komoju/install/images/lawson.png +0 -0
  39. data/lib/generators/spree_komoju/install/images/ministop.png +0 -0
  40. data/lib/generators/spree_komoju/install/images/seven-eleven.png +0 -0
  41. data/lib/generators/spree_komoju/install/images/sunkus.png +0 -0
  42. data/lib/generators/spree_komoju/install/install_generator.rb +36 -0
  43. data/lib/spree_komoju.rb +2 -0
  44. data/lib/spree_komoju/engine.rb +29 -0
  45. data/lib/spree_komoju/factories.rb +6 -0
  46. data/spec/controllers/spree/checkout_controller_spec.rb +13 -0
  47. data/spec/models/spree/bank_transfer_spec.rb +69 -0
  48. data/spec/models/spree/gateway/komoju_bank_transfer_spec.rb +59 -0
  49. data/spec/models/spree/gateway/komoju_credit_card_spec.rb +117 -0
  50. data/spec/models/spree/gateway/komoju_konbini_spec.rb +41 -0
  51. data/spec/models/spree/komoju_gateway_spec.rb +50 -0
  52. data/spec/models/spree/konbini_spec.rb +69 -0
  53. data/spec/spec_helper.rb +87 -0
  54. data/spree_komoju.gemspec +32 -0
  55. metadata +66 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d84887254aea0aabaafa1f4281797ac1d04fd5e
4
- data.tar.gz: 431bb1e03d7aa70c1075fe195a6cba6bf98c36ca
3
+ metadata.gz: a59f00120a8dee5f12decc447a0d680cb9fe1d0b
4
+ data.tar.gz: eed9feb3b0f69d63d6cbbe6facb03ea803f977fd
5
5
  SHA512:
6
- metadata.gz: 80d6e68c1fb6b3d3f1a1e8d90ff50ffa6ca2bb17db11064a737275061a4ad24856b38c77325a37500f9bfb66d7d2b60a0f7fa65ba56f4b45010479fa1edfda78
7
- data.tar.gz: 0fcd9412c4981152d076505c71e7494b7da243abf2b496585dbfa65801de1411e989c12d708790395596dd87e91d9fcc2ec1b7bbbc35e92fa67d6d39c3a0d45f
6
+ metadata.gz: afec5e66ccab75c9ae586f03bacc937cb529dda5e623dba4eb6c3b3929b39799e59eb4102b816ac576a7e59117c43aed8f750be9a62467be37d17614b93116eb
7
+ data.tar.gz: 73c41aeeef2f053578c00648945e3e94160c48e0a81dde828859a4bbb7305a4251b0c24b1432a606832b5622524b3a72388571eae57c3955e7f63b86d2d1630a
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ .sass-cache
8
+ coverage
9
+ Gemfile.lock
10
+ tmp
11
+ nbproject
12
+ pkg
13
+ *.swp
14
+ spec/dummy
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ script: bundle exec rspec
3
+ before_script:
4
+ - bundle exec rake test_app
5
+ cache: bundler
6
+ branches:
7
+ only:
8
+ - master
9
+ env:
10
+ global:
11
+ - RAILS_ENV=test
12
+ rvm:
13
+ - 2.2.3
14
+ notifications:
15
+ slack:
16
+ secure: P3aNJn3Wzvgt1m5aHZ/Pu0vRSgZ1q3vUnamOC+dTwapbuag2j0vHUR8kuzLaJCOHSsPWJ2wRwz31oNoYjrdqCBv1Ox9DpauVGsCvx+eYhHyaMCcSAY5tbGhgZT3U0UIwcE0oR0e68IbTAVFUAiBmYeQocLFMGVxy6HhPSLmKW9k=
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'spree', github: 'spree/spree', branch: '3-0-stable'
4
+ gem 'activemerchant', github: "komoju/active_merchant", branch: "add-komoju-gateway"
5
+ # Provides basic authentication functionality for testing parts of your engine
6
+ gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'
7
+
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2015 [name of plugin creator]
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ SpreeKomoju
2
+ ===========
3
+
4
+ Introduction goes here.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Add spree_komoju to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'spree_komoju'
13
+ ```
14
+
15
+ Bundle your dependencies and run the installation generator:
16
+
17
+ ```shell
18
+ bundle
19
+ bundle exec rails g spree_komoju:install
20
+ ```
21
+
22
+ Testing
23
+ -------
24
+
25
+ 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`.
26
+
27
+ ```shell
28
+ bundle
29
+ bundle exec rake
30
+ ```
31
+
32
+ When testing your applications integration with this extension you may use it's factories.
33
+ Simply add this require statement to your spec_helper:
34
+
35
+ ```ruby
36
+ require 'spree_komoju/factories'
37
+ ```
38
+
39
+ Copyright (c) 2015 [name of extension creator], 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_komoju'
20
+ Rake::Task['extension:test_app'].invoke
21
+ end
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js'
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js'
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
+ */
@@ -0,0 +1,18 @@
1
+ Spree::CheckoutController.class_eval do
2
+ def permitted_source_attributes
3
+ super.push(permitted_komoju_konbini_attributes)
4
+ super.push(permitted_komoju_banktransfer_attributes)
5
+ super.flatten
6
+ end
7
+
8
+ private
9
+
10
+ def permitted_komoju_konbini_attributes
11
+ :convenience
12
+ end
13
+
14
+ def permitted_komoju_banktransfer_attributes
15
+ [:email, :phone, :family_name, :given_name, :family_name_kana, :given_name_kana]
16
+ end
17
+ end
18
+
@@ -0,0 +1,26 @@
1
+ module Spree
2
+ class BankTransfer < Spree::Base
3
+ belongs_to :payment_method
4
+ belongs_to :user, class_name: Spree.user_class, foreign_key: 'user_id'
5
+ has_many :payments, as: :source
6
+
7
+ validates :email, :given_name, :family_name, :given_name_kana, :family_name_kana, presence: true
8
+
9
+ def actions
10
+ %w{capture void}
11
+ end
12
+
13
+ def can_capture?(payment)
14
+ return false unless ['checkout', 'pending'].include?(payment.state)
15
+ payment.source.expires_at && (payment.source.expires_at > DateTime.current)
16
+ end
17
+
18
+ def can_void?(payment)
19
+ payment.state != 'void'
20
+ end
21
+
22
+ def instructions_partial_path
23
+ "spree/orders/bank_transfer"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ module Spree
2
+ class Gateway::KomojuBankTransfer < KomojuGateway
3
+ def authorize(money, source, options)
4
+ details = {
5
+ type: "bank_transfer",
6
+ email: source.email,
7
+ phone: source.phone,
8
+ given_name: source.given_name,
9
+ family_name: source.family_name,
10
+ given_name_kana: source.given_name_kana,
11
+ family_name_kana: source.family_name_kana
12
+ }
13
+ options = change_options_to_dollar(options) if options[:currency] == "JPY"
14
+
15
+ response = provider.purchase(money - options[:tax], details, options)
16
+
17
+ source.update!(
18
+ expires_at: response.params["payment_deadline"].to_time,
19
+ order_id: response.params["payment_details"]["order_id"],
20
+ bank_number: response.params["payment_details"]["bank_number"]
21
+ )
22
+ response
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+ module Spree
2
+ class Gateway::KomojuCreditCard < KomojuGateway
3
+ def auto_capture?
4
+ true
5
+ end
6
+
7
+ def purchase(money, source, options)
8
+ options = change_options_to_dollar(options) if options[:currency] == "JPY"
9
+ if profile_id = source.gateway_payment_profile_id || source.gateway_customer_profile_id
10
+ payment_details = profile_id
11
+ else
12
+ payment_details = source.to_active_merchant
13
+ end
14
+ super(money - options[:tax], payment_details, options)
15
+ end
16
+
17
+ # enable either token-based profiles or customer-based profiles
18
+ def create_profile(payment)
19
+ return unless payment.source.number.present?
20
+
21
+ if SpreeKomoju.enable_customer_profiles
22
+ profile_id_name = :gateway_customer_profile_id
23
+ options = { email: payment.order.email, customer_profile: true }
24
+ else
25
+ profile_id_name = :gateway_payment_profile_id
26
+ end
27
+
28
+ profile_id = payment.source.public_send(profile_id_name)
29
+ if profile_id.nil?
30
+ response = provider.store(payment.source.to_active_merchant, options)
31
+
32
+ if response.success?
33
+ payment.source.update_attributes!(profile_id_name => response.params['id'])
34
+ else
35
+ payment.send(:gateway_error, response.message)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,23 @@
1
+ module Spree
2
+ class Gateway::KomojuKonbini < KomojuGateway
3
+ def authorize(money, source, options)
4
+ details = {
5
+ type: "konbini",
6
+ store: source.convenience,
7
+ phone: options[:billing_address][:phone],
8
+ email: options[:email]
9
+ }
10
+ options = change_options_to_dollar(options) if options[:currency] == "JPY"
11
+
12
+ response = provider.purchase(money - options[:tax], details, options)
13
+
14
+ source.update!(
15
+ expires_at: response.params["payment_deadline"].to_time,
16
+ receipt: response.params["payment_details"]["receipt"],
17
+ instructions_url: response.params["payment_details"]["instructions_url"],
18
+ confirmation_code: response.params["payment_details"]["confirmation_code"]
19
+ ) if response.success?
20
+ response
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,51 @@
1
+ module Spree
2
+ class KomojuGateway < Gateway
3
+ preference :api_key, :string
4
+
5
+ def provider_class
6
+ ActiveMerchant::Billing::KomojuGateway
7
+ end
8
+
9
+ def options
10
+ super.merge(login: preferred_api_key, test: preferred_test_mode)
11
+ end
12
+
13
+ def auto_capture?
14
+ false
15
+ end
16
+
17
+ def payment_profiles_supported?
18
+ true
19
+ end
20
+
21
+ def supports?(source)
22
+ true
23
+ end
24
+
25
+ # no-op, override where necessary
26
+ def create_profile(payment)
27
+ end
28
+
29
+ # We need to change shipping, tax, subtotal and discount from cents to dollar for Komoju gateway.
30
+ # Because, Komoju gateway supports JPY currency only.
31
+ #
32
+ # Spree changes price from dollar to cents. Almost payment gateway supports cents only.
33
+ # See. https://github.com/spree/spree/blob/master/core/app/models/spree/payment/gateway_options.rb
34
+ def change_options_to_dollar(options)
35
+ %i(shipping tax subtotal discount).each { |key| options[key] = options[key] / 100.0 }
36
+ options
37
+ end
38
+
39
+ def gateway_type
40
+ self.class.to_s.split("::Komoju").last.underscore
41
+ end
42
+
43
+ def method_type
44
+ "komoju_#{gateway_type}"
45
+ end
46
+
47
+ def payment_source_class
48
+ "Spree::#{gateway_type.camelcase}".constantize
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,32 @@
1
+ module Spree
2
+ class Konbini < Spree::Base
3
+ STORES = %i(lawson family-mart sunkus circle-k ministop daily-yamazaki seven-eleven)
4
+
5
+ belongs_to :payment_method
6
+ belongs_to :user, class_name: Spree.user_class, foreign_key: 'user_id'
7
+ has_many :payments, as: :source
8
+
9
+ validates :convenience, presence: true
10
+
11
+ def actions
12
+ %w{capture void}
13
+ end
14
+
15
+ def can_capture?(payment)
16
+ return false unless ['checkout', 'pending'].include?(payment.state)
17
+ payment.source.expires_at && (payment.source.expires_at > DateTime.current)
18
+ end
19
+
20
+ def can_void?(payment)
21
+ payment.state != 'void'
22
+ end
23
+
24
+ def instructions_partial_path
25
+ "spree/orders/konbini"
26
+ end
27
+
28
+ def imported
29
+ false
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+ Deface::Override.new(:virtual_path => 'spree/orders/show',
2
+ :name => 'add_instruction_to_order_show',
3
+ :insert_before => "fieldset#order_summary legend",
4
+ :text => "
5
+ <% unless @order.paid? %>
6
+ <% source = @order.payments.last.source %>
7
+ <%= render source.instructions_partial_path, source: source if source.respond_to?(:instructions_partial_path) %>
8
+ <% end %>")
@@ -0,0 +1 @@
1
+ <%= render "spree/admin/payments/source_views/gateway", payment: payment %>
@@ -0,0 +1,25 @@
1
+ <fieldset data-hook="konbini">
2
+ <legend><%= Spree.t(:konbini) %></legend>
3
+ <table class="table table-condensed table-bordered">
4
+ <tr>
5
+ <th width="20%"><%= Spree.t(:konbini_chain) %>:</th>
6
+ <td><%= payment.source.convenience %></td>
7
+ </tr>
8
+ <tr>
9
+ <th width="20%"><%= Spree.t(:konbini_receipt) %>:</th>
10
+ <td><%= payment.source.confirmation_code %></td>
11
+ </tr>
12
+ <tr>
13
+ <th width="20%"><%= Spree.t(:konbini_confirmation_code) %>:</th>
14
+ <td><%= payment.source.receipt %></td>
15
+ </tr>
16
+ <tr>
17
+ <th width="20%"><%= Spree.t(:konbini_instructions_url) %>:</th>
18
+ <td><%= payment.source.instructions_url %></td>
19
+ </tr>
20
+ <tr>
21
+ <th><%= Spree.t(:expires_at) %>:</th>
22
+ <td><%= payment.source.expires_at %></td>
23
+ </tr>
24
+ </table>
25
+ </fieldset>
@@ -0,0 +1,35 @@
1
+ <div class="well clearfix">
2
+ <% param_prefix = "payment_source[#{payment_method.id}]" %>
3
+
4
+ <p class="field">
5
+ <%= label_tag "email", Spree.t(:email) %><span class="required">*</span><br />
6
+ <%= text_field_tag "#{param_prefix}[email]", @order.email, { id: "email", class: 'form-control required'} %>
7
+ </p>
8
+
9
+ <p class="field">
10
+ <%= label_tag "phone", Spree.t(:phone) %><span class="required">*</span><br />
11
+ <%= text_field_tag "#{param_prefix}[phone]", @order.billing_address.phone, { id: "phone", class: 'form-control required'} %>
12
+ </p>
13
+
14
+ <div class="row">
15
+ <div class="col-md-6 field">
16
+ <%= label_tag "family_name", Spree.t(:family_name) %><span class="required">*</span><br />
17
+ <%= text_field_tag "#{param_prefix}[family_name]", @order.billing_lastname, { id: "family_name", class: 'form-control required'} %>
18
+ </div>
19
+ <div class="col-md-6 field">
20
+ <%= label_tag "given_name", Spree.t(:given_name) %><span class="required">*</span><br />
21
+ <%= text_field_tag "#{param_prefix}[given_name]", @order.billing_firstname, { id: "given_name", class: 'form-control required'} %>
22
+ </div>
23
+ </div>
24
+
25
+ <div class="row">
26
+ <div class="col-md-6 field">
27
+ <%= label_tag "family_name_kana", Spree.t(:family_name_kana) %><span class="required">*</span><br />
28
+ <%= text_field_tag "#{param_prefix}[family_name_kana]", "", { id: "family_name_kana", class: 'form-control required'} %>
29
+ </div>
30
+ <div class="col-md-6 field">
31
+ <%= label_tag "given_name_kana", Spree.t(:given_name_kana) %><span class="required">*</span><br />
32
+ <%= text_field_tag "#{param_prefix}[given_name_kana]", "", { id: "given_name_kana", class: 'form-control required'} %>
33
+ </div>
34
+ </div>
35
+ </div>