Giter Site home page Giter Site logo

sylvester254 / sample_flask_stripe_integration Goto Github PK

View Code? Open in Web Editor NEW

This project forked from holdenrehg-samples/sample_flask_stripe_integration

0.0 0.0 0.0 22 KB

Sample Application - Flask + Stripe Integration

Python 62.31% CSS 0.10% HTML 34.22% Mako 1.51% Dockerfile 1.86%

sample_flask_stripe_integration's Introduction

mystripeapp

Sample Flask + Stripe application.

Tutorial and explanation written up on medium.


Getting setup

1. Update your hosts file

Update your /etc/hosts file by adding the following line:

0.0.0.0 mystripeapp.local

2. Get the code

Clone down the repository.

The details in this readme are assuming you clone down the repo as mystripeapp so you may experience issues or have to slightly alter commands if you clone it down as another directory name.

$ git clone https://github.com/holdenrehg/sample_flask_stripe_integration mystripeapp

3. Update the environment variables

There is a set of environment variables located under mystripeapp/utils/__init__.py that need to be updated before running the application

The only two environment variables that you should need to change to get the application up and running are the stripe token and the stripe product code.

def environment():
    """
    This is not how you would want to handle environments in a real project,
    but for the sake of simplicity I'll create this function.

    Look at using environment variables or dotfiles for these.
    """
    return {
        "app": {"name": "mystripeapp.local", "port": "5200", "secret": "my_super_secret_key"},
        "billing": {"stripe": {"token": "****", "product": "****"}},
        "database": {
            "provider": "mysql",
            "host": "mariadb",
            "port": "3306",
            "username": "stripeapp",
            "password": "stripeapp",
            "database": "stripeapp",
        },
    }

It's also information for you to add your public stripe key to the javascript on the register form. See the mystripeapp/ui/views/auth/register.html file.

// Create a Stripe client.
var stripe = Stripe('****');

Running the application

Start the application

$ cd mystripeapp
$ docker-compose up

Migrate the database

Make sure to leave the application running before migrating the database:

$ docker-compose exec app flask db upgrade

Access the application

You'll be able to access at http://mystripeapp.local:5200 .


Testing the application manually

You can create an account using fake Stripe cards found at https://stripe.com/docs/testing . Use these on the http://mystripeapp.local:5200/register registration form.

Running automated tests

$ python3 setup.py test --container $(docker ps -q --filter name=mystripeapp_app)
$ python3 setup.py test --container $(docker ps -q --filter name=mystripeapp_app) --no-coverage

Useful commands

Since we are running the application with docker, here are some useful commands to know:

# Run a command inside of the app container
$ docker exec -it $(docker ps -q --filter=mystripeapp_app) {command}

$ docker exec -it $(docker ps -q --filter=mystripeapp_app) ipython3
$ docker exec -it $(docker ps -q --filter=mystripeapp_app) bash
$ docker exec -it $(docker ps -q --filter=mystripeapp_app) flask init db

While developing you'll often need some simple knowledge of the docker-compose commands such as:

$ docker-compose stop
$ docker-compose restart

sample_flask_stripe_integration's People

Contributors

holdenrehg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.