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

feat(dunning): Permit creation of payment request without email #2784

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/config/permissions/role-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ customers:
update: true
delete: true
dunning_campaigns:
view: false
view: true
create: false
update: false
subscriptions:
Expand Down
4 changes: 4 additions & 0 deletions app/mailers/payment_request_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class PaymentRequestMailer < ApplicationMailer
def requested
@payment_request = params[:payment_request]
@organization = @payment_request.organization

return if @payment_request.email.blank?
return if @organization.email.blank?

@customer = @payment_request.customer
@invoices = @payment_request.invoices
@payment_url = ::PaymentRequests::Payments::GeneratePaymentUrlService.call(payable: @payment_request).payment_url
Expand Down
3 changes: 1 addition & 2 deletions app/models/payment_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class PaymentRequest < ApplicationRecord
belongs_to :organization
belongs_to :customer, -> { with_discarded }

validates :email, presence: true
validates :amount_cents, presence: true
validates :amount_currency, presence: true

Expand Down Expand Up @@ -44,7 +43,7 @@ def total_amount_cents=(total_amount_cents)
# id :uuid not null, primary key
# amount_cents :bigint default(0), not null
# amount_currency :string not null
# email :string not null
# email :string
# payment_attempts :integer default(0), not null
# payment_status :integer default("pending"), not null
# ready_for_payment_processing :boolean default(TRUE), not null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class RemoveNotNullConstraintFromEmailInPaymentRequests < ActiveRecord::Migration[7.1]
def change
change_column_null :payment_requests, :email, true
end
end
4 changes: 2 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion spec/mailers/payment_request_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let(:organization) { create(:organization, document_number_prefix: 'ORG-123B') }
let(:first_invoice) { create(:invoice, total_amount_cents: 1000, organization:) }
let(:second_invoice) { create(:invoice, total_amount_cents: 2000, organization:) }
let(:payment_request) { create(:payment_request, invoices: [first_invoice, second_invoice]) }
let(:payment_request) { create(:payment_request, organization:, invoices: [first_invoice, second_invoice]) }

before do
first_invoice.file.attach(
Expand Down Expand Up @@ -57,6 +57,24 @@
.with(payable: payment_request)
end

context "when payment request email is nil" do
before { payment_request.update(email: nil) }

it "returns a mailer with nil values" do
mailer = payment_request_mailer.with(payment_request:).requested
expect(mailer.to).to be_nil
end
end

context "when organization email is nil" do
before { organization.update(email: nil) }

it "returns a mailer with nil values" do
mailer = payment_request_mailer.with(payment_request:).requested
expect(mailer.to).to be_nil
end
end

context "when no payment url is available" do
let(:payment_url_result) do
BaseService::Result.new.tap do |result|
Expand Down
5 changes: 0 additions & 5 deletions spec/models/payment_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
expect(payment_request).to be_valid
end

it "is not valid without email" do
payment_request.email = nil
expect(payment_request).not_to be_valid
end

it "is not valid without amount_cents" do
payment_request.amount_cents = nil
expect(payment_request).not_to be_valid
Expand Down