Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[billing] Cancel non-positive invoices on charge #491

Merged
merged 1 commit into from Jan 10, 2019

Conversation

guicassolato
Copy link
Contributor

What this PR does / why we need it

What the title says, it ensures invoices with non-positive cost are cancelled when charged.

Which issue(s) this PR fixes

Closes THREESCALE-1420

Verification steps

  • Subscribe to a paid plan (new application)
  • Before billing is run, change to a free plan (this will generate a non-positive invoice)
  • Charge the invoice
  • The invoice should not be charged and its state should change to 'cancelled'

@guicassolato guicassolato self-assigned this Jan 8, 2019
@codecov
Copy link

codecov bot commented Jan 9, 2019

Codecov Report

Merging #491 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #491      +/-   ##
==========================================
+ Coverage    92.7%   92.73%   +0.02%     
==========================================
  Files        2344     2342       -2     
  Lines       75695    75621      -74     
==========================================
- Hits        70173    70127      -46     
+ Misses       5522     5494      -28
Impacted Files Coverage Δ
app/models/invoice.rb 92.61% <100%> (+0.02%) ⬆️
test/unit/invoice_test.rb 100% <100%> (ø) ⬆️
...workers/destroy_all_deleted_objects_worker_test.rb 100% <0%> (ø) ⬆️
test/test_helpers/sidekiq.rb 100% <0%> (ø) ⬆️
config/environments/test.rb 100% <0%> (ø) ⬆️
config/jobs.rb 60% <0%> (ø) ⬆️
test/unit/tasks/services_test.rb 100% <0%> (ø) ⬆️
lib/gitlab/testing/request_inspector_middleware.rb
lib/gitlab/testing/request_blocker_middleware.rb

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8165f1...d208420. Read the comment docs.

end
nil
reason = CONDITIONS_TO_CHARGE.find { |condition| !method("#{condition}?").call }
I18n.t(reason, scope: %i[invoices reasons_cannot_charge]) if reason
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if not reason? Does it return null.. ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would be clearer with:

return unless (reason = CONDITIONS_TO_CHARGE.find { |condition| !method("#{condition}?").call })
I18n.t(reason, scope: %i[invoices reasons_cannot_charge])

But either way is fine 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't even have to touch this, TBH. Just did to make it shorter. It's Ruby language anyway.

Copy link
Contributor

@Martouta Martouta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me but I don't know much about Billing so it would be good if @hallelujah can review it as well 😄

@guicassolato guicassolato merged commit 9167428 into master Jan 10, 2019
@guicassolato guicassolato deleted the fix/negative-invoices branch January 10, 2019 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants