Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Improve docstrings and code styling

Marcin Gębalafd53c1c8096e
diff --git a/saleor/payment/__init__.py b/saleor/payment/__init__.py
index 91d10f0678..4efa6297c7 100644
--- a/saleor/payment/__init__.py
+++ b/saleor/payment/__init__.py
@@ -34,6 +34,8 @@ class OperationType(Enum):
class TransactionError(Enum):
+ """Represents a transaction error."""
+
INCORRECT_NUMBER = 'incorrect_number'
INVALID_NUMBER = 'invalid_number'
INCORRECT_CVV = 'incorrect_cvv'
@@ -47,16 +49,18 @@ class TransactionError(Enum):
class TransactionKind:
+ """Represents the type of a transaction.
+
+ The following transactions types are possible:
+ - AUTH - an amount reserved against the customer's funding source. Money
+ does not change hands until the authorization is captured.
+ - CHARGE - authorization and capture in a single step.
+ - VOID - a cancellation of a pending authorization or capture.
+ - CAPTURE - a transfer of the money that was reserved during the
+ authorization stage.
+ - REFUND - full or partial return of captured funds to the customer.
"""
- - Authorization: An amount reserved against the customer's funding
- source. Money does not change hands until the
- authorization is captured.
- - Charge: Authorization and capture in a single step.
- - Void: A cancellation of a pending authorization or capture.
- - Capture: A transfer of the money that was reserved during the
- authorization stage.
- - Refund: Full or partial return of captured funds to the customer.
- """
+
AUTH = 'auth'
CHARGE = 'charge'
CAPTURE = 'capture'
@@ -73,20 +77,18 @@ class TransactionKind:
class ChargeStatus:
+ """Represents possible statuses of a payment.
+
+ The following statuses are possible:
+ - CHARGED - funds were taken off the customer founding source,
+ partly or completely covering the payment amount.
+ - NOT_CHARGED - no funds were take off the customer founding source yet.
+ - FULLY_REFUNDED - all charged funds were returned to the customer.
"""
- - Charged: Funds were taken off the customer founding source, partly or
- completely covering the payment amount.
- - Not charged: No funds were take off the customer founding source yet.
- - Fully refunded: All charged funds were returned to the customer.
- """
+
CHARGED = 'charged'
NOT_CHARGED = 'not-charged'
FULLY_REFUNDED = 'fully-refunded'
- # FIXME
- # We could probably support other statuses, like:
- # partially refunded
- # fully charged
- # ...?
CHOICES = [
(CHARGED, pgettext_lazy('payment status', 'Charged')),
(NOT_CHARGED, pgettext_lazy('payment status', 'Not charged')),
diff --git a/saleor/payment/models.py b/saleor/payment/models.py
index b85a281b2b..579265dfe4 100644
--- a/saleor/payment/models.py
+++ b/saleor/payment/models.py
@@ -16,48 +16,28 @@ from ..order.models import Order
class Payment(models.Model):
- """Represents transactable payment information
- such as credit card details, gift card information or a customer's
- authorization to charge their PayPal account.
+ """A model that represents a single payment.
+
+ This might be a transactable payment information such as credit card
+ details, gift card information or a customer's authorization to charge
+ their PayPal account.
All payment process related pieces of information are stored
at the gateway level, we are operating on the reusable token
which is a unique identifier of the customer for given gateway.
- Several payment methods can be used within a single order.
+ Several payment methods can be used within a single order. Each payment
+ method may consist of multiple transactions.
"""
- # FIXME we should provide an option to store the card for later usage
- # FIXME probably we should have pending status for 3d secure
+
gateway = models.CharField(max_length=255)
is_active = models.BooleanField(default=True)
- #: Creation date and time
created = models.DateTimeField(auto_now_add=True)
- #: Date and time of last modification
modified = models.DateTimeField(auto_now=True)
charge_status = models.CharField(
- max_length=15,
- choices=ChargeStatus.CHOICES,
+ max_length=15, choices=ChargeStatus.CHOICES,
default=ChargeStatus.NOT_CHARGED)
-
- billing_first_name = models.CharField(max_length=256, blank=True)
- billing_last_name = models.CharField(max_length=256, blank=True)
- billing_company_name = models.CharField(max_length=256, blank=True)
- billing_address_1 = models.CharField(max_length=256, blank=True)
- billing_address_2 = models.CharField(max_length=256, blank=True)
- billing_city = models.CharField(max_length=256, blank=True)
- billing_city_area = models.CharField(max_length=128, blank=True)
- billing_postal_code = models.CharField(max_length=256, blank=True)
- billing_country_code = models.CharField(max_length=2, blank=True)
- billing_country_area = models.CharField(max_length=256, blank=True)
- billing_email = models.EmailField(blank=True)
- customer_ip_address = models.GenericIPAddressField(blank=True, null=True)
- extra_data = models.TextField(blank=True, default='')
token = models.CharField(max_length=128, blank=True, default='')
-
- #: Currency code (might be gateway-specific)
- # FIXME: add ISO4217 validator?
- currency = models.CharField(max_length=10)
- #: Total amount (gross)
total = models.DecimalField(
max_digits=settings.DEFAULT_MAX_DIGITS,
decimal_places=settings.DEFAULT_DECIMAL_PLACES,
@@ -66,23 +46,37 @@ class Payment(models.Model):
max_digits=settings.DEFAULT_MAX_DIGITS,
decimal_places=settings.DEFAULT_DECIMAL_PLACES,
default=Decimal('0.0'))
+ currency = models.CharField(max_length=10) # FIXME: add ISO4217 validator
checkout = models.ForeignKey(
Cart, null=True, related_name='payments', on_delete=models.SET_NULL)
order = models.ForeignKey(
Order, null=True, related_name='payments', on_delete=models.PROTECT)
- # Credit Card data, if applicable
+ billing_email = models.EmailField(blank=True)
+ billing_first_name = models.CharField(max_length=256, blank=True)
+ billing_last_name = models.CharField(max_length=256, blank=True)
+ billing_company_name = models.CharField(max_length=256, blank=True)
+ billing_address_1 = models.CharField(max_length=256, blank=True)
+ billing_address_2 = models.CharField(max_length=256, blank=True)
+ billing_city = models.CharField(max_length=256, blank=True)
+ billing_city_area = models.CharField(max_length=128, blank=True)
+ billing_postal_code = models.CharField(max_length=256, blank=True)
+ billing_country_code = models.CharField(max_length=2, blank=True)
+ billing_country_area = models.CharField(max_length=256, blank=True)
+
cc_first_digits = models.CharField(max_length=6, blank=True, default='')
cc_last_digits = models.CharField(max_length=4, blank=True, default='')
cc_brand = models.CharField(max_length=40, blank=True, default='')
cc_exp_month = models.PositiveIntegerField(
validators=[MinValueValidator(1), MaxValueValidator(12)],
null=True, blank=True)
- # exp year should be in 4 digits format
cc_exp_year = models.PositiveIntegerField(
validators=[MinValueValidator(1000)], null=True, blank=True)
+ customer_ip_address = models.GenericIPAddressField(blank=True, null=True)
+ extra_data = models.TextField(blank=True, default='')
+
class Meta:
ordering = ('pk', )
@@ -163,26 +157,23 @@ class Payment(models.Model):
class Transaction(models.Model):
- """Transaction represent attempts to transfer money between your store
+ """Represents a single payment operation.
+
+ Transaction is an attempt to transfer money between your store
and your customers, with a chosen payment method.
"""
+
created = models.DateTimeField(auto_now_add=True, editable=False)
payment = models.ForeignKey(
Payment, related_name='transactions', on_delete=models.PROTECT)
token = models.CharField(max_length=128, blank=True, default='')
kind = models.CharField(max_length=10, choices=TransactionKind.CHOICES)
- # FIXME probably we should have error/pending/success status instead of
- # a bool, eg for payments with 3d secure
is_success = models.BooleanField(default=False)
- #: Currency code (may be gateway-specific)
- # FIXME: ISO4217 validator?
currency = models.CharField(max_length=10)
- #: Total amount (gross)
amount = models.DecimalField(
max_digits=settings.DEFAULT_MAX_DIGITS,
decimal_places=settings.DEFAULT_DECIMAL_PLACES,
default=Decimal('0.0'))
- # Unified error code across all payment gateways
error = models.CharField(
choices=[(tag, tag.value) for tag in TransactionError],
max_length=256, null=True)