Skip to content

Commit

Permalink
Merge pull request devartis#10 from NafieAlhilaly/doc/update-readme-file
Browse files Browse the repository at this point in the history
doc: update readme file
  • Loading branch information
NafieAlhilaly authored Jul 15, 2022
2 parents 89d093e + 26f93c1 commit 1d47685
Showing 1 changed file with 32 additions and 61 deletions.
93 changes: 32 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# py-pkpass

[![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)


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
Expand Down Expand Up @@ -29,11 +34,12 @@ source <your-env-name>/bin/activate
* Password less Keys possible if wanted
* Validation of Fields and Passes including own Exception (PassParameterException)
* 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-compose
* Add docker/docker-compose
* Validate data
* Add NFC support
* Full Example including which Fields are Possible
Expand Down Expand Up @@ -71,53 +77,54 @@ source <your-env-name>/bin/activate
## Typical Usage
create your .py file on the root and try the following example
```python
from wallet.PassStyles import StoreCard
from wallet.PassStyles import StoreCard, EventTicket, Coupon, Generic, BoardingPass
from wallet.Pass import Pass
from wallet.PassProps.Barcode import Barcode
import uuid
from wallet.Schemas.FieldProps import FieldProps
pass_type_identifier = "pass.com.yourcompany.some_name"
team_identifier = "ABCDE123" # Your Apple team ID
card = StoreCard()
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(
**{
"pass_information": card,
"pass_type_identifier": pass_type_identifier,
"organization_name": "organization_name",
"team_identifier": team_identifier,
}
card,
pass_type_identifier,
team_identifier,
"organization_name",
**optional_pass_info
)
passfile.logoText = "Sharks"
# charge_response.id is trackable via the Stripe dashboard
passfile.serialNumber = str(uuid.uuid4())
passfile.barcodes.append(Barcode(message="testing", ))
passfile.description = "some discription"
passfile.backgroundColor = "rgb(38, 93, 205)"
passfile.foregroundColor = "rgb(255, 255, 255)"
passfile.labelColor = "rgb(189, 189, 189)"
# Including the icon and logo is necessary for the passbook to be valid.
passfile.add_file("icon.png", open("shark-icon.png", "rb"))
passfile.add_file("[email protected]", open("shark-icon.png", "rb"))
passfile.add_file("[email protected]", open("shark-icon.png", "rb"))
passfile.add_file("logo.png", open("shark-icon.png", "rb"))
passfile.add_file("[email protected]", open("shark-icon.png", "rb"))
passfile.add_file("[email protected]", open("shark-icon.png", "rb"))
passfile.add_file("strip.png", open("sea.jpg", "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",
Expand All @@ -126,6 +133,7 @@ passfile.create(
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
Expand All @@ -135,40 +143,3 @@ passfile.create(
* `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.");
}
});
```

0 comments on commit 1d47685

Please sign in to comment.