pip install shift4
import shift4 as shift4
shift4.secret_key = 'pk_test_my_secret_key'
try:
customer = shift4.customers.create({
'email': '[email protected]',
'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)
Please refer to detailed API docs (linked) for all available fields
- charges
- customers
- cards
- subscriptions
- plans
- events
- tokens
- blacklist
- checkoutRequest
- credits
- disputes
- fileUploads
- fraudWarnings
- paymentMethods
For further information, please refer to our official documentation at https://dev.shift4.com/docs.
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/