Class: Gateway::OnpayController

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

Instance Method Summary collapse

Instance Method Details

#apiObject



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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/gateway/onpay_controller.rb', line 32

def api
	# @out - hash for answer view
	@out = Hash.new
	@out["pay_for"] = params["pay_for"]

	if params["type"] == "check" then
		if params["md5"] == Digest::MD5.hexdigest([params["type"],
																											params["pay_for"],
																											params["order_amount"],
																											params["order_currency"],
																											@gateway.options[:priv_code]].join(';')).upcase
			if @gateway.options[:test_mode] then
				tst_valid_check(params["pay_for"],params["order_amount"],params["order_currency"]) ? out_code_comment(0,"All,OK") :	out_code_comment(3,"Error on parameters check")
			else
				valid_check(params["pay_for"],params["order_amount"],params["order_currency"]) ? out_code_comment(0,"All,OK") :	out_code_comment(3,"Error on parameters check")					
			end 
			@out["md5"] = create_check_md5(params["type"],params["pay_for"],params["order_amount"],
																	 params["order_currency"],@out["code"],@gateway.options[:priv_code])
			render :action => "check"
		else
			out_code_comment(7,"MD5 signature wrong")
			@out["md5"] = create_check_md5(params["type"],params["pay_for"],params["order_amount"],
																	 params["order_currency"],@out["code"],@gateway.options[:priv_code])
			render :action => "check"
		end
	end


	if params["type"] == "pay" then 
		if params["md5"] == Digest::MD5.hexdigest([params["type"],
																										params["pay_for"],
																										params["onpay_id"],
																										params["order_amount"],
																										params["order_currency"],
																										@gateway.options[:priv_code]].join(';')).upcase
			@out["onpay_id"] = params["onpay_id"]
			if @gateway.options[:test_mode] then
				if tst_valid_check(params["pay_for"],params["order_amount"],params["order_currency"]) then
					create_payment(params["order_amount"].to_f)
					out_code_comment(0,"OK")	
				else
					out_code_comment(3,"Error on parameters check")
				end
			else
				if valid_check(params["pay_for"],params["order_amount"],params["order_currency"]) then
					create_payment(params["order_amount"].to_f)
					out_code_comment(0,"OK")	
				else
					out_code_comment(3,"Error on parameters check")
				end
			end
			
			
			@out["md5"] = create_pay_md5(params["type"],params["pay_for"],params["onpay_id"],params["pay_for"],params["order_amount"],
																	params["order_currency"],@out["code"],@gateway.options[:priv_code])																	 
			render :action => "pay"
		else
			out_code_comment(7,"MD5 signature wrong")			
			@out["onpay_id"] = params["onpay_id"]
			@out["md5"] = create_pay_md5(params["type"],params["pay_for"],params["onpay_id"],params["pay_for"],params["order_amount"],
																 params["order_currency"],@out["code"],@gateway.options[:priv_code])				 
			render :action => "pay"
		end
	end

end

#showObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/gateway/onpay_controller.rb', line 7

def show
  @order =  Order.find(params[:order_id])
  @gateway = @order.available_payment_methods.find{|x| x.id == params[:gateway_id].to_i }

  if @order.blank? || @gateway.blank?
    flash[:error] = I18n.t("invalid_arguments")
    redirect_to :back
  else
	@pay_type = @gateway.options[:pay_type]
	@price = sprintf("%.2f",@order.total.to_f).to_f
	@currency = @gateway.options[:currency]
	@convert_currency = @gateway.options[:convert_currency] ? 'yes':'no'
	@price_final = @gateway.options[:price_final] ? 'yes':'no'
	@user_email = @order.email
	@md5 = Digest::MD5.hexdigest([@gateway.options[:pay_type],
															sprintf("%.1f",@order.total.to_f).to_f,
															@currency,
															@order.id,
															@convert_currency,
															@gateway.options[:priv_code]].join(';'))

    render :action => :show
  end
end