Module: Effective::Providers::MonerisCheckout

Extended by:
ActiveSupport::Concern
Included in:
OrdersController
Defined in:
app/controllers/effective/providers/moneris_checkout.rb

Instance Method Summary collapse

Instance Method Details

#moneris_checkoutObject



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
# File 'app/controllers/effective/providers/moneris_checkout.rb', line 6

def moneris_checkout
  raise('moneris_checkout provider is not available') unless EffectiveOrders.moneris_checkout?

  @order = Order.deep.find(params[:id])

  # We do this even if we're not authorized.
  EffectiveResources.authorized?(self, :update, @order)

  payment = moneris_checkout_receipt_request(moneris_checkout_params[:ticket])
  purchased = (1..49).include?(payment['response_code'].to_i) # Must be > 0 and < 50 to be valid. Sometimes we get the string 'null'

  if purchased == false
    return order_declined(
      payment: payment,
      provider: 'moneris_checkout',
      declined_url: moneris_checkout_params[:declined_url]
    )
  end

  if payment['card_type'].present?
    active_card = "**** **** **** #{payment['first6last4'].to_s.last(4)} #{payment['card_type']} #{payment['expiry_date'].to_s.first(2)}/#{payment['expiry_date'].to_s.last(2)}"
    payment = payment.except('first6last4').merge('active_card' => active_card)
  end

  order_purchased(
    payment: payment,
    provider: 'moneris_checkout',
    card: payment['card_type'],
    purchased_url: moneris_checkout_params[:purchased_url],
    current_user: current_user
  )
end