Skip to content

Commit

Permalink
feat(dunning): Permit creation of payment request without email
Browse files Browse the repository at this point in the history
  • Loading branch information
rsempe committed Nov 6, 2024
1 parent 592d415 commit e8a35f5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
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
1 change: 0 additions & 1 deletion 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
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

0 comments on commit e8a35f5

Please sign in to comment.