A simple Payment Script for downloadable Files

A simple Payment Script for downloadable Files

What is this?

Pay Script allow you to make files and digital products payable on your website.
All you need is a PayPal account and a PHP based website on an Apache Webserver. See requirements.


Installation and Configuration

Extract ZIP file into home directory of your website.
payscript_10.zip

After that you should see a sub directory /payscript/

1. Setup PayPal, E-Mail address, Tax Rate

Open: config_global.inc.php

And insert your PayPal+ Client ID and Secret. If you dont know how to get a Client ID and Secret from PayPal you will get help here.
Take care that you change the API URL to https://api.sandbox.paypal.com for Sand Box Accounts and https://api.paypal.com for Live Accounts.
If you dont want to use PayPal+ SOAP API you can configurate the older NVP API, see section in config_global.inc.php

...
"shop_email" => "shop@mydomain.com", // This email address must be allowed to send mails from server
"tax_rate" => 19, // This is the tax rate of your country to calculate the tax price submitted to PayPal

"paypal_api" => "plus", // plus and nvp possible, see configuration data below
"paypal_plus" => array (
   // PayPal+ login data
   "client_id" => "xxx",
   "secret" => "xxx",
   "api_url" => "https://api.paypal.com", // Live
...

2. Setup Products

Open: products.txt

# This is the database for all payable files.
# Files are located in download/ directory.
# Every line contain a file with following format:
# <filename>;<currency>;<price brutto>;<description>
#
# Example:
# program.zip;USD;10.0;Test Download
# Note: The Tax Rate is defined in config_global.inc.php

program.zip;USD;10.0;Test Download

After that copy your files into /payscript/download/ directory.

The Checkout Mask

If you access the payable file with https://mydomain.com/payscript/download/program.zip a checkout mask will be shown.

Checkout Example

If you want to change the look & feel of the checkout mask, feel free to change the file checkout.php and/or the CSS files in css/ directory.

After the payment was successful the customer will get an email from shop email address (configurated in config_global.inc.php) with a secret download link.

Templates

The template of the shop email can be configurated in tpl/buyer_email.html and tpl/buyer_email_subject.txt

<p>Hello {fullname},</p>
<p>thanks for ordering <b>{description}</b> with price of {total}.</p>
<p>This is your Download URL: <a href="{download_url}">{download_url}</a></p>
<p>Your PayPal Transaction-ID is {paypal_trs_id}.</p>
<p>Best regards.</p>

You can also change the templates of the checkout mask and notification email for shop administrator in tpl/checkout_xxx.html and tpl/admin_email.html

Following placeholders with brackets are possible:

Placeholder Description
{fullname} Full name of the buyer
{address} Address of the buyer
{zip} ZIP of the buyer
{city} City of the buyer
{country_code} Country Code (ISO format) of the buyer
{email} E-Mail address of the buyer
{phone} Phone of the buyer
{description} Description of the product
{version} Filename
{download_url} Secret url to download the file
{paypal_trs_id} PayPal Transaction-ID
{paypal_payer_id} PayPal Payer-ID
{paypal_fee} Fee of PayPal transaction
{total} Formatted total price
{netto} Formatted netto price
{tax} Formatted tax price
{currency} Currency e.g. USD
{date} Current date in format Y-m-d
{year} Current year

Logfiles

All orders and downloads are stored in CSV files located in log/orders.csv and log/downloads.csv

Do not delete the file orders.csv. It is neccesary for secure download links.

Requirements and Troubleshooting

You need a PHP version >= 5.4 with cURL module activated.

You need an Apache compatible Webserver with mod_rewrite module activated.

If E-Mail sending does not work, set your SMTP connection data in config_global.inc.php: smtp_host, smtp_auth, smtp_user, smtp_password