Skip to content

Commit

Permalink
Sign properly complex data (#2)
Browse files Browse the repository at this point in the history
* Sign properly complex data

Compose message from input data for signing accounting for nested
sequences and mappings.

* fixup - Correction from code review

* fixup - Fix typo

* fixup - Fix typo in docstring

* fixup - Code review (round 2)

* fixup - Add docs comment to enums

* fixup - Unnecessary trimming

* fixup - strip after trimming

* Correction from review - round 3

* fixup - Corrections from review (round 4)

* fixup - Change date/time related fields

* fixup - Custom formatting should have higher priority

* fixup - Add docstrings

* Improve type annotations

* Use all amounts always as integers

* fixup - README and type annotation

* fixup - Add enumerations

* Remove Python 3.8
  • Loading branch information
oto-stefan authored Jul 3, 2024
1 parent 74cc197 commit e628816
Show file tree
Hide file tree
Showing 6 changed files with 665 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.9, 3.10, 3.11]

steps:
- uses: actions/checkout@v2
Expand Down
42 changes: 42 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,48 @@ You can check payment status.
#[Out]# ('authCode', '042760'),
#[Out]# ('dttime', datetime.datetime(2016, 6, 15, 10, 45, 1))])
Structured data (i.e. ``cart``, ``customer`` and ``order``) are passed to ``payment_init`` as dataclasses, for some items
appropriate enumerations are available.

.. code-block:: python
tz = ZoneInfo("Europe/Prague")
data = {
"pay_operation": PayOperation.PAYMENT,
"pay_method": PayMethod.CARD,
"currency": Currency.CZK,
"close_payment": True,
"return_method": ReturnMethod.POST,
"cart": [
CartItem(name="Wireless sluchátka", quantity=2, amount=123400),
CartItem(name="Doprava", quantity=1, amount=0, description="DPL"),
],
"customer": Customer(
name="Jan Novák",
email="[email protected]",
mobile_phone="+420800-300-300",
account=CustomerAccount(created_at=datetime(2022, 1, 12, 12, 10, 37, tzinfo=tz),
changed_at=datetime(2022, 1, 15, 15, 10, 12, tzinfo=tz)),
login=CustomerLogin(auth=CustomerLoginType.ACCOUNT, auth_at=datetime(2022, 6, 25, 13, 10, 3, tzinfo=tz)),
),
"order": Order(
type=OrderType.PURCHASE,
availability=OrderAvailability.NOW,
delivery=OrderDelivery.SHIPPING,
delivery_mode=OrderDeliveryMode.SAME_DAY,
address_match=True,
billing=OrderAddress(
address_1="Karlova 1",
city="Praha",
zip="11000",
country="CZE",
),
),
"language": Language.CZECH,
}
r = c.payment_init(16, 123400, "http://twisto.dev/", "Testovací nákup", **data)
Custom payments are initialized with ``c.payment_init(pay_operation='customPayment')``, you can optionally set
payment validity by ``custom_expiry='YYYYMMDDhhmmss'``.

Expand Down
Loading

0 comments on commit e628816

Please sign in to comment.