sofizpay-python-sdk 1.1.0__tar.gz → 1.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/CHANGELOG.md +11 -0
- {sofizpay_python_sdk-1.1.0/sofizpay_python_sdk.egg-info → sofizpay_python_sdk-1.2.0}/PKG-INFO +23 -11
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/README.md +22 -10
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/pyproject.toml +1 -1
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/setup.py +1 -1
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay/__init__.py +7 -1
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay/client.py +42 -2
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0/sofizpay_python_sdk.egg-info}/PKG-INFO +23 -11
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/tests/test_basic.py +1 -1
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/LICENSE +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/MANIFEST.in +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/assets/sofizpay-logo.png +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/requirements-dev.txt +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/requirements.txt +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/setup.cfg +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay/exceptions.py +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay/payments.py +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay/transactions.py +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay/utils.py +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay_python_sdk.egg-info/SOURCES.txt +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay_python_sdk.egg-info/dependency_links.txt +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay_python_sdk.egg-info/not-zip-safe +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay_python_sdk.egg-info/requires.txt +0 -0
- {sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay_python_sdk.egg-info/top_level.txt +0 -0
|
@@ -9,6 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
## [1.2.0] - 2026-11-21
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- `SofizPayClient.verify_webhook_payload(payload, callback_url=None)` and module-level
|
|
16
|
+
`sofizpay.verify_webhook_payload`: verify the CIB webhook signature **and** that `payment_status`,
|
|
17
|
+
`amount` and `order_number` match the signed `message`. Use it before trusting those fields.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- `verify_signature` / `verify_webhook_signature` return `False` instead of raising when `message`
|
|
21
|
+
or `signature` is not a string.
|
|
22
|
+
|
|
12
23
|
## [1.0.2] - 2025-08-01
|
|
13
24
|
sd
|
|
14
25
|
|
{sofizpay_python_sdk-1.1.0/sofizpay_python_sdk.egg-info → sofizpay_python_sdk-1.2.0}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sofizpay-python-sdk
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: Professional Python SDK for SofizPay payments using Stellar blockchain
|
|
5
5
|
Home-page: https://github.com/SofizPay/sofizpay-python-sdk
|
|
6
6
|
Author: SofizPay Team
|
|
@@ -410,9 +410,19 @@ When a payment succeeds or fails, SofizPay delivers a server-to-server asynchron
|
|
|
410
410
|
}
|
|
411
411
|
```
|
|
412
412
|
|
|
413
|
-
### Verifying
|
|
413
|
+
### Verifying Webhooks (`verify_webhook_payload`)
|
|
414
414
|
|
|
415
|
-
Always verify the
|
|
415
|
+
Always verify the webhook before processing payments in your database.
|
|
416
|
+
|
|
417
|
+
> ⚠️ **Use `verify_webhook_payload`, not only `verify_webhook_signature`.** The RSA signature covers only the
|
|
418
|
+
> `message` string (`callback_url + payment_status + amount + order_number`). The top-level fields such as
|
|
419
|
+
> `payment_status`, `amount` and `order_number` are **not** signed by themselves. `verify_webhook_payload`
|
|
420
|
+
> checks the signature **and** that those fields match the signed `message`, so they can be trusted.
|
|
421
|
+
|
|
422
|
+
Recommended hardening:
|
|
423
|
+
- Pass `callback_url`, the URL prefix exactly as it appears at the start of `message` in a real webhook (including any trailing `/`), for an exact match.
|
|
424
|
+
- Check that `amount` equals the amount you stored for that order.
|
|
425
|
+
- Process each order only once (webhooks can be replayed).
|
|
416
426
|
|
|
417
427
|
```python
|
|
418
428
|
from fastapi import FastAPI, Request, HTTPException
|
|
@@ -425,14 +435,16 @@ client = SofizPayClient()
|
|
|
425
435
|
async def handle_cib_webhook(request: Request):
|
|
426
436
|
payload = await request.json()
|
|
427
437
|
|
|
428
|
-
# 1. Validate
|
|
429
|
-
|
|
430
|
-
|
|
438
|
+
# 1. Validate signature AND that payment_status / amount / order_number match the signed message
|
|
439
|
+
callback_url = "https://yourstore.com/api/cib-webhook/" # optional, recommended
|
|
440
|
+
if not client.verify_webhook_payload(payload, callback_url):
|
|
441
|
+
raise HTTPException(status_code=400, detail="Invalid webhook")
|
|
431
442
|
|
|
432
|
-
# 2. Process order upon confirmation
|
|
433
|
-
if payload
|
|
434
|
-
order_number = payload
|
|
435
|
-
amount_in_dzd = (payload
|
|
443
|
+
# 2. Process order upon confirmation (only the signed fields are used)
|
|
444
|
+
if payload["payment_status"] == "success":
|
|
445
|
+
order_number = payload["order_number"]
|
|
446
|
+
amount_in_dzd = int(payload["amount"]) / 100
|
|
447
|
+
# ✅ Also check payload["amount"] equals the amount stored for this order, and process each order once
|
|
436
448
|
|
|
437
449
|
# ✅ Mark order as PAID in your database:
|
|
438
450
|
# await db.orders.update({"order_id": order_number}, {"status": "PAID", "amount": amount_in_dzd})
|
|
@@ -522,5 +534,5 @@ All async methods return a dictionary with a `success` flag:
|
|
|
522
534
|
|
|
523
535
|
MIT © [SofizPay Team](https://github.com/kenandarabeh)
|
|
524
536
|
|
|
525
|
-
**Built with ❤️ for Python developers | Version `1.
|
|
537
|
+
**Built with ❤️ for Python developers | Version `1.2.0`**
|
|
526
538
|
|
|
@@ -358,9 +358,19 @@ When a payment succeeds or fails, SofizPay delivers a server-to-server asynchron
|
|
|
358
358
|
}
|
|
359
359
|
```
|
|
360
360
|
|
|
361
|
-
### Verifying
|
|
361
|
+
### Verifying Webhooks (`verify_webhook_payload`)
|
|
362
362
|
|
|
363
|
-
Always verify the
|
|
363
|
+
Always verify the webhook before processing payments in your database.
|
|
364
|
+
|
|
365
|
+
> ⚠️ **Use `verify_webhook_payload`, not only `verify_webhook_signature`.** The RSA signature covers only the
|
|
366
|
+
> `message` string (`callback_url + payment_status + amount + order_number`). The top-level fields such as
|
|
367
|
+
> `payment_status`, `amount` and `order_number` are **not** signed by themselves. `verify_webhook_payload`
|
|
368
|
+
> checks the signature **and** that those fields match the signed `message`, so they can be trusted.
|
|
369
|
+
|
|
370
|
+
Recommended hardening:
|
|
371
|
+
- Pass `callback_url`, the URL prefix exactly as it appears at the start of `message` in a real webhook (including any trailing `/`), for an exact match.
|
|
372
|
+
- Check that `amount` equals the amount you stored for that order.
|
|
373
|
+
- Process each order only once (webhooks can be replayed).
|
|
364
374
|
|
|
365
375
|
```python
|
|
366
376
|
from fastapi import FastAPI, Request, HTTPException
|
|
@@ -373,14 +383,16 @@ client = SofizPayClient()
|
|
|
373
383
|
async def handle_cib_webhook(request: Request):
|
|
374
384
|
payload = await request.json()
|
|
375
385
|
|
|
376
|
-
# 1. Validate
|
|
377
|
-
|
|
378
|
-
|
|
386
|
+
# 1. Validate signature AND that payment_status / amount / order_number match the signed message
|
|
387
|
+
callback_url = "https://yourstore.com/api/cib-webhook/" # optional, recommended
|
|
388
|
+
if not client.verify_webhook_payload(payload, callback_url):
|
|
389
|
+
raise HTTPException(status_code=400, detail="Invalid webhook")
|
|
379
390
|
|
|
380
|
-
# 2. Process order upon confirmation
|
|
381
|
-
if payload
|
|
382
|
-
order_number = payload
|
|
383
|
-
amount_in_dzd = (payload
|
|
391
|
+
# 2. Process order upon confirmation (only the signed fields are used)
|
|
392
|
+
if payload["payment_status"] == "success":
|
|
393
|
+
order_number = payload["order_number"]
|
|
394
|
+
amount_in_dzd = int(payload["amount"]) / 100
|
|
395
|
+
# ✅ Also check payload["amount"] equals the amount stored for this order, and process each order once
|
|
384
396
|
|
|
385
397
|
# ✅ Mark order as PAID in your database:
|
|
386
398
|
# await db.orders.update({"order_id": order_number}, {"status": "PAID", "amount": amount_in_dzd})
|
|
@@ -470,5 +482,5 @@ All async methods return a dictionary with a `success` flag:
|
|
|
470
482
|
|
|
471
483
|
MIT © [SofizPay Team](https://github.com/kenandarabeh)
|
|
472
484
|
|
|
473
|
-
**Built with ❤️ for Python developers | Version `1.
|
|
485
|
+
**Built with ❤️ for Python developers | Version `1.2.0`**
|
|
474
486
|
|
|
@@ -8,7 +8,7 @@ with open("requirements.txt", "r", encoding="utf-8") as fh:
|
|
|
8
8
|
|
|
9
9
|
setup(
|
|
10
10
|
name="sofizpay-python-sdk",
|
|
11
|
-
version = "1.
|
|
11
|
+
version = "1.2.0",
|
|
12
12
|
author="SofizPay Team",
|
|
13
13
|
author_email="support@sofizpay.com",
|
|
14
14
|
description="Professional Python SDK for SofizPay payments using Stellar blockchain",
|
|
@@ -16,7 +16,7 @@ from .exceptions import (
|
|
|
16
16
|
ValidationError
|
|
17
17
|
)
|
|
18
18
|
|
|
19
|
-
__version__ = "1.
|
|
19
|
+
__version__ = "1.2.0"
|
|
20
20
|
__author__ = "SofizPay Team"
|
|
21
21
|
__email__ = "support@sofizpay.com"
|
|
22
22
|
|
|
@@ -38,6 +38,7 @@ __all__ = [
|
|
|
38
38
|
"make_sandbox_cib_transaction",
|
|
39
39
|
"verify_signature",
|
|
40
40
|
"verify_webhook_signature",
|
|
41
|
+
"verify_webhook_payload",
|
|
41
42
|
"verify_sofizpay_signature"
|
|
42
43
|
]
|
|
43
44
|
|
|
@@ -61,6 +62,11 @@ def verify_webhook_signature(webhook_payload):
|
|
|
61
62
|
client = SofizPayClient()
|
|
62
63
|
return client.verify_webhook_signature(webhook_payload)
|
|
63
64
|
|
|
65
|
+
def verify_webhook_payload(webhook_payload, callback_url=None):
|
|
66
|
+
"""Convenience function: verify webhook signature AND that its fields match the signed message"""
|
|
67
|
+
client = SofizPayClient()
|
|
68
|
+
return client.verify_webhook_payload(webhook_payload, callback_url)
|
|
69
|
+
|
|
64
70
|
def verify_sofizpay_signature(verification_data):
|
|
65
71
|
"""Convenience function to verify SofizPay signature (backward-compatible)"""
|
|
66
72
|
client = SofizPayClient()
|
|
@@ -5,6 +5,7 @@ from datetime import datetime
|
|
|
5
5
|
from typing import Optional, Dict, Any, List, Callable
|
|
6
6
|
import requests
|
|
7
7
|
import base64
|
|
8
|
+
import hmac
|
|
8
9
|
from cryptography.hazmat.primitives import hashes, serialization
|
|
9
10
|
from cryptography.hazmat.primitives.asymmetric import padding
|
|
10
11
|
from cryptography.exceptions import InvalidSignature
|
|
@@ -373,7 +374,8 @@ THV3WRcKrP2krz3ruRGF6yP6PVHEuPc0YDLsYjV5uhfs7JtIksNKhRRAQ16bAsj/
|
|
|
373
374
|
message = verification_data.get('message', '')
|
|
374
375
|
sig = verification_data.get('signature_url_safe') or verification_data.get('signature', '')
|
|
375
376
|
|
|
376
|
-
|
|
377
|
+
# Webhook JSON may carry any type here (dict, int, None...); only non-empty strings are valid
|
|
378
|
+
if not isinstance(message, str) or not isinstance(sig, str) or not message or not sig:
|
|
377
379
|
return False
|
|
378
380
|
|
|
379
381
|
try:
|
|
@@ -580,7 +582,45 @@ THV3WRcKrP2krz3ruRGF6yP6PVHEuPc0YDLsYjV5uhfs7JtIksNKhRRAQ16bAsj/
|
|
|
580
582
|
True if signature is valid
|
|
581
583
|
"""
|
|
582
584
|
return self.verify_signature(webhook_payload)
|
|
583
|
-
|
|
585
|
+
|
|
586
|
+
def verify_webhook_payload(self, webhook_payload: Dict[str, Any], callback_url: Optional[str] = None) -> bool:
|
|
587
|
+
"""
|
|
588
|
+
Verify a CIB webhook end to end: the RSA signature over ``message`` AND that the
|
|
589
|
+
unsigned top-level fields (``payment_status``, ``amount``, ``order_number``) match
|
|
590
|
+
the signed message. Use this before trusting any of those fields.
|
|
591
|
+
|
|
592
|
+
The signed message is ``callback_url + payment_status + amount + order_number``.
|
|
593
|
+
|
|
594
|
+
Args:
|
|
595
|
+
webhook_payload: Parsed webhook JSON body
|
|
596
|
+
callback_url: Your webhook URL as registered with SofizPay; when given,
|
|
597
|
+
the message must match it exactly
|
|
598
|
+
|
|
599
|
+
Returns:
|
|
600
|
+
True only if the signature is valid and the fields are consistent
|
|
601
|
+
"""
|
|
602
|
+
if not isinstance(webhook_payload, dict) or not self.verify_webhook_signature(webhook_payload):
|
|
603
|
+
return False
|
|
604
|
+
|
|
605
|
+
def to_part(value: Any) -> Optional[str]:
|
|
606
|
+
if isinstance(value, str):
|
|
607
|
+
return value
|
|
608
|
+
if isinstance(value, int) and not isinstance(value, bool):
|
|
609
|
+
return str(value)
|
|
610
|
+
return None
|
|
611
|
+
|
|
612
|
+
status = to_part(webhook_payload.get('payment_status'))
|
|
613
|
+
amount = to_part(webhook_payload.get('amount'))
|
|
614
|
+
order_number = to_part(webhook_payload.get('order_number'))
|
|
615
|
+
if not status or not amount or not order_number:
|
|
616
|
+
return False
|
|
617
|
+
|
|
618
|
+
signed_fields = status + amount + order_number
|
|
619
|
+
message = webhook_payload['message']
|
|
620
|
+
if callback_url:
|
|
621
|
+
return hmac.compare_digest((callback_url + signed_fields).encode('utf-8'), message.encode('utf-8'))
|
|
622
|
+
return len(message) > len(signed_fields) and message.endswith(signed_fields)
|
|
623
|
+
|
|
584
624
|
def verify_sofizpay_signature(self, verification_data: Dict[str, str]) -> bool:
|
|
585
625
|
"""Backward-compatible alias for signature verification"""
|
|
586
626
|
return self.verify_signature(verification_data)
|
{sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0/sofizpay_python_sdk.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sofizpay-python-sdk
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: Professional Python SDK for SofizPay payments using Stellar blockchain
|
|
5
5
|
Home-page: https://github.com/SofizPay/sofizpay-python-sdk
|
|
6
6
|
Author: SofizPay Team
|
|
@@ -410,9 +410,19 @@ When a payment succeeds or fails, SofizPay delivers a server-to-server asynchron
|
|
|
410
410
|
}
|
|
411
411
|
```
|
|
412
412
|
|
|
413
|
-
### Verifying
|
|
413
|
+
### Verifying Webhooks (`verify_webhook_payload`)
|
|
414
414
|
|
|
415
|
-
Always verify the
|
|
415
|
+
Always verify the webhook before processing payments in your database.
|
|
416
|
+
|
|
417
|
+
> ⚠️ **Use `verify_webhook_payload`, not only `verify_webhook_signature`.** The RSA signature covers only the
|
|
418
|
+
> `message` string (`callback_url + payment_status + amount + order_number`). The top-level fields such as
|
|
419
|
+
> `payment_status`, `amount` and `order_number` are **not** signed by themselves. `verify_webhook_payload`
|
|
420
|
+
> checks the signature **and** that those fields match the signed `message`, so they can be trusted.
|
|
421
|
+
|
|
422
|
+
Recommended hardening:
|
|
423
|
+
- Pass `callback_url`, the URL prefix exactly as it appears at the start of `message` in a real webhook (including any trailing `/`), for an exact match.
|
|
424
|
+
- Check that `amount` equals the amount you stored for that order.
|
|
425
|
+
- Process each order only once (webhooks can be replayed).
|
|
416
426
|
|
|
417
427
|
```python
|
|
418
428
|
from fastapi import FastAPI, Request, HTTPException
|
|
@@ -425,14 +435,16 @@ client = SofizPayClient()
|
|
|
425
435
|
async def handle_cib_webhook(request: Request):
|
|
426
436
|
payload = await request.json()
|
|
427
437
|
|
|
428
|
-
# 1. Validate
|
|
429
|
-
|
|
430
|
-
|
|
438
|
+
# 1. Validate signature AND that payment_status / amount / order_number match the signed message
|
|
439
|
+
callback_url = "https://yourstore.com/api/cib-webhook/" # optional, recommended
|
|
440
|
+
if not client.verify_webhook_payload(payload, callback_url):
|
|
441
|
+
raise HTTPException(status_code=400, detail="Invalid webhook")
|
|
431
442
|
|
|
432
|
-
# 2. Process order upon confirmation
|
|
433
|
-
if payload
|
|
434
|
-
order_number = payload
|
|
435
|
-
amount_in_dzd = (payload
|
|
443
|
+
# 2. Process order upon confirmation (only the signed fields are used)
|
|
444
|
+
if payload["payment_status"] == "success":
|
|
445
|
+
order_number = payload["order_number"]
|
|
446
|
+
amount_in_dzd = int(payload["amount"]) / 100
|
|
447
|
+
# ✅ Also check payload["amount"] equals the amount stored for this order, and process each order once
|
|
436
448
|
|
|
437
449
|
# ✅ Mark order as PAID in your database:
|
|
438
450
|
# await db.orders.update({"order_id": order_number}, {"status": "PAID", "amount": amount_in_dzd})
|
|
@@ -522,5 +534,5 @@ All async methods return a dictionary with a `success` flag:
|
|
|
522
534
|
|
|
523
535
|
MIT © [SofizPay Team](https://github.com/kenandarabeh)
|
|
524
536
|
|
|
525
|
-
**Built with ❤️ for Python developers | Version `1.
|
|
537
|
+
**Built with ❤️ for Python developers | Version `1.2.0`**
|
|
526
538
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay_python_sdk.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay_python_sdk.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay_python_sdk.egg-info/requires.txt
RENAMED
|
File without changes
|
{sofizpay_python_sdk-1.1.0 → sofizpay_python_sdk-1.2.0}/sofizpay_python_sdk.egg-info/top_level.txt
RENAMED
|
File without changes
|