Skip to content

Commit

Permalink
Implement Source model and enums
Browse files Browse the repository at this point in the history
  • Loading branch information
jleclanche committed Jan 8, 2018
1 parent 7a17e4a commit 27cabe3
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
53 changes: 53 additions & 0 deletions djstripe/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,66 @@ class PlanInterval(Enum):
year = _("Year")


class SourceFlow(Enum):
redirect = _("Redirect")
receiver = _("Receiver")
code_verification = _("Code verification")
none = _("None")


class SourceStatus(Enum):
canceled = _("Canceled")
chargeable = _("Chargeable")
consumed = _("Consumed")
failed = _("Failed")
pending = _("Pending")


class SourceType(Enum):
card = _("Card")
three_d_secure = _("3D Secure")
alipay = _("Alipay")
ach_credit_transfer = _("ACH Credit Transfer")
bancontact = _("Bancontact")
bitcoin = _("Bitcoin")
giropay = _("Giropay")
ideal = _("iDEAL")
p24 = _("P24")
sepa_debit = _("SEPA Direct Debit")
sofort = _("SOFORT")


class LegacySourceType(Enum):
card = _("Card")
bank_account = _("Bank account")
bitcoin_receiver = _("Bitcoin receiver")
alipay_account = _("Alipay account")


class SourceUsage(Enum):
reusable = _("Reusable")
single_use = _("Single-use")


class SourceCodeVerificationStatus(Enum):
pending = _("Pending")
succeeded = _("Succeeded")
failed = _("Failed")


class SourceRedirectFailureReason(Enum):
user_abort = _("User-aborted")
declined = _("Declined")
processing_error = _("Processing error")


class SourceRedirectStatus(Enum):
pending = _("Pending")
succeeded = _("Succeeded")
not_required = _("Not required")
failed = _("Failed")


class SubscriptionStatus(Enum):
trialing = _("Trialing")
active = _("Active")
Expand Down
70 changes: 70 additions & 0 deletions djstripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,76 @@ def create_token(
StripeSource = Card


class Source(StripeObject):
amount = StripeCurrencyField(null=True, blank=True, help_text=(
"Amount associated with the source. "
"This is the amount for which the source will be chargeable once ready. "
"Required for `single_use` sources."
))
client_secret = StripeCharField(max_length=255, help_text=(
"The client secret of the source. "
"Used for client-side retrieval using a publishable key."
))
currency = StripeCharField(null=True, blank=True, max_length=3, help_text="Three-letter ISO currency code")
flow = StripeCharField(
max_length=17, choices=enums.SourceFlow.choices, help_text=(
"The authentication flow of the source."
)
)
owner = StripeJSONField(help_text=(
"Information about the owner of the payment instrument that may be "
"used or required by particular source types."
))
statement_descriptor = StripeCharField(
null=True, blank=True, max_length=255, help_text=(
"Extra information about a source. "
"This will appear on your customer’s statement every time you charge the source."
)
)
status = StripeCharField(
max_length=10, choices=enums.SourceStatus.choices, help_text=(
"The status of the source. Only `chargeable` sources can be used to create a charge."
)
)
type = StripeCharField(
max_length=19, choices=enums.SourceType.choices, help_text="The type of the source."
)
usage = StripeCharField(
max_length=10, choices=enums.SourceUsage.choices, help_text=(
"Whether this source should be reusable or not. "
"Some source types may or may not be reusable by construction, "
"while other may leave the option at creation."
)
)

# Flows
code_verification = StripeJSONField(
null=True, blank=True, stripe_required=False, help_text=(
"Information related to the code verification flow. "
"Present if the source is authenticated by a verification code (`flow` is `code_verification`)."
)
)
receiver = StripeJSONField(
null=True, blank=True, stripe_required=False, help_text=(
"Information related to the receiver flow. "
"Present if the source is a receiver (`flow` is `receiver`)."
)
)
redirect = StripeJSONField(
null=True, blank=True, stripe_required=False, help_text=(
"Information related to the redirect flow. "
"Present if the source is authenticated by a redirect (`flow` is `redirect`)."
)
)

customer = models.ForeignKey(
"Customer", on_delete=models.CASCADE, related_name="sources_v3"
)

stripe_class = stripe.Source
stripe_dashboard_item_name = "sources"


# ============================================================================ #
# Subscriptions #
# ============================================================================ #
Expand Down

0 comments on commit 27cabe3

Please sign in to comment.