Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added payment id override #37

Merged
merged 6 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pypayment/lava.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class LavaPayment(Payment):
def __init__(self,
amount: float,
description: str = "",
id: Optional[str] = None,
wallet_to: Optional[str] = None,
expiration_duration: Optional[timedelta] = None,
charge_commission: Optional[ChargeCommission] = None,
Expand All @@ -45,6 +46,7 @@ def __init__(self,

:param amount: The amount to be invoiced.
:param description: Payment comment.
:param id: Unique Payment ID (default: generated with uuid4).
:param wallet_to: Account number to which the funds will be credited. (e.x. R40510054)
:param expiration_duration: The time that the invoice will be available for payment.
:param charge_commission: ChargeCommission enum.
Expand All @@ -63,7 +65,7 @@ def __init__(self,
self._success_url = LavaPayment._success_url if success_url is None else success_url
self._fail_url = LavaPayment._fail_url if fail_url is None else fail_url

super().__init__(amount, description)
super().__init__(amount, description, id)

self._url = self._create()

Expand Down
6 changes: 3 additions & 3 deletions pypayment/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
class Payment(ABC):
"""Payment interface than allows to create and check invoices."""

def __init__(self, amount: float, description: str = ""):
def __init__(self, amount: float, description: str = "", id: Optional[str] = None):
self.amount = amount
"""The amount to be invoiced."""
self.description = description
"""Payment comment."""
self.id = str(uuid4())
"""Unique Payment ID (generated with uuid4)."""
self.id = id if id is not None else str(uuid4())
"""Unique Payment ID (default: generated with uuid4)."""

@property
@abstractmethod
Expand Down
5 changes: 4 additions & 1 deletion pypayment/payok.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class PayOkPayment(Payment):
def __init__(self,
amount: float,
description: str = "",
id: Optional[str] = None,
payment_type: Optional[PayOkPaymentType] = None,
currency: Optional[PayOkCurrency] = None,
success_url: Optional[str] = None):
Expand All @@ -97,6 +98,8 @@ def __init__(self,
Passed parameters will be applied to instance, but won't override default ones.

:param amount: The amount to be invoiced.
:param description: Payment comment.
:param id: Unique Payment ID (default: generated with uuid4).
:param payment_type: PayOkPaymentType enum.
:param currency: PayOkCurrency enum.
:param success_url: User will be redirected to this url after paying.
Expand All @@ -111,7 +114,7 @@ def __init__(self,
self._currency = PayOkPayment._currency if currency is None else currency
self._success_url = PayOkPayment._success_url if success_url is None else success_url

super().__init__(amount, description)
super().__init__(amount, description, id)
self.id: str = str(self.id[:16])
if not description:
self.description = self.id
Expand Down
4 changes: 3 additions & 1 deletion pypayment/qiwi.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class QiwiPayment(Payment):
def __init__(self,
amount: float,
description: str = "",
id: Optional[str] = None,
theme_code: Optional[str] = None,
expiration_duration: Optional[timedelta] = None,
payment_type: Optional[QiwiPaymentType] = None):
Expand All @@ -51,6 +52,7 @@ def __init__(self,

:param amount: The amount to be invoiced.
:param description: Payment comment.
:param id: Unique Payment ID (default: generated with uuid4).
:param theme_code: Theme code from https://qiwi.com/p2p-admin/transfers/link
:param expiration_duration: Time that the invoice will be available for payment.
:param payment_type: QiwiPaymentType enum.
Expand All @@ -65,7 +67,7 @@ def __init__(self,
self._expiration_duration = QiwiPayment._expiration_duration if expiration_duration is None else expiration_duration
self._payment_type = QiwiPayment._payment_type if payment_type is None else payment_type

super().__init__(amount, description)
super().__init__(amount, description, id)

self._url = self._create()

Expand Down
5 changes: 4 additions & 1 deletion pypayment/yoomoney.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class YooMoneyPayment(Payment):
def __init__(self,
amount: float,
description: str = "",
id: Optional[str] = None,
payment_type: Optional[YooMoneyPaymentType] = None,
charge_commission: Optional[ChargeCommission] = None,
success_url: Optional[str] = None):
Expand All @@ -55,6 +56,8 @@ def __init__(self,
Passed parameters will be applied to instance, but won't override default ones.

:param amount: The amount to be invoiced.
:param description: Payment comment.
:param id: Unique Payment ID (default: generated with uuid4).
:param payment_type: YooMoneyPaymentType enum.
:param success_url: User will be redirected to this url after paying.

Expand All @@ -68,7 +71,7 @@ def __init__(self,
self._charge_commission = YooMoneyPayment._charge_commission if charge_commission is None else charge_commission
self._success_url = YooMoneyPayment._success_url if success_url is None else success_url

super().__init__(amount, description)
super().__init__(amount, description, id)

self._url = self._create()

Expand Down