Skip to content

Latest commit

 

History

History
113 lines (79 loc) · 3.97 KB

README.md

File metadata and controls

113 lines (79 loc) · 3.97 KB

The Container Vending Machine

or how to integrate Stripe with a container registry and sell your software.

The purpose of this example is to show how a software vendor can integrate a subscription management service with a container registry with the purpose of distributing software as a container image.

The article Distributing Commercial Software Through Container Images Level-up your software distribution provides background information and dives into other related the concepts.

High-level summary of the example

Create Harbor robot accounts for your customers to allow them to pull your software from a Harbor registry.

  • Receive Stripe webhooks, use the information to create customer records in our own database.
  • Provision access to a Harbor repository, and remove access if a Stripe subscription expires.

The application is implemented using Python and Django. We use a managed Harbor registry provided by Container Registry.

Limitations of the example

  • We use the Subscription Expired webhook from Stripe to remove access to a Harbor account. A better way to do this would be to set an expiry date for a Harbor robot account, and to extend that date when an outstanding invoice is paid in Stripe.
  • We send the Harbor credentials to customers through email.
  • Harbor usernames are generated automatically from the customer’s email on the subscription and can’t be customized.
  • Error handling is limited, both for Stripe and Harbor.

The most interesting parts of the example

A lot of this example is basic Django code, the most valuable pieces with the business logic are:

Running the example

Requirements:

  • faas-cli (optional)
  • Docker
  • Stripe

Step 1: Create an environment file at Stripe Harbor Example/stripe_harbor/strip_harbor_api/.env. Here’s an example of the .env file’s content (remember to use your Stripe and Harbor credentials):

DEBUG=True
SECRET_KEY='secret key'
STRIPE_API_KEY='api key'
HARBOR_HOST='io.com'
HARBOR_USERNAME='x'
HARBOR_PASSWORD='xxxx'
HARBOR_PROJECT_ID='xxxx'
MAILERSEND_API_KEY="xxxxx"
FROM_EMAIL="[email protected]"
TEMPLATE_ID="xxxx"
ACCOUNT_NAME="example"
SUPPORT_EMAIL="[email protected]"

Step 2:

  1. Login into Docker
$ docker login <server> --username <user> --password-stdin
  1. Login into Faas-cli
$ faas-cli login -g <gateway> -u <username> -p <password>

Step 3:

Build the Docker Image

 Make changes in 'strip-harbor.yml file' for Function and Image(FQDN)  
$ faas-cli build -f <filename.yml> 

Step 4:

Push the Docker Image

$ docker push <image name>

Step 5:

Deploy the Image into Openfaas(for that change gateway in 'strip-harbor.yml file' )

$ faas-cli deploy <filename.yml>

Step 6:

1 . Create webhook in stripe(https://dashboard.stripe.com/test/webhooks)

  1. Create Stripe Customer(for Local testing please install strip cli)

Navigate to Downloaded Strip Folder(For Local Testing)

$ ./stripe customers create --email=<email_id> --name=<name>
  1. Create Subscription for the Customer
$ ./stripe subscriptions create --customer=<customer_id> -d "items[0][price]"=<price_id>

Questions and issues

If you have a question or if you found a bug, please open a new issue on this repository.