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