Skip to main content

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.

Build Status Coverage Code Health

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sofort-0.4.3.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sofort-0.4.3-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

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

Hashes for sofort-0.4.3.tar.gz
Algorithm Hash digest
SHA256 1469bb66038ea1358e6801e877bf049967e44be0089720d5a25bb480d6770a6c
MD5 dcec24e4e35de7b52a776a413ad50ddc
BLAKE2b-256 6a7116ab7eafc49fbe719b27c19caa7f9854b63f826839f1e3f268dd36aee659

See more details on using hashes here.

File details

Details for the file sofort-0.4.3-py3-none-any.whl.

File metadata

File hashes

Hashes for sofort-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e787895e2f2338d42c59dedf0b71180ee36227eee59e72462df990e0d22a44a5
MD5 a77c4dc89c83708b770bf2280f49d2c3
BLAKE2b-256 8d85b51f32001315aed58dc7db71fc558b0c14b2f311f18292854f2981826910

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page