Skip to content

Instantly share code, notes, and snippets.

@dhruvbaldawa
Created January 31, 2018 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhruvbaldawa/df47e103894673a60d4f0aba4b973117 to your computer and use it in GitHub Desktop.
Save dhruvbaldawa/df47e103894673a60d4f0aba4b973117 to your computer and use it in GitHub Desktop.
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