Class: PaymentSessions::Adyen

Inherits:
PaymentSession
  • Object
show all
Defined in:
app/models/spree/payment_sessions/adyen.rb

Constant Summary collapse

AVAILABLE_CHANNELS =
{
  ios: 'iOS',
  android: 'Android',
  web: 'Web'
}.freeze

Instance Method Summary collapse

Instance Method Details

#accepted?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/spree/payment_sessions/adyen.rb', line 30

def accepted?
  status == 'completed'
end

#adyen_idObject

Adyen-specific accessors from external_data



10
11
12
# File 'app/models/spree/payment_sessions/adyen.rb', line 10

def adyen_id
  external_id
end

#channelObject



22
23
24
# File 'app/models/spree/payment_sessions/adyen.rb', line 22

def channel
  external_data&.dig('channel') || AVAILABLE_CHANNELS[:web]
end

#client_keyObject



18
19
20
# File 'app/models/spree/payment_sessions/adyen.rb', line 18

def client_key
  payment_method.preferred_client_key
end

#find_or_create_payment!(metadata = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/spree/payment_sessions/adyen.rb', line 38

def find_or_create_payment!( = {})
  return unless persisted?
  return payment if payment.present?

  order.with_lock do
    existing_payment = order.payments.where(
      payment_method: payment_method,
      response_code: external_id
    ).first

    return existing_payment if existing_payment.present?

    order.payments.create!(
      payment_method: payment_method,
      amount: amount,
      response_code: external_id,
      skip_source_requirement: true
    )
  end
end

#return_urlObject



26
27
28
# File 'app/models/spree/payment_sessions/adyen.rb', line 26

def return_url
  external_data&.dig('return_url')
end

#session_dataObject



14
15
16
# File 'app/models/spree/payment_sessions/adyen.rb', line 14

def session_data
  external_data&.dig('session_data')
end

#successful?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/spree/payment_sessions/adyen.rb', line 34

def successful?
  status == 'completed'
end