软API
sofort的Python项目详细描述
在您的应用程序中构建砖块以简化Sofort付款。
这个图书馆仍处于艰难的发展中,因此当有疑问时,请检查原件 出口Reference。
安装
$ pip install git+https://github.com/spreecode/python-sofort.git
用法
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)
当支付被处理时,客户端将被重定向到success_url,并且 sofort服务器将尽快向notification_urls发送post请求 交易状态将更改。您可以在中使用sofort.TRANSACTION_ID。 url参数,因此通知url可以如下:
'http://mysite.de/notify.php?trn=' + sofort.TRANSACTION_ID
它将被替换为
http://mysite.de/notify.php?trn=123456-321321-56A29EC6-066A
所以您可以捕获事务id并检查它的状态(所有响应都是 用Schematics模型包装)
>>> 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}
测试
$ pip install -e '.[test]' # to obtain mock library $ python setup.py test
小心,事务ID包含一些敏感数据
123456-321321-56A29EC6-066A ^^^^^^ ^^^^^^ | | User ID | Project ID
当然,客户可以在付款页面看到这些数据, 没有api密钥几乎没用。不过,我还是觉得把东西藏起来是不好的。 回购中的交易ID。