Module: Workarea::Storefront::PaypalHelper

Defined in:
app/helpers/workarea/storefront/paypal_helper.rb

Instance Method Summary collapse

Instance Method Details

#include_paypal_javascript_tag(params: {}, data: {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/workarea/storefront/paypal_helper.rb', line 14

def include_paypal_javascript_tag(params: {}, data: {})
  return unless Workarea::Paypal.gateway.configured?

  params =
    Workarea.config.paypal_sdk_params
      .merge('client-id' => Workarea::Paypal.gateway.client_id)
      .merge(params)
      .compact

  components = params['components'].to_s.split(',')
  components << 'buttons'
  components << 'hosted-fields' if Workarea.config.use_paypal_hosted_fields
  params['components'] = components.compact.uniq.join(',')

  javascript_include_tag(
    "https://www.paypal.com/sdk/js?#{params.to_query}",
    data: {
      partner_attribution_id: 'Workarea_SP', # Do not change this
      client_token: @paypal_client_token
    }.merge(data)
  )
end

#set_paypal_client_tokenObject



4
5
6
7
8
9
10
11
12
# File 'app/helpers/workarea/storefront/paypal_helper.rb', line 4

def set_paypal_client_token
  return unless Workarea::Paypal.gateway.configured?

  @paypal_client_token =
    if Workarea.config.use_paypal_hosted_fields
      request = Workarea::Paypal.gateway.generate_token(user: current_user)
      request.result.client_token
    end
end