Class: Payment::Gateways::Default

Inherits:
BasePaymentGateway
  • Object
show all
Defined in:
app/services/payment/gateways/default.rb

Overview

Pass-through gateway used as the fallback strategy for payment
categories that don't talk to an external processor (Cash, Store
Credit, etc). Authorize and void simply flip the local state machine;
the remaining actions raise to make accidental misuse loud.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(payment, _delivery = nil) ⇒ Default

Returns a new instance of Default.



11
12
13
14
15
# File 'app/services/payment/gateways/default.rb', line 11

def initialize(payment, _delivery = nil)
  @payment = payment
  success = nil
  message = nil
end

Instance Method Details

#authorizePayment::Gateways::Default::Result

Mark the Payment authorized without contacting any gateway.



20
21
22
23
# File 'app/services/payment/gateways/default.rb', line 20

def authorize
  @payment.payment_authorized!
  Result.new(success: true)
end

#capture(params1 = nil, options = {}) ⇒ Object

Raises:

  • (StandardError)


42
43
44
# File 'app/services/payment/gateways/default.rb', line 42

def capture(params1=nil, options = {})
  raise StandardError, "Payment 'Capture' action reached but not supported. Payment ID #{@payment.id}"
end

#credit(params1 = nil) ⇒ Object

Raises:

  • (StandardError)


54
55
56
# File 'app/services/payment/gateways/default.rb', line 54

def credit(params1=nil)
  raise StandardError, "Payment 'Credit' action reached but not supported. Payment ID #{@payment.id}"
end

#purchase(params1 = nil, options = {}) ⇒ Object

Raises:

  • (StandardError)


46
47
48
# File 'app/services/payment/gateways/default.rb', line 46

def purchase(params1=nil, options = {})
  raise StandardError, "Payment 'Purchase' action reached but not supported. Payment ID #{@payment.id}"
end

#reauthorize(params1 = nil) ⇒ Object

Raises:

  • (StandardError)


50
51
52
# File 'app/services/payment/gateways/default.rb', line 50

def reauthorize(params1=nil)
  raise StandardError, "Payment 'Reauthorize' action reached but not supported. Payment ID #{@payment.id}"
end

#refund(params1 = nil, params2 = nil) ⇒ Object

Raises:

  • (StandardError)


38
39
40
# File 'app/services/payment/gateways/default.rb', line 38

def refund(params1=nil, params2=nil)
  raise StandardError, "Payment 'Refund' action reached but not supported. Payment ID #{@payment.id}"
end

#void(report_fraud = false) ⇒ Payment::Gateways::Default::Result

Void an authorized non-gateway payment via the local state
machine. No-op (returns failure) for non-authorized payments.

Parameters:

  • report_fraud (Boolean) (defaults to: false)

    retained for API parity with
    CreditCard#void

Returns:



31
32
33
34
35
36
# File 'app/services/payment/gateways/default.rb', line 31

def void(report_fraud = false)
  return Result.new(success: false) unless @payment.authorized?

  @payment.payment_voided!
  Result.new(success: true)
end