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