Class: Payment::Gateways::BasePaymentGateway

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/payment/gateways/base_payment_gateway.rb

Overview

Common superclass for payment gateway strategy services
(Payment::Gateways::CreditCard, Payment::Gateways::Paypal, etc).
Provides shared exception reporting that funnels gateway failures into
AppSignal with payment context.

Instance Method Summary collapse

Instance Method Details

#report_exception(exception, options = {}) ⇒ Object

Log and report a gateway exception with attached payment context.
The error is logged with full backtrace locally and forwarded to
AppSignal so the on-call engineer can correlate.

Parameters:

  • exception (StandardError)
  • options (Hash{Symbol=>Object}) (defaults to: {})

Options Hash (options):

  • :payment (Payment)
  • :payment_id (Integer)

    used when no payment object is around

  • :message (String)

    human-readable summary



17
18
19
20
21
22
23
24
25
# File 'app/services/payment/gateways/base_payment_gateway.rb', line 17

def report_exception(exception, options={})
  payment_id = options[:payment]&.id || options[:payment_id]
  message = options[:message] || String.new("General Payment Error")
  log_message = message.dup
  log_message << ". For payment id #{payment_id}" if payment_id
  log_message << "#{exception.message}.\n #{exception.backtrace.join("\n")}"
  logger.error log_message
  ErrorReporting.error exception, payment_id: payment_id, message: message
end