transaction_id should be unique in class
transaction_id is used to find the payment response for one transaction, this id should be unique in all the payments. For example,
if PaymentProcessorResponse.objects.filter(transaction_id=transaction_id).exists(): raise RedundantPaymentNotificationError
We can add
unique = True to ensure the data’s integrity in the first place.
class PaymentProcessorResponse(models.Model): """ Auditing model used to save all responses received from payment processors, which includes payments and refunds. """ processor_name = models.CharField(max_length=255, verbose_name=_('Payment Processor')) transaction_id = models.CharField(max_length=255, verbose_name=_('Transaction ID'), null=True, blank=True)
coupon field should be unique in the CouponVouchers. Each coupon_product should have one CouponVouchers object, otherwise, it may cause exceptions in usage like
get_or_create. We can add a
unique=True for this field to ensure data integrity.
class CouponVouchers(models.Model): ... coupon = models.ForeignKey('catalogue.Product', related_name='coupon_vouchers', on_delete=models.CASCADE)