-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…#45) And do some more or less related fixes + refactorings
- Loading branch information
1 parent
d2cbf4b
commit 031d32d
Showing
16 changed files
with
146 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import typing as t | ||
|
||
from viur.core import errors, exposed, utils | ||
from viur.core.skeleton import SkeletonInstance | ||
|
||
from . import PaymentProviderAbstract | ||
from ..globals import SHOP_LOGGER | ||
from ..types.exceptions import IllegalOperationError | ||
|
||
logger = SHOP_LOGGER.getChild(__name__) | ||
|
||
|
||
class Invoice(PaymentProviderAbstract): | ||
""" | ||
Order is directly RTS, but not paid. | ||
The customer pays this order in the next x days, independent of shipping. | ||
But this will not be handled or checked here. | ||
""" | ||
|
||
name: t.Final[str] = "invoice" | ||
|
||
def checkout( | ||
self, | ||
order_skel: SkeletonInstance, | ||
) -> None: | ||
# TODO: Standardize this, write in txn | ||
order_skel["payment"].setdefault("payments", []).append({ | ||
"pp": self.name, | ||
"creationdate": utils.utcNow().isoformat(), | ||
}) | ||
order_skel.toDB() | ||
return None | ||
|
||
def charge(self) -> None: | ||
# An invoice cannot be charged, The user has to do this on his own | ||
raise IllegalOperationError("An invoice cannot be charged") | ||
|
||
def check_payment_state( | ||
self, | ||
order_skel: SkeletonInstance, | ||
) -> tuple[bool, t.Any]: | ||
# An invoice payment state cannot be checked without access to the target bank account | ||
# Use meth:`Order.set_paid` to mark an order by external events as paid. | ||
raise IllegalOperationError("The invoice payment_state cannot be checked by this PaymentProvider") | ||
|
||
@exposed | ||
def return_handler(self): | ||
raise errors.NotImplemented # TODO: We need a generalized solution for this | ||
|
||
@exposed | ||
def webhook(self): | ||
# Use meth:`Order.set_paid` to mark an order by external events as paid. | ||
raise errors.NotImplemented("An invoice has no webhook") # This NotImplemented is fully intentional | ||
|
||
@exposed | ||
def get_debug_information(self): | ||
raise errors.NotImplemented # TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,67 @@ | ||
import typing as t | ||
from viur.core import errors, exposed | ||
|
||
from deprecated.sphinx import deprecated | ||
from viur.core import errors, exposed, utils | ||
from viur.core.skeleton import SkeletonInstance | ||
|
||
from . import PaymentProviderAbstract | ||
from ..globals import SHOP_LOGGER | ||
from ..types.exceptions import IllegalOperationError | ||
|
||
logger = SHOP_LOGGER.getChild(__name__) | ||
|
||
|
||
class PrePayment(PaymentProviderAbstract): | ||
name = "prepayment" | ||
class Prepayment(PaymentProviderAbstract): | ||
""" | ||
Order is RTS as soon as the customer has paid. | ||
The customer pays this order in the next x days, shipping will wait. | ||
But this will not be handled or checked here. | ||
""" | ||
name: t.Final[str] = "prepayment" | ||
|
||
def checkout( | ||
self, | ||
order_skel: SkeletonInstance, | ||
) -> t.Any: | ||
raise errors.NotImplemented() | ||
# TODO: Standardize this, write in txn | ||
order_skel["payment"].setdefault("payments", []).append({ | ||
"pp": self.name, | ||
"creationdate": utils.utcNow().isoformat(), | ||
}) | ||
order_skel.toDB() | ||
return None | ||
|
||
def charge(self): | ||
raise errors.NotImplemented() | ||
def charge(self) -> None: | ||
# An invoice cannot be charged, The user has to do this on his own | ||
raise IllegalOperationError("A prepayment cannot be charged") | ||
|
||
def check_payment_state(self): | ||
raise errors.NotImplemented() | ||
def check_payment_state( | ||
self, | ||
order_skel: SkeletonInstance, | ||
) -> tuple[bool, t.Any]: | ||
# A prepayment payment state cannot be checked without access to the target bank account | ||
# Use meth:`Order.set_paid` to mark an order by external events as paid. | ||
raise IllegalOperationError("The invoice payment_state cannot be checked by this PaymentProvider") | ||
|
||
@exposed | ||
def return_handler(self): | ||
raise errors.NotImplemented() | ||
raise errors.NotImplemented # TODO: We need a generalized solution for this | ||
|
||
@exposed | ||
def webhook(self): | ||
raise errors.NotImplemented() | ||
# Use meth:`Order.set_paid` to mark an order by external events as paid. | ||
raise errors.NotImplemented("An invoice has no webhook") # This NotImplemented is fully intentional | ||
|
||
@exposed | ||
def get_debug_information(self): | ||
raise errors.NotImplemented() | ||
raise errors.NotImplemented # TODO | ||
|
||
|
||
@deprecated( | ||
reason="Class has been renamed, Use :class:`Prepayment`", | ||
version="0.1.0.dev24", | ||
action="always", | ||
) | ||
class PrePayment(Prepayment): | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters