Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shift4-Team committed Nov 3, 2022
0 parents commit 3950373
Show file tree
Hide file tree
Showing 96 changed files with 2,645 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build and validate
on: [ push ]

jobs:
tests:
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.7, 3.9, 3.11 ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: python -m pip install --upgrade pip -r requirements.txt -r test_requirements.txt

- name: Run tests
run: pytest tests

style-check:
name: Style check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: 3.11

- name: Install dependencies
run: python -m pip install --upgrade pip -r requirements.txt -r test_requirements.txt

- name: Run style checks
run: black --check setup.py shift4/ tests/
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish
on:
release:
types: [ prereleased, released ]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.11

- name: Install pypa/build
run: python -m pip install build --user

- name: Install dependencies
run: python -m pip install --upgrade pip -r requirements.txt

- name: Build a binary wheel and a source tarball
run: python -m build --sdist --wheel

- name: Publish distribution 📦 to Test PyPI
if: github.event.action == 'prereleased'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/

- name: Publish distribution 📦 to PyPI
if: github.event.action == 'released'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
82 changes: 82 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# idea
.idea

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
.pypirc

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask instance folder
instance/

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# dotenv
.env

# Spyder project settings
.spyderproject
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

©2022 Shift4. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
161 changes: 161 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
Python library for Shift4 API
===================================
[![Build](https://github.com/shift4developer/shift4-python/actions/workflows/build.yml/badge.svg)](https://github.com/shift4developer/shift4-python/actions/workflows/build.yml)

Installation
------------

```
pip install shift4
```

Quick start
-----------

```python
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)
```

API reference
-------------

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

- charges
- [create(params)](https://dev.shift4.com/docs/api#charge-create)
- [get(charge_id)](https://dev.shift4.com/docs/api#charge-retrieve)
- [update(charge_id, params)](https://dev.shift4.com/docs/api#charge-update)
- [capture(charge_id)](https://dev.shift4.com/docs/api#charge-capture)
- [refund(charge_id, [params])](https://dev.shift4.com/docs/api#charge-capture)
- [list([params])](https://dev.shift4.com/docs/api#charge-list)
- customers
- [create(params)](https://dev.shift4.com/docs/api#customer-create)
- [get(customer_id)](https://dev.shift4.com/docs/api#customer-retrieve)
- [update(customer_id, params)](https://dev.shift4.com/docs/api#customer-update)
- [delete(customer_id)](https://dev.shift4.com/docs/api#customer-delete)
- [list([params])](https://dev.shift4.com/docs/api#customer-list)
- cards
- [create(customer_id, params)](https://dev.shift4.com/docs/api#card-create)
- [get(customer_id, card_id)](https://dev.shift4.com/docs/api#card-retrieve)
- [update(customer_id, card_id, params)](https://dev.shift4.com/docs/api#card-update)
- [delete(customer_id, card_id)](https://dev.shift4.com/docs/api#card-delete)
- [list(customer_id, [params])](https://dev.shift4.com/docs/api#card-list)
- subscriptions
- [create(params)](https://dev.shift4.com/docs/api#subscription-create)
- [get(subscription_id)](https://dev.shift4.com/docs/api#subscription-retrieve)
- [update(subscription_id, params)](https://dev.shift4.com/docs/api#subscription-update)
- [cancel(subscription_id, [params])](https://dev.shift4.com/docs/api#subscription-cancel)
- [list([params])](https://dev.shift4.com/docs/api#subscription-list)
- plans
- [create(params)](https://dev.shift4.com/docs/api#plan-create)
- [get(plan_id)](https://dev.shift4.com/docs/api#plan-retrieve)
- [update(plan_id, params)](https://dev.shift4.com/docs/api#plan-update)
- [delete(plan_id)](https://dev.shift4.com/docs/api#plan-delete)
- [list([params])](https://dev.shift4.com/docs/api#plan-list)
- events
- [get(event_id)](https://dev.shift4.com/docs/api#event-retrieve)
- [list([params])](https://dev.shift4.com/docs/api#event-list)
- tokens
- [create(params)](https://dev.shift4.com/docs/api#token-create)
- [get(token_id)](https://dev.shift4.com/docs/api#token-retrieve)
- blacklist
- [create(params)](https://dev.shift4.com/docs/api#blacklist-rule-create)
- [get(blacklist_rule_id)](https://dev.shift4.com/docs/api#blacklist-rule-retrieve)
- [delete(blacklist_rule_id)](https://dev.shift4.com/docs/api#blacklist-rule-delete)
- [list([params])](https://dev.shift4.com/docs/api#blacklist-rule-list)
- checkoutRequest
- [sign(checkoutRequestObjectOrJson)](https://dev.shift4.com/docs/api#checkout-request-sign)
- crossSaleOffers
- [create(params)](https://dev.shift4.com/docs/api#cross-sale-offer-create)
- [get(cross_sale_offer_id)](https://dev.shift4.com/docs/api#cross-sale-offer-retrieve)
- [update(cross_sale_offer_id, params)](https://dev.shift4.com/docs/api#cross-sale-offer-update)
- [delete(cross_sale_offer_id)](https://dev.shift4.com/docs/api#cross-sale-offer-delete)
- [list([params])](https://dev.shift4.com/docs/api#cross-sale-offer-list)
- credits
- [create(params)](https://dev.shift4.com/docs/api#credit-create)
- [get(credit_id)](https://dev.shift4.com/docs/api#credit-retrieve)
- [update(credit_id, params)](https://dev.shift4.com/docs/api#credit-update)
- [list([params])](https://dev.shift4.com/docs/api#credit-list)
- disputes
- [get(dispute_id)](https://dev.shift4.com/docs/api#dispute-retrieve)
- [update(dispute_id, params)](https://dev.shift4.com/docs/api#dispute-update)
- [close(dispute_id)](https://dev.shift4.com/docs/api#dispute-close)
- [list([params])](https://dev.shift4.com/docs/api#dispute-list)
- fileUploads
- [upload(content, params)](https://dev.shift4.com/docs/api#file-upload-create)
- [get(file_upload_id)](https://dev.shift4.com/docs/api#file-upload-retrieve)
- [list([params])](https://dev.shift4.com/docs/api#file-upload-list)
- fraudWarnings
- [get(fraud_warning_id)](https://dev.shift4.com/docs/api#fraud-warning-retrieve)
- [list([params])](https://dev.shift4.com/docs/api#fraud-warning-list)
- paymentMethods
- [create(params)](https://dev.shift4.com/docs/api#payment-method-create)
- [retrieve(payment_method_id)](https://dev.shift4.com/docs/api#payment-method-retrieve)
- [delete(payment_method_id)](https://dev.shift4.com/docs/api#payment-method-delete)
- [list([params])](https://dev.shift4.com/docs/api#payment-methods-list)


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


Developing
----------

Optionally setup a virtual environment
```sh
python -m venv ./venv --clear
source ./venv/bin/activate
```

Install the package dependencies:
```sh
pip install -r requirements.txt -r test_requirements.txt
```

To connect to different backend:

```python
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:

```sh
SECRET_KEY=pk_test_my_secret_key pytest tests
```

Format the package files using `black`:

```sh
black setup.py shift4/ tests/
```
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests >= 2.27.1
34 changes: 34 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pathlib

from setuptools import setup, find_packages

HERE = pathlib.Path(__file__).parent
exec(open(HERE / "shift4/__version__.py").read())
INSTALL_REQUIRES = (HERE / "requirements.txt").read_text().splitlines()


setup(
name="shift4",
version=__version__,
description="Shift4 Python Library",
long_description="Python library for Shift4 API",
url="https://github.com/shift4developer/shift4-python",
author="Shift4",
author_email="[email protected]",
license="MIT",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Software Development :: Build Tools",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
keywords="payment",
packages=find_packages(exclude=["tests*"]),
install_requires=INSTALL_REQUIRES,
test_suite="tests",
)
Loading

0 comments on commit 3950373

Please sign in to comment.