Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pfpayments/python-sdk
The python SDK allows an easy integration of PostFinance Checkout into python applications.
https://github.com/pfpayments/python-sdk
Last synced: about 2 months ago
JSON representation
The python SDK allows an easy integration of PostFinance Checkout into python applications.
- Host: GitHub
- URL: https://github.com/pfpayments/python-sdk
- Owner: pfpayments
- License: apache-2.0
- Created: 2020-03-31T07:38:00.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-08T10:10:30.000Z (9 months ago)
- Last Synced: 2024-08-11T08:52:40.068Z (5 months ago)
- Language: Python
- Homepage:
- Size: 783 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/pfpayments/python-sdk.svg?branch=master)](https://travis-ci.org/pfpayments/python-sdk)
# PostFinance Checkout Python SDK
Python SDK to access PostFinance Checkout web services API.
Library facilitates your interaction with various services such as transactions, accounts, and subscriptions.
## API documentation
[PostFinance Checkout Web Service API](https://checkout.postfinance.ch/doc/api/web-service)
## Requirements
- Python 3.7+
## Installation
### pip3 install (recommended)
```sh
pip3 install --upgrade postfinancecheckout
```### pip3 install from source via GitHub
```sh
pip3 install git+http://github.com/pfpayments/python-sdk.git
```
(you may need to run `pip3` with root permission: `sudo pip3 install git+http://github.com/pfpayments/python-sdk.git` )### install from source via Setuptools
Install via [Setuptools](http://pypi.python.org/pypi/setuptools).
```sh
pip3 install setuptoolspython setup.py install
```
(or `sudo python setup.py install` to install the package for all users)## Usage
The library needs to be configured with your account's space id, user id, and secret key which are available in your [PostFinance Checkout
account dashboard](https://checkout.postfinance.ch/account/select). Set `space_id`, `user_id`, and `api_secret` to their values.
You can also optionally set `default_headers` to set some headers that will be sent to all requests### Configuring a Service
```python
from postfinancecheckout import Configuration
from postfinancecheckout.api import TransactionServiceApi, TransactionPaymentPageServiceApispace_id = 405
# default_headers is an optional param, that represents headers sent to all requests
config = Configuration(
user_id=512,
api_secret='FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ=',
default_headers={'x-meta-custom-header': 'value-1', 'x-meta-custom-header-2': 'value-2'},
# set a custom request timeout if needed. (If not set, then the default value is: 25 seconds)
request_timeout = 30
)transaction_service = TransactionServiceApi(configuration=config)
transaction_payment_page_service = TransactionPaymentPageServiceApi(configuration=config)```
To get started with sending transactions, please review the example below:
```python
from postfinancecheckout import Configuration
from postfinancecheckout.api import TransactionServiceApi, TransactionPaymentPageServiceApi
from postfinancecheckout.models import LineItem, LineItemType, TransactionCreatespace_id = 405
config = Configuration(
user_id=512,
api_secret='FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ=',
# set a custom request timeout if needed. (If not set, then the default value is: 25 seconds)
request_timeout = 30
)transaction_service = TransactionServiceApi(configuration=config)
transaction_payment_page_service = TransactionPaymentPageServiceApi(configuration=config)# create line item
line_item = LineItem(
name='Red T-Shirt',
unique_id='5412',
sku='red-t-shirt-123',
quantity=1,
amount_including_tax=29.95,
type=LineItemType.PRODUCT
)# create transaction model
transaction = TransactionCreate(
line_items=[line_item],
auto_confirmation_enabled=True,
currency='EUR',
)transaction_create = transaction_service.create(space_id=space_id, transaction=transaction)
payment_page_url = transaction_payment_page_service.payment_page_url(space_id=space_id, id=transaction_create.id)
# redirect your customer to this payment_page_url
```### Integrating Webhook Payload Signing Mechanism into webhook callback handler
The HTTP request which is sent for a state change of an entity now includes an additional field `state`, which provides information about the update of the monitored entity's state. This enhancement is a result of the implementation of our webhook encryption mechanism.
Payload field `state` provides direct information about the state update of the entity, making additional API calls to retrieve the entity state redundant.
#### ⚠️ Warning: Generic Pseudocode
> **The provided pseudocode is intentionally generic and serves to illustrate the process of enhancing your API to leverage webhook payload signing. It is not a complete implementation.**
>
> Please ensure that you adapt and extend this code to meet the specific needs of your application, including appropriate security measures and error handling.
For a detailed webhook payload signing mechanism understanding we highly recommend referring to our comprehensive
[Webhook Payload Signing Documentation](https://checkout.postfinance.ch/doc/webhooks#_webhook_payload_signing_mechanism).```python
@app.route('/webhook/callback', methods=['POST'])
def handle_webhook():
request_payload = request.data.decode('utf-8')
signature = request.headers.get('x-signature')if not signature:
# Make additional API call to retrieve the entity state
# ...
else:
if webhook_encryption_service().is_content_valid(signature_header=signature, content_to_verify=request_payload):
# Parse request_payload to extract 'state' value
# Process entity's state change
# ...# Process the received webhook data
# ...```
## License
Please see the [license file](https://github.com/pfpayments/python-sdk/blob/master/LICENSE) for more information.