Class: Spree::BankPayments::Reconcilers::Base

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/bank_payments/reconcilers/base.rb

Direct Known Subclasses

Manual

Defined Under Namespace

Classes: NotConfiguredError

Constant Summary collapse

HEALTH_STATES =
%i[ok transient consent_revoked].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payment_method:) ⇒ Base

Returns a new instance of Base.



28
29
30
# File 'app/models/spree/bank_payments/reconcilers/base.rb', line 28

def initialize(payment_method:)
  @payment_method = payment_method
end

Instance Attribute Details

#payment_methodObject (readonly)

Returns the value of attribute payment_method.



26
27
28
# File 'app/models/spree/bank_payments/reconcilers/base.rb', line 26

def payment_method
  @payment_method
end

Class Method Details

.build(payment_method:) ⇒ Object



16
17
18
19
20
21
22
23
# File 'app/models/spree/bank_payments/reconcilers/base.rb', line 16

def build(payment_method:)
  key = payment_method.preferred_reconciler.to_s
  klass = registry.fetch(key) do
    raise ArgumentError, "unknown reconciler #{key.inspect}"
  end

  klass.new(payment_method: payment_method)
end

.register(key, klass) ⇒ Object



12
13
14
# File 'app/models/spree/bank_payments/reconcilers/base.rb', line 12

def register(key, klass)
  registry[key.to_s] = klass
end

.registryObject



8
9
10
# File 'app/models/spree/bank_payments/reconcilers/base.rb', line 8

def registry
  @registry ||= {}
end

Instance Method Details

#configured?Boolean

Returns whether credentials and settings are complete.

Returns:

  • (Boolean)

    whether credentials and settings are complete

Raises:

  • (NotImplementedError)


75
76
77
# File 'app/models/spree/bank_payments/reconcilers/base.rb', line 75

def configured?
  raise NotImplementedError, "#{self.class} must implement #configured?"
end

#healthSymbol

:transient still offers at checkout -- a brief provider outage must not pull bank transfer off the storefront, because the money still arrives and reconciles once the provider returns. Only :consent_revoked withdraws it, because in that state nothing will ever reconcile.

Providers written against <= 5.2 implement #healthy? only, so the default derives from it.

Returns:

  • (Symbol)

    one of HEALTH_STATES.



56
57
58
# File 'app/models/spree/bank_payments/reconcilers/base.rb', line 56

def health
  healthy? ? :ok : :transient
end

#healthy?Boolean

Providers written against >= 5.3 may implement #health only, so the default derives from it. The two defaults are mutually recursive by construction; the owner check breaks the cycle and turns "overrode neither" into a clear contract error instead of a SystemStackError.

Returns:

  • (Boolean)

    false means the expiry job must not cancel anything



66
67
68
69
70
71
72
# File 'app/models/spree/bank_payments/reconcilers/base.rb', line 66

def healthy?
  if method(:health).owner == Spree::BankPayments::Reconcilers::Base
    raise NotImplementedError, "#{self.class} must implement #health or #healthy?"
  end

  health == :ok
end

#parse_webhook(raw_body, headers) ⇒ Spree::BankPayments::TransferData?

Returns nil for unsupported events.

Returns:

Raises:

  • (Spree::PaymentMethod::WebhookSignatureError)


40
41
42
# File 'app/models/spree/bank_payments/reconcilers/base.rb', line 40

def parse_webhook(raw_body, headers)
  raise NotImplementedError, "#{self.class} must implement #parse_webhook"
end

#poll(since:) ⇒ Array<Spree::BankPayments::TransferData>

Parameters:

  • since (Time)

Returns:

Raises:

  • (NotImplementedError)


34
35
36
# File 'app/models/spree/bank_payments/reconcilers/base.rb', line 34

def poll(since:)
  raise NotImplementedError, "#{self.class} must implement #poll"
end

#sync_accountsArray<Spree::BankPayments::AccountData>

Accounts this provider can see, for the admin sync flow. Providers that cannot enumerate accounts return [].



83
84
85
# File 'app/models/spree/bank_payments/reconcilers/base.rb', line 83

def sync_accounts
  []
end