Module: ReceiptPayment
- Extended by:
- ActiveSupport::Concern
- Included in:
- Receipt
- Defined in:
- app/models/concerns/receipt_payment.rb
Overview
Payment-method predicates and gateway charge metadata (credit-card /
echeck classification, authorization mapping, ActiveMerchant options).
Instance Method Summary collapse
-
#authorization_code ⇒ String?
Auth code from the linked Payment, when any.
-
#category_for_authorization_type ⇒ String?
Map this receipt's user-facing
categoryonto the value the authorization service expects (credit_card/check). - #credit_card? ⇒ Boolean
-
#default_cc_options(payment) ⇒ Hash
Default ActiveMerchant-style options hash used when running a purchase against a Payment.
- #echeck? ⇒ Boolean
-
#payment_description(_auth) ⇒ String?
Combined description for gateway charge metadata (statement descriptors, processor receipts).
Instance Method Details
#authorization_code ⇒ String?
Returns auth code from the linked Payment, when any.
32 33 34 |
# File 'app/models/concerns/receipt_payment.rb', line 32 def payment.try(:authorization_code) end |
#category_for_authorization_type ⇒ String?
Map this receipt's user-facing category onto the value the
authorization service expects (credit_card / check). Returns nil
for cash/non-cash receipts that don't have an auth.
15 16 17 18 19 20 21 |
# File 'app/models/concerns/receipt_payment.rb', line 15 def if category == 'Credit Card' 'credit_card' elsif category == 'Echeck' 'check' end end |
#credit_card? ⇒ Boolean
23 24 25 |
# File 'app/models/concerns/receipt_payment.rb', line 23 def credit_card? category == 'Credit Card' end |
#default_cc_options(payment) ⇒ Hash
Default ActiveMerchant-style options hash used when running a
purchase against a Payment. Supplies description, statement
descriptor, currency, IP/email metadata, and (for vault charges)
the Stripe customer id.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/concerns/receipt_payment.rb', line 54 def (payment) = { description: payment_description(payment) || 'Receipt', statement_description: 'WarmlyYours', currency: payment.currency, metadata: { ip: payment.remote_ip_address, email: payment.email, receipt_id: id, payment_id: payment.id } } # only add the customer id if we're charging a stored card, otherwise it will automatically charge the first card on the customer's account # and besides ActiveMerchant .purchase will not work right with a payment token [:customer] = customer.stripe_customer_id if payment.vault_id.present? && customer end |
#echeck? ⇒ Boolean
27 28 29 |
# File 'app/models/concerns/receipt_payment.rb', line 27 def echeck? category == 'Echeck' end |
#payment_description(_auth) ⇒ String?
Combined description for gateway charge metadata (statement
descriptors, processor receipts).
42 43 44 45 |
# File 'app/models/concerns/receipt_payment.rb', line 42 def payment_description(_auth) desc = receipt_details.filter_map(&:description).join(' / ') desc.presence end |