Class: MpayConfirmationController

Inherits:
Spree::BaseController
  • Object
show all
Defined in:
app/controllers/mpay_confirmation_controller.rb

Constant Summary collapse

TRANSACTION_STATES =

possible transaction states

["ERROR", "RESERVED", "BILLED", "REVERSED", "CREDITED", "SUSPENDED"]

Instance Method Summary collapse

Instance Method Details

#showObject

Confirmation interface is a GET request



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
# File 'app/controllers/mpay_confirmation_controller.rb', line 7

def show

  BillingIntegration::Mpay.current.verify_ip(request)

  check_operation(params["OPERATION"])
  check_status(params["STATUS"])

  # get the order
  order = BillingIntegration::Mpay.current.find_order(params["TID"])

  case params["STATUS"]
  when "BILLED"
    # check if the retrieved order is the same as the outgoing one
    if verify_currency(order, params["CURRENCY"])

      # create new payment object
      payment_details = MPaySource.create ({
        :p_type => params["P_TYPE"],
        :brand => params["BRAND"],
        :mpayid => params["MPAYTID"]
	})

      payment_details.save!

      payment_method = PaymentMethod.where(:type => "BillingIntegration::Mpay").where(:environment => RAILS_ENV.to_s).first

      # TODO log the payment
      payment = order.payments.create({
        :amount => params["PRICE"],
        :payment_method_id => payment_method,
        :source => payment_details
	})

      # TODO: create this before (when sending the request?)
	# TODO: but do we even want this?
      payment.started_processing!
      payment.complete!
      payment.save!

      payment_details.payment = payment
      payment_details.save!
      order.update!
    end
  when "RESERVED"
    raise "send the confirmation request out".inspect
  else
    raise "what is going on?".inspect
  end

  render :text => "OK", :status => 200
end