Module: EffectiveMonerisCheckoutHelper

Defined in:
app/helpers/effective_moneris_checkout_helper.rb

Instance Method Summary collapse

Instance Method Details

#moneris_checkout_preload_request(order) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/effective_moneris_checkout_helper.rb', line 3

def moneris_checkout_preload_request(order)
  # Make the Preload Request
  params = {
    # Required
    environment: EffectiveOrders.moneris_checkout.fetch(:environment),

    api_token: EffectiveOrders.moneris_checkout.fetch(:api_token),
    store_id: EffectiveOrders.moneris_checkout.fetch(:store_id),
    checkout_id: EffectiveOrders.moneris_checkout.fetch(:checkout_id),

    action: :preload,
    txn_total: price_to_currency(order.total).gsub(',', '').gsub('$', ''),

    # Optional
    order_no: order.transaction_id, # Has to be unique. This is order number, billing name and Time.now
    cust_id: order.user_id,
    language: 'en',

    contact_details: {
      first_name: order.billing_first_name,
      last_name: order.billing_last_name,
      email: order.email,
    }
  }

  if (address = order.billing_address).present?
    params.merge!(
      billing_details: {
        address_1: address.address1,
        address_2: address.address2,
        city: address.city,
        province: address.state_code,
        country: address.country_code,
        postal_code: address.postal_code
      }
    )
  end

  if (address = order.shipping_address).present?
    params.merge!(
      shipping_details: {
        address_1: address.address1,
        address_2: address.address2,
        city: address.city,
        province: address.state_code,
        country: address.country_code,
        postal_code: address.postal_code
      }
    )
  end

  response = Effective::Http.post(EffectiveOrders.moneris_request_url, params: params)
  preload = response['response'] if response

  raise("moneris preload error #{response}") unless preload && preload['success'].to_s == 'true'

  payload = {
    environment: EffectiveOrders.moneris_checkout.fetch(:environment),
    ticket: preload['ticket']
  }
end