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

Commit

Permalink
no refund for in-app (bug 719215)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy McKay committed Mar 30, 2012
1 parent 5dd06c9 commit 7b0eee3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
4 changes: 2 additions & 2 deletions mkt/account/templates/account/helpers/refund_info.html
@@ -1,14 +1,14 @@
{% set contributions = contributions.get(product.pk, []) %}
{% if contributions %}
<ul class="vitals contributions">
{% set last_contrib = contributions[-1].type == amo.CONTRIB_PURCHASE
{% set last_contrib = contributions[-1].type in [amo.CONTRIB_PURCHASE, amo.CONTRIB_INAPP]
and contributions[-1].id %}
{% for contribution in contributions %}
{# Show "Request Support" link if this is the last contribution
and is a purchase. #}
{% set get_support = contribution.id == last_contrib %}
<li>
{% if contribution.type == amo.CONTRIB_PURCHASE %}
{% if contribution.type in [amo.CONTRIB_PURCHASE, amo.CONTRIB_INAPP] %}
<span class="purchase{{ ' supportable' if get_support }}">
{% trans date=contribution.created|datetime,
amt=contribution.get_amount_locale() %}
Expand Down
7 changes: 6 additions & 1 deletion mkt/account/tests/test_views.py
Expand Up @@ -415,7 +415,12 @@ def test_no_purchases_attribute(self):
doc = pq(self.client.get(self.url).content)
eq_(doc('body').attr('data-purchases'), '')

def test_refund_link(self):
def test_support_link(self):
eq_(self.get_pq()('a.request-support').eq(0).attr('href'),
self.get_support_url())

def test_support_link_inapp(self):
self.con.update(type=amo.CONTRIB_INAPP)
eq_(self.get_pq()('a.request-support').eq(0).attr('href'),
self.get_support_url())

Expand Down
4 changes: 2 additions & 2 deletions mkt/account/views.py
Expand Up @@ -109,8 +109,8 @@ def purchases(request, product_id=None, template=None):
"""A list of purchases that a user has made through the Marketplace."""
cs = (Contribution.objects
.filter(user=request.amo_user,
type__in=[amo.CONTRIB_PURCHASE, amo.CONTRIB_REFUND,
amo.CONTRIB_CHARGEBACK])
type__in=[amo.CONTRIB_PURCHASE, amo.CONTRIB_INAPP,
amo.CONTRIB_REFUND, amo.CONTRIB_CHARGEBACK])
.order_by('created'))
if product_id:
cs = cs.filter(addon=product_id)
Expand Down
8 changes: 6 additions & 2 deletions mkt/support/templates/support/start.html
Expand Up @@ -8,8 +8,12 @@ <h1>{{ _('What do you need help with?') }}</h1>
<li><a href="{{ url('support', contribution.pk, 'resources') }}">
{{ _('I have billing or payment concerns') }} &raquo;</a></li>
{% if waffle.switch('allow-refund') %}
<li><a href="{{ url('support', contribution.pk, 'request') }}">
{{ _('I want to request a refund') }} &raquo;</a></li>
{% if contribution.can_we_refund() %}
<li><a href="{{ url('support', contribution.pk, 'request') }}">
{{ _('I want to request a refund') }} &raquo;</a></li>
{% elif contribution.type == amo.CONTRIB_INAPP %}
<li>{{ _('In-app purchases cannot be refunded through the Marketplace.') }}</li>
{% endif %}
{% else %}
{# No L10n or even `loc` on purpose. #}
<li>
Expand Down
16 changes: 16 additions & 0 deletions mkt/support/tests/test_views.py
Expand Up @@ -30,6 +30,12 @@ def test_support_page_form(self):
eq_(doc('#support-start').find('a').eq(0).attr('href'),
self.get_support_url('author'))

def test_start_no_inapp_refund(self):
self.con.update(type=amo.CONTRIB_INAPP)
content = self.client.get(self.get_support_url()).content
eq_(len(pq(content)('#support-start').find('a')), 3)
assert self.get_support_url('request') not in content

def test_support_page_external_link(self):
self.app.support_url = 'http://omg.org/yes'
self.app.save()
Expand Down Expand Up @@ -86,6 +92,11 @@ def test_contact_mozilla_fails(self):
res = self.client.post(self.get_support_url('mozilla'), {'b': 'c'})
assert 'text' in res.context['form'].errors

def test_no_request_inapp(self):
self.con.update(type=amo.CONTRIB_INAPP)
res = self.client.post(self.get_support_url('request'))
eq_(res.status_code, 403)

def test_refund_remove(self):
res = self.client.post(self.get_support_url('request'), {'remove': 1})
eq_(res.status_code, 302)
Expand Down Expand Up @@ -114,6 +125,11 @@ def test_no_txnid_request(self):
eq_(len(mail.outbox), 0)
self.assertRedirects(res, reverse('account.purchases'), 302)

def test_no_reason_inapp(self):
self.con.update(type=amo.CONTRIB_INAPP)
res = self.client.post(self.get_support_url('reason'))
eq_(res.status_code, 403)

@mock.patch('stats.models.Contribution.is_instant_refund')
def test_request_mails(self, is_instant_refund):
is_instant_refund.return_value = False
Expand Down
6 changes: 6 additions & 0 deletions mkt/support/views.py
Expand Up @@ -98,6 +98,9 @@ def support_mozilla(request, contribution, wizard):

@waffle_switch('allow-refund')
def refund_request(request, contribution, wizard):
if not contribution.can_we_refund():
return http.HttpResponseForbidden()

addon = contribution.addon
if request.method == 'POST':
return redirect('support', contribution.pk, 'reason')
Expand All @@ -108,6 +111,9 @@ def refund_request(request, contribution, wizard):

@waffle_switch('allow-refund')
def refund_reason(request, contribution, wizard):
if not contribution.can_we_refund():
return http.HttpResponseForbidden()

addon = contribution.addon
if not 'request' in wizard.get_progress():
return redirect('support', contribution.pk, 'request')
Expand Down

0 comments on commit 7b0eee3

Please sign in to comment.