Skip to content

Simple Python CGI script for processing user payments for a website.

License

Notifications You must be signed in to change notification settings

pigeonburger/stripe-gateway-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stripe Payment Gateway - Python Implementation

A Simple Python CGI script for processing user payments for a website, using the Stripe payment gateway.

This script was originally made in PHP (the original can be found here) but was translated into Python by me. I had many extra dependencies that required me to use Python instead of PHP on my website, so I made this script.

Requirements

  • Python >= 3.6
  • stripe and mysql-connector-python Python packages.
  • A web server configured to run Python CGI scripts.
  • A MySQL Database.
  • A Stripe account with API keys.

More detailed setup instructions are down below

Setup:

First, download the Python and HTML files, extract them and put them both in the same folder somewhere in your web server directory.

Get your Stripe API keys:

  1. Navigate to the API Keys section under Developers on your Stripe dashboard.

image

  1. Copy your Publishable Key and Secret Key from under the "Standard keys" section. You will need them later.

image

Install the required Python packages:

pip install stripe
pip install mysql-connector-python

Setting up the Database:

Create a new MySQL database called stripepayments, then run the following commands in the MySQL command-line:

USE stripepayments;
CREATE TABLE `orders` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
 `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `card_num` bigint(20) NOT NULL,
 `card_cvc` int(5) NOT NULL,
 `card_exp_month` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
 `card_exp_year` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
 `item_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `item_number` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
 `item_price` float(10,2) NOT NULL,
 `item_price_currency` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'usd',
 `paid_amount` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
 `paid_amount_currency` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
 `txn_id` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
 `payment_status` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
 `created` datetime NOT NULL,
 `modified` datetime NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Editing the Python and HTML files:

  • On line 11, in index.html, insert your Stripe Publishable key that you got earlier.
  • On line 19, in submit.py, insert your Stripe Secret key that you got earlier.
  • On line 47, in submit.py, add the required details to connect to your MySQL database.

The files now have the basic working functionality, and can be further edited to suit your needs!

About

Simple Python CGI script for processing user payments for a website.

Resources

License

Stars

Watchers

Forks

Packages

No packages published