shift4

Shift4 Python Library


Keywords
payment
License
MIT
Install
pip install shift4==2.0.0

Documentation

Python library for Shift4 API

Build

Installation

pip install shift4

Quick start

import shift4 as shift4

shift4.secret_key = 'pk_test_my_secret_key'

try:
    customer = shift4.customers.create({
        'email': 'user@example.com',
        'description': 'User description'
    })
    print("Created customer:", customer)
    card = shift4.cards.create(customer['id'], {
        'number': '4242424242424242',
        'expMonth': '12',
        'expYear': '2023',
        'cvc': '123',
        'cardholderName': 'John Smith'
    })
    print("Created card:", card)
    charge = shift4.charges.create({
      'amount': 1000,
      'currency': 'EUR',
      'customerId': card['customerId']
    })
    print("Created charge:", charge)
except shift4.Shift4Exception as e:
  print(e)

API reference

Please refer to detailed API docs (linked) for all available fields

For further information, please refer to our official documentation at https://dev.shift4.com/docs.

Developing

Optionally setup a virtual environment

python -m venv ./venv --clear
source ./venv/bin/activate 

Install the package dependencies:

pip install -r requirements.txt -r test_requirements.txt

To connect to different backend:

import shift4 as api

api.secret_key = 'pk_test_my_secret_key'
api.api_url = 'https://api.myshift4env.com'
api.uploads_url = 'https://uploads.myshift4env.com'

To run tests:

SECRET_KEY=pk_test_my_secret_key pytest tests

Format the package files using black:

black setup.py shift4/ tests/