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