Skip to content

Commit

Permalink
Implement ApplicationFeeRefund model
Browse files Browse the repository at this point in the history
  • Loading branch information
jleclanche committed Jul 25, 2018
1 parent c23a93a commit d616a5e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
10 changes: 8 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ History
This includes ``date``, ``destination_type`` (``type``), ``failure_code``,
``failure_message``, ``statement_descriptor`` and ``status``.
- Fixed IntegrityError when ``REMOTE_ADDR`` is missing (#640).
- New models: ``BalanceTransaction``, ``CountrySpec``, ``SubscriptionItem``,
``TransferReversal``, ``UsageRecord``
- New models:
- ``ApplicationFee``
- ``ApplicationFeeRefund``
- ``BalanceTransaction``
- ``CountrySpec``
- ``SubscriptionItem``
- ``TransferReversal``
- ``UsageRecord``
- The ``fee`` and ``fee_details`` attributes of both the ``Charge`` and
``Transfer`` objects are no longer stored in the database. Instead, they
access their respective new ``balance_transaction`` foreign key.
Expand Down
20 changes: 20 additions & 0 deletions djstripe/migrations/0002_auto_20180627_1121.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,26 @@ class Migration(migrations.Migration):
"abstract": False,
},
),
migrations.CreateModel(
name="ApplicationFeeRefund",
fields=[
("djstripe_id", models.BigAutoField(primary_key=True, serialize=False, verbose_name="ID")),
("id", djstripe.fields.StripeIdField(max_length=255, unique=True)),
("livemode", models.NullBooleanField(default=None, help_text="Null here indicates that the livemode status is unknown or was previously unrecorded. Otherwise, this field indicates whether this record comes from Stripe test mode or live mode operation.")),
("created", djstripe.fields.StripeDateTimeField(blank=True, help_text="The datetime this object was created in stripe.", null=True)),
("metadata", djstripe.fields.JSONField(blank=True, help_text="A set of key/value pairs that you can attach to an object. It can be useful for storing additional information about an object in a structured format.", null=True)),
("djstripe_created", models.DateTimeField(auto_now_add=True)),
("djstripe_updated", models.DateTimeField(auto_now=True)),
("amount", djstripe.fields.StripeQuantumCurrencyAmountField(help_text="Amount refunded.")),
("currency", djstripe.fields.StripeCurrencyCodeField(help_text="Three-letter ISO currency code", max_length=3)),
("balance_transaction", models.ForeignKey(help_text="Balance transaction that describes the impact on your account balance.", on_delete=django.db.models.deletion.CASCADE, to="djstripe.BalanceTransaction")),
("fee", models.ForeignKey(help_text="The application fee that was refunded", on_delete=django.db.models.deletion.CASCADE, related_name="refunds", to="djstripe.ApplicationFee")),
],
options={
"get_latest_by": "created",
"abstract": False,
},
),
migrations.AddField(
model_name="charge",
name="balance_transaction",
Expand Down
25 changes: 24 additions & 1 deletion djstripe/models/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,30 @@ class ApplicationFee(StripeModel):
"Whether the fee has been fully refunded. If the fee is only "
"partially refunded, this attribute will still be false."
))
# TODO refunds (reverse from ApplicationFeeRefund)


class ApplicationFeeRefund(StripeModel):
"""
ApplicationFeeRefund objects allow you to refund an ApplicationFee that
has previously been created but not yet refunded.
Funds will be refunded to the Stripe account from which the fee was
originally collected.
Stripe documentation: https://stripe.com/docs/api#fee_refunds
"""
description = None

amount = StripeQuantumCurrencyAmountField(help_text="Amount refunded.")
balance_transaction = models.ForeignKey(
"BalanceTransaction", on_delete=models.CASCADE,
help_text="Balance transaction that describes the impact on your account balance."
)
currency = StripeCurrencyCodeField()
fee = models.ForeignKey(
"ApplicationFee", on_delete=models.CASCADE,
related_name="refunds",
help_text="The application fee that was refunded"
)


class CountrySpec(StripeModel):
Expand Down

0 comments on commit d616a5e

Please sign in to comment.