solidus_open_pay 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +61 -0
  3. data/.github/stale.yml +1 -0
  4. data/.gitignore +22 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +249 -0
  7. data/Gemfile +49 -0
  8. data/LICENSE +26 -0
  9. data/README.md +37 -0
  10. data/Rakefile +11 -0
  11. data/app/assets/images/solidus_open_pay/.gitkeep +0 -0
  12. data/app/assets/javascripts/spree/backend/solidus_open_pay.js +2 -0
  13. data/app/assets/javascripts/spree/frontend/solidus_open_pay.js +2 -0
  14. data/app/assets/stylesheets/spree/backend/solidus_openpay.css +3 -0
  15. data/app/assets/stylesheets/spree/frontend/solidus_openpay.css +3 -0
  16. data/app/models/concerns/solidus_open_pay/attributes_access.rb +83 -0
  17. data/app/models/solidus_open_pay/builders/charge.rb +72 -0
  18. data/app/models/solidus_open_pay/gateway.rb +98 -0
  19. data/app/models/solidus_open_pay/payment_method.rb +30 -0
  20. data/app/models/solidus_open_pay/payment_source.rb +25 -0
  21. data/app/models/solidus_open_pay/response.rb +63 -0
  22. data/app/views/checkouts/payment/_open_pay.html.erb +171 -0
  23. data/app/views/spree/admin/payments/source_views/_open_pay.html.erb +21 -0
  24. data/app/views/spree/api/payments/source_views/_open_pay.json.jbuilder +3 -0
  25. data/app/views/spree/checkout/payment/_open_pay.html.erb +183 -0
  26. data/bin/console +17 -0
  27. data/bin/rails +7 -0
  28. data/bin/rails-engine +13 -0
  29. data/bin/rails-sandbox +16 -0
  30. data/bin/rake +7 -0
  31. data/bin/sandbox +86 -0
  32. data/bin/setup +8 -0
  33. data/config/locales/en.yml +44 -0
  34. data/config/locales/es-MX.yml +44 -0
  35. data/config/locales/es.yml +44 -0
  36. data/config/routes.rb +7 -0
  37. data/db/migrate/20241120003957_add_open_pay_sources.rb +23 -0
  38. data/lib/generators/solidus_open_pay/install/install_generator.rb +113 -0
  39. data/lib/generators/solidus_open_pay/install/templates/config/initializers/solidus_open_pay.rb +6 -0
  40. data/lib/solidus_open_pay/configuration.rb +27 -0
  41. data/lib/solidus_open_pay/engine.rb +38 -0
  42. data/lib/solidus_open_pay/testing_support/factories.rb +34 -0
  43. data/lib/solidus_open_pay/version.rb +5 -0
  44. data/lib/solidus_open_pay.rb +5 -0
  45. data/lib/tasks/solidus_openpay_tasks.rake +6 -0
  46. data/solidus_open_pay.gemspec +39 -0
  47. data/spec/models/solidus_open_pay/payment_method_spec.rb +417 -0
  48. data/spec/solidus_open_pay_spec_helper.rb +5 -0
  49. data/spec/spec_helper.rb +34 -0
  50. data/spec/support/factory_bot.rb +10 -0
  51. data/spec/support/solidus.rb +18 -0
  52. data/spec/support/solidus_open_pay/gateway_helpers.rb +27 -0
  53. metadata +197 -0
data/bin/sandbox ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ case "$DB" in
6
+ postgres|postgresql)
7
+ RAILSDB="postgresql"
8
+ ;;
9
+ mysql)
10
+ RAILSDB="mysql"
11
+ ;;
12
+ sqlite|'')
13
+ RAILSDB="sqlite3"
14
+ ;;
15
+ *)
16
+ echo "Invalid DB specified: $DB"
17
+ exit 1
18
+ ;;
19
+ esac
20
+
21
+ if [ ! -z $SOLIDUS_BRANCH ]
22
+ then
23
+ BRANCH=$SOLIDUS_BRANCH
24
+ else
25
+ BRANCH="master"
26
+ fi
27
+
28
+ extension_name="solidus_open_pay"
29
+
30
+ # Stay away from the bundler env of the containing extension.
31
+ function unbundled {
32
+ ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
33
+ }
34
+
35
+ rm -rf ./sandbox
36
+ unbundled bundle exec rails new sandbox --database="$RAILSDB" \
37
+ --skip-bundle \
38
+ --skip-git \
39
+ --skip-keeps \
40
+ --skip-rc \
41
+ --skip-spring \
42
+ --skip-test \
43
+ --skip-javascript
44
+
45
+ if [ ! -d "sandbox" ]; then
46
+ echo 'sandbox rails application failed'
47
+ exit 1
48
+ fi
49
+
50
+ cd ./sandbox
51
+ cat <<RUBY >> Gemfile
52
+ gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH'
53
+ gem 'solidus_auth_devise', '>= 2.1.0'
54
+ gem 'rails-i18n'
55
+ gem 'solidus_i18n'
56
+
57
+ gem '$extension_name', path: '..'
58
+
59
+ group :test, :development do
60
+ platforms :mri do
61
+ gem 'pry-byebug'
62
+ end
63
+ end
64
+ RUBY
65
+
66
+ unbundled bundle install --gemfile Gemfile
67
+
68
+ unbundled bundle exec rake db:drop db:create
69
+
70
+ unbundled bundle exec rails generate solidus:install \
71
+ --auto-accept \
72
+ --user_class=Spree::User \
73
+ --enforce_available_locales=true \
74
+ --with-authentication=false \
75
+ --payment-method=none \
76
+ $@
77
+
78
+ unbundled bundle exec rails generate solidus:auth:install
79
+ unbundled bundle exec rails generate ${extension_name}:install
80
+
81
+ echo
82
+ echo "🚀 Sandbox app successfully created for $extension_name!"
83
+ echo "🚀 Using $RAILSDB and Solidus $BRANCH"
84
+ echo "🚀 Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter"
85
+ echo "🚀 Use 'export SOLIDUS_BRANCH=<BRANCH-NAME>' to control the Solidus version"
86
+ echo "🚀 This app is intended for test purposes."
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+ bundle update
8
+ bin/rake clobber
@@ -0,0 +1,44 @@
1
+ en:
2
+ solidus_open_pay:
3
+ admin:
4
+ card:
5
+ brand: Brand
6
+ card_number: Card Number
7
+ device_session_id: Device Session ID
8
+ token_id: Token ID
9
+ form:
10
+ placeholder:
11
+ card_code: 123
12
+ card_name: John Doe
13
+ card_number: XXXX XXXX XXXX XXXX
14
+ gateway_rejection_reasons:
15
+ 1000: Internal server error, contact suppor
16
+ 1001: Bad Request
17
+ 1002: The api key or merchant id are invalid
18
+ 1003: Parameters look valid but request failed
19
+ 1004: The resource is unavailable at this moment. Please try again later
20
+ 1005: The requested resource doesn't exist
21
+ 1006: The order_id has already been processed
22
+ 1007: Operation rejected by processor
23
+ 1008: The account is inactive
24
+ 2004: The card number verification digit is invalid
25
+ 2005: The expiration date has expired
26
+ 2006: The CVV2 security code is required
27
+ 2007: The card number is only valid in sandbox
28
+ 2009: The CVV2 security code is invalid
29
+ 2010: 3D Secure authentication failed
30
+ 2011: Card product type not supported
31
+ 3001: The card was declined by the bank
32
+ 3002: The card has expired
33
+ 3003: The card doesn't have sufficient funds
34
+ 3004: The card was reported as stolen
35
+ 3005: Fraud risk detected by anti-fraud system --- Found in blacklist
36
+ 3006: Request not allowed
37
+ 3009: The card was reported as lost
38
+ 3010: The bank has restricted the card
39
+ 3011: The bank has requested the card to be retained
40
+ 3012: Bank authorization is required for this charge
41
+ activerecord:
42
+ models:
43
+ solidus_open_pay/payment_source: Solidus OpenPay Payment Source
44
+ solidus_open_pay/payment_method: OpenPay Credit Card
@@ -0,0 +1,44 @@
1
+ es-MX:
2
+ solidus_open_pay:
3
+ admin:
4
+ card:
5
+ brand: Tarjeta
6
+ card_number: Número de Tarjeta
7
+ device_session_id: ID Sesión Dispositivo
8
+ token_id: Token ID
9
+ form:
10
+ placeholder:
11
+ card_code: 123
12
+ card_name: John Doe
13
+ card_number: XXXX XXXX XXXX XXXX
14
+ gateway_rejection_reasons:
15
+ 1000: Error interno del servidor, comuníquese con el soporte
16
+ 1001: Solicitud incorrecta
17
+ 1002: La clave de API o la identificación del comerciante no son válidas
18
+ 1003: Los parámetros parecen válidos, pero la solicitud falló
19
+ 1004: El recurso no está disponible en este momento. Inténtalo de nuevo más tarde
20
+ 1005: El recurso solicitado no existe
21
+ 1006: El order_id ya ha sido procesado
22
+ 1007: Operación rechazada por el procesador
23
+ 1008: La cuenta está inactiva
24
+ 2004: El dígito de verificación del número de tarjeta no es válido
25
+ 2005: La fecha de caducidad ha expirado
26
+ 2006: Se requiere el código de seguridad CVV2
27
+ 2007: El número de tarjeta solo es válido en sandbox
28
+ 2009: El código de seguridad CVV2 no es válido
29
+ 2010: Falló la autenticación 3D Secure
30
+ 2011: Tipo de producto de tarjeta no compatible
31
+ 3001: El banco rechazó la tarjeta
32
+ 3002: La tarjeta ha expirado
33
+ 3003: La tarjeta no tiene fondos suficientes
34
+ 3004: La tarjeta fue reportada como robada
35
+ 3005: Riesgo de fraude detectado por el sistema antifraude --- Encontrado en la lista negra
36
+ 3006: Solicitud no permitida
37
+ 3009: La tarjeta fue reportada como perdida
38
+ 3010: El banco ha restringido la tarjeta
39
+ 3011: El banco ha solicitado que se retenga la tarjeta
40
+ 3012: Se requiere autorización del banco para este cargo
41
+ activerecord:
42
+ models:
43
+ solidus_open_pay/payment_source: Solidus OpenPay Fuente de Pago
44
+ solidus_open_pay/payment_method: OpenPay Tarjeta de Credito
@@ -0,0 +1,44 @@
1
+ es:
2
+ solidus_open_pay:
3
+ admin:
4
+ card:
5
+ brand: Tarjeta
6
+ card_number: Número de Tarjeta
7
+ device_session_id: ID Sesión Dispositivo
8
+ token_id: Token ID
9
+ form:
10
+ placeholder:
11
+ card_code: 123
12
+ card_name: John Doe
13
+ card_number: XXXX XXXX XXXX XXXX
14
+ gateway_rejection_reasons:
15
+ 1000: Error interno del servidor, comuníquese con el soporte
16
+ 1001: Solicitud incorrecta
17
+ 1002: La clave de API o la identificación del comerciante no son válidas
18
+ 1003: Los parámetros parecen válidos, pero la solicitud falló
19
+ 1004: El recurso no está disponible en este momento. Inténtalo de nuevo más tarde
20
+ 1005: El recurso solicitado no existe
21
+ 1006: El order_id ya ha sido procesado
22
+ 1007: Operación rechazada por el procesador
23
+ 1008: La cuenta está inactiva
24
+ 2004: El dígito de verificación del número de tarjeta no es válido
25
+ 2005: La fecha de caducidad ha expirado
26
+ 2006: Se requiere el código de seguridad CVV2
27
+ 2007: El número de tarjeta solo es válido en sandbox
28
+ 2009: El código de seguridad CVV2 no es válido
29
+ 2010: Falló la autenticación 3D Secure
30
+ 2011: Tipo de producto de tarjeta no compatible
31
+ 3001: El banco rechazó la tarjeta
32
+ 3002: La tarjeta ha expirado
33
+ 3003: La tarjeta no tiene fondos suficientes
34
+ 3004: La tarjeta fue reportada como robada
35
+ 3005: Riesgo de fraude detectado por el sistema antifraude --- Encontrado en la lista negra
36
+ 3006: Solicitud no permitida
37
+ 3009: La tarjeta fue reportada como perdida
38
+ 3010: El banco ha restringido la tarjeta
39
+ 3011: El banco ha solicitado que se retenga la tarjeta
40
+ 3012: Se requiere autorización del banco para este cargo
41
+ activerecord:
42
+ models:
43
+ solidus_open_pay/payment_source: Solidus OpenPay Fuente de Pago
44
+ solidus_open_pay/payment_method: OpenPay Tarjeta de Credito
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::Core::Engine.routes.draw do
4
+ namespace :open_pay do
5
+ resources :payments, only: %i[create show]
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddOpenPaySources < SolidusSupport::Migration[4.2]
4
+ def change
5
+ create_table :open_pay_sources do |t|
6
+ t.integer :payment_method_id
7
+ t.string :authorization_id
8
+ t.string :capture_id
9
+ t.string :name
10
+ t.string :device_session_id
11
+ t.string :verification_value
12
+ t.string :token_id
13
+ t.string :number
14
+ t.integer :expiration_month
15
+ t.integer :expiration_year
16
+ t.string :brand
17
+ t.boolean :points_card, default: false
18
+ t.string :points_type
19
+
20
+ t.timestamps
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusOpenPay
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ class_option :migrate, type: :boolean, default: true
7
+ class_option :backend, type: :boolean, default: true
8
+ class_option :frontend, type: :string, default: 'starter'
9
+
10
+ # This is only used to run all-specs during development and CI, regular installation limits
11
+ # installed specs to frontend, which are the ones related to code copied to the target application.
12
+ class_option :specs, type: :string, enum: %w[all frontend], default: 'frontend', hide: true
13
+
14
+ source_root File.expand_path('templates', __dir__)
15
+
16
+ def normalize_components_options
17
+ @components = {
18
+ backend: options[:backend],
19
+ starter_frontend: options[:frontend] == 'starter',
20
+ classic_frontend: options[:frontend] == 'classic'
21
+ }
22
+ end
23
+
24
+ def install_solidus_core_support
25
+ directory 'config/initializers', 'config/initializers'
26
+ rake 'railties:install:migrations FROM=solidus_open_pay'
27
+ run 'bin/rails db:migrate' if options[:migrate]
28
+ route "mount SolidusOpenPay::Engine, at: '#{solidus_mount_point}solidus_open_pay'"
29
+ end
30
+
31
+ def install_solidus_backend_support
32
+ support_code_for(:backend) do
33
+ append_file(
34
+ 'vendor/assets/javascripts/spree/backend/all.js',
35
+ "//= require spree/backend/solidus_open_pay\n"
36
+ )
37
+ inject_into_file(
38
+ 'vendor/assets/stylesheets/spree/backend/all.css',
39
+ " *= require spree/backend/solidus_open_pay\n",
40
+ before: %r{\*/},
41
+ verbose: true
42
+ )
43
+ end
44
+ end
45
+
46
+ def install_solidus_starter_frontend_support
47
+ support_code_for(:starter_frontend) do
48
+ directory 'app', 'app'
49
+ append_file(
50
+ 'app/assets/javascripts/solidus_starter_frontend.js',
51
+ "//= require spree/frontend/solidus_open_pay\n"
52
+ )
53
+ inject_into_file(
54
+ 'app/assets/stylesheets/solidus_starter_frontend.css',
55
+ " *= require spree/frontend/solidus_open_pay\n",
56
+ before: %r{\*/},
57
+ verbose: true
58
+ )
59
+
60
+ spec_paths =
61
+ case options[:specs]
62
+ when 'all' then %w[spec]
63
+ when 'frontend'
64
+ %w[
65
+ spec/spec_helper.rb
66
+ spec/support
67
+ ]
68
+ end
69
+
70
+ spec_paths.each do |path|
71
+ if engine.root.join(path).directory?
72
+ directory engine.root.join(path), path
73
+ else
74
+ template engine.root.join(path), path
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ def alert_no_classic_frontend_support
81
+ support_code_for(:classic_frontend) do
82
+ message = <<~TEXT
83
+ For solidus_frontend compatibility, please use the deprecated version 0.x.
84
+ The new version of this extension only supports Solidus Starter Frontend.
85
+ No frontend code has been copied to your application.
86
+ TEXT
87
+ say_status :error, set_color(message.tr("\n", ' '), :red), :red
88
+ end
89
+ end
90
+
91
+ private
92
+
93
+ def solidus_mount_point
94
+ mount_point = ::Spree::Core::Engine.routes.find_script_name({})
95
+ mount_point += '/' unless mount_point.end_with?('/')
96
+ mount_point
97
+ end
98
+
99
+ def support_code_for(component_name, &block)
100
+ if @components[component_name]
101
+ say_status :install, "[#{engine.engine_name}] solidus_#{component_name}", :blue
102
+ shell.indent(&block)
103
+ else
104
+ say_status :skip, "[#{engine.engine_name}] solidus_#{component_name}", :blue
105
+ end
106
+ end
107
+
108
+ def engine
109
+ SolidusOpenPay::Engine
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ SolidusOpenPay.configure do |config|
4
+ # TODO: Remember to change this with the actual preferences you have implemented!
5
+ # config.sample_preference = 'sample_value'
6
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusOpenPay
4
+ class Configuration
5
+ attr_accessor :installment_options, :installment_default
6
+
7
+ # def installment_options
8
+ # @installment_options ||= :installment_options
9
+ # end
10
+
11
+ # def installment_default
12
+ # @installment_default ||= :installment_default
13
+ # end
14
+ end
15
+
16
+ class << self
17
+ def configuration
18
+ @configuration ||= Configuration.new
19
+ end
20
+
21
+ alias config configuration
22
+
23
+ def configure
24
+ yield configuration
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'solidus_core'
4
+ require 'solidus_support'
5
+
6
+ module SolidusOpenPay
7
+ class Engine < Rails::Engine
8
+ include SolidusSupport::EngineExtensions
9
+
10
+ isolate_namespace ::Spree
11
+ engine_name 'solidus_open_pay'
12
+
13
+ initializer 'spree.gateway.payment_methods', after: 'spree.register.payment_methods' do |app|
14
+ app.config.spree.payment_methods << 'SolidusOpenPay::PaymentMethod'
15
+
16
+ Spree::PermittedAttributes.source_attributes.push(
17
+ :address_attributes,
18
+ :cc_type,
19
+ :number,
20
+ :name,
21
+ :verification_value,
22
+ :token_id,
23
+ :type,
24
+ :brand,
25
+ :points_card,
26
+ :points_type,
27
+ :expiration_month,
28
+ :expiration_year,
29
+ :device_session_id
30
+ )
31
+ end
32
+
33
+ # Use rspec for tests
34
+ config.generators do |g|
35
+ g.test_framework :rspec
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :open_pay_payment_method, class: 'SolidusOpenPay::PaymentMethod' do
5
+ type { 'SolidusOpenPay::PaymentMethod' }
6
+ name { 'OpenPay Payment Method' }
7
+ active { true }
8
+ auto_capture { false }
9
+ preferences {
10
+ {
11
+ server: 'test',
12
+ public_key: SecureRandom.hex(10),
13
+ private_key: SecureRandom.hex(10),
14
+ merchant_id: SecureRandom.hex(8),
15
+ country: '',
16
+ test_mode: true
17
+ }
18
+ }
19
+ end
20
+
21
+ factory :open_pay_payment_source, class: 'SolidusOpenPay::PaymentSource' do
22
+ name { 'User Test' }
23
+ device_session_id { 'noycha3iERwYIJCy74Uv57fI0CsfXMU4' }
24
+ verification_value { 'ABC123' }
25
+ token_id { SecureRandom.hex(10) }
26
+ number { '4242' }
27
+ expiration_month { '9' }
28
+ expiration_year { '29' }
29
+ brand { 'visa' }
30
+ points_card { true }
31
+ points_type { 'bancomer' }
32
+ payment_method { create(:open_pay_payment_method) }
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusOpenPay
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'solidus_open_pay/configuration'
4
+ require 'solidus_open_pay/version'
5
+ require 'solidus_open_pay/engine'
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # desc "Explaining what the task does"
4
+ # task :solidus_open_pay do
5
+ # # Task goes here
6
+ # end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/solidus_open_pay/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'solidus_open_pay'
7
+ s.version = SolidusOpenPay::VERSION
8
+ s.authors = %w(Jonathan Tapia)
9
+ s.email = %w(jtapia.dev@gmail.com)
10
+
11
+ s.summary = 'Solidus Engine for Openpay Mexican Payment Gateway'
12
+ s.homepage = 'http://github.com/jtapia/solidus_open_pay'
13
+ s.license = 'BSD-3-Clause'
14
+
15
+ s.metadata['homepage_uri'] = s.homepage
16
+ s.metadata['source_code_uri'] = 'https://github.com/jtapia/solidus_open_pay'
17
+ s.metadata['changelog_uri'] = 'https://github.com/jtapia/solidus_open_pay/blob/master/CHANGELOG.md'
18
+
19
+ s.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 4')
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
24
+
25
+ s.files = files.grep_v(%r{^(test|spec|features)/})
26
+ s.test_files = files.grep(%r{^(test|spec|features)/})
27
+ s.bindir = "exe"
28
+ s.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ s.require_paths = ["lib"]
30
+
31
+ s.add_dependency 'deface', '~> 1.5'
32
+ s.add_dependency 'solidus_core', '>= 3.0', '< 5.0'
33
+ s.add_dependency 'solidus_support', '>= 0.8.0'
34
+
35
+ s.add_dependency 'openpay'
36
+
37
+ s.add_development_dependency 'rails-controller-testing'
38
+ s.add_development_dependency 'solidus_dev_support', '~> 2.5'
39
+ end