Class: PartyAuthenticableLinkedPartyFinder

Inherits:
Object
  • Object
show all
Defined in:
app/models/party_authenticable_linked_party_finder.rb

Overview

Resolves a Party + Account pair for “checkout as” / linked authenticable flows
when an email exists only on ContactPoint rows (see PartyAccount.search_for_authenticable_linked_party_by_email).

See Also:

Constant Summary collapse

CUSTOMER_SINCE_CUTOFF =
DateTime.parse('2001-1-1').freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email_input) ⇒ void

Parameters:

  • email_input (String)


18
19
20
# File 'app/models/party_authenticable_linked_party_finder.rb', line 18

def initialize(email_input)
  @email = email_input.to_s.strip.downcase
end

Class Method Details

.call(email_input) ⇒ Hash?

Returns when permitted, includes :account and :party; otherwise nil.

Parameters:

  • email_input (String)

    email from login or checkout form

Returns:

  • (Hash, nil)

    when permitted, includes :account and :party; otherwise nil



12
13
14
# File 'app/models/party_authenticable_linked_party_finder.rb', line 12

def self.call(email_input)
  new(email_input).result
end

Instance Method Details

#resultHash?

Returns when permitted, includes :account and :party; otherwise nil.

Returns:

  • (Hash, nil)

    when permitted, includes :account and :party; otherwise nil



23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/party_authenticable_linked_party_finder.rb', line 23

def result
  return nil if @email.blank? || Account.exists?(email: @email)

  party = first_party_matching_email
  return nil if party&.customer.blank?

   = party.customer.
  return nil unless permitted?(party, )

  { account:, party: }
end