Skip to content

Commit 5b30f0f

Browse files
authored
fix: Correct and extend several docstring and some smaller implementation fixes (viur-framework#130)
1 parent 150cf61 commit 5b30f0f

24 files changed

Lines changed: 118 additions & 50 deletions

src/viur/shop/modules/address.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from viur.core.prototypes.skelmodule import DEFAULT_ORDER_TYPE
66
from viur.core.skeleton import SkeletonInstance
77
from .abstract import ShopModuleAbstract
8-
from .. import AddressSkel, SkeletonInstance_T
98
from ..globals import SHOP_LOGGER
9+
from ..skeletons import AddressSkel
10+
from ..types import SkeletonInstance_T
1011

1112
logger = SHOP_LOGGER.getChild(__name__)
1213

src/viur/shop/modules/order.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def can_order(
439439
return errors
440440

441441
def set_checkout_in_progress(self, order_skel: "SkeletonInstance") -> "SkeletonInstance":
442-
"""Set an order to the state _is_checkout_in_progress_"""
442+
"""Set an order to the state *is_checkout_in_progress*"""
443443
order_skel = toolkit.set_status(
444444
key=order_skel["key"],
445445
skel=order_skel,
@@ -450,7 +450,7 @@ def set_checkout_in_progress(self, order_skel: "SkeletonInstance") -> "SkeletonI
450450
return order_skel
451451

452452
def set_ordered(self, order_skel: "SkeletonInstance", payment: t.Any) -> "SkeletonInstance":
453-
"""Set an order to the state _ordered_"""
453+
"""Set an order to the state *ordered*"""
454454
order_skel = toolkit.set_status(
455455
key=order_skel["key"],
456456
skel=order_skel,
@@ -461,7 +461,7 @@ def set_ordered(self, order_skel: "SkeletonInstance", payment: t.Any) -> "Skelet
461461
return order_skel
462462

463463
def set_paid(self, order_skel: "SkeletonInstance") -> "SkeletonInstance":
464-
"""Set an order to the state _paid_"""
464+
"""Set an order to the state *paid*"""
465465
order_skel = toolkit.set_status(
466466
key=order_skel["key"],
467467
skel=order_skel,
@@ -472,7 +472,7 @@ def set_paid(self, order_skel: "SkeletonInstance") -> "SkeletonInstance":
472472
return order_skel
473473

474474
def set_rts(self, order_skel: "SkeletonInstance") -> "SkeletonInstance":
475-
"""Set an order to the state _Ready to ship_"""
475+
"""Set an order to the state *Ready to ship*"""
476476
order_skel = toolkit.set_status(
477477
key=order_skel["key"],
478478
skel=order_skel,

src/viur/shop/payment_providers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
try:
88
import unzer
99
except ImportError:
10-
# The unzer extras was not enabled, we don't import the related providers
10+
# The unzer extra was not enabled, we don't import the related providers
1111
...
1212
else:
1313
del unzer

src/viur/shop/payment_providers/abstract.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@
1818

1919

2020
class PaymentProviderAbstract(InstancedModule, Module, abc.ABC):
21+
"""
22+
Abstract base class for all payment providers in the ViUR Shop.
23+
24+
Provides a standardized interface for implementing different payment methods,
25+
including methods for checkout, charging, and handling payment states.
26+
27+
Subclasses must implement the required methods to integrate specific payment providers.
28+
"""
29+
2130
shop: "Shop" = None
31+
"""Reference to the main :class:`Shop` instance."""
2232

2333
def __init__(
2434
self,

src/viur/shop/payment_providers/amazon_pay.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111

1212
class AmazonPay(PaymentProviderAbstract):
13+
"""
14+
Amazon Pay integration for the ViUR Shop.
15+
16+
Handles the checkout process using Amazon Pay, including authorization and payment capture.
17+
Requires Amazon MWS credentials and configuration parameters.
18+
"""
1319
name: t.Final[str] = "amazonpay"
1420

1521
def __init__(
@@ -26,6 +32,18 @@ def __init__(
2632
language: str = "en",
2733
**kwargs: t.Any,
2834
) -> None:
35+
"""
36+
37+
:param mws_access_key: Amazon MWS access key.
38+
:param mws_secret_key: Amazon MWS secret key.
39+
:param merchant_id: Amazon merchant ID.
40+
:param client_id: Amazon client ID.
41+
:param client_secret: Amazon client secret.
42+
:param region: Region code (default: 'de').
43+
:param currency_code: Currency code (default: 'EUR').
44+
:param sandbox: Use sandbox environment (default: False).
45+
:param language: Language code (default: 'en').
46+
"""
2947
super().__init__(**kwargs)
3048
self.mws_access_key = mws_access_key
3149
self.mws_secret_key = mws_secret_key

src/viur/shop/payment_providers/invoice.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212

1313
class Invoice(PaymentProviderAbstract):
1414
"""
15-
Order is directly RTS, but not paid.
15+
Invoice payment method for the ViUR Shop.
1616
17-
The customer pays this order in the next x days, independent of shipping.
18-
But this will not be handled or checked here.
17+
Allows customers to place orders with the agreement to pay later via invoice.
18+
The order can be marked as ready to ship (RTS) immediately but is not considered paid.
19+
20+
Note:
21+
Payment processing (the customer pays this order in the next x days)
22+
and verification are handled externally and not within this module.
1923
"""
2024

2125
name: t.Final[str] = "invoice"

src/viur/shop/payment_providers/paypal_plus.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111

1212
class PayPalPlus(PaymentProviderAbstract):
13+
"""
14+
PayPal Plus integration for the ViUR Shop.
15+
16+
Supports multiple payment methods through PayPal Plus, including PayPal, credit card, and more.
17+
Handles the checkout process, payment state checks, and webhook handling for payment updates.
18+
"""
19+
1320
name: t.Final[str] = "paypal_plus"
1421

1522
def checkout(

src/viur/shop/payment_providers/prepayment.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@
1515

1616
class Prepayment(PaymentProviderAbstract):
1717
"""
18-
Order is RTS as soon as the customer has paid.
18+
Prepayment method for the ViUR Shop.
19+
20+
Allows customers to place orders with the agreement to pay in advance.
21+
The order is marked as ready to ship (RTS) once payment is received.
1922
2023
The customer pays this order in the next x days, shipping will wait.
21-
But this will not be handled or checked here.
24+
25+
Note:
26+
Payment receipt verification (The customer pays this order in the next x days,
27+
shipping will wait) is handled externally and not within this module.
2228
"""
29+
2330
name: t.Final[str] = "prepayment"
2431

2532
def checkout(

src/viur/shop/payment_providers/unzer_abstract.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class UnzerClientViURShop(unzer.UnzerClient):
2626
def _request(self, url, method, headers, payload, auth):
2727
# Extend with ViUR Logic:
2828
# Before the request is performed, we update the accept-language with
29-
# the language of the current request, except it's explicit set.
29+
# the language of the current request, unless it has been explicitly set.
3030
if self.language is None:
3131
# language for translation of customerMessage in errors
3232
headers["accept-language"] = current.language.get()
@@ -35,6 +35,12 @@ def _request(self, url, method, headers, payload, auth):
3535

3636

3737
class UnzerAbstract(PaymentProviderAbstract):
38+
"""
39+
Abstract base class for Unzer payment methods in the ViUR Shop.
40+
41+
Provides common functionality for Unzer-based payment providers,
42+
including API communication and payment type handling.
43+
"""
3844

3945
def __init__(
4046
self,
@@ -155,14 +161,18 @@ def can_order(
155161
def charge(self):
156162
raise errors.NotImplemented()
157163

158-
def get_order_by_pay_id(self, payment_id, public_key, *args, **kwargs):
164+
def get_order_by_pay_id(
165+
self,
166+
payment_id: str,
167+
public_key: str,
168+
*args, **kwargs
169+
) -> SkeletonInstance_T[OrderSkel] | None:
159170
"""Helper method to get the order skel for a payment-id.
160171
161172
:param payment_id: The payment id. (ex: s-pay-1).
162173
:param public_key: Public key of the key pair.
163174
164-
:return: The order-skel if the key seems to be valid. None otherwise.
165-
:rtype: OrderSkel | None
175+
:return: The order-skel if the key seems valid. None otherwise.
166176
"""
167177
logger.debug(f"get_order_by_pay_id({payment_id=} | {public_key=})")
168178

@@ -235,7 +245,7 @@ def webhook(self, *args, **kwargs):
235245
raise errors.BadRequest("Invalid payload")
236246
logger.info(f"Received request via webhook. {args=}, {kwargs=}")
237247
logger.info(f"{payload=}")
238-
logger.info(f"headers={current.request.get().request.headers!r}")
248+
logger.info(f"headers={dict(current.request.get().request.headers)!r}")
239249

240250
ip = current.request.get().request.remote_addr
241251
logger.info(f"{ip=}")

src/viur/shop/payment_providers/unzer_bancontact.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212

1313
class UnzerBancontact(UnzerAbstract):
14+
"""
15+
Unzer Bancontact payment method integration for the ViUR Shop.
16+
17+
Enables customers to pay using Bancontact through the Unzer payment gateway.
18+
"""
19+
1420
name: t.Final[str] = "unzer-bancontact"
1521

1622
def get_payment_type(

0 commit comments

Comments
 (0)