solidus_paypal_commerce_platform 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d729015bdddd523c8210fb8276c47d11a79b6a3e91ef1107a51c9ced0e9a840
4
- data.tar.gz: ed5a4f61038c0596b75ae0d6914f3a98a225b3408911bdc64eb287d5131fcde7
3
+ metadata.gz: 9978b8449f0f9ae68173743517e3b4c1316a590e9407fff1768eeef0b3a087a2
4
+ data.tar.gz: 3fc6310b89a972b8950917e2ead0b23144e262d536f8465a9d2096ca51ec967b
5
5
  SHA512:
6
- metadata.gz: 48a8ac2f5d03d0d0e32f0a5d36d53a78ea1baccc6bd4a59e09b24a6d8820d92a4e2a98e0a30fb22c5d969d5bf75a423ed7c8f3bdbbab937ecb7857e270a0778f
7
- data.tar.gz: e714276710dea1c6538cd46e475a0b689060c905ca0d3a69743e0d8236b16dc8d55b5226012ddc365fc8c0339836cc2b4e3c2662be5e77ccf357c7464c9dc7f7
6
+ metadata.gz: 4d17b5204087cc10c13db4dc384cb7b961e37c50d13e775f05e4d7531e454be94798a072274b36e4b30557a1e58c2afe9671e035d7a50a8d7c7160845aa224e4
7
+ data.tar.gz: 0df8558dd967fd6c8c62157a35f7b17809bb92cdbf5d8cfca5d622c34faef779f54bda2b61eb46a8ede1932db91f6a4b63fe7e6dde6b58c7f08d0edd29986d5c
@@ -7,15 +7,12 @@ AllCops:
7
7
  - spec/dummy/**/*
8
8
  - vendor/bundle/**/*
9
9
 
10
- Layout/IndentFirstArgument:
10
+ Layout/FirstArgumentIndentation:
11
11
  EnforcedStyle: consistent
12
12
 
13
- Layout/IndentFirstArrayElement:
13
+ Layout/FirstArrayElementIndentation:
14
14
  EnforcedStyle: consistent
15
15
 
16
- Metrics/LineLength:
17
- Max: 120
18
-
19
16
  # We use this extensively, the alternatives are not viable or desirable.
20
17
  RSpec/AnyInstance:
21
18
  Enabled: false
@@ -54,3 +51,28 @@ Style/FrozenStringLiteralComment:
54
51
  Security/YAMLLoad:
55
52
  Exclude:
56
53
  - spec/**/*
54
+
55
+ RSpec/MultipleMemoizedHelpers:
56
+ Exclude:
57
+ - spec/jobs/solidus_paypal_commerce_platform/webhook_job_spec.rb
58
+ - spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb
59
+ - spec/models/solidus_paypal_commerce_platform/payment_source_spec.rb
60
+
61
+ Rails/Inquiry:
62
+ Enabled: true
63
+ Exclude:
64
+ - spec/lib/solidus_paypal_commerce_platform/configuration_spec.rb
65
+
66
+ # New cops (2020-09-03)
67
+
68
+ Rails/ActiveRecordCallbacksOrder: {Enabled: true}
69
+ Rails/FindById: {Enabled: true}
70
+ Rails/MailerName: {Enabled: true}
71
+ Rails/MatchRoute: {Enabled: true}
72
+ Rails/NegateInclude: {Enabled: true}
73
+ Rails/Pluck: {Enabled: true}
74
+ Rails/PluckInWhere: {Enabled: true}
75
+ Rails/RenderInline: {Enabled: true}
76
+ Rails/RenderPlainText: {Enabled: true}
77
+ Rails/ShortI18n: {Enabled: true}
78
+ Rails/WhereExists: {Enabled: true}
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # SolidusPaypalCommercePlatform
1
+ # Solidus Paypal Commerce Platform
2
2
 
3
- [![CircleCI](https://circleci.com/gh/nebulab/solidus_paypal_commerce_platform.svg?style=shield)](https://circleci.com/gh/nebulab/solidus_paypal_commerce_platform)
4
- [![codecov](https://codecov.io/gh/nebulab/solidus_paypal_commerce_platform/branch/master/graph/badge.svg)](https://codecov.io/gh/nebulab/solidus_paypal_commerce_platform)
3
+ [![CircleCI](https://circleci.com/gh/solidusio-contrib/solidus_paypal_commerce_platform.svg?style=shield)](https://circleci.com/gh/solidusio-contrib/solidus_paypal_commerce_platform)
4
+ [![codecov](https://codecov.io/gh/solidusio-contrib/solidus_paypal_commerce_platform/branch/master/graph/badge.svg)](https://codecov.io/gh/solidusio-contrib/solidus_paypal_commerce_platform)
5
5
 
6
6
  The official PayPal integration of Solidus.
7
7
 
@@ -110,6 +110,26 @@ end
110
110
 
111
111
  The instances of your wizard class should respond to `#name` and `#partial_name`, where `partial_name` will return the path to the partial you'd like to display on the wizard setup section. In our case, we just display a button to direct the user to PayPal.
112
112
 
113
+ ## State Guesser
114
+ PayPal users can change their shipping address directly on PayPal, which will
115
+ update their address on Solidus as well. However, in some instances, Solidus
116
+ uses the incorrect subregion level for states, which causes validation problems
117
+ with the addresses that PayPal sends to us.
118
+
119
+ For instance, if your user lives in Pescara, Italy, then PayPal will return
120
+ "Pescara" as the state. However on older version of Solidus, the region
121
+ "Abruzzo" is used, so the address will not be able to validate. To solve this
122
+ issue, we've implented a class that attempts to guess the state of the user
123
+ using Carmen subregions if the state cannot be initially found. You can, of
124
+ course, implement your own state guesser and set it like this:
125
+
126
+ ```ruby
127
+ # config/initializers/use_my_guesser.rb
128
+ SolidusPaypalCommercePlatform.configure do |config|
129
+ config.state_guesser_class = "MyApp::MyStateGuesser"
130
+ end
131
+ ```
132
+
113
133
  ## Custom Checkout Steps
114
134
 
115
135
  With product and cart page checkout, the user is directed to the checkout confirmation step when they return from PayPal. If you've removed the confirmation step, you'll need to override the `SolidusPaypalCommercePlatform.finalizeOrder` JavaScript method to instead complete the order.
@@ -165,7 +185,7 @@ Use Ctrl-C to stop
165
185
  Your new extension version can be released using `gem-release` like this:
166
186
 
167
187
  ```shell
168
- bundle exec gem bump -v VERSION --tag --push --remote upstream && gem release
188
+ bundle exec gem bump -v VERSION --tag --push --remote origin && gem release
169
189
  ```
170
190
 
171
191
  ## License
@@ -6,6 +6,12 @@ SolidusPaypalCommercePlatform.hideOverlay = function() {
6
6
  document.getElementById("paypal_commerce_platform_overlay").style.display = "none";
7
7
  }
8
8
 
9
+ SolidusPaypalCommercePlatform.handleError = function(error) {
10
+ console.log(error.name, error.message)
11
+ console.log("PayPal Debug ID: " + error.debug_id)
12
+ alert("There was a problem connecting with PayPal.")
13
+ }
14
+
9
15
  SolidusPaypalCommercePlatform.sendOrder = function(payment_method_id) {
10
16
  return Spree.ajax({
11
17
  url: '/solidus_paypal_commerce_platform/paypal_orders/' + Spree.current_order_id,
@@ -14,8 +20,10 @@ SolidusPaypalCommercePlatform.sendOrder = function(payment_method_id) {
14
20
  payment_method_id: payment_method_id,
15
21
  order_token: Spree.current_order_token
16
22
  }
17
- }).then(function(response) {
18
- return response.table.id;
23
+ }).then(function(success_response) {
24
+ return success_response.table.result.table.id
25
+ }, function(failure_response) {
26
+ return failure_response.responseJSON.table.error.table
19
27
  })
20
28
  }
21
29
 
@@ -97,8 +105,10 @@ SolidusPaypalCommercePlatform.shippingChange = function(data, actions) {
97
105
  actions.reject()
98
106
  }
99
107
  }).then(function(response) {
100
- actions.order.patch([response]);
101
- });
108
+ actions.order.patch([response]).catch(function() {
109
+ actions.reject()
110
+ })
111
+ })
102
112
  }
103
113
 
104
114
  SolidusPaypalCommercePlatform.verifyTotal = function(paypal_total) {
@@ -3,7 +3,8 @@ SolidusPaypalCommercePlatform.renderButton = function(payment_method_id, style)
3
3
  style: style,
4
4
  createOrder: SolidusPaypalCommercePlatform.sendOrder.bind(null, payment_method_id),
5
5
  onApprove: SolidusPaypalCommercePlatform.approveOrder,
6
- onShippingChange: SolidusPaypalCommercePlatform.shippingChange
6
+ onShippingChange: SolidusPaypalCommercePlatform.shippingChange,
7
+ onError: SolidusPaypalCommercePlatform.handleError
7
8
  }).render('#paypal-button-container')
8
9
  }
9
10
 
@@ -12,7 +13,8 @@ SolidusPaypalCommercePlatform.renderCartButton = function(payment_method_id, sty
12
13
  style: style,
13
14
  createOrder: SolidusPaypalCommercePlatform.sendOrder.bind(null, payment_method_id),
14
15
  onApprove: SolidusPaypalCommercePlatform.finalizeOrder.bind(null, payment_method_id),
15
- onShippingChange: SolidusPaypalCommercePlatform.shippingChange
16
+ onShippingChange: SolidusPaypalCommercePlatform.shippingChange,
17
+ onError: SolidusPaypalCommercePlatform.handleError
16
18
  }).render('#paypal-button-container')
17
19
  }
18
20
 
@@ -21,6 +23,7 @@ SolidusPaypalCommercePlatform.renderProductButton = function(payment_method_id,
21
23
  style: style,
22
24
  createOrder: SolidusPaypalCommercePlatform.createAndSendOrder.bind(null, payment_method_id),
23
25
  onApprove: SolidusPaypalCommercePlatform.finalizeOrder.bind(null, payment_method_id),
24
- onShippingChange: SolidusPaypalCommercePlatform.shippingChange
26
+ onShippingChange: SolidusPaypalCommercePlatform.shippingChange,
27
+ onError: SolidusPaypalCommercePlatform.handleError
25
28
  }).render('#paypal-button-container')
26
29
  }
@@ -7,7 +7,9 @@ module SolidusPaypalCommercePlatform
7
7
 
8
8
  def show
9
9
  authorize! :show, @order, order_token
10
- render json: @payment_method.gateway.create_order(@order, @payment_method.auto_capture), status: :ok
10
+ order_request = @payment_method.gateway.create_order(@order, @payment_method.auto_capture)
11
+
12
+ render json: order_request, status: order_request.status_code
11
13
  end
12
14
 
13
15
  private
@@ -77,8 +77,7 @@ module SolidusPaypalCommercePlatform
77
77
  request = OrdersCreateRequest.new
78
78
  paypal_order = SolidusPaypalCommercePlatform::PaypalOrder.new(order)
79
79
  request.request_body paypal_order.to_json(intent)
80
-
81
- @client.execute(request).result
80
+ @client.execute(request)
82
81
  end
83
82
 
84
83
  def get_order(order_id)
@@ -42,12 +42,20 @@ module SolidusPaypalCommercePlatform
42
42
  @order.update(email: recipient[:email_address])
43
43
  end
44
44
 
45
+ def find_state(state_name, country)
46
+ if state = country.states.find_by(abbr: state_name) || country.states.find_by(name: state_name)
47
+ state
48
+ else
49
+ SolidusPaypalCommercePlatform.config.state_guesser_class.new(state_name, country).guess
50
+ end
51
+ end
52
+
45
53
  def format_simulated_address(paypal_address)
46
54
  country = ::Spree::Country.find_by(iso: paypal_address[:country_code])
47
55
  # Also adds fake information for a few fields, so validations can run
48
56
  ::Spree::Address.new(
49
57
  city: paypal_address[:city],
50
- state: country.states.find_by(abbr: paypal_address[:state]),
58
+ state: find_state(paypal_address[:state], country),
51
59
  state_name: paypal_address[:state],
52
60
  zipcode: paypal_address[:postal_code],
53
61
  country: country,
@@ -61,14 +69,11 @@ module SolidusPaypalCommercePlatform
61
69
  address = paypal_address[:updated_address]
62
70
  recipient = paypal_address[:recipient]
63
71
  country = ::Spree::Country.find_by(iso: address[:country_code])
64
- state = country.states.where(abbr: address[:admin_area_1]).or(
65
- country.states.where(name: address[:admin_area_1])
66
- ).first
67
72
 
68
73
  {
69
74
  address1: address[:address_line_1],
70
75
  address2: address[:address_line_2],
71
- state: state,
76
+ state: find_state(address[:admin_area_1], country),
72
77
  state_name: address[:admin_area_1],
73
78
  city: address[:admin_area_2],
74
79
  country: country,
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusPaypalCommercePlatform
4
+ class StateGuesser
5
+ def initialize(state_name, country)
6
+ @state_name = state_name
7
+ @country = country
8
+ end
9
+
10
+ def guess
11
+ carmen_state = state_list.find{ |s| s.name == @state_name || s.code == @state_name }
12
+ return if carmen_state.blank?
13
+
14
+ guessed_state = spree_state(carmen_state.name)
15
+ guessed_state || spree_state(carmen_state.parent.name)
16
+ end
17
+
18
+ private
19
+
20
+ def state_list
21
+ Carmen::Country.coded(@country.iso).subregions.map{ |s| [s, s.subregions] }.flatten
22
+ end
23
+
24
+ def spree_state(name)
25
+ Spree::State.find_by(name: name)
26
+ end
27
+ end
28
+ end
@@ -1,13 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # frozen_string_literal: true
4
-
5
3
  app_root = 'sandbox'
6
4
 
7
5
  unless File.exist? "#{app_root}/bin/rails"
8
6
  warn 'Creating the sandbox app...'
9
7
  Dir.chdir "#{__dir__}/.." do
10
- system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
8
+ system "#{__dir__}/sandbox" or begin
11
9
  warn 'Automatic creation of the sandbox app failed'
12
10
  exit 1
13
11
  end
@@ -72,11 +72,11 @@ unbundled bundle exec rails generate spree:install \
72
72
  --user_class=Spree::User \
73
73
  --enforce_available_locales=true \
74
74
  --with-authentication=false \
75
+ --payment-method=none
75
76
  $@
76
77
 
77
78
  unbundled bundle exec rails generate solidus:auth:install
78
- unbundled bundle exec rails generate solidus_paypal_commerce_platform:install
79
- unbundled bundle exec rails db:migrate
79
+ unbundled bundle exec rails generate ${extension_name}:install
80
80
 
81
81
  echo
82
82
  echo "🚀 Sandbox app successfully created for $extension_name!"
@@ -6,13 +6,13 @@ module SolidusPaypalCommercePlatform
6
6
  class_option :auto_run_migrations, type: :boolean, default: false
7
7
 
8
8
  def add_javascripts
9
- append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_paypal_commerce_platform\n" # rubocop:disable Metrics/LineLength
10
- append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_paypal_commerce_platform\n" # rubocop:disable Metrics/LineLength
9
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_paypal_commerce_platform\n" # rubocop:disable Layout/LineLength
10
+ append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_paypal_commerce_platform\n" # rubocop:disable Layout/LineLength
11
11
  end
12
12
 
13
13
  def add_stylesheets
14
- inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_paypal_commerce_platform\n", before: %r{\*/}, verbose: true # rubocop:disable Metrics/LineLength
15
- inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_paypal_commerce_platform\n", before: %r{\*/}, verbose: true # rubocop:disable Metrics/LineLength
14
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_paypal_commerce_platform\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
15
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_paypal_commerce_platform\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
16
16
  end
17
17
 
18
18
  def add_migrations
@@ -26,7 +26,7 @@ module SolidusPaypalCommercePlatform
26
26
  end
27
27
 
28
28
  def run_migrations
29
- run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Metrics/LineLength
29
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
30
30
  if run_migrations
31
31
  run 'bin/rails db:migrate'
32
32
  else
@@ -27,8 +27,9 @@ module SolidusPaypalCommercePlatform
27
27
 
28
28
  def execute(request)
29
29
  @paypal_client.execute(request)
30
- rescue PayPalHttp::HttpError
31
- OpenStruct.new(status_code: nil)
30
+ rescue PayPalHttp::HttpError => e
31
+ Rails.logger.error e.result
32
+ OpenStruct.new(status_code: 422, error: e.result)
32
33
  end
33
34
 
34
35
  def execute_with_response(request, success_message: nil, failure_message: nil)
@@ -4,6 +4,8 @@ require 'paypal-checkout-sdk'
4
4
 
5
5
  module SolidusPaypalCommercePlatform
6
6
  class Configuration
7
+ attr_writer :state_guesser_class, :partner_id, :partner_client_id
8
+
7
9
  InvalidEnvironment = Class.new(StandardError)
8
10
 
9
11
  DEFAULT_PARTNER_ID = {
@@ -16,6 +18,12 @@ module SolidusPaypalCommercePlatform
16
18
  live: "ASOxaUMkeX5bv7PbXnWUDnqb3SVYkzRSosApmLGFih-eAhB_OS_Wo6juijE5t8NCmWDgpN2ugHMmQFWA",
17
19
  }.freeze
18
20
 
21
+ def state_guesser_class
22
+ self.state_guesser_class = "SolidusPaypalCommercePlatform::StateGuesser" unless @state_guesser_class
23
+
24
+ @state_guesser_class.constantize
25
+ end
26
+
19
27
  def env=(value)
20
28
  unless %w[live sandbox].include? value
21
29
  raise InvalidEnvironment, "#{value} is not a valid environment"
@@ -35,9 +43,9 @@ module SolidusPaypalCommercePlatform
35
43
 
36
44
  case Rails.env
37
45
  when 'production'
38
- return 'live'
46
+ 'live'
39
47
  when 'test', 'development'
40
- return 'sandbox'
48
+ 'sandbox'
41
49
  else
42
50
  raise InvalidEnvironment, "Unable to guess the PayPal env, please set #{self}.env= explicitly."
43
51
  end
@@ -51,8 +59,6 @@ module SolidusPaypalCommercePlatform
51
59
  env.live? ? "www.paypal.com" : "www.sandbox.paypal.com"
52
60
  end
53
61
 
54
- attr_writer :partner_id, :partner_client_id
55
-
56
62
  def partner_id
57
63
  @partner_id ||= ENV['PAYPAL_PARTNER_ID'] || DEFAULT_PARTNER_ID[env.to_sym]
58
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusPaypalCommercePlatform
4
- VERSION = '0.0.1'
4
+ VERSION = '0.1.0'
5
5
  end
@@ -9,12 +9,12 @@ Gem::Specification.new do |spec|
9
9
  spec.email = 'contact@solidus.io'
10
10
 
11
11
  spec.summary = 'Integrate Solidus with Paypal Commerce Platform'
12
- spec.homepage = 'https://github.com/nebulab/solidus_paypal_commerce_platform#readme'
12
+ spec.homepage = 'https://github.com/solidusio-contrib/solidus_paypal_commerce_platform#readme'
13
13
  spec.license = 'BSD-3-Clause'
14
14
 
15
15
  spec.metadata['homepage_uri'] = spec.homepage
16
- spec.metadata['source_code_uri'] = 'https://github.com/nebulab/solidus_paypal_commerce_platform'
17
- spec.metadata['changelog_uri'] = 'https://github.com/nebulab/solidus_paypal_commerce_platform/releases'
16
+ spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_paypal_commerce_platform#readme'
17
+ spec.metadata['changelog_uri'] = 'https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/releases'
18
18
 
19
19
  spec.required_ruby_version = Gem::Requirement.new('~> 2.5')
20
20
 
@@ -35,5 +35,6 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_dependency 'paypal-checkout-sdk'
37
37
 
38
+ spec.add_development_dependency 'cuprite'
38
39
  spec.add_development_dependency 'solidus_dev_support'
39
40
  end
@@ -48,12 +48,14 @@ RSpec.describe "Product page", js: true do
48
48
 
49
49
  it "creates an order successfully" do
50
50
  page.evaluate_script("SolidusPaypalCommercePlatform.createOrder()")
51
+ page.driver.wait_for_network_idle
51
52
 
52
53
  expect(Spree::Order.last).not_to be nil
53
54
  end
54
55
 
55
56
  it "sets the Spree number and token variables" do
56
57
  page.evaluate_script("SolidusPaypalCommercePlatform.createOrder()")
58
+ page.driver.wait_for_network_idle
57
59
 
58
60
  expect(page.evaluate_script("Spree.current_order_id")).to eq Spree::Order.last.number
59
61
  expect(page.evaluate_script("Spree.current_order_token")).to eq Spree::Order.last.guest_token
@@ -64,6 +66,7 @@ RSpec.describe "Product page", js: true do
64
66
  fill_in('quantity', with: quantity)
65
67
 
66
68
  page.evaluate_script("SolidusPaypalCommercePlatform.createOrder()")
69
+ page.driver.wait_for_network_idle
67
70
 
68
71
  expect(Spree::Order.last.line_items.first.quantity).to eq quantity
69
72
  end
@@ -71,6 +74,7 @@ RSpec.describe "Product page", js: true do
71
74
  it "uses the selected variant" do
72
75
  page.choose("variant_id_#{variant_two.id}")
73
76
  page.evaluate_script("SolidusPaypalCommercePlatform.createOrder()")
77
+ page.driver.wait_for_network_idle
74
78
 
75
79
  expect(Spree::Order.last.line_items.first.variant_id).to eq variant_two.id
76
80
  end
@@ -64,4 +64,22 @@ RSpec.describe SolidusPaypalCommercePlatform::Configuration do
64
64
  expect(subject.env_domain).to eq("www.sandbox.paypal.com")
65
65
  end
66
66
  end
67
+
68
+ describe "#state_guesser_class" do
69
+ before do
70
+ stub_const('SolidusPaypalCommercePlatform::BetterStateGuesser', Class.new)
71
+ end
72
+
73
+ it "returns a class" do
74
+ expect(subject.state_guesser_class).to be_kind_of(Class)
75
+ end
76
+
77
+ it "is settable" do
78
+ expect(subject.state_guesser_class).to eq(SolidusPaypalCommercePlatform::StateGuesser)
79
+
80
+ subject.state_guesser_class = "SolidusPaypalCommercePlatform::BetterStateGuesser"
81
+
82
+ expect(subject.state_guesser_class).to eq(SolidusPaypalCommercePlatform::BetterStateGuesser)
83
+ end
84
+ end
67
85
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe SolidusPaypalCommercePlatform::StateGuesser, type: :model do
4
+ let(:country) { create(:country, iso: "IT") }
5
+ let!(:state) { create(:state, country: country, name: "Abruzzo") }
6
+
7
+ describe "#guess" do
8
+ context "with a guessable state error" do
9
+ it "correctly guesses the state" do
10
+ expect(
11
+ described_class.new("Pescara", country).guess
12
+ ).to eq state
13
+ end
14
+
15
+ it "guesses the state using an abbreviation" do
16
+ expect(
17
+ described_class.new("PE", country).guess
18
+ ).to eq state
19
+ end
20
+ end
21
+
22
+ context "with an unsolvable state error" do
23
+ it "returns nil" do
24
+ expect(
25
+ described_class.new("Gondor", country).guess
26
+ ).to eq nil
27
+ end
28
+ end
29
+
30
+ context "with an already correct state" do
31
+ it "returns the correct state" do
32
+ expect(
33
+ described_class.new("Abruzzo", country).guess
34
+ ).to eq state
35
+ end
36
+ end
37
+ end
38
+ end
@@ -7,11 +7,9 @@ ENV['RAILS_ENV'] = 'test'
7
7
  require 'solidus_dev_support/rspec/coverage'
8
8
 
9
9
  # Create the dummy app if it's still missing.
10
- dummy_app_environment = File.expand_path('dummy/config/environment.rb', __dir__).tap do |file|
11
- system 'bin/rake extension:test_app' unless File.exist? file
12
- end
13
-
14
- require dummy_app_environment
10
+ dummy_env = "#{__dir__}/dummy/config/environment.rb"
11
+ system 'bin/rake extension:test_app' unless File.exist? dummy_env
12
+ require dummy_env
15
13
 
16
14
  # Requires factories and other useful helpers defined in spree_core.
17
15
  require 'solidus_dev_support/rspec/feature_helper'
@@ -19,7 +17,7 @@ require 'spree/testing_support/order_walkthrough'
19
17
 
20
18
  # Requires supporting ruby files with custom matchers and macros, etc,
21
19
  # in spec/support/ and its subdirectories.
22
- Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
20
+ Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
23
21
 
24
22
  # Requires factories defined in lib/solidus_paypal_commerce_platform/factories.rb
25
23
  require 'solidus_paypal_commerce_platform/factories'
@@ -27,4 +25,8 @@ require 'solidus_paypal_commerce_platform/factories'
27
25
  RSpec.configure do |config|
28
26
  config.infer_spec_type_from_file_location!
29
27
  config.use_transactional_fixtures = false
28
+
29
+ if Spree.solidus_gem_version < Gem::Version.new('2.11')
30
+ config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
31
+ end
30
32
  end
@@ -0,0 +1,11 @@
1
+ require "capybara/cuprite"
2
+
3
+ Capybara.javascript_driver = :cuprite
4
+
5
+ Capybara.register_driver(:cuprite) do |app|
6
+ # Set `export INSPECTOR=true` and add `page.driver.debug(binding)` to open a Chrome tab
7
+ # to debug the browser status.
8
+ #
9
+ # See also: https://github.com/rubycdp/cuprite#debugging
10
+ Capybara::Cuprite::Driver.new(app, window_size: [1920, 1080], inspector: ENV["INSPECTOR"])
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_paypal_commerce_platform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Denny
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-08-10 00:00:00.000000000 Z
12
+ date: 2020-09-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: deface
@@ -87,6 +87,20 @@ dependencies:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
+ - !ruby/object:Gem::Dependency
91
+ name: cuprite
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
90
104
  - !ruby/object:Gem::Dependency
91
105
  name: solidus_dev_support
92
106
  requirement: !ruby/object:Gem::Requirement
@@ -141,6 +155,7 @@ files:
141
155
  - app/models/solidus_paypal_commerce_platform/paypal_address.rb
142
156
  - app/models/solidus_paypal_commerce_platform/paypal_order.rb
143
157
  - app/models/solidus_paypal_commerce_platform/pricing_options.rb
158
+ - app/models/solidus_paypal_commerce_platform/state_guesser.rb
144
159
  - app/models/solidus_paypal_commerce_platform/wizard.rb
145
160
  - app/overrides/spree/admin/payment_methods/form/insert_email_verification_notification.rb
146
161
  - app/overrides/spree/admin/payment_methods/index/insert_setup_wizards.rb
@@ -201,18 +216,20 @@ files:
201
216
  - spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb
202
217
  - spec/models/solidus_paypal_commerce_platform/payment_source_spec.rb
203
218
  - spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb
219
+ - spec/models/solidus_paypal_commerce_platform/state_guesser_spec.rb
204
220
  - spec/models/solidus_paypal_commerce_platform/wizard_spec.rb
205
221
  - spec/requests/solidus_paypal_commerce_platform/orders_controller_spec.rb
206
222
  - spec/requests/solidus_paypal_commerce_platform/shipping_rates_controller_spec.rb
207
223
  - spec/requests/solidus_paypal_commerce_platform/wizard_controller_spec.rb
208
224
  - spec/spec_helper.rb
209
- homepage: https://github.com/nebulab/solidus_paypal_commerce_platform#readme
225
+ - spec/support/capybara.rb
226
+ homepage: https://github.com/solidusio-contrib/solidus_paypal_commerce_platform#readme
210
227
  licenses:
211
228
  - BSD-3-Clause
212
229
  metadata:
213
- homepage_uri: https://github.com/nebulab/solidus_paypal_commerce_platform#readme
214
- source_code_uri: https://github.com/nebulab/solidus_paypal_commerce_platform
215
- changelog_uri: https://github.com/nebulab/solidus_paypal_commerce_platform/releases
230
+ homepage_uri: https://github.com/solidusio-contrib/solidus_paypal_commerce_platform#readme
231
+ source_code_uri: https://github.com/solidusio-contrib/solidus_paypal_commerce_platform#readme
232
+ changelog_uri: https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/releases
216
233
  post_install_message:
217
234
  rdoc_options: []
218
235
  require_paths:
@@ -251,8 +268,10 @@ test_files:
251
268
  - spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb
252
269
  - spec/models/solidus_paypal_commerce_platform/payment_source_spec.rb
253
270
  - spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb
271
+ - spec/models/solidus_paypal_commerce_platform/state_guesser_spec.rb
254
272
  - spec/models/solidus_paypal_commerce_platform/wizard_spec.rb
255
273
  - spec/requests/solidus_paypal_commerce_platform/orders_controller_spec.rb
256
274
  - spec/requests/solidus_paypal_commerce_platform/shipping_rates_controller_spec.rb
257
275
  - spec/requests/solidus_paypal_commerce_platform/wizard_controller_spec.rb
258
276
  - spec/spec_helper.rb
277
+ - spec/support/capybara.rb