Module: Portage::Ucp::PaymentEnrollmentGuard

Defined in:
lib/portage/ucp/payment_enrollment_guard.rb

Overview

Boundary guard for Adapter#create_payment_enrollment / #get_payment_enrollment results (design-log §33/Phase B). PaymentEnrollment (value_objects.rb) has no validation of its own — every Data.define in that file is raise-free by convention — so an adapter can otherwise hand back status: "banana", or a "complete" enrollment with no payment_token, and it would construct and ship fine. Same posture as PaymentTokenGuard: catch clear misintegration, don't try to prove full validity.

Constant Summary collapse

VALID_STATUSES =
%w[pending complete].freeze

Class Method Summary collapse

Class Method Details

.validate!(enrollment) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/portage/ucp/payment_enrollment_guard.rb', line 14

def self.validate!(enrollment)
  status = enrollment.status
  unless VALID_STATUSES.include?(status)
    raise Portage::Ucp::InvalidPaymentEnrollmentError,
          "payment enrollment #{enrollment.id.inspect} has unknown status #{status.inspect} — " \
          "expected one of #{VALID_STATUSES}"
  end

  status == "pending" ? validate_pending!(enrollment) : validate_complete!(enrollment)
end