Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pydanny/dj-stripe.git
Browse files Browse the repository at this point in the history
Conflicts:
	AUTHORS.rst
  • Loading branch information
kavdev committed May 2, 2015
2 parents a2c19a7 + 46c703e commit b432540
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 4 deletions.
4 changes: 2 additions & 2 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Contributors
* Thomas Parslow (@almost)
* Leonid Shvechikov (@shvechikov)
* sromero84
* Mahdi Yusuf (@myusuf3)
* Peter Baumgartner (@ipmb)
* Vikas (@vikasgulati)
* Colton Allen (@cmanallen)
* Filip Wasilewski (@nigma)
* Martin Hill (@martinhill)
* Michael Thornhill <[email protected]>
* Tobias Lorenz (@Tyrdall)
* Ben Whalley
* Ben Whalley
* nanvel
4 changes: 3 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
History
=======

0.5.0 (2015-04-??)
0.5.0 (2015-05-??)
---------------------

* Removed the StripeSubscriptionSignupForm
Expand All @@ -12,6 +12,8 @@ History
* The sync_subscriber argument has been renamed from subscriber_model to subscriber
* Moved available currencies to the DJSTRIPE_CURRENCIES setting (Thanks @martinhill)
* Allow passing of extra parameters to stripe Charge API (Thanks @mthornhill)
* charge.refund() now returns the refunded charge object (Thanks @mthornhill)
* Charge model now has captured field and a capture method (Thanks @mthornhill)
* South migrations are now up to date (Thanks @Tyrdall)

0.4.0 (2015-04-05)
Expand Down
20 changes: 20 additions & 0 deletions djstripe/migrations/0005_charge_captured.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('djstripe', '0004_auto_20150427_1609'),
]

operations = [
migrations.AddField(
model_name='charge',
name='captured',
field=models.NullBooleanField(),
preserve_default=True,
),
]
15 changes: 14 additions & 1 deletion djstripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ class Charge(StripeObject):
paid = models.NullBooleanField(null=True)
disputed = models.NullBooleanField(null=True)
refunded = models.NullBooleanField(null=True)
captured = models.NullBooleanField(null=True)
fee = models.DecimalField(decimal_places=2, max_digits=7, null=True)
receipt_sent = models.BooleanField(default=False)
charge_created = models.DateTimeField(null=True, blank=True)
Expand All @@ -847,7 +848,18 @@ def refund(self, amount=None):
).refund(
amount=self.calculate_refund_amount(amount=amount)
)
Charge.sync_from_stripe_data(charge_obj)
return Charge.sync_from_stripe_data(charge_obj)

def capture(self):
"""
Capture the payment of an existing, uncaptured, charge. This is the second half of the two-step payment flow,
where first you created a charge with the capture option set to false.
See https://stripe.com/docs/api#capture_charge
"""
charge_obj = stripe.Charge.retrieve(
self.stripe_id
).capture()
return Charge.sync_from_stripe_data(charge_obj)

@classmethod
def sync_from_stripe_data(cls, data):
Expand All @@ -862,6 +874,7 @@ def sync_from_stripe_data(cls, data):
obj.amount = (data["amount"] / decimal.Decimal("100"))
obj.paid = data["paid"]
obj.refunded = data["refunded"]
obj.captured = data["captured"]
obj.fee = (data["fee"] / decimal.Decimal("100"))
obj.disputed = data["dispute"] is not None
obj.charge_created = convert_tstamp(data, "created")
Expand Down
222 changes: 222 additions & 0 deletions djstripe/south_migrations/0007_auto__add_field_charge_captured.py

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions tests/test_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_record_charge(self, RetrieveMock):
"amount": 1000,
"paid": True,
"refunded": False,
"captured": True,
"fee": 499,
"dispute": None,
"created": 1363911708,
Expand Down Expand Up @@ -100,6 +101,7 @@ def test_refund_charge(self, RetrieveMock):
"amount": 1000,
"paid": True,
"refunded": True,
"captured": True,
"amount_refunded": 1000,
"fee": 499,
"dispute": None,
Expand All @@ -111,6 +113,72 @@ def test_refund_charge(self, RetrieveMock):
self.assertEquals(charge2.refunded, True)
self.assertEquals(charge2.amount_refunded, decimal.Decimal("10.00"))

@patch("stripe.Charge.retrieve")
def test_capture_charge(self, RetrieveMock):
charge = Charge.objects.create(
stripe_id="ch_XXXXXX",
customer=self.customer,
card_last_4="4323",
card_kind="Visa",
amount=decimal.Decimal("10.00"),
paid=True,
refunded=False,
captured=False,
fee=decimal.Decimal("4.99"),
disputed=False
)
RetrieveMock.return_value.capture.return_value = {
"id": "ch_XXXXXX",
"card": {
"last4": "4323",
"type": "Visa"
},
"amount": 1000,
"paid": True,
"refunded": True,
"captured": True,
"amount_refunded": 1000,
"fee": 499,
"dispute": None,
"created": 1363911708,
"customer": "cus_xxxxxxxxxxxxxxx"
}
charge2 = charge.capture()
self.assertEquals(charge2.captured, True)

@patch("stripe.Charge.retrieve")
def test_refund_charge_object_returned(self, RetrieveMock):
charge = Charge.objects.create(
stripe_id="ch_XXXXXX",
customer=self.customer,
card_last_4="4323",
card_kind="Visa",
amount=decimal.Decimal("10.00"),
paid=True,
refunded=False,
fee=decimal.Decimal("4.99"),
disputed=False
)
RetrieveMock.return_value.refund.return_value = {
"id": "ch_XXXXXX",
"card": {
"last4": "4323",
"type": "Visa"
},
"amount": 1000,
"paid": True,
"refunded": True,
"captured": True,
"amount_refunded": 1000,
"fee": 499,
"dispute": None,
"created": 1363911708,
"customer": "cus_xxxxxxxxxxxxxxx"
}
charge2 = charge.refund()
self.assertEquals(charge2.refunded, True)
self.assertEquals(charge2.amount_refunded, decimal.Decimal("10.00"))

def test_calculate_refund_amount_full_refund(self):
charge = Charge(
stripe_id="ch_111111",
Expand Down Expand Up @@ -157,6 +225,7 @@ def test_charge_converts_dollars_into_cents(self, ChargeMock, RetrieveMock):
"amount": 1000,
"paid": True,
"refunded": False,
"captured": True,
"fee": 499,
"dispute": None,
"created": 1363911708,
Expand All @@ -181,6 +250,7 @@ def test_charge_passes_extra_arguments(self, ChargeMock, RetrieveMock):
"amount": 1000,
"paid": True,
"refunded": False,
"captured": True,
"fee": 499,
"dispute": None,
"created": 1363911708,
Expand Down
1 change: 1 addition & 0 deletions tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_email_reciept_renders_amount_properly(self, ChargeMock, RetrieveMock):
"amount": 40000,
"paid": True,
"refunded": False,
"captured": True,
"fee": 499,
"dispute": None,
"created": 1363911708,
Expand Down

0 comments on commit b432540

Please sign in to comment.