Class: SpreeAdyen::Webhooks::Event

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree_adyen/webhooks/event.rb

Instance Method Summary collapse

Constructor Details

#initialize(event_data:) ⇒ Event

Returns a new instance of Event.



4
5
6
# File 'app/services/spree_adyen/webhooks/event.rb', line 4

def initialize(event_data:)
  @event_data = event_data.to_h.with_indifferent_access
end

Instance Method Details

#amountObject



62
63
64
65
66
67
68
69
# File 'app/services/spree_adyen/webhooks/event.rb', line 62

def amount
  @amount ||= begin
    amount_data = body['amount']
    return nil unless amount_data&.key?('value') && amount_data.key?('currency')

    Spree::Money.new(amount_data['value'] / 100.0, currency: amount_data['currency'])
  end
end

#billing_addressObject



32
33
34
35
36
37
38
# File 'app/services/spree_adyen/webhooks/event.rb', line 32

def billing_address
  @billing_address ||= begin
    return {} unless additional_data['billingAddress']

    SpreeAdyen::AddressPresenter.new(additional_data['billingAddress']).to_h
  end
end

#card_detailsObject



58
59
60
# File 'app/services/spree_adyen/webhooks/event.rb', line 58

def card_details
  @card_details ||= additional_data.slice('expiryDate', 'cardSummary', 'type')
end

#codeObject



24
25
26
# File 'app/services/spree_adyen/webhooks/event.rb', line 24

def code
  @code ||= body['eventCode']
end

#event_dateObject



79
80
81
# File 'app/services/spree_adyen/webhooks/event.rb', line 79

def event_date
  @event_date ||= body['eventDate'].to_datetime
end

#fetch(attribute) ⇒ Object



87
88
89
# File 'app/services/spree_adyen/webhooks/event.rb', line 87

def fetch(attribute)
  body[attribute]
end

#idObject



8
9
10
# File 'app/services/spree_adyen/webhooks/event.rb', line 8

def id
  @id ||= body['pspReference']
end

#merchant_referenceObject



71
72
73
# File 'app/services/spree_adyen/webhooks/event.rb', line 71

def merchant_reference
  @merchant_reference ||= body['merchantReference']
end

#order_numberObject



16
17
18
# File 'app/services/spree_adyen/webhooks/event.rb', line 16

def order_number
  @order_number ||= merchant_reference.split('_')[0]
end

#payloadObject



12
13
14
# File 'app/services/spree_adyen/webhooks/event.rb', line 12

def payload
  event_data
end

#payment_method_idObject



20
21
22
# File 'app/services/spree_adyen/webhooks/event.rb', line 20

def payment_method_id
  @payment_method_id ||= merchant_reference.split('_')[1]
end

#payment_method_referenceObject



48
49
50
# File 'app/services/spree_adyen/webhooks/event.rb', line 48

def payment_method_reference
  @payment_method_reference ||= body['paymentMethod'].to_sym
end

#psp_referenceObject



83
84
85
# File 'app/services/spree_adyen/webhooks/event.rb', line 83

def psp_reference
  @psp_reference ||= body['pspReference']
end

#session_idObject



75
76
77
# File 'app/services/spree_adyen/webhooks/event.rb', line 75

def session_id
  @session_id ||= additional_data['checkoutSessionId']
end

#shipping_addressObject



40
41
42
43
44
45
46
# File 'app/services/spree_adyen/webhooks/event.rb', line 40

def shipping_address
  @shipping_address ||= begin
    return {} unless additional_data['deliveryAddress']

    SpreeAdyen::AddressPresenter.new(additional_data['deliveryAddress']).to_h
  end
end

#stored_payment_method_idObject



52
53
54
55
56
# File 'app/services/spree_adyen/webhooks/event.rb', line 52

def stored_payment_method_id
  @stored_payment_method_id ||= additional_data['tokenization.storedPaymentMethodId'] ||
                                 additional_data['storedPaymentMethodId'] ||
                                 additional_data['recurring.recurringDetailReference']
end

#success?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/services/spree_adyen/webhooks/event.rb', line 28

def success?
  body['success'] == 'true'
end