use minibrowser and whilst there remove the USE_EMBEDDED flag, we aren't going back in a hurry (bug 672560)
This commit is contained in:
Родитель
2830b47eb8
Коммит
d78ddfea6b
|
@ -1,5 +1,3 @@
|
|||
from django.conf import settings
|
||||
|
||||
import jinja2
|
||||
|
||||
from jingo import register, env
|
||||
|
@ -47,8 +45,7 @@ def flag(context, addon):
|
|||
@register.function
|
||||
def support_addon(addon):
|
||||
t = env.get_template('addons/support_addon.html')
|
||||
return jinja2.Markup(t.render(addon=addon, amo=amo,
|
||||
use_embedded=settings.PAYPAL_USE_EMBEDDED))
|
||||
return jinja2.Markup(t.render(addon=addon, amo=amo))
|
||||
|
||||
|
||||
@register.inclusion_tag('addons/performance_note.html')
|
||||
|
|
|
@ -65,17 +65,6 @@
|
|||
'$', '<input type="text" name="onetime-amount" value=""/>')|safe }}
|
||||
</label>
|
||||
</li>
|
||||
{% if not settings.PAYPAL_USE_EMBEDDED %}
|
||||
<li>
|
||||
<input type="radio" name="type" value="monthly"
|
||||
id="contrib-monthly"/>
|
||||
<label for="contrib-monthly">
|
||||
{# L10n: {0} is a currency symbol (e.g., $),
|
||||
{1} is an amount input field #}
|
||||
{{ _('A regular monthly contribution of {0} {1}')|f(
|
||||
'$', '</label><input type="text" name="monthly-amount" value=""/>')|safe }}
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
<h4 class="comment">
|
||||
|
|
|
@ -22,11 +22,7 @@
|
|||
{% endtrans %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if use_embedded %}
|
||||
<a href="{{ url('addons.detail', addon.slug) }}?src=browse#contribute-confirm" id="paypal-{{ pk }}" class="no-suggested-amount">{{ _('Support this add-on') }}</a>
|
||||
{% else %}
|
||||
<a href="{{ base }}">{{ _('Support this add-on') }}</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -4,7 +4,6 @@ from datetime import datetime
|
|||
from decimal import Decimal
|
||||
import json
|
||||
import re
|
||||
import urlparse
|
||||
|
||||
from django import test
|
||||
from django.conf import settings
|
||||
|
@ -149,7 +148,6 @@ class TestContributeEmbedded(test_utils.TestCase):
|
|||
fixtures = ['base/apps', 'base/addon_3615', 'base/addon_592']
|
||||
|
||||
def setUp(self):
|
||||
settings.PAYPAL_USE_EMBEDDED = True
|
||||
self.addon = Addon.objects.get(pk=592)
|
||||
self.detail_url = reverse('addons.detail', args=[self.addon.slug])
|
||||
|
||||
|
@ -249,150 +247,6 @@ class TestContributeEmbedded(test_utils.TestCase):
|
|||
assert not json.loads(res.content)['paykey']
|
||||
|
||||
|
||||
class TestContribute(test_utils.TestCase):
|
||||
fixtures = ['base/apps', 'base/addon_3615', 'base/addon_592']
|
||||
|
||||
def setUp(self):
|
||||
settings.PAYPAL_USE_EMBEDDED = False
|
||||
|
||||
def test_invalid_is_404(self):
|
||||
"""we get a 404 in case of invalid addon id"""
|
||||
response = self.client.get(reverse('addons.contribute', args=[1]))
|
||||
eq_(response.status_code, 404)
|
||||
|
||||
def test_redirect_params_no_type(self):
|
||||
"""Test that we have the required ppal params when no type is given"""
|
||||
response = self.client.get(reverse('addons.contribute',
|
||||
args=['a592']), follow=True)
|
||||
redirect_url = response.redirect_chain[0][0]
|
||||
required_params = ['bn', 'business', 'charset', 'cmd', 'item_name',
|
||||
'no_shipping', 'notify_url',
|
||||
'return', 'item_number']
|
||||
for param in required_params:
|
||||
assert(redirect_url.find(param + '=') > -1), \
|
||||
"param [%s] not found" % param
|
||||
|
||||
def test_redirect_params_common(self):
|
||||
"""Test for the common values that do not change based on type,
|
||||
Check that they have expected values"""
|
||||
response = self.client.get(reverse('addons.contribute',
|
||||
args=['a592']), follow=True)
|
||||
redirect_url = response.redirect_chain[0][0]
|
||||
assert(re.search('business=([^&]+)', redirect_url))
|
||||
common_params = {'bn': r'-AddonID592',
|
||||
'business': r'gmailsmime%40seantek.com',
|
||||
'charset': r'utf-8',
|
||||
'cmd': r'_donations',
|
||||
'item_name': r'Contribution\+for\+Gmail\+S%2FMIME',
|
||||
'no_shipping': r'1',
|
||||
'notify_url': r'%2Fservices%2Fpaypal',
|
||||
'return': r'x',
|
||||
'item_number': r'[a-f\d]{32}'}
|
||||
|
||||
message = 'param [%s] unexpected value: given [%s], ' \
|
||||
+ 'expected pattern [%s]'
|
||||
for param, value_pattern in common_params.items():
|
||||
match = re.search(r'%s=([^&]+)' % param, redirect_url)
|
||||
assert(match and re.search(value_pattern, match.group(1))), \
|
||||
message % (param, match.group(1), value_pattern)
|
||||
|
||||
def test_redirect_params_type_suggested(self):
|
||||
"""Test that we have the required ppal param when type
|
||||
suggested is given"""
|
||||
request_params = '?type=suggested'
|
||||
response = self.client.get(reverse('addons.contribute',
|
||||
args=['a592']) + request_params,
|
||||
follow=True)
|
||||
redirect_url = response.redirect_chain[0][0]
|
||||
required_params = ['amount', 'bn', 'business', 'charset',
|
||||
'cmd', 'item_name', 'no_shipping', 'notify_url',
|
||||
'return', 'item_number']
|
||||
for param in required_params:
|
||||
assert(redirect_url.find(param + '=') > -1), \
|
||||
"param [%s] not found" % param
|
||||
|
||||
def test_redirect_params_type_onetime(self):
|
||||
"""Test that we have the required ppal param when
|
||||
type onetime is given"""
|
||||
request_params = '?type=onetime&onetime-amount=42'
|
||||
response = self.client.get(reverse('addons.contribute',
|
||||
args=['a592']) + request_params,
|
||||
follow=True)
|
||||
redirect_url = response.redirect_chain[0][0]
|
||||
required_params = ['amount', 'bn', 'business', 'charset', 'cmd',
|
||||
'item_name', 'no_shipping', 'notify_url',
|
||||
'return', 'item_number']
|
||||
for param in required_params:
|
||||
assert(redirect_url.find(param + '=') > -1), \
|
||||
"param [%s] not found" % param
|
||||
|
||||
assert(redirect_url.find('amount=42') > -1)
|
||||
|
||||
def test_ppal_return_url_not_relative(self):
|
||||
response = self.client.get(reverse('addons.contribute',
|
||||
args=['a592']), follow=True)
|
||||
redirect_url = response.redirect_chain[0][0]
|
||||
|
||||
assert(re.search('\?|&return=https?%3A%2F%2F', redirect_url)), \
|
||||
("return URL param did not start w/ "
|
||||
"http%3A%2F%2F (http://) [%s]" % redirect_url)
|
||||
|
||||
def test_redirect_params_type_monthly(self):
|
||||
"""Test that we have the required ppal param when
|
||||
type monthly is given"""
|
||||
request_params = '?type=monthly&monthly-amount=42'
|
||||
response = self.client.get(reverse('addons.contribute',
|
||||
args=['a592']) + request_params,
|
||||
follow=True)
|
||||
redirect_url = response.redirect_chain[0][0]
|
||||
required_params = ['no_note', 'a3', 't3', 'p3', 'bn', 'business',
|
||||
'charset', 'cmd', 'item_name', 'no_shipping',
|
||||
'notify_url', 'return', 'item_number']
|
||||
for param in required_params:
|
||||
assert(redirect_url.find(param + '=') > -1), \
|
||||
"param [%s] not found" % param
|
||||
|
||||
assert(redirect_url.find('cmd=_xclick-subscriptions') > -1), \
|
||||
'param a3 was not 42'
|
||||
assert(redirect_url.find('p3=12') > -1), 'param p3 was not 12'
|
||||
assert(redirect_url.find('t3=M') > -1), 'param t3 was not M'
|
||||
assert(redirect_url.find('a3=42') > -1), 'param a3 was not 42'
|
||||
assert(redirect_url.find('no_note=1') > -1), 'param no_note was not 1'
|
||||
|
||||
def test_paypal_bounce(self):
|
||||
"""Paypal is retarded and posts to this page."""
|
||||
args = dict(args=['a3615'])
|
||||
r = self.client.post(reverse('addons.thanks', **args))
|
||||
self.assertRedirects(r, reverse('addons.detail', **args))
|
||||
|
||||
def test_unicode_comment(self):
|
||||
r = self.client.get(reverse('addons.contribute', args=['a592']),
|
||||
{'comment': u'版本历史记录'})
|
||||
eq_(r.status_code, 302)
|
||||
assert r['Location'].startswith(settings.PAYPAL_CGI_URL)
|
||||
|
||||
def test_organization(self):
|
||||
c = Charity.objects.create(name='moz', url='moz.com', paypal='mozcom')
|
||||
addon = Addon.objects.get(id=592)
|
||||
addon.update(charity=c)
|
||||
|
||||
r = self.client.get(reverse('addons.contribute', args=['a592']))
|
||||
eq_(r.status_code, 302)
|
||||
qs = dict(urlparse.parse_qsl(r['Location']))
|
||||
eq_(qs['item_name'], 'Contribution for moz')
|
||||
eq_(qs['business'], 'mozcom')
|
||||
|
||||
contrib = Contribution.objects.get(addon=addon)
|
||||
eq_(addon.charity_id, contrib.charity_id)
|
||||
|
||||
def test_no_org(self):
|
||||
addon = Addon.objects.get(id=592)
|
||||
r = self.client.get(reverse('addons.contribute', args=['a592']))
|
||||
eq_(r.status_code, 302)
|
||||
contrib = Contribution.objects.get(addon=addon)
|
||||
eq_(contrib.charity_id, None)
|
||||
|
||||
|
||||
class TestDeveloperPages(test_utils.TestCase):
|
||||
fixtures = ['base/apps', 'base/addon_3615', 'base/addon_592',
|
||||
'base/users', 'addons/eula+contrib-addon',
|
||||
|
|
|
@ -540,8 +540,6 @@ def developers(request, addon, page):
|
|||
else:
|
||||
version = addon.current_version
|
||||
|
||||
|
||||
|
||||
if 'src' in request.GET:
|
||||
contribution_src = src = request.GET['src']
|
||||
else:
|
||||
|
@ -563,55 +561,8 @@ def developers(request, addon, page):
|
|||
'version': version})
|
||||
|
||||
|
||||
def old_contribute(request, addon):
|
||||
contrib_type = request.GET.get('type', '')
|
||||
is_suggested = contrib_type == 'suggested'
|
||||
source = request.GET.get('source', '')
|
||||
comment = request.GET.get('comment', '')
|
||||
|
||||
amount = {
|
||||
'suggested': addon.suggested_amount,
|
||||
'onetime': request.GET.get('onetime-amount', ''),
|
||||
'monthly': request.GET.get('monthly-amount', '')}.get(contrib_type, '')
|
||||
|
||||
contribution_uuid = hashlib.md5(str(uuid.uuid4())).hexdigest()
|
||||
|
||||
contrib = Contribution(addon_id=addon.id,
|
||||
charity_id=addon.charity_id,
|
||||
amount=amount,
|
||||
source=source,
|
||||
source_locale=request.LANG,
|
||||
annoying=addon.annoying,
|
||||
uuid=str(contribution_uuid),
|
||||
is_suggested=is_suggested,
|
||||
suggested_amount=addon.suggested_amount,
|
||||
comment=comment)
|
||||
contrib.save()
|
||||
|
||||
return_url = "%s?%s" % (reverse('addons.thanks', args=[addon.slug]),
|
||||
urllib.urlencode({'uuid': contribution_uuid}))
|
||||
# L10n: {0} is an add-on name.
|
||||
if addon.charity:
|
||||
name, paypal = addon.charity.name, addon.charity.paypal
|
||||
else:
|
||||
name, paypal = addon.name, addon.paypal_id
|
||||
contrib_for = _(u'Contribution for {0}').format(jinja2.escape(name))
|
||||
redirect_url_params = contribute_url_params(
|
||||
paypal,
|
||||
addon.id,
|
||||
contrib_for,
|
||||
absolutify(return_url),
|
||||
amount,
|
||||
contribution_uuid,
|
||||
contrib_type == 'monthly',
|
||||
comment)
|
||||
|
||||
return http.HttpResponseRedirect(settings.PAYPAL_CGI_URL
|
||||
+ '?'
|
||||
+ urllib.urlencode(redirect_url_params))
|
||||
|
||||
|
||||
def embedded_contribute(request, addon):
|
||||
@addon_view
|
||||
def contribute(request, addon):
|
||||
contrib_type = request.GET.get('type', 'suggested')
|
||||
is_suggested = contrib_type == 'suggested'
|
||||
source = request.GET.get('source', '')
|
||||
|
@ -680,14 +631,6 @@ def embedded_contribute(request, addon):
|
|||
return http.HttpResponseRedirect(url)
|
||||
|
||||
|
||||
@addon_view
|
||||
def contribute(request, addon):
|
||||
if settings.PAYPAL_USE_EMBEDDED:
|
||||
return embedded_contribute(request, addon)
|
||||
else:
|
||||
return old_contribute(request, addon)
|
||||
|
||||
|
||||
def contribute_url_params(business, addon_id, item_name, return_url,
|
||||
amount='', item_number='',
|
||||
monthly=False, comment=''):
|
||||
|
|
|
@ -3,12 +3,11 @@ import urllib
|
|||
|
||||
from django import http, test
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache, parse_backend_uri
|
||||
from django.core.cache import cache
|
||||
|
||||
import commonware.log
|
||||
from lxml import etree
|
||||
from mock import patch, Mock
|
||||
from nose import SkipTest
|
||||
from nose.tools import eq_
|
||||
from pyquery import PyQuery as pq
|
||||
import test_utils
|
||||
|
@ -164,7 +163,6 @@ class TestImpala(test_utils.TestCase):
|
|||
eq_(request.amo_user.is_developer, False)
|
||||
eq_(acl.action_allowed(request, 'Editors', '%'), True)
|
||||
|
||||
|
||||
eq_(nav.find('li.tools').length, 1)
|
||||
eq_(nav.find('li.tools li').length, 2)
|
||||
eq_(nav.find('li.tools > a').length, 1)
|
||||
|
@ -178,6 +176,7 @@ class TestImpala(test_utils.TestCase):
|
|||
eq_(item.text(), "Editor Tools")
|
||||
eq_(item.attr('href'), reverse('editors.home'))
|
||||
|
||||
|
||||
class TestStuff(test_utils.TestCase):
|
||||
fixtures = ('base/users', 'base/global-stats', 'base/configs',
|
||||
'base/addon_3615')
|
||||
|
@ -358,7 +357,6 @@ class TestPaypal(test_utils.TestCase):
|
|||
self.url = reverse('amo.paypal')
|
||||
self.item = 1234567890
|
||||
self.client = Client()
|
||||
settings.PAYPAL_USE_EMBEDDED = True
|
||||
|
||||
def urlopener(self, status):
|
||||
m = Mock()
|
||||
|
|
|
@ -2,33 +2,29 @@ $(document).ready(function() {
|
|||
$("#contribute-why").popup("#contribute-more-info", {
|
||||
pointTo: "#contribute-more-info"
|
||||
});
|
||||
if (PAYPAL !== undefined) {
|
||||
$('div.contribute a.suggested-amount').live('click', function(event) {
|
||||
var el = this;
|
||||
$.getJSON($(this).attr('href') + '&result_type=json',
|
||||
function(json) {
|
||||
if (json.paykey) {
|
||||
dgFlow = new PAYPAL.apps.DGFlow({clicked: el.id});
|
||||
dgFlow.startFlow(json.url);
|
||||
} else {
|
||||
if (!$('#paypal-error').length) {
|
||||
$(el).closest('div').append('<div id="paypal-error" class="popup"></div>');
|
||||
}
|
||||
$('#paypal-error').text(json.error).popup(el, {pointTo:el}).render();
|
||||
$('div.contribute a.suggested-amount').live('click', function(event) {
|
||||
var el = this;
|
||||
$.getJSON($(this).attr('href') + '&result_type=json',
|
||||
function(json) {
|
||||
if (json.paykey) {
|
||||
dgFlow = new PAYPAL.apps.DGFlow({expType: 'mini'});
|
||||
dgFlow.startFlow(json.url);
|
||||
} else {
|
||||
if (!$('#paypal-error').length) {
|
||||
$(el).closest('div').append('<div id="paypal-error" class="popup"></div>');
|
||||
}
|
||||
$('#paypal-error').text(json.error).popup(el, {pointTo:el}).render();
|
||||
}
|
||||
);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
if (PAYPAL !== undefined) {
|
||||
if ($('#paypal-result').length) {
|
||||
top_dgFlow = top.dgFlow || (top.opener && top.opener.top.dgFlow);
|
||||
if (top_dgFlow !== null) {
|
||||
top_dgFlow.closeFlow();
|
||||
if (top !== null) {
|
||||
top.close();
|
||||
}
|
||||
}
|
||||
);
|
||||
return false;
|
||||
});
|
||||
if ($('#paypal-result').length) {
|
||||
top_dgFlow = top.dgFlow || (top.opener && top.opener.top.dgFlow);
|
||||
if (top_dgFlow !== null) {
|
||||
top_dgFlow.closeFlow();
|
||||
if (top !== null) {
|
||||
top.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,25 +80,20 @@ var contributions = {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (PAYPAL !== undefined) {
|
||||
var $self = $(this);
|
||||
$.ajax({type: 'GET',
|
||||
url: $(this).attr('action') + '?result_type=json',
|
||||
data: $(this).serialize(),
|
||||
success: function(json) {
|
||||
if (json.paykey) {
|
||||
dgFlow = new PAYPAL.apps.DGFlow({clicked: 'contribute-box'});
|
||||
dgFlow.startFlow(json.url);
|
||||
$self.find('span.cancel a').click();
|
||||
} else {
|
||||
$self.find('#paypal-error').show();
|
||||
}
|
||||
var $self = $(this);
|
||||
$.ajax({type: 'GET',
|
||||
url: $(this).attr('action') + '?result_type=json',
|
||||
data: $(this).serialize(),
|
||||
success: function(json) {
|
||||
if (json.paykey) {
|
||||
dgFlow = new PAYPAL.apps.DGFlow({expType:'mini'});
|
||||
dgFlow.startFlow(json.url);
|
||||
$self.find('span.cancel a').click();
|
||||
} else {
|
||||
$self.find('#paypal-error').show();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// enable overlay; make sure we have the jqm package available.
|
||||
|
|
|
@ -54,9 +54,6 @@ var paypalFixtures = {
|
|||
|
||||
module('Contributions', paypalFixtures);
|
||||
|
||||
// We don't need to pull in Paypal, but we do need a global var.
|
||||
PAYPAL = '';
|
||||
|
||||
asyncTest('Paypal failure', function() {
|
||||
var self = this;
|
||||
$.mockjax({
|
||||
|
|
|
@ -751,7 +751,6 @@ PAYPAL_BN = ''
|
|||
PAYPAL_CGI_URL = 'https://www.paypal.com/cgi-bin/webscr'
|
||||
PAYPAL_CGI_AUTH = {'USER': '', 'PASSWORD': '', 'SIGNATURE': ''}
|
||||
|
||||
PAYPAL_USE_EMBEDDED = True
|
||||
PAYPAL_PAY_URL = 'https://svcs.paypal.com/AdaptivePayments/Pay'
|
||||
PAYPAL_FLOW_URL = 'https://paypal.com/webapps/adaptivepayment/flow/pay'
|
||||
PAYPAL_JS_URL = 'https://www.paypalobjects.com/js/external/dg.js'
|
||||
|
|
|
@ -143,7 +143,7 @@
|
|||
<script src="{{ static(url('jsi18n')) }}"></script>
|
||||
{{ js('common') }}
|
||||
<script async defer src="{{ static(url('addons.buttons.js')) }}"></script>
|
||||
{% if settings.PAYPAL_USE_EMBEDDED %}<script async defer src="{{ settings.PAYPAL_JS_URL }}"></script>{% endif %}
|
||||
<script async defer src="{{ settings.PAYPAL_JS_URL }}"></script>
|
||||
{% endblock %}
|
||||
{% block js %}{% endblock %}
|
||||
{% block footer %}
|
||||
|
|
|
@ -49,7 +49,6 @@
|
|||
data-anonymous="{{ (not request.user.is_authenticated())|json }}"
|
||||
data-readonly="{{ settings.READ_ONLY|json }}"
|
||||
data-media-url="{{ MEDIA_URL }}"
|
||||
{% if settings.PAYPAL_USE_EMBEDDED %}data-paypal-url="{{ settings.PAYPAL_JS_URL }}"{% endif %}
|
||||
{% block bodyattrs %}{% endblock %}>
|
||||
|
||||
{% if ADMIN_MESSAGE or settings.READ_ONLY%}
|
||||
|
@ -174,6 +173,7 @@
|
|||
<script src="{{ static(url('jsi18n')) }}"></script>
|
||||
{{ js('impala') }}
|
||||
<script async defer src="{{ static(url('addons.buttons.js')) }}"></script>
|
||||
<script async defer src="{{ settings.PAYPAL_JS_URL }}"></script>
|
||||
{% endblock %}
|
||||
{% block js %}{% endblock %}
|
||||
{% block footer %}
|
||||
|
|
Загрузка…
Ссылка в новой задаче