Module: SolidusNexio::CheckoutHelper

Defined in:
app/helpers/solidus_nexio/checkout_helper.rb

Instance Method Summary collapse

Instance Method Details

#apm_token_config(user, order, payment_method) ⇒ Object



39
40
41
42
43
44
45
46
# File 'app/helpers/solidus_nexio/checkout_helper.rb', line 39

def apm_token_config(user, order, payment_method)
  {
    data: NexioData.one_time_token(user: user, order: order),
    paths: {
      oneTimeToken: solidus_nexio.payment_method_one_time_tokens_path(payment_method)
    }
  }.to_json
end

#setup_custom_redirect(payment_method, order, user: nil) ⇒ Object



34
35
36
37
# File 'app/helpers/solidus_nexio/checkout_helper.rb', line 34

def setup_custom_redirect(payment_method, order, user: nil)
  setup_nexio_checkout
  javascript_tag("window.addNexioCustomerRedirect(#{payment_method.id}, #{apm_token_config(user, order, payment_method)});")
end

#setup_nexio_apm(payment_method, order, user: nil) ⇒ Object



29
30
31
32
# File 'app/helpers/solidus_nexio/checkout_helper.rb', line 29

def setup_nexio_apm(payment_method, order, user: nil)
  setup_nexio_checkout
  javascript_tag("window.addNexioAPM(#{payment_method.id}, #{apm_token_config(user, order, payment_method)});")
end

#setup_nexio_checkoutObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/helpers/solidus_nexio/checkout_helper.rb', line 48

def setup_nexio_checkout
  # include js script only once per request
  return if @__nexio_checkout_script

  # `cd #{::SolidusNexio.gem_dir}; yarn webpack --config webpack.config.js` if Rails.env.development?
  content_for(:head) do
    javascript_tag("window.nexioErrorMessages = #{I18n.t('nexio.errors').to_json};") +
      javascript_include_tag('solidus_nexio/checkout.js')
  end
  @__nexio_checkout_script = true

  nil
end

#setup_nexio_own_form(payment_method, type: :default, user: nil, order: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/solidus_nexio/checkout_helper.rb', line 5

def setup_nexio_own_form(payment_method, type: :default, user: nil, order: nil)
  setup_nexio_checkout

  config = {
    type: type,
    publicKey: payment_method.preferred_public_key,
    threeDSecure: payment_method.preferred_three_d_secure,
    paths: {
      oneTimeToken: solidus_nexio.payment_method_one_time_tokens_path(payment_method),
      creditCard: solidus_nexio.payment_method_credit_cards_path(payment_method),
      payment: solidus_nexio.payment_method_payments_path(payment_method)
    },
    data: NexioData.one_time_token(user: user, order: order)
  }

  if @wallet_payment_sources
    config[:walletCardIds] = @wallet_payment_sources.each_with_object([]) do |wps, acc|
      acc.push(wps.id) if wps.payment_source && wps.payment_source.payment_method_id == payment_method.id
    end
  end

  javascript_tag("window.addNexioOwnForm(#{payment_method.id}, #{config.to_json});")
end