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).

See Also:

Instance Method Summary collapse

Instance Method Details

#authorization_codeString?

Returns auth code from the linked Payment, when any.

Returns:

  • (String, nil)

    auth code from the linked Payment, when any



32
33
34
# File 'app/models/concerns/receipt_payment.rb', line 32

def authorization_code
  payment.try(:authorization_code)
end

#category_for_authorization_typeString?

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.

Returns:

  • (String, nil)


15
16
17
18
19
20
21
# File 'app/models/concerns/receipt_payment.rb', line 15

def category_for_authorization_type
  if category == 'Credit Card'
    'credit_card'
  elsif category == 'Echeck'
    'check'
  end
end

#credit_card?Boolean

Returns:

  • (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.

Parameters:

Returns:

  • (Hash)


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 default_cc_options(payment)
  options = {
    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
  options[:customer] = customer.stripe_customer_id if payment.vault_id.present? && customer
  options
end

#echeck?Boolean

Returns:

  • (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).

Parameters:

  • _auth (Object)

    retained for compat with callers that pass
    a LegacyAuthorization

Returns:

  • (String, nil)


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