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



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

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

  @order ||= Effective::Order.find(params[:response_order_id])

  (EffectiveResources.authorize!(self, :update, @order) rescue false)

  # Delete the Purchased and Declined Redirect URLs
  purchased_url = params.delete(:rvar_purchased_url)
  declined_url = params.delete(:rvar_declined_url)

  if @order.purchased?  # Fallback to a success condition of the Order is already purchased
    return order_purchased(payment: params, provider: 'moneris', card: params[:card], purchased_url: purchased_url)
  end

  # Invalid Result
  if params[:result].to_s != '1' || params[:transactionKey].blank?
    return order_declined(payment: params, provider: 'moneris', card: params[:card], declined_url: declined_url)
  end

  # Verify response from moneris
  payment = params.merge(verify_moneris_transaction(params[:transactionKey]))
  valid = (1..49).include?(payment[:response_code].to_i)  # Must be > 0 and < 50 to be valid. Sometimes we get the string 'null'

  if valid == false
    return order_declined(payment: payment, provider: 'moneris', card: params[:card], declined_url: declined_url)
  end

  order_purchased(payment: payment, provider: 'moneris', card: params[:card], purchased_url: purchased_url)
end