Sofort API
Project description
Building brick to ease Sofort payments in your application.
This library is still in hard development so when in doubt, check original Sofort Reference.
Installation
$ pip install git+https://github.com/spreecode/python-sofort.git
Usage
import sofort
import some_abstract_http_framework as webserver
import some_abstract_data_storage as db
client = sofort.Client(my_user_id, my_api_key, my_project_id,
success_url='https://mysite.de/thanks.html',
abort_url='https://mysite.de/abort_payment.html',
notification_urls={
'default': 'https://mysite.de/notify.php?' + sofort.TRANSACTION_ID
})
payment_data = client.payment(
200,
reasons=[
'Invoice 0001 payment',
sofort.TRANSACTION_ID
]
)
db.save_transaction(payment_data.transaction)
webserver.redirect(payment_data.payment_url)
When payment is proccessed, client will be redirected to success_url and Sofort server will send POST-request to notification_urls as soon as transaction status will be changed. You can use sofort.TRANSACTION_ID in URL params, so notification url could be like this:
'http://mysite.de/notify.php?trn=' + sofort.TRANSACTION_ID
it will be substituted to something like
http://mysite.de/notify.php?trn=123456-321321-56A29EC6-066A
So you can catch transaction ID and check it’s status (all responses are wrapped with Schematics models)
>>> details = client.details('123456-321321-56A29EC6-066A')
>>> details[0]._data
{'amount': Decimal('234.00'),
'amount_refunded': Decimal('0.00'),
'costs': <CostsModel: CostsModel object>,
'currency_code': u'EUR',
'email_customer': None,
'exchange_rate': Decimal('1.0000'),
'language_code': u'de',
'payment_method': u'su',
'phone_customer': None,
'project_id': 123456,
'reasons': [u'Invoice 52'],
'recipient': <BankAccountModel: BankAccountModel object>,
'sender': <BankAccountModel: BankAccountModel object>,
'status': u'untraceable',
'status_history_items': [<StatusHistoryItemModel: StatusHistoryItemModel object>],
'status_modified': datetime.datetime(2016, 2, 28, 10, 1, 52, tzinfo=<FixedOffset u'+01:00' datetime.timedelta(0, 3600)>),
'status_reason': u'sofort_bank_account_needed',
'su': <SuModel: SuModel object>,
'test': True,
'time': datetime.datetime(2016, 2, 28, 10, 1, 52, tzinfo=<FixedOffset u'+01:00' datetime.timedelta(0, 3600)>),
'transaction': u'123456-321321-56A29EC6-066A',
'user_variables': None}
Testing
$ pip install -e '.[test]' # to obtain mock library $ python setup.py test
Be careful, transaction ID contains some sensitive data
123456-321321-56A29EC6-066A
^^^^^^ ^^^^^^
| |
User ID |
Project ID
Of course this data will be visible to customer on payment page, and it’s almost useless without API key. Still I think it’s bad idea to store unmasked transaction IDs in repo.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sofort-0.4.3.tar.gz.
File metadata
- Download URL: sofort-0.4.3.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1469bb66038ea1358e6801e877bf049967e44be0089720d5a25bb480d6770a6c
|
|
| MD5 |
dcec24e4e35de7b52a776a413ad50ddc
|
|
| BLAKE2b-256 |
6a7116ab7eafc49fbe719b27c19caa7f9854b63f826839f1e3f268dd36aee659
|
File details
Details for the file sofort-0.4.3-py3-none-any.whl.
File metadata
- Download URL: sofort-0.4.3-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e787895e2f2338d42c59dedf0b71180ee36227eee59e72462df990e0d22a44a5
|
|
| MD5 |
a77c4dc89c83708b770bf2280f49d2c3
|
|
| BLAKE2b-256 |
8d85b51f32001315aed58dc7db71fc558b0c14b2f311f18292854f2981826910
|