Skip to content

Commit

Permalink
close #236 fix rubocop linter warning
Browse files Browse the repository at this point in the history
  • Loading branch information
theachoem committed Jan 23, 2025
1 parent 494e78f commit 3c49421
Show file tree
Hide file tree
Showing 73 changed files with 340 additions and 318 deletions.
40 changes: 39 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AllCops:
NewCops: enable
DisplayCopNames: true
TargetRubyVersion: 2.5
TargetRubyVersion: 3.2.0
Include:
- "**/Gemfile"
- "**/Rakefile"
Expand All @@ -16,3 +16,41 @@ Style/Documentation:

Style/FrozenStringLiteralComment:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

# Rails recommends using `{ remark: }` instead of `{ remark: remark }`.
# However, most of our existing code uses the older style. Disabling this cop to maintain consistency.
Style/HashSyntax:
Enabled: false

# Rails suggests using `return unless`, but this doesn't work well in controllers as actions must render a response.
# Disabling this cop for controllers.
#
# Example:
# def show
# if success?
# @options = { app_checkout: true }
# end
# end
Style/GuardClause:
Exclude:
- 'app/controllers/**/*'

# Most of our code doesn't have these metrics.
# Let's review code quality ourselves.
Metrics/ClassLength:
Enabled: false
Layout/LineLength:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ group :development, :test do
gem 'webmock'
end

group :development do
gem 'pg'
gem 'spree_dev_tools'
end

group :test do
gem 'shoulda-matchers'
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Spree
module Admin
module PaymentMethodsControllerDecorator

def scope
scope = current_store.payment_methods_including_vendor.accessible_by(current_ability, :index)
scope = scope.where.not(vendor_id: nil) if params[:tab] == 'vendors'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ module Spree
module Admin
class PaymentPaywayCheckersController < PaymentPaywayBaseController
include Spree::Backend::Callbacks

def update
options = {
updated_by_user_id: try_spree_current_user.id,
updated_reason: Spree.t('vpago.payments.checker_updated_by_description')
updated_reason: Spree.t('vpago.payments.checker_updated_by_description')
}
spree_updater = payment_request_update_service.new(@payment, options)
spree_updater.call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PaymentPaywayMarkersController < PaymentPaywayBaseController
def update
reason = params[:updated_reason]&.strip

if(reason.blank?)
if reason.blank?
flash[:error] = Spree.t('vpago.payments.failed_require_updated_reason')
return redirect_to admin_order_payment_path(order_id: @payment.order.number, id: @payment.number)
end
Expand All @@ -15,8 +15,9 @@ def update
updated_by_user_id: try_spree_current_user.id,
updated_reason: reason,
status: true,
description: "vpago.payments.mark_with_reason"
description: 'vpago.payments.mark_with_reason'
}

spree_updater = status_marker_service.new(@payment, options)
spree_updater.call

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class PaymentPaywayQueriersController < PaymentPaywayBaseController
include Spree::Backend::Callbacks
around_action :set_writing_role, only: %i[show]


def show
tran_status = transaction_status_service.new(@payment)
tran_status.call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Admin
class PaymentWingSdkBaseController < Spree::Admin::BaseController
include Spree::Backend::Callbacks

before_action :load_payment, only: [:show, :update]
before_action :load_payment, only: %i[show update]
before_action :validate_order, only: [:update]

def validate_order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PaymentWingSdkCheckersController < PaymentWingSdkBaseController
def update
options = {
updated_by_user_id: try_spree_current_user.id,
updated_reason: Spree.t('vpago.payments.checker_updated_by_description')
updated_reason: Spree.t('vpago.payments.checker_updated_by_description')
}
spree_updater = Vpago::WingSdk::PaymentRequestUpdater.new(@payment, options)
spree_updater.call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PaymentWingSdkMarkersController < PaymentWingSdkBaseController
def update
reason = params[:updated_reason]&.strip

if(reason.blank?)
if reason.blank?
flash[:error] = Spree.t('vpago.payments.failed_require_updated_reason')
return redirect_to admin_order_payment_path(order_id: @payment.order.number, id: @payment.number)
end
Expand All @@ -15,8 +15,9 @@ def update
updated_by_user_id: try_spree_current_user.id,
updated_reason: reason,
status: true,
description: "vpago.payments.mark_with_reason"
description: 'vpago.payments.mark_with_reason'
}

spree_updater = Vpago::PaymentStatusMarker.new(@payment, options)
spree_updater.call

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/spree/admin/payout_profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def verify_with_bank

if instance.call
flash[:success] = flash_message_for(@object, :successfully_updated)
redirect_to edit_object_url(@object)
else
flash[:error] = instance.error_messages.to_s
redirect_to edit_object_url(@object)
end

redirect_to edit_object_url(@object)
end

def request_updater
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/spree/webhook/acleda_mobiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def find_payment
service = Vpago::AcledaMobile::PaymentRetriever.new(options)
service.call

return render_hashing_error if !service.data_valid?
return render_hashing_error unless service.data_valid?

@payment = service.payment
return render_payment_not_found if @payment.blank?
Expand Down Expand Up @@ -66,12 +66,11 @@ def render_hashing_error

acleda_mobile_response(response_data, status_code)
end


def acleda_mobile_response(response_data, status_code)
render json: response_data, status: status_code
end

def acleda_mobile_response_data(message, code)
{
status: {
Expand Down
20 changes: 12 additions & 8 deletions app/controllers/spree/webhook/acledas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Webhook
class AcledasController < BaseController
skip_before_action :verify_authenticity_token, only: [:return]

before_action :find_payment, only: [:success, :error, :return]
before_action :find_payment, only: %i[success error return]

rescue_from ::ActiveRecord::RecordNotFound, with: :record_not_found

Expand All @@ -24,18 +24,20 @@ def error
order = @payment.order

if order.paid?
flash[:order_completed] = "1" # required by order_just_completed for purchase tracking
flash[:order_completed] = '1' # required by order_just_completed for purchase tracking
end

pending_or_paid = order.paid? || @payment.pending?
if params[:app_checkout].to_s == '1'
redirect_to order.paid? || @payment.pending? ? success_payway_results_path : failed_payway_results_path
redirect_to pending_or_paid ? success_payway_results_path : failed_payway_results_path
else
redirect_to order.paid? || @payment.pending? ? order_path(order) : checkout_state_path(:payment)
redirect_to pending_or_paid ? order_path(order) : checkout_state_path(:payment)
end
end

private
def check_and_redirect(render_plain=false)

def check_and_redirect(render_plain: false)
request_updater = ::Vpago::Acleda::PaymentRequestUpdater.new(@payment)
request_updater.call

Expand All @@ -50,11 +52,13 @@ def check_and_redirect(render_plain=false)
end

def redirect_order(order)
pending_or_paid = order.paid? || @payment.pending?

if params[:app_checkout].to_s == '1'
redirect_to order.paid? || @payment.pending? ? success_payway_results_path : failed_payway_results_path
redirect_to pending_or_paid ? success_payway_results_path : failed_payway_results_path
else
flash[:order_completed] = "1" if order.paid? # required by order_just_completed for purchase tracking
redirect_to order.paid? || @payment.pending? ? order_path(order) : checkout_state_path(:payment)
flash[:order_completed] = '1' if order.paid? # required by order_just_completed for purchase tracking
redirect_to pending_or_paid ? order_path(order) : checkout_state_path(:payment)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spree/webhook/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module Webhook
class BaseController < ::ApplicationController
end
end
end
end
16 changes: 8 additions & 8 deletions app/controllers/spree/webhook/payways_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Spree
module Webhook
class PaywaysController < BaseController
skip_before_action :verify_authenticity_token, only: [:return, :v2_return, :continue, :v2_continue]
skip_before_action :verify_authenticity_token, only: %i[return v2_return continue v2_continue]

# match via: [:get, :post]
# {"response"=>"{\"tran_id\":\"PE13LXT1\",\"status\":0"}"}
Expand All @@ -27,20 +27,19 @@ def continue
end

private

def v2_request_updater_service
::Vpago::PaywayV2::PaymentRequestUpdater
end

def request_updater_service
::Vpago::Payway::PaymentRequestUpdater
end

# the callback invoke by PAYWAY in case of success
def return_callback_handler(handler_service)
# pawway send get request with nothing
if(request.method == "GET")
return render plain: :ok
end
return render plain: :ok if request.method == 'GET'

builder = Vpago::PaywayReturnOptionsBuilder.new(params: params)
payment = builder.payment
Expand All @@ -63,13 +62,14 @@ def continue_callback_handler
order = payment.order

if order.paid?
flash[:order_completed] = "1" # required by order_just_completed for purchase tracking
flash[:order_completed] = '1' # required by order_just_completed for purchase tracking
end

pending_or_paid = order.paid? || payment.pending?
if params[:app_checkout] == 'yes'
redirect_to order.paid? || payment.pending? ? success_payway_results_path : failed_payway_results_path
redirect_to pending_or_paid ? success_payway_results_path : failed_payway_results_path
else
redirect_to order.paid? || payment.pending? ? order_path(order) : checkout_state_path(:payment)
redirect_to pending_or_paid ? order_path(order) : checkout_state_path(:payment)
end
end
end
Expand Down
20 changes: 12 additions & 8 deletions app/controllers/spree/webhook/wings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
module Spree
module Webhook
class WingsController < BaseController
skip_before_action :verify_authenticity_token, only: [:return, :continue, :create]
skip_before_action :verify_authenticity_token, only: %i[return continue create]

before_action :retrive_payment, only: [:create]
before_action :find_payment, only: [:return, :continue]
before_action :find_payment, only: %i[return continue]

def create
render_plain = true
check_and_redirect(render_plain)
end

## click on button Done: POST { wing_id: payment_number, response: {"remark"=>"PNRE5V5E", "amount"=>" USD 30.00", "total"=>" USD 30.00", "transaction_id"=>"ONL031157", "customer_name"=>"Wing Testing WCX-USD", "biller_name"=>"VTENH"}}
## click on button Back: GET { wing_id: payment_number }
def return
check_and_redirect
end

private

def find_payment
@payment = ::Spree::Payment.find_by(number: params[:wing_id])
end
Expand All @@ -32,26 +34,28 @@ def retrive_payment
@payment = payment_retriever.payment
end

def check_and_redirect(render_plain=false)
def check_and_redirect(render_plain: false)
request_updater = ::Vpago::WingSdk::PaymentRequestUpdater.new(@payment)
request_updater.call

order = @payment.order
order = order.reload

pending_or_paid = order.paid? || @payment.pending?
if render_plain
order.paid? || @payment.pending? ? render(plain: :success) : render(plain: :failed, status: 400)
pending_or_paid ? render(plain: :success) : render(plain: :failed, status: 400)
else
redirect_order(order)
end
end

def redirect_order(order)
pending_or_paid = order.paid? || @payment.pending?
if params[:app_checkout] == 'yes'
redirect_to order.paid? || @payment.pending? ? success_payway_results_path : failed_payway_results_path
redirect_to pending_or_paid ? success_payway_results_path : failed_payway_results_path
else
flash[:order_completed] = "1" if order.paid? # required by order_just_completed for purchase tracking
redirect_to order.paid? || @payment.pending? ? order_path(order) : checkout_state_path(:payment)
flash[:order_completed] = '1' if order.paid? # required by order_just_completed for purchase tracking
redirect_to pending_or_paid ? order_path(order) : checkout_state_path(:payment)
end
end
end
Expand Down
14 changes: 10 additions & 4 deletions app/controllers/spree/wing/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ def wing_http_authenticate!
wing_payment_method = Spree::PaymentMethod.find_by(type: Spree::PaymentMethod::TYPE_WINGSDK)

authenticate_or_request_with_http_basic do |username, password|
false if !wing_payment_method.present?
false if wing_payment_method.preferred_basic_auth_username.blank? || wing_payment_method.preferred_basic_auth_password.blank?
username == wing_payment_method.preferred_basic_auth_username && password == wing_payment_method.preferred_basic_auth_password
return false unless wing_payment_method.present?

if wing_payment_method.preferred_basic_auth_username.blank? ||
wing_payment_method.preferred_basic_auth_password.blank?
return false
end

username == wing_payment_method.preferred_basic_auth_username &&
password == wing_payment_method.preferred_basic_auth_password
end
end

def not_found
render json: {response_code: 404, response_msg: I18n.t(:resource_not_found, scope: 'spree.api')}, status: 404
render json: { response_code: 404, response_msg: I18n.t(:resource_not_found, scope: 'spree.api') }, status: 404
end
end
end
Expand Down
Loading

0 comments on commit 3c49421

Please sign in to comment.