Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Add support for showing the donation type in Authorize #26

Merged
merged 1 commit into from Jul 18, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion armstrong/apps/donations/backends.py
Expand Up @@ -127,9 +127,13 @@ def onetime_purchase(self, donation, form):
api = self.get_api()
data = form.get_data_for_charge(donation)
donor = donation.donor
if donation.donation_type:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a potential attribute error here? I feel like we saw that before – not sure if it's worth being more defensive by using hasattr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's equal to None it looks like if it's not set.

description = u"Membership: %s" % donation.donation_type.name
else:
description = u"Donation: $%d" % donation.amount
data.update({
"amount": donation.amount,
"description": u"Donation: $%d" % donation.amount,
"description": description,
"first_name": unicode(donor.first_name),
"last_name": unicode(donor.last_name),

Expand Down
28 changes: 28 additions & 0 deletions armstrong/apps/donations/tests/backends.py
Expand Up @@ -233,6 +233,34 @@ def test_dispatches_to_authorize_to_create_transaction(self):
backend.purchase(donation, donation_form)
fudge.verify()

def test_includes_donation_type_if_provided_for_transaction(self):
donation, donation_form = self.random_donation_and_form
donation.donation_type = self.random_monthly_type

api = fudge.Fake("api")
api.expects("transaction").with_args(
amount=donation.amount,
card_num=donation_form.cleaned_data["card_number"],
card_code=donation_form.cleaned_data["ccv_code"],
exp_date=u"%02d-%04d" % (
int(donation_form.cleaned_data["expiration_month"]),
int(donation_form.cleaned_data["expiration_year"])),
description=u"Membership: %s" % donation.donation_type.name,
first_name=unicode(donation.donor.first_name),
last_name=unicode(donation.donor.last_name),
address=donation.donor.address.address,
city=donation.donor.address.city,
state=donation.donor.address.state,
zip=donation.donor.address.zipcode,
).returns({"reason_code": u"1", "reason_text": u"Some random Reason"})
get_api = fudge.Fake().expects_call().returns(api)

backend = backends.AuthorizeNetBackend()
with fudge.patched_context(backend, "get_api", get_api):
backend.purchase(donation, donation_form)
fudge.verify()


def test_adds_test_request_to_kwargs_if_in_testing_mode(self):
donation, donation_form = self.random_donation_and_form

Expand Down