From 000bab30e2c6b7810b728ea9af19610afd6f0eae Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 30 Aug 2022 10:12:33 +0200 Subject: [PATCH 1/5] Add rexml gem to the gemspec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It became an external gem in recent Ruby versions. Co-Authored-By: Marc Busqué --- solidus_stripe.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/solidus_stripe.gemspec b/solidus_stripe.gemspec index e6ebedcf..e3c67ecd 100644 --- a/solidus_stripe.gemspec +++ b/solidus_stripe.gemspec @@ -32,6 +32,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'solidus_core', ['>= 2.3', '< 4'] spec.add_dependency 'solidus_support', '~> 0.8' spec.add_dependency 'activemerchant', '>= 1.105' + spec.add_dependency 'rexml' spec.add_development_dependency 'solidus_dev_support', '~> 2.3' end From dfa6017985f74f4d363e5ddb1c090357d010cb61 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 30 Aug 2022 10:21:12 +0200 Subject: [PATCH 2/5] Update the extension with the latest dev-support generator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Marc Busqué --- .circleci/config.yml | 12 ++++++++++-- Gemfile | 15 +++++++-------- README.md | 15 ++++++++++----- bin/sandbox | 2 +- lib/solidus_stripe/configuration.rb | 2 +- solidus_stripe.gemspec | 4 ++-- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 291afdd1..18b94fa7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,14 +1,15 @@ version: 2.1 orbs: + # Required for feature specs. + browser-tools: circleci/browser-tools@1.1 + # Always take the latest version of the orb, this allows us to # run specs against Solidus supported versions only without the need # to change this configuration every time a Solidus version is released # or goes EOL. solidusio_extensions: solidusio/extensions@volatile - browser-tools: circleci/browser-tools@1.1 - jobs: run-specs-with-postgres: executor: solidusio_extensions/postgres @@ -20,6 +21,11 @@ jobs: steps: - browser-tools/install-browser-tools - solidusio_extensions/run-tests + run-specs-with-sqlite: + executor: solidusio_extensions/sqlite-memory + steps: + - browser-tools/install-browser-tools + - solidusio_extensions/run-tests lint-code: executor: solidusio_extensions/sqlite-memory steps: @@ -30,6 +36,8 @@ workflows: jobs: - run-specs-with-postgres - run-specs-with-mysql + - run-specs-with-sqlite + - lint-code "Weekly run specs against master": triggers: diff --git a/Gemfile b/Gemfile index 661491e6..c338a8cd 100644 --- a/Gemfile +++ b/Gemfile @@ -4,13 +4,12 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } branch = ENV.fetch('SOLIDUS_BRANCH', 'master') -solidus_git, solidus_frontend_git = if (branch == 'master') || (branch >= 'v3.2') - %w[solidusio/solidus solidusio/solidus_frontend] - else - %w[solidusio/solidus] * 2 - end -gem 'solidus', github: solidus_git, branch: branch -gem 'solidus_frontend', github: solidus_frontend_git, branch: branch +gem 'solidus', github: 'solidusio/solidus', branch: branch + +# The solidus_frontend gem has been pulled out since v3.2 +if (branch == 'master') || (branch >= 'v3.2') + gem 'solidus_frontend', github: 'solidusio/solidus_frontend', branch: branch +end # Needed to help Bundler figure out how to resolve dependencies, # otherwise it takes forever to resolve them. @@ -20,7 +19,7 @@ gem 'rails', '>0.a' # Provides basic authentication functionality for testing parts of your engine gem 'solidus_auth_devise' -case ENV['DB'] +case ENV.fetch('DB', nil) when 'mysql' gem 'mysql2' when 'postgresql' diff --git a/README.md b/README.md index 1064a1bb..dfaf48bd 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,8 @@ Stripe Payment Method for Solidus. It works as a wrapper for the ActiveMerchant Stripe gateway. ---- +## Installation -Installation ------------- Run from the command line: @@ -277,10 +275,17 @@ bundle exec rubocop ``` When testing your application's integration with this extension you may use its factories. -Simply add this require statement to your spec_helper: +Simply add this require statement to your `spec/spec_helper.rb`: ```ruby -require '<%= file_name %>/factories' +require 'solidus_stripe/testing_support/factories' +``` + +Or, if you are using `FactoryBot.definition_file_paths`, you can load Solidus core +factories along with this extension's factories using this statement: + +```ruby +SolidusDevSupport::TestingSupport::Factories.load_for(SolidusStripe::Engine) ``` ### Running the sandbox diff --git a/bin/sandbox b/bin/sandbox index 8736bef9..fff63379 100755 --- a/bin/sandbox +++ b/bin/sandbox @@ -67,7 +67,7 @@ unbundled bundle install --gemfile Gemfile unbundled bundle exec rake db:drop db:create -unbundled bundle exec rails generate spree:install \ +unbundled bundle exec rails generate solidus:install \ --auto-accept \ --user_class=Spree::User \ --enforce_available_locales=true \ diff --git a/lib/solidus_stripe/configuration.rb b/lib/solidus_stripe/configuration.rb index 0c6eb54f..86b12421 100644 --- a/lib/solidus_stripe/configuration.rb +++ b/lib/solidus_stripe/configuration.rb @@ -2,7 +2,7 @@ module SolidusStripe class Configuration - # Define here the settings for this extensions, e.g.: + # Define here the settings for this extension, e.g.: # # attr_accessor :my_setting end diff --git a/solidus_stripe.gemspec b/solidus_stripe.gemspec index e3c67ecd..ea434af8 100644 --- a/solidus_stripe.gemspec +++ b/solidus_stripe.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |spec| spec.metadata['source_code_uri'] = 'https://github.com/solidusio/solidus_stripe' spec.metadata['changelog_uri'] = 'https://github.com/solidusio/solidus_stripe/blob/master/CHANGELOG.md' - spec.required_ruby_version = '>= 2.4.0' + spec.required_ruby_version = Gem::Requirement.new('>= 2.5') # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. @@ -34,5 +34,5 @@ Gem::Specification.new do |spec| spec.add_dependency 'activemerchant', '>= 1.105' spec.add_dependency 'rexml' - spec.add_development_dependency 'solidus_dev_support', '~> 2.3' + spec.add_development_dependency 'solidus_dev_support', '~> 2.5' end From 84e84cc2eb99e21c1bd361772c725ba3d3daa53e Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 30 Aug 2022 13:15:45 +0200 Subject: [PATCH 3/5] Use the state abbr from the current order for payments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Marc Busqué --- .../solidus_stripe/create_intents_payment_service_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/solidus_stripe/create_intents_payment_service_spec.rb b/spec/models/solidus_stripe/create_intents_payment_service_spec.rb index f14a278c..4db47bf4 100644 --- a/spec/models/solidus_stripe/create_intents_payment_service_spec.rb +++ b/spec/models/solidus_stripe/create_intents_payment_service_spec.rb @@ -26,12 +26,12 @@ stripe_payment_intent_id: intent_id, form_data: { addressLine: ["31 Cotton Rd"], - city: "San Diego", - country: "US", + city: order.bill_address.city, + country: order.bill_address.country.iso, + region: order.bill_address.state.abbr, phone: "+188836412312", postalCode: "12345", recipient: "James Edwards", - region: "CA" } } end From 0625e3abb32f949f69cb90131dd9ef84ebc5e9e6 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 30 Aug 2022 16:03:16 +0200 Subject: [PATCH 4/5] Run specs on sqlite and only install chrome We're only using chrome and skipping the firefox installation saves time. --- .circleci/config.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 18b94fa7..215d3de0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,21 +10,30 @@ orbs: # or goes EOL. solidusio_extensions: solidusio/extensions@volatile +executors: + sqlite: + description: Run specs with an in-memory SQLite + docker: + - image: cimg/ruby:2.7-browsers + environment: + RAILS_ENV: test + DB: sqlite + jobs: run-specs-with-postgres: executor: solidusio_extensions/postgres steps: - - browser-tools/install-browser-tools + - browser-tools/install-chrome - solidusio_extensions/run-tests run-specs-with-mysql: executor: solidusio_extensions/mysql steps: - - browser-tools/install-browser-tools + - browser-tools/install-chrome - solidusio_extensions/run-tests run-specs-with-sqlite: - executor: solidusio_extensions/sqlite-memory + executor: sqlite steps: - - browser-tools/install-browser-tools + - browser-tools/install-chrome - solidusio_extensions/run-tests lint-code: executor: solidusio_extensions/sqlite-memory From f85251a25273502061edfeac10135eebcaa23b74 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 30 Aug 2022 16:10:17 +0200 Subject: [PATCH 5/5] Add a rubocop todo and fix a couple of violations --- .rubocop.yml | 2 + .rubocop_todo.yml | 298 ++++++++++++++++++ .../solidus_stripe/intents_controller.rb | 4 +- .../payment_request_controller.rb | 6 +- 4 files changed, 305 insertions(+), 5 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index b075a8f6..ed101ebf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +inherit_from: .rubocop_todo.yml + require: - solidus_dev_support/rubocop diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..e425a163 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,298 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2022-08-30 14:09:43 UTC using RuboCop version 1.35.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'solidus_stripe.gemspec' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_argument, with_fixed_indentation +Layout/ArgumentAlignment: + Exclude: + - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Layout/ClosingParenthesisIndentation: + Exclude: + - 'spec/requests/payment_requests_spec.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Layout/ElseAlignment: + Exclude: + - 'app/models/solidus_stripe/address_from_params_service.rb' + - 'spec/models/solidus_stripe/address_from_params_service_spec.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyleAlignWith, Severity. +# SupportedStylesAlignWith: keyword, variable, start_of_line +Layout/EndAlignment: + Exclude: + - 'app/models/solidus_stripe/address_from_params_service.rb' + - 'spec/models/solidus_stripe/address_from_params_service_spec.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Width, AllowedPatterns, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'app/models/solidus_stripe/address_from_params_service.rb' + - 'spec/models/solidus_stripe/address_from_params_service_spec.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineMethodCallBraceLayout: + Exclude: + - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented, indented_relative_to_receiver +Layout/MultilineMethodCallIndentation: + Exclude: + - 'spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBrackets: space, no_space +Layout/SpaceInsideArrayLiteralBrackets: + Exclude: + - 'spec/models/solidus_stripe/address_from_params_service_spec.rb' + +# Offense count: 5 +# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods. +Lint/AmbiguousBlockAssociation: + Exclude: + - 'spec/models/solidus_stripe/create_intents_payment_service_spec.rb' + - 'spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb' + - 'spec/requests/payment_requests_spec.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Lint/RedundantCopDisableDirective: + Exclude: + - 'bin/sandbox_rails' + - 'lib/generators/solidus_stripe/install/install_generator.rb' + +# Offense count: 10 +RSpec/AnyInstance: + Exclude: + - 'spec/models/solidus_stripe/create_intents_payment_service_spec.rb' + - 'spec/requests/payment_requests_spec.rb' + +# Offense count: 6 +# Configuration parameters: Prefixes. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb' + +# Offense count: 8 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: method_call, block +RSpec/ExpectChange: + Exclude: + - 'spec/models/solidus_stripe/create_intents_payment_service_spec.rb' + - 'spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb' + - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb' + +# Offense count: 6 +RSpec/ExpectInHook: + Exclude: + - 'spec/features/stripe_checkout_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +RSpec/LeadingSubject: + Exclude: + - 'spec/models/solidus_stripe/address_from_params_service_spec.rb' + +# Offense count: 2 +RSpec/LetSetup: + Exclude: + - 'spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb' + - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb' + +# Offense count: 9 +# Configuration parameters: . +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + EnforcedStyle: receive + +# Offense count: 13 +RSpec/MultipleExpectations: + Max: 15 + +# Offense count: 40 +# Configuration parameters: AllowSubject. +RSpec/MultipleMemoizedHelpers: + Max: 11 + +# Offense count: 47 +# Configuration parameters: IgnoreSharedExamples. +RSpec/NamedSubject: + Exclude: + - 'spec/models/solidus_stripe/address_from_params_service_spec.rb' + - 'spec/models/solidus_stripe/create_intents_payment_service_spec.rb' + - 'spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb' + - 'spec/models/solidus_stripe/shipping_rates_service_spec.rb' + - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb' + +# Offense count: 13 +RSpec/NestedGroups: + Max: 5 + +# Offense count: 2 +RSpec/RepeatedExampleGroupBody: + Exclude: + - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: and_return, block +RSpec/ReturnFromStub: + Exclude: + - 'spec/models/solidus_stripe/create_intents_payment_service_spec.rb' + - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb' + +# Offense count: 4 +RSpec/StubbedMock: + Exclude: + - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb' + +# Offense count: 3 +RSpec/SubjectStub: + Exclude: + - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb' + +# Offense count: 12 +# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. +RSpec/VerifiedDoubles: + Exclude: + - 'spec/models/solidus_stripe/create_intents_payment_service_spec.rb' + - 'spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb' + - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforceForPrefixed. +Rails/Delegate: + Exclude: + - 'app/models/spree/payment_method/stripe_credit_card.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Whitelist, AllowedMethods, AllowedReceivers. +# Whitelist: find_by_sql +# AllowedMethods: find_by_sql +# AllowedReceivers: Gem::Specification +Rails/DynamicFindBy: + Exclude: + - 'app/models/solidus_stripe/address_from_params_service.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Include, IgnoredMethods. +# Include: app/models/**/*.rb +# IgnoredMethods: order, limit, select, lock +Rails/FindEach: + Exclude: + - 'app/models/solidus_stripe/create_intents_payment_service.rb' + +# Offense count: 5 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Include. +# Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb +Rails/Output: + Exclude: + - 'db/seeds.rb' + +# Offense count: 3 +# Configuration parameters: ForbiddenMethods, AllowedMethods. +# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all +Rails/SkipsModelValidations: + Exclude: + - 'db/migrate/20181010123508_update_stripe_payment_method_type_to_credit_card.rb' + - 'spec/models/solidus_stripe/shipping_rates_service_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Exclude: + - 'app/models/spree/payment_method/stripe_credit_card.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/ExplicitBlockArgument: + Exclude: + - 'spec/features/stripe_checkout_spec.rb' + +# Offense count: 2 +# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals. +Style/GuardClause: + Exclude: + - 'app/decorators/models/spree/order_update_attributes_decorator.rb' + - 'app/models/solidus_stripe/create_intents_payment_service.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/MultilineIfModifier: + Exclude: + - 'app/models/spree/payment_method/stripe_credit_card.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: literals, strict +Style/MutableConstant: + Exclude: + - 'app/models/spree/payment_method/stripe_credit_card.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowedMethods. +# AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with +Style/NestedParenthesizedCalls: + Exclude: + - 'lib/solidus_stripe/testing_support/card_input_helper.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantBegin: + Exclude: + - 'app/models/solidus_stripe/address_from_params_service.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/RedundantInterpolation: + Exclude: + - 'lib/solidus_stripe/testing_support/card_input_helper.rb' + +# Offense count: 19 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 163 diff --git a/app/controllers/solidus_stripe/intents_controller.rb b/app/controllers/solidus_stripe/intents_controller.rb index a98173f1..cbc0aa86 100644 --- a/app/controllers/solidus_stripe/intents_controller.rb +++ b/app/controllers/solidus_stripe/intents_controller.rb @@ -19,7 +19,7 @@ def create_payment if create_payment_service.call render json: { success: true } else - render json: { error: "Could not create payment" }, status: 500 + render json: { error: "Could not create payment" }, status: :internal_server_error end end @@ -45,7 +45,7 @@ def generate_payment_response stripe_payment_intent_id: response['id'] } else - render json: { error: response['error']['message'] }, status: 500 + render json: { error: response['error']['message'] }, status: :internal_server_error end end diff --git a/app/controllers/solidus_stripe/payment_request_controller.rb b/app/controllers/solidus_stripe/payment_request_controller.rb index f7e7da13..c2c32117 100644 --- a/app/controllers/solidus_stripe/payment_request_controller.rb +++ b/app/controllers/solidus_stripe/payment_request_controller.rb @@ -14,7 +14,7 @@ def shipping_rates if rates.any? render json: { success: true, shipping_rates: rates } else - render json: { success: false, error: 'No shipping method available for that address' }, status: 500 + render json: { success: false, error: 'No shipping method available for that address' }, status: :internal_server_error end end @@ -32,10 +32,10 @@ def update_order if current_order.payment? render json: { success: true } else - render json: { success: false, error: 'Order not ready for payment. Try manual checkout.' }, status: 500 + render json: { success: false, error: 'Order not ready for payment. Try manual checkout.' }, status: :internal_server_error end else - render json: { success: false, error: address.errors.full_messages.to_sentence }, status: 500 + render json: { success: false, error: address.errors.full_messages.to_sentence }, status: :internal_server_error end end