Skip to content

Instantly share code, notes, and snippets.

@nickhargreaves
Last active June 4, 2018 17:10
Show Gist options
  • Save nickhargreaves/24f14478c4277680476af0b9e4be93e6 to your computer and use it in GitHub Desktop.
Save nickhargreaves/24f14478c4277680476af0b9e4be93e6 to your computer and use it in GitHub Desktop.
class SpaceShip(models.Model):
# Sample merchant product
model = models.CharField(max_length=255, blank=False, null=False)
price = models.DecimalField(max_digits=99, decimal_places=2)
currency = models.CharField(max_length=55, default='KES', blank=False, null=False)
def __str__(self):
return self.model
class Payment(models.Model):
"""
This is model to hold payment information. There's an on create signal to handle the actual payment process
via the provider's API
"""
NEW = 'new'
REQUEST_SENT = 'request_sent'
SUCCESS = 'success'
FAILED = 'failed'
PAYMENT_STATUSES = ((NEW, 'new'), (REQUEST_SENT, 'request_sent'), (SUCCESS, 'success'), (FAILED, 'failed'))
phone_number = models.CharField(max_length=50, blank=False, null=False)
# item is tied to the merchant product. In a real scenario this should support different types of items
item = models.ForeignKey(SpaceShip, blank=False, null=False, on_delete=models.DO_NOTHING)
status = models.CharField(max_length=20, choices=PAYMENT_STATUSES, default=NEW)
# request_response is a simple way to log our API responses when a payment is made
request_response = models.TextField(null=True, blank=True)
# remote_id will store the reference from the payment provider
remote_id = models.CharField(max_length=255, blank=True, null=True)
def __str__(self):
return str(self.item) + ' ' + str(self.phone_number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment