Module: Effective::Providers::Moneris

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

Instance Method Summary collapse

Instance Method Details

#moneris_postbackObject

Raises:

  • (ActiveRecord::RecordNotFound)


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

def moneris_postback
  response_order_id = (EffectiveOrders.obfuscate_order_ids == true ? Effective::Order.deobfuscate(params[:response_order_id]).to_i : params[:response_order_id].to_i)
  response_order_id = response_order_id - EffectiveOrders.moneris[:order_nudge].to_i

  @order ||= Effective::Order.find_by_id(response_order_id)
  raise ActiveRecord::RecordNotFound unless @order

  EffectiveOrders.authorized?(self, :update, @order)

  # Store the Order Nudge if present, so we can have this information in our order_purchased hash
  params[:order_nudge] = EffectiveOrders.moneris[:order_nudge] if EffectiveOrders.moneris[:order_nudge].to_i > 0

  # Delete the Purchased and Declined Redirect URLs
  purchased_redirect_url = params.delete(:rvar_purchased_redirect_url)
  declined_redirect_url = params.delete(:rvar_declined_redirect_url)

  if params[:result].to_s == '1' && params[:transactionKey].present?
    verify_params = parse_moneris_response(send_moneris_verify_request(params[:transactionKey])) || {}

    response_code = verify_params[:response_code].to_i # Sometimes moneris sends us the string 'null'

    if response_code > 0 && response_code < 50  # Less than 50 means a successful validation
      order_purchased(params.merge(verify_params), purchased_redirect_url)
    else
      order_declined(params.merge(verify_params), declined_redirect_url)
    end
  else
    order_declined(params, declined_redirect_url)
  end
end