#!/usr/bin/python
# Certified Open - PayPal IPN CGI script
#
# Copyright 2007 BYTEWISE Software GmbH
#
# This file is part of Certified Open Database Backend
#
# Certified Open Database Backend is free software; you can redistribute
# it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2, or (at
# your option) any later version.
#
# Certified Open Database Backend is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied 
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Certified Open Database Backend; see the file COPYING. If
# not, write to the Free Software Foundation, Inc., 59 Temple Place -
# Suite 330, Boston, MA 02111-1307, USA.

import cgi
import sys
import urllib
import Pyro.core
backend = Pyro.core.getProxyForURI("PYROLOC://localhost:7766/backend")

params = sys.stdin.read()
param_dict = cgi.parse_qs(params)
confirm = urllib.urlopen("https://www.sandbox.paypal.com/cgi-bin/webscr",
        params + "&cmd=_notify-validate")
status = confirm.read()
if status = 'VERIFIED':
    backend.paypal_ipn(param_dict)
print "Content-type: text/plain\n\n--- ipn processed ---"
