Class: Spree::BankPayments::Reconcilers::Base
- Inherits:
-
Object
- Object
- Spree::BankPayments::Reconcilers::Base
- Defined in:
- app/models/spree/bank_payments/reconcilers/base.rb
Direct Known Subclasses
Defined Under Namespace
Classes: NotConfiguredError
Constant Summary collapse
- HEALTH_STATES =
%i[ok transient consent_revoked].freeze
Instance Attribute Summary collapse
-
#payment_method ⇒ Object
readonly
Returns the value of attribute payment_method.
Class Method Summary collapse
Instance Method Summary collapse
-
#configured? ⇒ Boolean
Whether credentials and settings are complete.
-
#health ⇒ Symbol
: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.
-
#healthy? ⇒ Boolean
Providers written against >= 5.3 may implement #health only, so the default derives from it.
-
#initialize(payment_method:) ⇒ Base
constructor
A new instance of Base.
-
#parse_webhook(raw_body, headers) ⇒ Spree::BankPayments::TransferData?
Nil for unsupported events.
- #poll(since:) ⇒ Array<Spree::BankPayments::TransferData>
-
#sync_accounts ⇒ Array<Spree::BankPayments::AccountData>
Accounts this provider can see, for the admin sync flow.
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_method ⇒ Object (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 |
.registry ⇒ Object
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.
75 76 77 |
# File 'app/models/spree/bank_payments/reconcilers/base.rb', line 75 def configured? raise NotImplementedError, "#{self.class} must implement #configured?" end |
#health ⇒ Symbol
: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.
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.
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.
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>
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_accounts ⇒ Array<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 |