Module: ReceiptTransmission
- Extended by:
- ActiveSupport::Concern
- Included in:
- Receipt
- Defined in:
- app/models/concerns/receipt_transmission.rb
Overview
Customer-facing receipt email + transmission addressing: recipient
resolution, notification channels, and the contact points/first document
used to address communications.
Instance Method Summary collapse
-
#billing_address ⇒ Address?
Customer billing address used for emails/PDFs.
-
#determine_email ⇒ String
Recipient list for the receipt email.
-
#first_document ⇒ Invoice, ...
First Invoice or CreditMemo this receipt touches, used as the canonical "what does this receipt represent" object for emails and contact resolution.
-
#notification_emails ⇒ Array<String>
Email contact points the customer marked as receiving invoice notifications.
-
#primary_transmission_contact ⇒ ContactPoint?
Primary contact (per the first applied document) used when sending transmission/email events.
-
#send_email ⇒ Object
Send the customer-facing receipt email.
-
#transmission_contact_points ⇒ Array<ContactPoint>
All contact points associated with the first applied document, used to address transmission communications.
Instance Method Details
#billing_address ⇒ Address?
Returns customer billing address used for emails/PDFs.
39 40 41 |
# File 'app/models/concerns/receipt_transmission.rb', line 39 def billing_address customer&.billing_address end |
#determine_email ⇒ String
Recipient list for the receipt email. Online orders fan out to every
invoice notification address on the customer; back-office receipts
use the single email column captured at create time.
30 31 32 33 34 35 36 |
# File 'app/models/concerns/receipt_transmission.rb', line 30 def determine_email if (payment&.order&.order_reception_type == 'Online') && notification_emails.any? notification_emails.join(',') else email end end |
#first_document ⇒ Invoice, ...
First Invoice or CreditMemo this receipt touches, used as the
canonical "what does this receipt represent" object for emails and
contact resolution.
76 77 78 79 80 |
# File 'app/models/concerns/receipt_transmission.rb', line 76 def first_document return nil if receipt_details.empty? receipt_details.first.invoice || receipt_details.first.credit_memo end |
#notification_emails ⇒ Array<String>
Email contact points the customer marked as receiving invoice
notifications.
47 48 49 |
# File 'app/models/concerns/receipt_transmission.rb', line 47 def notification_emails customer.all_notification_channels.email.invoices.distinct.pluck(ContactPoint[:detail]) end |
#primary_transmission_contact ⇒ ContactPoint?
Primary contact (per the first applied document) used when sending
transmission/email events.
55 56 57 58 59 |
# File 'app/models/concerns/receipt_transmission.rb', line 55 def primary_transmission_contact return nil if first_document.nil? first_document.primary_transmission_contact end |
#send_email ⇒ Object
Send the customer-facing receipt email. Sender is the customer's
primary sales rep when present (BCC'd on the outgoing message);
otherwise the generic info inbox is used.
14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/concerns/receipt_transmission.rb', line 14 def send_email sender = customer.try(:primary_sales_rep) CommunicationBuilder.new( resource: self, sender_party: sender, sender: (sender.nil? ? INFO_EMAIL : nil), emails: determine_email, bcc: sender&.email ).create end |
#transmission_contact_points ⇒ Array<ContactPoint>
All contact points associated with the first applied document, used
to address transmission communications.
65 66 67 68 69 |
# File 'app/models/concerns/receipt_transmission.rb', line 65 def transmission_contact_points return [] if first_document.nil? first_document.transmission_contact_points end |