Created
January 31, 2018 05:53
-
-
Save dhruvbaldawa/df47e103894673a60d4f0aba4b973117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Payment(models.Model): | |
is_started = models.BooleanField(default=True) | |
is_captured = models.BooleanField(default=False) | |
is_completed = models.BooleanField(default=False) | |
def can_capture(self): | |
return self.is_started and not self.is_captured and not self.is_completed | |
def can_complete(self): | |
return self.is_captured | |
def contact_payment_gateway(self): | |
""" does payment gateway magic """ | |
def notify_user(self): | |
""" notifies the user that their payment is complete """ | |
def capture(self): | |
if self.can_capture(): | |
self.contact_payment_gateway() | |
self.is_captured = True | |
self.save() | |
else: | |
raise ValueError() | |
def complete(self): | |
if self.can_complete(): | |
self.is_completed = True | |
self.save() | |
self.notify_user() | |
else: | |
raise ValueError() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment