add a button on the thank you page for pre-approval (bug 707376)

This commit is contained in:
Andy McKay 2011-12-20 14:33:13 -08:00
Родитель 23a0dd979b
Коммит 1800465f7d
6 изменённых файлов: 56 добавлений и 7 удалений

Просмотреть файл

@ -25,6 +25,18 @@
{% endwith %}
</p>
</section>
{% if waffle.flag('allow-pre-auth') and not amo_user.has_preapproval_key() %}
<section class="paypal-parent">
<form form id="preapproval" method="post" action="{{ url('users.payments.preapproval') }}">
{{ csrf() }}
<p>{{ loc('Want to do this faster next time?') }}</p>
<p>{{ loc('Setting up PayPal pre-approval allows you to buy apps quickly on this site. They also allow you to use in-app purchases that go through this site.') }}</p>
<p><button>{{ loc('Set up pre-approval') }}</button></p>
</form>
</section>
{% endif %}
<section class="paypal-parent">
<a href="{{ url('users.purchases') }}">{{ loc('My Purchases') }}</a>
{# TODO(marketplace-docs)

Просмотреть файл

@ -457,6 +457,25 @@ class TestPurchaseEmbedded(amo.tests.TestCase):
self.make_contribution(type=amo.CONTRIB_PURCHASE)
eq_(self.client.get(url).status_code, 200)
@patch.object(waffle, 'flag_is_active', lambda x, y: True)
@patch('users.models.UserProfile.has_preapproval_key')
def test_prompt_preapproval(self, has_preapproval_key):
url = reverse('addons.purchase.thanks', args=[self.addon.slug])
self.make_contribution(type=amo.CONTRIB_PURCHASE)
has_preapproval_key.return_value = False
res = self.client.get(url)
eq_(pq(res.content)('#preapproval').attr('action'),
reverse('users.payments.preapproval'))
@patch.object(waffle, 'flag_is_active', lambda x, y: True)
@patch('users.models.UserProfile.has_preapproval_key')
def test_already_preapproved(self, has_preapproval_key):
url = reverse('addons.purchase.thanks', args=[self.addon.slug])
self.make_contribution(type=amo.CONTRIB_PURCHASE)
has_preapproval_key.return_value = True
res = self.client.get(url)
eq_(len(pq(res.content)('#preapproval')), 0)
def test_trigger(self):
url = reverse('addons.purchase.thanks', args=[self.addon.slug])
self.make_contribution(type=amo.CONTRIB_PURCHASE)

Просмотреть файл

@ -202,3 +202,10 @@ class TestUserPreApproval(amo.tests.TestCase):
eq_(self.user.get_preapproval(), None)
pre = PreApprovalUser.objects.create(user=self.user)
eq_(self.user.get_preapproval(), pre)
def test_has_key(self):
assert not self.user.has_preapproval_key()
pre = PreApprovalUser.objects.create(user=self.user, paypal_key='')
assert not self.user.has_preapproval_key()
pre.update(paypal_key='123')
assert UserProfile.objects.get(pk=self.user.pk).has_preapproval_key()

Просмотреть файл

@ -368,6 +368,13 @@ class UserProfile(amo.models.OnChangeMixin, amo.models.ModelBase):
except ObjectDoesNotExist:
pass
def has_preapproval_key(self):
"""
Returns the pre approval paypal key for this user, or '' if the
pre_approval doesn't exist or the key is blank.
"""
return bool(getattr(self.get_preapproval(), 'paypal_key', ''))
@dispatch.receiver(models.signals.post_save, sender=UserProfile,
dispatch_uid='user.post_save')

Просмотреть файл

@ -1668,6 +1668,9 @@ class TestPreapproval(amo.tests.TestCase):
res = self.client.post(self.get_url('complete'))
eq_(res.status_code, 200)
eq_(self.user.preapprovaluser.paypal_key, 'xyz')
# Check that re-loading doesn't error.
res = self.client.post(self.get_url('complete'))
eq_(res.status_code, 200)
def test_preapproval_cancel(self):
PreApprovalUser.objects.create(user=self.user, paypal_key='xyz')

Просмотреть файл

@ -945,13 +945,14 @@ def payments(request, status=None):
if status == 'complete':
# The user has completed the setup at PayPal and bounced back.
messages.success(request, loc('Pre-approval setup.'))
paypal_log.info(u'Preapproval key created for user: %s'
% request.amo_user)
data = request.session.get('setup-preapproval', {})
pre.update(paypal_key=data.get('key'),
paypal_expiry=data.get('expiry'))
del request.session['setup-preapproval']
if 'setup-preapproval' in request.session:
messages.success(request, loc('Pre-approval setup.'))
paypal_log.info(u'Preapproval key created for user: %s'
% request.amo_user)
data = request.session.get('setup-preapproval', {})
pre.update(paypal_key=data.get('key'),
paypal_expiry=data.get('expiry'))
del request.session['setup-preapproval']
elif status == 'cancel':
# The user has chosen to cancel out of PayPal. Nothing really