|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 |
| -import enum |
4 | 3 | import json
|
5 | 4 | from typing import Iterable
|
6 | 5 | from uuid import uuid4
|
|
13 | 12 | from . import FraudStatus
|
14 | 13 | from . import PaymentStatus
|
15 | 14 | from . import PurchasedItem
|
| 15 | +from . import WalletStatus |
16 | 16 | from .core import provider_factory
|
17 | 17 |
|
18 | 18 |
|
@@ -40,58 +40,29 @@ def __setattr__(self, key, value):
|
40 | 40 | return None
|
41 | 41 |
|
42 | 42 |
|
43 |
| -class BaseSubscription(models.Model): |
| 43 | +class BaseWallet(models.Model): |
44 | 44 | token = models.CharField(
|
45 |
| - _("subscription token/id"), |
46 |
| - help_text=_("Token/id used to identify subscription by provider"), |
| 45 | + _("wallet token/id"), |
| 46 | + help_text=_("Token/id used to identify wallet by provider"), |
47 | 47 | max_length=255,
|
48 | 48 | default=None,
|
49 | 49 | null=True,
|
50 | 50 | blank=True,
|
51 | 51 | )
|
52 |
| - payment_provider = models.CharField( |
53 |
| - _("payment provider"), |
54 |
| - help_text=_("Provider variant, that will be used for payment renewal"), |
55 |
| - max_length=255, |
56 |
| - default=None, |
57 |
| - null=True, |
58 |
| - blank=True, |
| 52 | + status = models.CharField( |
| 53 | + max_length=10, choices=WalletStatus.CHOICES, default=WalletStatus.PENDING |
59 | 54 | )
|
60 |
| - subscribtion_data = models.JSONField( |
61 |
| - _("subscription data"), |
62 |
| - help_text=_("Provider-specific data associated with subscription"), |
| 55 | + extra_data = models.JSONField( |
| 56 | + _("extra data"), |
| 57 | + help_text=_("Provider-specific data associated with wallet"), |
63 | 58 | default=dict,
|
64 | 59 | )
|
65 | 60 |
|
66 |
| - class TimeUnit(enum.Enum): |
67 |
| - year = "year" |
68 |
| - month = "month" |
69 |
| - day = "day" |
70 |
| - |
71 |
| - def set_recurrence(self, token: str, **kwargs): |
72 |
| - """ |
73 |
| - Sets token and other values associated with subscription recurrence |
74 |
| - Kwargs can contain provider-specific values |
75 |
| - """ |
76 |
| - self.token = token |
77 |
| - self.subscribtion_data = kwargs |
78 |
| - |
79 |
| - def get_period(self) -> int: |
80 |
| - raise NotImplementedError |
81 |
| - |
82 |
| - def get_unit(self) -> TimeUnit: |
83 |
| - raise NotImplementedError |
84 |
| - |
85 |
| - def cancel(self): |
| 61 | + def payment_completed(self, payment): |
86 | 62 | """
|
87 |
| - Cancel the subscription by provider |
88 |
| - Used by providers, that use provider initiated subscription workflow |
89 |
| - Implementer is responsible for cancelling the subscription model |
90 |
| -
|
91 |
| - Raises PaymentError if the cancellation didn't pass through |
| 63 | + Concrete implementation specific logic called whenever a payment is completed |
| 64 | + using this wallet. |
92 | 65 | """
|
93 |
| - provider = provider_factory(self.variant) |
94 |
| - provider.cancel_subscription(self) |
95 | 66 |
|
96 | 67 | class Meta:
|
97 | 68 | abstract = True
|
@@ -251,30 +222,18 @@ def get_payment_url(self) -> str:
|
251 | 222 | """
|
252 | 223 | raise NotImplementedError
|
253 | 224 |
|
254 |
| - def get_subscription(self) -> BaseSubscription | None: |
255 |
| - """ |
256 |
| - Returns subscription object associated with this payment |
257 |
| - or None if the payment is not recurring |
258 |
| - """ |
259 |
| - return None |
260 |
| - |
261 |
| - def is_recurring(self) -> bool: |
262 |
| - return self.get_subscription() is not None |
263 |
| - |
264 |
| - def autocomplete_with_subscription(self): |
| 225 | + def autocomplete_with_wallet(self): |
265 | 226 | """
|
266 |
| - Complete the payment with subscription |
| 227 | + Complete the payment with wallet |
267 | 228 |
|
268 | 229 | If the provider uses workflow such that the payments are initiated from
|
269 | 230 | implementer's side.
|
270 |
| - Call this function right before the subscription end to |
271 |
| - make a new subscription payment. |
272 | 231 |
|
273 | 232 | Throws RedirectNeeded if there is problem with the payment
|
274 | 233 | that needs to be solved by user
|
275 | 234 | """
|
276 | 235 | provider = provider_factory(self.variant)
|
277 |
| - provider.autocomplete_with_subscription(self) |
| 236 | + provider.autocomplete_with_wallet(self) |
278 | 237 |
|
279 | 238 | def capture(self, amount=None):
|
280 | 239 | """Capture a pre-authorized payment.
|
|
0 commit comments