https://github.com/halturin/applepay
a Python library for decrypting Apple Pay payment tokens.
https://github.com/halturin/applepay
apple-pay encryption python python-library token
Last synced: 11 months ago
JSON representation
a Python library for decrypting Apple Pay payment tokens.
- Host: GitHub
- URL: https://github.com/halturin/applepay
- Owner: halturin
- License: mit
- Created: 2016-09-26T13:01:54.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-03-08T10:15:30.000Z (about 5 years ago)
- Last Synced: 2025-03-24T10:17:51.235Z (12 months ago)
- Topics: apple-pay, encryption, python, python-library, token
- Language: Python
- Homepage:
- Size: 50.8 KB
- Stars: 64
- Watchers: 5
- Forks: 15
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A Python library for decrypting Apple Pay payment tokens.
ApplePay reference https://developer.apple.com/library/ios/documentation/PassKit/Reference/PaymentTokenJSON/PaymentTokenJSON.html
## Apple's intermediate and root certificates
```sh
$ wget 'https://www.apple.com/certificateauthority/AppleAAICAG3.cer'
$ wget 'https://www.apple.com/certificateauthority/AppleRootCA-G3.cer'
```
## Install
Installing library into your environment:
```sh
$ pip install applepay
```
## Usage
Step by step:
```python
from applepay import payment as apple
# payment_json value example:
#
# {"data":"<>",
# "header":
# {"publicKeyHash":"<>",
# "ephemeralPublicKey":"<>",
# "transactionId":"<>"},
# "version":"EC_v1"}
certificate_pem = open('merchant_cert.pem', 'rb').read()
private_key_pem = open('merchant_private_key', 'rb').read()
payment = apple.Payment(certificate_pem, private_key_pem)
decrypted_json = payment.decrypt(payment_json['header']['ephemeralPublicKey'], payment_json['data'])
# decrypted_json value example
# {
# "applicationPrimaryAccountNumber"=>"4804123456789012",
# "applicationExpirationDate"=>"190123",
# "currencyCode"=>"123",
# "transactionAmount"=>700,
# "deviceManufacturerIdentifier"=>"123456789012",
# "paymentDataType"=>"3DSecure",
# "paymentData"=> {
# "onlinePaymentCryptogram"=>"<>",
# "eciIndicator"=>"5"
# }
# }
```
## Testing
```sh
$ python setup.py test
```
## Contributors