Class: SpreeAdyen::Webhooks::Event
- Inherits:
-
Object
- Object
- SpreeAdyen::Webhooks::Event
- Defined in:
- app/services/spree_adyen/webhooks/event.rb
Instance Method Summary collapse
- #amount ⇒ Object
- #billing_address ⇒ Object
- #card_details ⇒ Object
- #code ⇒ Object
- #event_date ⇒ Object
- #fetch(attribute) ⇒ Object
- #id ⇒ Object
-
#initialize(event_data:) ⇒ Event
constructor
A new instance of Event.
- #merchant_reference ⇒ Object
- #order_number ⇒ Object
- #payload ⇒ Object
- #payment_method_id ⇒ Object
- #payment_method_reference ⇒ Object
- #psp_reference ⇒ Object
- #session_id ⇒ Object
- #shipping_address ⇒ Object
- #stored_payment_method_id ⇒ Object
- #success? ⇒ Boolean
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
#amount ⇒ Object
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_address ⇒ Object
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_details ⇒ Object
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 |
#code ⇒ Object
24 25 26 |
# File 'app/services/spree_adyen/webhooks/event.rb', line 24 def code @code ||= body['eventCode'] end |
#event_date ⇒ Object
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 |
#id ⇒ Object
8 9 10 |
# File 'app/services/spree_adyen/webhooks/event.rb', line 8 def id @id ||= body['pspReference'] end |
#merchant_reference ⇒ Object
71 72 73 |
# File 'app/services/spree_adyen/webhooks/event.rb', line 71 def merchant_reference @merchant_reference ||= body['merchantReference'] end |
#order_number ⇒ Object
16 17 18 |
# File 'app/services/spree_adyen/webhooks/event.rb', line 16 def order_number @order_number ||= merchant_reference.split('_')[0] end |
#payload ⇒ Object
12 13 14 |
# File 'app/services/spree_adyen/webhooks/event.rb', line 12 def payload event_data end |
#payment_method_id ⇒ Object
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_reference ⇒ Object
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_reference ⇒ Object
83 84 85 |
# File 'app/services/spree_adyen/webhooks/event.rb', line 83 def psp_reference @psp_reference ||= body['pspReference'] end |
#session_id ⇒ Object
75 76 77 |
# File 'app/services/spree_adyen/webhooks/event.rb', line 75 def session_id @session_id ||= additional_data['checkoutSessionId'] end |
#shipping_address ⇒ Object
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_id ⇒ Object
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
28 29 30 |
# File 'app/services/spree_adyen/webhooks/event.rb', line 28 def success? body['success'] == 'true' end |