Skip to content

Commit

Permalink
clean up controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Nov 21, 2024
1 parent 48a9cb0 commit 6f77e12
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/controllers/process_payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create
username: current_user.username, transaction_id: @transaction.id,
message: "Total Amount: #{total_amount}"

redirect_to redirect_to_payment_broker_path(transaction_id: @transaction.id)
redirect_to to_payment_broker_path(transaction_id: @transaction.id)
else
redirect_to new_process_payment_path, flash: { error: "Please select an item to pay." }
end
Expand Down
7 changes: 0 additions & 7 deletions app/controllers/reports/transaction_logs_controller.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
class Redirectors::ToPaymentBrokerController < AuthenticatedController
class ToPaymentBrokerController < AuthenticatedController
def show

@transaction = PaymentTransaction.find params[:transaction_id]

if @transaction.status == PaymentTransaction::STATUS_NEW

# lets build the broker, depending on which fees we are processing
broker = setup_broker @transaction

TLOG.log_ypb_steps current_user.username, @transaction.id, "Getting the Token from YPB Payment Broker"
Expand All @@ -18,15 +14,14 @@ def show
@transaction.save

TLOG.log_ypb_steps current_user.username, @transaction.id, "Redirecting to YPB Payment Broker"

## setup payment broker stuff and send person there
redirect_to "#{Settings.ypb.payment_page_url}?tokenid=#{token_id}", allow_other_host: true
else
TLOG.log_ypb_steps current_user.username, @transaction.id, "ERROR: TRIED REDIRECTING WITH EXISTING TRANSACTION"
redirect_to transaction_path @transaction
end
end

private
def setup_broker(transaction)
if transaction.records.first.fee.owner_id == Alma::Fee::OWNER_OSGOODE
TLOG.log_ypb_steps current_user.username, transaction.id, "Redirecting to YPB Payment Broker FOR OSGOODE ACCOUNT"
Expand All @@ -38,5 +33,4 @@ def setup_broker(transaction)
Ypb::Broker.new_broker_instance(ypb_postback_url, false)
end
end

end
6 changes: 1 addition & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
get "/load_fees" => "home#load_fees"

## REDIRECTOR to payment broker
get "redirecting/to_payment_broker" => "redirectors/to_payment_broker#show", as: :redirect_to_payment_broker

## REDIRECTOR to alma fine payment
get "redirecting/to_alma_fines" => "redirectors/to_alma_fines#show", as: :redirect_to_alma_fines
get "to_payment_broker" => "to_payment_broker#show"

## POSTBACK From YPB
resource :ypb_postback, only: :create, controller: "ypb_postback"
Expand All @@ -32,7 +29,6 @@
## REPORTS ##
get "/reports" => "reports#index", as: :reports
get "/reports/transaction/:id" => "reports/transactions#show", as: :report_transaction
get "/reports/transaction/:id/logs" => "reports/transaction_logs#show", as: :report_transaction_log

## DUMMY ALMA API ##
unless Rails.env.production?
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/process_payments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ProcessPaymentsControllerTest < ActionDispatch::IntegrationTest
assert_equal records.find_by_fee_id(fee2.id).alma_fee_id, fee2.fee_id
assert_equal records.find_by_fee_id(fee1.id).alma_fee_id, fee1.fee_id

assert_redirected_to redirect_to_payment_broker_path(transaction_id: transaction.id)
assert_redirected_to to_payment_broker_path(transaction_id: transaction.id)
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'test_helper'

class Redirectors::ToPaymentBrokerControllerTest < ActionDispatch::IntegrationTest
class ToPaymentBrokerControllerTest < ActionDispatch::IntegrationTest
logged_in_with_user do
should "redirect to transaction details path if status is not new" do
transaction = create :payment_transaction, status: PaymentTransaction::STATUS_APPROVED, amount: 10

get redirect_to_payment_broker_path(transaction_id: transaction.id)
get to_payment_broker_path(transaction_id: transaction.id)
assert_response :redirect
assert_redirected_to transaction_path(transaction)
end
Expand Down

0 comments on commit 6f77e12

Please sign in to comment.