Skip to content

Commit

Permalink
Merge pull request #2438 from internetee/ignore-statuses-update-if-in…
Browse files Browse the repository at this point in the history
…voice-already-paid

Ignore statuses update if invoice already paid
  • Loading branch information
vohmar authored Sep 13, 2022
2 parents ef920f0 + 43c7101 commit e3a5f15
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/controllers/eis_billing/payment_status_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class PaymentStatusController < EisBilling::BaseController
def update
payment_status = define_payment_status(params[:payment_state])
invoice = Invoice.find_by(number: params[:order_reference])

return if invoice.paid?

bank = create_bank_transfer(invoice: invoice, sum: params[:standing_amount], paid_at: params[:transaction_time])
create_payment_order(invoice: invoice, everypay_response: params, payment_status: payment_status)

Expand Down
32 changes: 32 additions & 0 deletions test/integration/eis_billing/payment_status_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'test_helper'

class PaymentStatusTest < ApplicationIntegrationTest
setup do
sign_in users(:api_bestnames)
@invoice = invoices(:one)
@unpaid = invoices(:unpaid)
@registrar = registrars(:bestnames)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end

def shoudl_update_buyer_balance
assert @invoice.paid?
assert_equal @invoice.buyer.balance.to_f, 100.0

payload = {
payment_state: 'settled',
order_reference: @unpaid.number,
standing_amount: @unpaid.total,
transaction_time: Time.zone.now,
}

put eis_billing_payment_status_path, params: payload

@invoice.reload
@invoice.buyer.reload
@registrar.reload

assert @invoice.paid?
assert_equal @invoice.buyer.balance.to_f, 100.0
end
end

0 comments on commit e3a5f15

Please sign in to comment.