We have 4 products available in the form of a digital download and usage of each product is in the form of a renewable licence. Currently the licences are emailed to purchasers personally, resulting in inevitable delivery delays.
We want a simple PayPal IPN listening PHP script which, if a payment is successful, first checks the purchaser's email address against the appropriate existing MySQL database for that product to determine if the purchase is from a new user or if it is a licence renewal from an existing user.
If it is from a new user, the PHP should generate a random 32 character hex product key, write this product key together with some other details as a new entry in the database and email the key to the purchaser.
If the purchase is from an existing user, the PHP should extend the days allowed on the licence and email the purchaser.
The script should be able to handle purchases of multiple products through the "Add to cart" button.