finish invoce

mail@pastecode.io avatar
unknown
ruby
2 years ago
1.1 kB
6
Indexable
Never
	get '/finishInvoice' do
		result = @api.query("", { :url => "http://10.5.0.3:3000/invoices/closeInvoice?id=" + params['MERCHANT_ORDER_ID'].to_s })
		if (result == 'true') then
			invoice = @api.query("", { :url => "http://10.5.0.3:3000/invoices/getInvoices?id=" + params['MERCHANT_ORDER_ID'].to_s })
			login = invoice[0]['login']
			adm_user = {
				:username => @config[:site][:adm_login],
				:login => @config[:site][:adm_login],
				:password => Digest::MD5.hexdigest(@config[:site][:adm_pass])
			}
			users = @api.query('getUsers', {}, adm_user, false, true )
			users = JSON.parse(JSON.parse(users)['response'])
			for user in users
				if (user['username'] == login) then
					account = user['account']
					balance = user['balance'].to_f
					eur = user['eur_course'].to_f
					balance = balance * eur

					res = @api.query("updateAccount", {
						:account => account,
						:balance => (balance + params['AMOUNT'].to_f * (1 - @config[:site][:comission])).to_f.round
					}, adm_user, false, true)

				end
			end
		end
		return 'OK'
	end