Module: NimbleshopPaypalwp::ExposedHelper

Includes:
ActiveMerchant::Billing::Integrations::ActionViewHelper
Defined in:
app/helpers/nimbleshop_paypalwp/exposed_helper.rb

Instance Method Summary collapse

Instance Method Details

#nimbleshop_paypalwp_available_payment_options_iconsObject



20
21
22
23
# File 'app/helpers/nimbleshop_paypalwp/exposed_helper.rb', line 20

def nimbleshop_paypalwp_available_payment_options_icons
  return unless NimbleshopPaypalwp::Paypalwp.first
  image_tag "engines/nimbleshop_paypalwp/paypal_small.png", alt: 'paypal icon'
end

#nimbleshop_paypalwp_cancel_url(order) ⇒ Object



65
66
67
# File 'app/helpers/nimbleshop_paypalwp/exposed_helper.rb', line 65

def nimbleshop_paypalwp_cancel_url(order)
  Nimbleshop::Util.localhost2public_url( new_checkout_payment_path, nimbleshop_paypalwp_protocol )
end

#nimbleshop_paypalwp_crud_formObject



46
47
48
49
# File 'app/helpers/nimbleshop_paypalwp/exposed_helper.rb', line 46

def nimbleshop_paypalwp_crud_form
  return unless NimbleshopPaypalwp::Paypalwp.first
  render partial: '/nimbleshop_paypalwp/paypalwps/edit'
end

#nimbleshop_paypalwp_icon_for_order_payment(order) ⇒ Object



25
26
27
# File 'app/helpers/nimbleshop_paypalwp/exposed_helper.rb', line 25

def nimbleshop_paypalwp_icon_for_order_payment(order)
  image_tag "engines/nimbleshop_paypalwp/paypal_small.png", alt: 'paypal icon', height: '10px'
end

#nimbleshop_paypalwp_notify_urlObject



57
58
59
# File 'app/helpers/nimbleshop_paypalwp/exposed_helper.rb', line 57

def nimbleshop_paypalwp_notify_url
  Nimbleshop::Util.localhost2public_url( '/nimbleshop_paypalwp/paypalwp/notify', nimbleshop_paypalwp_protocol )
end

#nimbleshop_paypalwp_order_show_extra_info(order) ⇒ Object



15
16
17
18
# File 'app/helpers/nimbleshop_paypalwp/exposed_helper.rb', line 15

def nimbleshop_paypalwp_order_show_extra_info(order)
  return unless NimbleshopPaypalwp::Paypalwp.first
  render partial: '/nimbleshop_paypalwp/payments/order_show_extra_info', locals: { transaction: order.payment_transactions.last }
end

#nimbleshop_paypalwp_payment_form(order) ⇒ Object



51
52
53
54
55
# File 'app/helpers/nimbleshop_paypalwp/exposed_helper.rb', line 51

def nimbleshop_paypalwp_payment_form(order)
   ActiveMerchant::Billing::Base.integration_mode = Rails.env.production? ? :production : :test
  return unless NimbleshopPaypalwp::Paypalwp.first
  render partial: '/nimbleshop_paypalwp/payments/new', locals: { order: order }
end

#nimbleshop_paypalwp_picture_on_admin_payment_methodsObject



11
12
13
# File 'app/helpers/nimbleshop_paypalwp/exposed_helper.rb', line 11

def nimbleshop_paypalwp_picture_on_admin_payment_methods
  image_tag "engines/nimbleshop_paypalwp/paypal_big.png", alt: 'paypal logo'
end

#nimbleshop_paypalwp_protocolObject



69
70
71
72
# File 'app/helpers/nimbleshop_paypalwp/exposed_helper.rb', line 69

def nimbleshop_paypalwp_protocol
  # TODO do not hardcode decision based on env
  NimbleshopPaypalwp::Paypalwp.first.mode == 'production' ? 'https' : 'http'
end

#nimbleshop_paypalwp_return_url(order) ⇒ Object



61
62
63
# File 'app/helpers/nimbleshop_paypalwp/exposed_helper.rb', line 61

def nimbleshop_paypalwp_return_url(order)
  Nimbleshop::Util.localhost2public_url( order_path(id: order.number), nimbleshop_paypalwp_protocol )
end

#nimbleshop_paypalwp_small_imageObject



7
8
9
# File 'app/helpers/nimbleshop_paypalwp/exposed_helper.rb', line 7

def nimbleshop_paypalwp_small_image
  image_tag "engines/nimbleshop_paypalwp/paypal_small.png", alt: 'paypal icon'
end

#update_service_with_attributes(service, order) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/nimbleshop_paypalwp/exposed_helper.rb', line 29

def update_service_with_attributes(service, order)
  service.customer email: order.email

  service.billing_address order.final_billing_address.attributes.slice(:city, :address1,:address2, :state, :country,:zip)

  service.invoice      order.number
  service.line_items   order.line_items
  service.shipping     order.shipping_cost.to_f.round(2)
  service.tax          order.tax.to_f.round(2)

  service.notify_url         nimbleshop_paypalwp_notify_url
  service.return_url         nimbleshop_paypalwp_return_url(order)
  service.cancel_return_url  nimbleshop_paypalwp_cancel_url(order)

  Rails.logger.debug "service attributes: #{service.inspect}"
end