Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Bastian-Kuhn/wallet
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: NafieAlhilaly/py-pkpass
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: develop
Choose a head ref
Able to merge. These branches can be automatically merged.

Commits on Jul 13, 2022

  1. Copy the full SHA
    ee3cda0 View commit details
  2. test: dummy test

    NafieAlhilaly committed Jul 13, 2022
    Copy the full SHA
    4bc10f1 View commit details
  3. Merge pull request devartis#1 from NafieAlhilaly/style/lint-format-st…

    …ructure
    
    style: lint, format and restructure files
    NafieAlhilaly authored Jul 13, 2022
    Copy the full SHA
    7084904 View commit details
  4. Copy the full SHA
    6ec714f View commit details
  5. Merge pull request devartis#2 from NafieAlhilaly/feat/field-validation

    feat: add Field validation
    NafieAlhilaly authored Jul 13, 2022
    Copy the full SHA
    8327fe4 View commit details
  6. Copy the full SHA
    78d1b83 View commit details
  7. Merge pull request devartis#4 from NafieAlhilaly/refactor/refactor-Ba…

    …rcode-params-and-docs
    
    refactor: refactor Barcode params and update readme
    NafieAlhilaly authored Jul 13, 2022
    Copy the full SHA
    c8d7c31 View commit details
  8. feat: add screenshot

    NafieAlhilaly committed Jul 13, 2022
    Copy the full SHA
    f2f7932 View commit details
  9. Copy the full SHA
    ddc0a73 View commit details
  10. docs: update readme

    NafieAlhilaly committed Jul 13, 2022
    Copy the full SHA
    e4e4cdb View commit details
  11. Copy the full SHA
    bbf29a6 View commit details

Commits on Jul 15, 2022

  1. Copy the full SHA
    fd44285 View commit details
  2. Merge pull request devartis#7 from NafieAlhilaly/test/add-tests

    test: add tests and test assets
    NafieAlhilaly authored Jul 15, 2022
    Copy the full SHA
    f1cf88f View commit details
  3. refactor: pass class

    NafieAlhilaly committed Jul 15, 2022
    Copy the full SHA
    9c702fc View commit details
  4. Copy the full SHA
    a288f59 View commit details
  5. Copy the full SHA
    0db31eb View commit details
  6. Merge pull request devartis#11 from NafieAlhilaly/feat/enhance-pass-r…

    …ead_file
    
    feat: enhance pass add_file function to accept bytes or BufferedReader
    NafieAlhilaly authored Jul 15, 2022
    Copy the full SHA
    89d093e View commit details
  7. Copy the full SHA
    26f93c1 View commit details
  8. Copy the full SHA
    1d47685 View commit details

Commits on Jul 18, 2022

  1. Copy the full SHA
    81c2578 View commit details
  2. Merge pull request devartis#12 from NafieAlhilaly/feat/run-ci-on-mult…

    …ible-python-versions
    
    ci: run test on multible python versions
    NafieAlhilaly authored Jul 18, 2022
    Copy the full SHA
    377bcce View commit details

Commits on Jul 21, 2022

  1. feat: add NFC support

    NafieAlhilaly committed Jul 21, 2022
    Copy the full SHA
    40915d6 View commit details

Commits on Jul 22, 2022

  1. Merge pull request devartis#13 from NafieAlhilaly/feat/add-nfc

    feat: add NFC support
    NafieAlhilaly committed Jul 22, 2022
    Copy the full SHA
    40a2579 View commit details
44 changes: 44 additions & 0 deletions .github/workflows/on_pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Checks
on:
pull_request:
branches:
- "develop"
- "master"
workflow_dispatch:
jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v2
codelint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- name: Lint with flake8
run: |
python -m pip install --upgrade pip
pip install flake8
flake8 . --ignore=E203,W605,W503 --count --show-source --max-complexity=16 --max-line-length=127 \
--statistics --exclude .git,__pycache__,__init__.py,test
unittests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- name: start the app & run unit tests with python ${{ matrix.python-version }}
shell: bash
run: |
python -m pip install --upgrade pip
pip install pydantic
pip install pytest
pytest
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
*.py[co]
*.py~

# pytest
.pytest_cache
__pycache__

# Packages
MANIFEST
*.egg
@@ -31,3 +35,19 @@ pip-log.txt
.DS_Store
.idea/
*.swp

venv
.vscode
poetry.lock

wallet/tmp

.env

generate_test_pass.py

test_pass.pkpass

icon2x.png
shark-icon.png
sea.jpg
165 changes: 89 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
# Wallet-py3k
# py-pkpass

Python library to read/write [Apple Wallet](http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/PassKit_PG/Chapters/Introduction.html#//apple_ref/doc/uid/TP40012195-CH1-SW1) (.pkpass) files
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge&logo=python)](https://github.com/psf/black)
![](https://img.shields.io/badge/Cov-83%25-green?style=for-the-badge&logo=appveyor)
![](https://img.shields.io/github/workflow/status/NafieAlhilaly/py-pkpass/Checks?label=Test&style=for-the-badge)

This is a fork of https://github.com/ofw/wallet-py3k which does not suits my needs

Python library to read/write [Apple Wallet](http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/PassKit_PG/Chapters/Introduction.html#//apple_ref/doc/uid/TP40012195-CH1-SW1) (.pkpass) files, see also [Pass Design and Creation](https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/PassKit_PG/Creating.html)

This is a fork of https://github.com/Bastian-Kuhn/wallet , the original fork https://github.com/devartis/passbook

## Getting started
```bash
git clone https://github.com/NafieAlhilaly/py-pkpass.git
```
move to py-pkpass dir
```bash
cd py-pkpass
```

create python virtual environment
```bash
python3 -m venv venv
```

activate your virtual environmetn
```bash
source <your-env-name>/bin/activate
```


## New Features
* Direct Generation of passes without thee need to store them on a filesystem (if wanted)
* Password less Keys possible if wanted
* Validation of Fields and Passes including own Exception (PassParameterException)
* Complete Refactored and Simplified Code
* Complete Refactored and Simplified Code (Still WIP)
* adding file to pass can be from eather IO(locally) or form a URL.


## ToDos
* Update of Getting Started
* Add docker/docker-compose
* Validate data
* Add NFC support
* Full Example including which Fields are Possible


## Old: Getting Started
This part from here needs to be updated:

## Before creating a pkpass file you need to :
1. Create a Pass Type Id:
1. Visit the [Visit the iOS Provisioning Portal](https://developer.apple.com/account/resources/certificates/list)
2. On the left, click Identifiers
@@ -51,40 +77,64 @@ This part from here needs to be updated:
## Typical Usage
create your .py file on the root and try the following example
```python
from wallet.models import Pass, Barcode, StoreCard
pass_type_identifier = "pass.com.yourcompany.some_name"
team_identifier = "ABCDE1234" # Your Apple team ID
cert_pem = "certficate.pem"
key_pem = "key.pem"
wwdr_pem = "AppleWWDRCA.pem"
key_pem_password = "your_password"
cardInfo = StoreCard()
cardInfo.addPrimaryField('name', 'John Doe', 'Name')
passfile = Pass(cardInfo,
passTypeIdentifier=cls.pass_type_identifier,
organizationName=cls.organization_name,
teamIdentifier=cls.team_identifier)
# charge_response.id is trackable via the Stripe dashboard
passfile.serialNumber = charge_response.id
passfile.barcode = Barcode(message = charge_response.id, format=BarcodeFormat.PDF417)
passfile.description = charge_response.description
# Including the icon and logo is necessary for the passbook to be valid.
passfile.addFile("icon.png", open("icon.png", "rb"))
passfile.addFile("logo.png", open("logo.png", "rb"))
_ = passfile.create(cls.cert_pem,
cls.key_pem,
cls.wwdr_pem,
cls.key_pem_password,
"pass_name.pkpass")
from wallet.PassStyles import StoreCard, EventTicket, Coupon, Generic, BoardingPass
from wallet.Pass import Pass
from wallet.PassProps.Barcode import Barcode
from wallet.Schemas.FieldProps import FieldProps
pass_type_identifier = "pass.com.yourcompany.some_name"
team_identifier = "ABCDE123" # Your Apple team ID
card = StoreCard() # or EventTicket, or Coupon, or Generic, or BoardingPass
card.add_header_field(FieldProps(key="k2", value="69", label="Points"))
card.add_secondary_field(FieldProps(key="k3", value="Small shark", label="Level"))
card.add_back_field(FieldProps(key="k5", value="first backfield", label="bf1"))
optional_pass_info = {
"logo_text": "Sharks",
"description": "some discription",
"background_color": "rgb(38, 93, 205)",
"foreground_color": "rgb(255, 255, 255)",
"label_color": "rgb(189, 189, 189)",
"barcodes": [Barcode(message="testing")]
}
passfile = Pass(
card,
pass_type_identifier,
team_identifier,
"organization_name",
**optional_pass_info
)
passfile.add_file("icon.png", open("shark-icon.png", "rb"))
passfile.add_file("icon@2x.png", open("shark-icon.png", "rb"))
passfile.add_file("icon@3x.png", open("shark-icon.png", "rb"))
passfile.add_file("logo.png", open("shark-icon.png", "rb"))
passfile.add_file("logo@2x.png", open("shark-icon.png", "rb"))
passfile.add_file("logo@3x.png", open("shark-icon.png", "rb"))
# strip image is optional
# you can pass an image url directly to add_file
strip = get("https://images.pexels.com/photos/5967796/pexels-photo-5967796.jpeg").content
passfile.add_file("strip.png", strip)
passfile.create(
"signerCert.pem",
"signerKey.pem",
"wwdr.pem",
password="password",
file_name="test_pass.pkpass",
)
```
### example pass
<img src="https://github.com/NafieAlhilaly/py-pkpass/blob/develop/Screenshot/pass_screenshot.png" alt="drawing" style="width:200px;"/>
### Notes
@@ -93,40 +143,3 @@ This part from here needs to be updated:
* `passfile.create()` returns the name of the generated file, which matches what you pass to it as the fifth parameter.
* Valid `cardInfo` constructors mirror the pass types defined by Apple. For example, `StoreCard()`, `BoardingPass()`, `Coupon()`, etc.
* The various "add field" methods (e.g. `addPrimaryField()`) take three unnamed parameters in the order `key`, `value`, `label`
An example Flask route handler to return the generated pass files:
```python
@application.route("/passes/<path:fname>")
def passes_proxy(fname):
"""static passes serve"""
return send_from_directory("passes", fname, mimetype="application/vnd.apple.pkpass")
```
An example usage in a React app using Stripe and Stripe Elements to process payments and generate a store pass:
```javascript
paymentRequest.on('token', async (ev) => {
try {
const response = await fetch('https://your_server/charge', {
method: 'POST',
body: JSON.stringify({
token: ev.token.id,
amount: totalInCents,
description: purchasedItems.join(',\n')
}),
headers: {'content-type': 'application/json'},
});
if (!response.ok) {
throw new Error('There was a problem processing your payment.');
}
// Report to the browser that the payment was successful, prompting
// it to download the pass file to the user's Wallet
ev.complete('success');
const pkpass = await response.json();
window.location.href = `https://your_server/passes/${pkpass.filename}`;
} catch (error) {
throw new Error("There was a problem processing your payment.");
}
});
```
Binary file added Screenshot/pass_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "py-pkpass"
version = "0.1.1"
description = "python library to create pkpass files (Apple Wallet files)"
authors = []
license = "MIT license"

[tool.poetry.dependencies]
python = "^3.10"
pydantic = "^1.9.1"

[tool.poetry.dev-dependencies]
six = "^1.16.0"
black = "^22.6.0"
flake8 = "^4.0.1"
pytest = "^7.1.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@

install_requires=install_requires,

classifiers = [
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Other Environment',
'Intended Audience :: Developers',
5 changes: 5 additions & 0 deletions wallet/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length= 127
ignore = E203,W605,W503
max-complexity= 16
exclude = .git,__pycache__,__init__.py,.mypy_cache,.pytest_cache,test
Loading