Skip to content

Commit

Permalink
Revert "Upgrade json_api_client gem (#158)"
Browse files Browse the repository at this point in the history
This reverts commit 621299a.
  • Loading branch information
praWeb committed Feb 18, 2019
1 parent 49feac5 commit a655352
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 114 deletions.
10 changes: 1 addition & 9 deletions app/models/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,8 @@ class LineItem < FlexCommerceApi::ApiBase
has_one :item
belongs_to :cart, class_name: "::FlexCommerce::Cart"


# note: only embedded in order responses, not carts
has_many :line_item_discounts, class_name: "::FlexCommerce::LineItemDiscount"

# This allows us to set the `path` parameter automatically from the provided
# cart_id or container_id
def self.path(params = nil, *args)
cart_id = params["cart_id"] || params["container_id"]
params["path"] = { "cart_id" => cart_id } if cart_id

super
end
end
end
3 changes: 3 additions & 0 deletions config/locales/payments.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
en:
payment_setup:
shipping_method_not_available: "Shipping method not available"
2 changes: 1 addition & 1 deletion flex-commerce-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "json_matchers", ["~> 0.5", ">= 0.5.1"]

spec.add_dependency "oj", "~> 2.12"
spec.add_runtime_dependency "json_api_client", "1.5.3"
spec.add_runtime_dependency "json_api_client", "1.1.1"
spec.add_runtime_dependency "activesupport", ">= 4.0"
spec.add_runtime_dependency "rack", ">= 1.6"
spec.add_runtime_dependency "faraday-http-cache", "1.3.0"
Expand Down
6 changes: 0 additions & 6 deletions lib/flex_commerce_api/base_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
require "flex_commerce_api/json_api_client_extension/remote_builder"

module FlexCommerceApi
# Set the pagination param
JsonApiClientExtension::Paginator.page_param = "number"
JsonApiClientExtension::Paginator.per_page_param = "size"

#
# Base class for all flex commerce models
#
Expand Down Expand Up @@ -110,14 +106,12 @@ def reconfigure_api_base options = {}

def reconfigure options = {}
self.site = append_version(FlexCommerceApi.config.api_base_url)

base_options = {
adapter: FlexCommerceApi.config.adapter || :net_http,
http_cache: FlexCommerceApi.config.http_cache,
timeout: FlexCommerceApi.config.timeout,
open_timeout: FlexCommerceApi.config.open_timeout
}

self.connection_options.delete(:include_previewed)
self.connection_options = connection_options.merge(base_options).merge(options)
reload_connection_if_required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def initialize(options = {})
add_json_api_extension = options.fetch(:add_json_api_extension, true)
authenticate = options.fetch(:authenticate, true)
include_previewed = options.fetch :include_previewed, false

@faraday = Faraday.new(site) do |builder|
builder.request :json
builder.use JsonApiClientExtension::SaveRequestBodyMiddleware
Expand Down Expand Up @@ -43,7 +42,6 @@ def run(*args)
end

private

def cache_options(options)
{
# treats the cache like a client, not a proxy
Expand All @@ -56,7 +54,6 @@ def cache_options(options)
logger: FlexCommerceApi.logger
}.merge(options.fetch(:http_cache, {}))
end

end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ def encoded(part)
end
end
end
end
end
17 changes: 0 additions & 17 deletions lib/patches/json_api_client/builder.rb

This file was deleted.

15 changes: 11 additions & 4 deletions lib/patches/json_api_client/resource.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "json_api_client/version"

if ["1.1.1", "1.5.3"].include?(JsonApiClient::VERSION)
if ["1.1.1"].include?(JsonApiClient::VERSION)
require "json_api_client/resource"
module JsonApiClient
class Resource
Expand All @@ -12,8 +11,15 @@ def save
else
self.class.requestor.create(self)
end

if last_result_set.has_errors?
fill_errors
last_result_set.errors.each do |error|
if error.source_parameter
errors.add(error.source_parameter, error.title || error.detail)
else
errors.add(:base, error.title || error.detail)
end
end
false
else
self.errors.clear if self.errors
Expand All @@ -37,7 +43,8 @@ def save
Please check these two PRs:
* https://github.com/chingor13/json_api_client/pull/238 (This was released in version 1.5.0)
* https://github.com/JsonApiClient/json_api_client/pull/285 (This hasn't yet been released at the time of writing this)
If both have been merged into the gem version you are using, remove this file (#{__FILE__}).
If both have been merged into the gem version you are using, remove this file (#{__FILE__}).
If not, add the current version to the allowed array at the top of this file.
)
end
22 changes: 8 additions & 14 deletions lib/paypal_express/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
module FlexCommerce
module PaypalExpress
# @class Setup
#
#
# This is the main class, which talks to ActiveMerchant gem to initiate a transaction using Paypal
class Setup
include ::FlexCommerce::PaypalExpress::Api


# @initialize
#
#
# @param {FlexCommerce::PaymentProviderSetup} payment_provider_setup
# @param {FlexCommerce::Cart} cart
# @param {Paypal Gateway} [gateway_class = ::ActiveMerchant::Billing::PaypalExpressGateway]
Expand All @@ -23,7 +23,7 @@ class Setup
# @param {FlexCommerce::ShippingMethod} shipping_method_model = FlexCommerce::ShippingMethod
# @param {boolean} [use_mobile_payments = false]
# @param {String} [description = nil]
#
#
# @note:
# For `::ActiveMerchant::Billing::PaypalExpressGateway` to work
# rails-site should include active merchant gem. Ideally this gem should be included in the gemspec.
Expand All @@ -43,7 +43,7 @@ def initialize(cart:, gateway_class: ::ActiveMerchant::Billing::PaypalExpressGat

def call
validate_shipping_method

response = gateway.setup_order(convert_amount(cart.total), paypal_params)
# If paypal setup went fine, redirect to the paypal page
if response.success?
Expand Down Expand Up @@ -76,21 +76,15 @@ def paypal_params
end

# @method shipping_methods
#
#
# @returns shipping methods with promotions applied
def shipping_methods
@shipping_methods ||= ShippingMethodsForCart.new(cart: cart, shipping_methods: shipping_method_model.all).call.sort_by(&:total)
end

def validate_shipping_method
unless cart.shipping_method_id.nil? || shipping_methods.any? { |sm| sm.id == cart.shipping_method_id }
if cart.shipping_method_id.nil?
error_message = "Shipping method not specified on cart."
else
error_message = "Shipping method not available: #{cart.shipping_method_id}"
error_message += " (in #{shipping_methods.to_a.collect(&:id).join(", ")})"
end
raise ::FlexCommerce::PaypalExpress::Exception::AccessDenied.new(error_message)
unless cart.shipping_method_id.nil? || shipping_methods.any? {|sm| sm.id == cart.shipping_method_id} then
raise ::FlexCommerce::PaypalExpress::Exception::AccessDenied.new(I18n.t("payment_setup.shipping_method_not_available"))
end
end
end
Expand Down
58 changes: 0 additions & 58 deletions spec/e2e/line_items_api_e2e_spec.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/support/global_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
config.logger = nil
config.order_test_mode = false
config.logger = ActiveSupport::Logger.new(STDOUT)
end
end

0 comments on commit a655352

Please sign in to comment.