Class: SpreeAdyen::Payments::RequestPayloadPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/spree_adyen/payments/request_payload_presenter.rb

Constant Summary collapse

DEFAULT_PARAMS =
{
  recurringProcessingModel: 'UnscheduledCardOnFile',
  shopperInteraction: 'ContAuth'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(source:, amount_in_cents:, manual_capture:, gateway_options:) ⇒ RequestPayloadPresenter

Returns a new instance of RequestPayloadPresenter.



9
10
11
12
13
14
# File 'app/presenters/spree_adyen/payments/request_payload_presenter.rb', line 9

def initialize(source:, amount_in_cents:, manual_capture:, gateway_options:)
  @source = source
  @amount_in_cents = amount_in_cents
  @manual_capture = manual_capture
  @gateway_options = gateway_options.with_indifferent_access
end

Instance Method Details

#to_hObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/presenters/spree_adyen/payments/request_payload_presenter.rb', line 16

def to_h
  {
    metadata: { # unfortunately metadata is not always available in webhooks, even for AUTHORISATION events
      spree_payment_method_id: source.payment_method_id,
      spree_order_id: order_number
    },
    amount: {
      value: amount_in_cents,
      currency: currency
    },
    paymentMethod: {
      type: 'scheme',
      storedPaymentMethodId: source.gateway_payment_profile_id
    },
    reference: reference,
    shopperReference: shopper_reference,
    merchantAccount: source.payment_method.
  }.merge!(DEFAULT_PARAMS, additional_data_params, SpreeAdyen::ApplicationInfoPresenter.new.to_h)
end