workarea-checkoutdotcom 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintrc +24 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.github/workflows/ci.yml +54 -0
  7. data/.gitignore +23 -0
  8. data/.rubocop.yml +3 -0
  9. data/.stylelintrc.json +8 -0
  10. data/CHANGELOG.md +59 -0
  11. data/Gemfile +6 -0
  12. data/README.md +74 -0
  13. data/Rakefile +60 -0
  14. data/app/lib/active_merchant/billing/gateways/checkout_v2.decorator +22 -0
  15. data/app/models/workarea/payment/authorize/credit_card.decorator +41 -0
  16. data/app/models/workarea/payment/purchase/credit_card.decorator +44 -0
  17. data/app/models/workarea/payment/store_credit_card.decorator +17 -0
  18. data/bin/rails +20 -0
  19. data/config/initializers/workarea.rb +1 -0
  20. data/lib/active_merchant/billing/bogus_checkout_v2_gateway.rb +42 -0
  21. data/lib/workarea/checkoutdotcom.rb +46 -0
  22. data/lib/workarea/checkoutdotcom/engine.rb +8 -0
  23. data/lib/workarea/checkoutdotcom/version.rb +5 -0
  24. data/script/admin_ci +9 -0
  25. data/script/ci +11 -0
  26. data/script/core_ci +9 -0
  27. data/script/plugins_ci +9 -0
  28. data/script/storefront_ci +9 -0
  29. data/test/dummy/Rakefile +6 -0
  30. data/test/dummy/bin/bundle +3 -0
  31. data/test/dummy/bin/rails +4 -0
  32. data/test/dummy/bin/rake +4 -0
  33. data/test/dummy/bin/setup +30 -0
  34. data/test/dummy/bin/update +26 -0
  35. data/test/dummy/bin/yarn +11 -0
  36. data/test/dummy/config.ru +5 -0
  37. data/test/dummy/config/application.rb +30 -0
  38. data/test/dummy/config/boot.rb +5 -0
  39. data/test/dummy/config/cable.yml +10 -0
  40. data/test/dummy/config/environment.rb +5 -0
  41. data/test/dummy/config/environments/development.rb +51 -0
  42. data/test/dummy/config/environments/production.rb +88 -0
  43. data/test/dummy/config/environments/test.rb +44 -0
  44. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  45. data/test/dummy/config/initializers/assets.rb +14 -0
  46. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  47. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  48. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  49. data/test/dummy/config/initializers/inflections.rb +16 -0
  50. data/test/dummy/config/initializers/mime_types.rb +4 -0
  51. data/test/dummy/config/initializers/workarea.rb +5 -0
  52. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  53. data/test/dummy/config/locales/en.yml +33 -0
  54. data/test/dummy/config/puma.rb +56 -0
  55. data/test/dummy/config/routes.rb +5 -0
  56. data/test/dummy/config/secrets.yml +32 -0
  57. data/test/dummy/config/spring.rb +6 -0
  58. data/test/dummy/db/seeds.rb +2 -0
  59. data/test/dummy/log/.keep +0 -0
  60. data/test/models/workarea/payment/authorize/credit_card_test.decorator +38 -0
  61. data/test/models/workarea/payment/capture_test.decorator +27 -0
  62. data/test/models/workarea/payment/checkoutdotcom_integration_test.rb +178 -0
  63. data/test/models/workarea/payment/credit_card_integration_test.decorator +107 -0
  64. data/test/models/workarea/payment/purchase/credit_card_test.decorator +38 -0
  65. data/test/models/workarea/payment/refund_test.decorator +27 -0
  66. data/test/support/workarea/checkoutdotcom_gateway_vcr_config.rb +20 -0
  67. data/test/support/workarea/workarea_3_2_backports.rb +57 -0
  68. data/test/teaspoon_env.rb +6 -0
  69. data/test/test_helper.rb +10 -0
  70. data/test/vcr_cassettes/checkoutdotcom/auth_capture.yml +154 -0
  71. data/test/vcr_cassettes/checkoutdotcom/auth_capture_refund.yml +225 -0
  72. data/test/vcr_cassettes/checkoutdotcom/auth_void.yml +154 -0
  73. data/test/vcr_cassettes/checkoutdotcom/purchase_refund.yml +225 -0
  74. data/test/vcr_cassettes/checkoutdotcom/store_auth.yml +83 -0
  75. data/test/vcr_cassettes/checkoutdotcom/store_purchase.yml +154 -0
  76. data/test/vcr_cassettes/credit_card/auth_capture.yml +154 -0
  77. data/test/vcr_cassettes/credit_card/auth_capture_refund.yml +225 -0
  78. data/test/vcr_cassettes/credit_card/auth_void.yml +154 -0
  79. data/test/vcr_cassettes/credit_card/purchase_refund.yml +225 -0
  80. data/test/vcr_cassettes/credit_card/store_auth.yml +83 -0
  81. data/test/vcr_cassettes/credit_card/store_purchase.yml +154 -0
  82. data/test/workers/workarea/send_refund_email_test.decorator +27 -0
  83. data/workarea-checkoutdotcom.gemspec +19 -0
  84. metadata +144 -0
@@ -0,0 +1,44 @@
1
+ module Workarea
2
+ decorate Payment::Purchase::CreditCard, with: :checkoutdotcom do
3
+ decorated do
4
+ delegate :address, to: :tender
5
+ end
6
+
7
+ def complete!
8
+ transaction.response = handle_active_merchant_errors do
9
+ gateway.purchase(
10
+ transaction.amount.cents,
11
+ tender.to_token_or_active_merchant,
12
+ transaction_options
13
+ )
14
+ end
15
+
16
+ if transaction.response.success? && tender.token.blank?
17
+ tender.token = transaction.response.params["source"]["id"]
18
+ tender.save!
19
+
20
+ end
21
+ transaction.response
22
+ end
23
+
24
+ private
25
+
26
+ def transaction_options
27
+ options = {
28
+ reference: tender.payment.id,
29
+ customer: {
30
+ email: tender.profile.email,
31
+ name: address.first_name + ' ' + address.last_name
32
+ },
33
+ billing_address: {
34
+ address1: address.street,
35
+ address2: address.street_2,
36
+ city: address.city,
37
+ state: address.region,
38
+ country: address.country.alpha2,
39
+ zip: address.postal_code
40
+ }
41
+ }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ module Workarea
2
+ decorate Payment::StoreCreditCard, with: :checkoutdotcom do
3
+ def perform!
4
+ return true if @credit_card.token.present?
5
+
6
+ response = handle_active_merchant_errors do
7
+ gateway.verify(@credit_card.to_active_merchant, email: @credit_card.profile.email)
8
+ end
9
+
10
+ if response.success?
11
+ @credit_card.token = response.params["source"]["id"]
12
+ end
13
+
14
+ response.success?
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/workarea/checkoutdotcom/engine', __FILE__)
7
+ APP_PATH = File.expand_path('../../test/dummy/config/application', __FILE__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
11
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
12
+
13
+ require "action_controller/railtie"
14
+ require "action_view/railtie"
15
+ require "action_mailer/railtie"
16
+ require "rails/test_unit/railtie"
17
+ require "sprockets/railtie"
18
+ require 'teaspoon-mocha'
19
+
20
+ require 'rails/engine/commands'
@@ -0,0 +1 @@
1
+ Workarea::Checkoutdotcom.auto_initialize_gateway
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveMerchant
4
+ module Billing
5
+ class BogusCheckoutV2Gateway < BogusGateway
6
+ def verify(paysource, options = {})
7
+ case normalize(paysource)
8
+ when /1$/
9
+ Response.new(true, SUCCESS_MESSAGE, { "source" => { "id" => "111", "customerId" => "cust_123" } }, test: true, authorization: AUTHORIZATION)
10
+ when /2$/
11
+ Response.new(false, FAILURE_MESSAGE, { error: FAILURE_MESSAGE }, test: true, error_code: STANDARD_ERROR_CODE[:processing_error])
12
+ else
13
+ raise Error, error_message(paysource)
14
+ end
15
+ end
16
+
17
+ def authorize_swipe(money, paysource, options = {})
18
+ money = amount(money)
19
+ case normalize(paysource)
20
+ when /1$/, AUTHORIZATION
21
+ Response.new(true, SUCCESS_MESSAGE, { "source" => { "id" => "111", "customerId" => "cust_123" }, "authorized_amount" => money }, test: true, authorization: AUTHORIZATION)
22
+ when /2$/
23
+ Response.new(false, FAILURE_MESSAGE, { authorized_amount: money, error: FAILURE_MESSAGE }, test: true, error_code: STANDARD_ERROR_CODE[:processing_error])
24
+ else
25
+ raise Error, error_message(paysource)
26
+ end
27
+ end
28
+
29
+ def purchase_swipe(money, paysource, options = {})
30
+ money = amount(money)
31
+ case normalize(paysource)
32
+ when /1$/, AUTHORIZATION
33
+ Response.new(true, SUCCESS_MESSAGE, { "source" => { "id" => "111", "customerId" => "cust_123" }, "paid_amount" => money }, test: true, authorization: AUTHORIZATION)
34
+ when /2$/
35
+ Response.new(false, FAILURE_MESSAGE, { paid_amount: money, error: FAILURE_MESSAGE }, test: true, error_code: STANDARD_ERROR_CODE[:processing_error])
36
+ else
37
+ raise Error, error_message(paysource)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,46 @@
1
+ require 'workarea'
2
+ require 'workarea/storefront'
3
+ require 'workarea/admin'
4
+
5
+ require 'workarea/checkoutdotcom/engine'
6
+ require 'workarea/checkoutdotcom/version'
7
+
8
+ require 'active_merchant/billing/bogus_checkout_v2_gateway'
9
+
10
+ module Workarea
11
+ module Checkoutdotcom
12
+ # Credentials for checkoutdotcom from Rails secrets.
13
+ #
14
+ # @return [Hash]
15
+ def self.credentials
16
+ return {} unless Rails.application.secrets.checkoutdotcom.present?
17
+ Rails.application.secrets.checkoutdotcom.symbolize_keys
18
+ end
19
+
20
+ # Conditionally use the real gateway when secrets are present.
21
+ # Otherwise, use the bogus gateway.
22
+ #
23
+ # @return [ActiveMerchant::Billing::Gateway]
24
+ def self.gateway
25
+ Workarea.config.gateways.credit_card
26
+ end
27
+
28
+ def self.gateway=(gateway)
29
+ Workarea.config.gateways.credit_card = gateway
30
+ end
31
+
32
+ def self.auto_initialize_gateway
33
+ if credentials.present?
34
+ if ENV['HTTP_PROXY'].present?
35
+ uri = URI.parse(ENV['HTTP_PROXY'])
36
+ ActiveMerchant::Billing::CheckoutV2Gateway.proxy_address = uri.host
37
+ ActiveMerchant::Billing::CheckoutV2Gateway.proxy_port = uri.port
38
+ end
39
+
40
+ self.gateway = ActiveMerchant::Billing::CheckoutV2Gateway.new credentials
41
+ else
42
+ self.gateway = ActiveMerchant::Billing::BogusCheckoutV2Gateway.new
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ module Workarea
2
+ module Checkoutdotcom
3
+ class Engine < ::Rails::Engine
4
+ include Workarea::Plugin
5
+ isolate_namespace Workarea::Checkoutdotcom
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Workarea
2
+ module Checkoutdotcom
3
+ VERSION = "1.2.0"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ gem install bundler
4
+ bundle update
5
+
6
+ CI_GEM_PATH="$(bundle show workarea-ci)"
7
+ . ${CI_GEM_PATH}/exe/workarea-set-ci-env
8
+
9
+ bin/rails app:workarea:test:admin
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bash
2
+
3
+ gem install bundler
4
+ bundle update
5
+
6
+ CI_GEM_PATH="$(bundle show workarea-ci)"
7
+ . ${CI_GEM_PATH}/exe/workarea-set-ci-env
8
+
9
+ bundle exec workarea-lint
10
+ bundle exec workarea-audit
11
+ bin/rails test test/**/*_test.rb
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ gem install bundler
4
+ bundle update
5
+
6
+ CI_GEM_PATH="$(bundle show workarea-ci)"
7
+ . ${CI_GEM_PATH}/exe/workarea-set-ci-env
8
+
9
+ bin/rails app:workarea:test:core
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ gem install bundler
4
+ bundle update
5
+
6
+ CI_GEM_PATH="$(bundle show workarea-ci)"
7
+ . ${CI_GEM_PATH}/exe/workarea-set-ci-env
8
+
9
+ bin/rails app:workarea:test:plugins
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ gem install bundler
4
+ bundle update
5
+
6
+ CI_GEM_PATH="$(bundle show workarea-ci)"
7
+ . ${CI_GEM_PATH}/exe/workarea-set-ci-env
8
+
9
+ bin/rails app:workarea:test:storefront
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a starting point to setup your application.
15
+ # Add necessary setup steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ # Install JavaScript dependencies if using Yarn
22
+ # system('bin/yarn')
23
+
24
+
25
+ puts "\n== Removing old logs and tempfiles =="
26
+ system! 'bin/rails log:clear tmp:clear'
27
+
28
+ puts "\n== Restarting application server =="
29
+ system! 'bin/rails restart'
30
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a way to update your development environment automatically.
15
+ # Add necessary update steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ puts "\n== Removing old logs and tempfiles =="
22
+ system! 'bin/rails log:clear tmp:clear'
23
+
24
+ puts "\n== Restarting application server =="
25
+ system! 'bin/rails restart'
26
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ VENDOR_PATH = File.expand_path('..', __dir__)
3
+ Dir.chdir(VENDOR_PATH) do
4
+ begin
5
+ exec "yarnpkg #{ARGV.join(" ")}"
6
+ rescue Errno::ENOENT
7
+ $stderr.puts "Yarn executable was not detected in the system."
8
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9
+ exit 1
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
@@ -0,0 +1,30 @@
1
+ require_relative 'boot'
2
+
3
+ # Pick the frameworks you want:
4
+ # require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+ require "active_job/railtie"
9
+ # require "action_cable/engine"
10
+ require "rails/test_unit/railtie"
11
+ require "sprockets/railtie"
12
+
13
+ # Workarea must be required before other gems to ensure control over Rails.env
14
+ # for running tests
15
+ require 'workarea/core'
16
+ require 'workarea/admin'
17
+ require 'workarea/storefront'
18
+ Bundler.require(*Rails.groups)
19
+ require "workarea/checkoutdotcom"
20
+
21
+ module Dummy
22
+ class Application < Rails::Application
23
+ # Initialize configuration defaults for originally generated Rails version.
24
+ config.load_defaults 5.1
25
+
26
+ # Settings in config/environments/* take precedence over those specified here.
27
+ # Application configuration should go into files in config/initializers
28
+ # -- all .rb files in that directory are automatically loaded.
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -0,0 +1,10 @@
1
+ development:
2
+ adapter: async
3
+
4
+ test:
5
+ adapter: async
6
+
7
+ production:
8
+ adapter: redis
9
+ url: redis://localhost:6379/1
10
+ channel_prefix: dummy_production
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative 'application'
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,51 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports.
13
+ config.consider_all_requests_local = true
14
+
15
+ # Enable/disable caching. By default caching is disabled.
16
+ if Rails.root.join('tmp/caching-dev.txt').exist?
17
+ config.action_controller.perform_caching = true
18
+
19
+ config.cache_store = :memory_store
20
+ config.public_file_server.headers = {
21
+ 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
22
+ }
23
+ else
24
+ config.action_controller.perform_caching = false
25
+
26
+ config.cache_store = :null_store
27
+ end
28
+
29
+ # Don't care if the mailer can't send.
30
+ config.action_mailer.raise_delivery_errors = false
31
+
32
+ config.action_mailer.perform_caching = false
33
+
34
+ # Print deprecation notices to the Rails logger.
35
+ config.active_support.deprecation = :log
36
+
37
+ # Debug mode disables concatenation and preprocessing of assets.
38
+ # This option may cause significant delays in view rendering with a large
39
+ # number of complex assets.
40
+ config.assets.debug = true
41
+
42
+ # Suppress logger output for asset requests.
43
+ config.assets.quiet = true
44
+
45
+ # Raises error for missing translations
46
+ # config.action_view.raise_on_missing_translations = true
47
+
48
+ # Use an evented file watcher to asynchronously detect changes in source code,
49
+ # routes, locales, etc. This feature depends on the listen gem.
50
+ # config.file_watcher = ActiveSupport::EventedFileUpdateChecker
51
+ end