Permalink
Browse files

Set up redirect endpoints (bug 795143)

  • Loading branch information...
1 parent 796a6bb commit 2c2d00114487bb49858191c71f5f03475e9dd5f1 @kumar303 kumar303 committed Dec 19, 2012
View
8 lib/solitude/api.py
@@ -133,7 +133,9 @@ def verify_pin(self, uuid, pin):
def configure_product_for_billing(self, webpay_trans_id,
seller_uuid,
product_id, product_name,
- currency, amount):
+ currency, amount,
+ redirect_url_onsuccess,
+ redirect_url_onerror):
"""
Get the billing configuration ID for a Bango transaction.
"""
@@ -161,7 +163,9 @@ def configure_product_for_billing(self, webpay_trans_id,
'pageTitle': product_name,
'price_currency': currency,
'price_amount': str(amount),
- 'seller_product_bango': bango_product_uri
+ 'seller_product_bango': bango_product_uri,
+ 'redirect_url_onsuccess': redirect_url_onsuccess,
+ 'redirect_url_onerror': redirect_url_onerror,
})
bill_id = res['billingConfigurationId']
log.info('transaction %s: billing config ID: %s'
View
0 webpay/bango/__init__.py
No changes.
View
5 webpay/bango/templates/bango/error.html
@@ -0,0 +1,5 @@
+{% extends "base.html" %}
+
+{% block content %}
+ <p>There was an error processing your payment.</p>
+{% endblock %}
View
3 webpay/pay/templates/pay/complete.html → webpay/bango/templates/bango/success.html
@@ -6,4 +6,7 @@
{% block content %}
<p>Your payment is complete. This window will now close!</p>
+ {% if simulated %}
+ <p>This was only a simulated payment.</p>
+ {% endif %}
{% endblock %}
View
8 webpay/bango/urls.py
@@ -0,0 +1,8 @@
+from django.conf.urls.defaults import patterns, url
+
+import views
+
+urlpatterns = patterns('',
+ url(r'^success$', views.success, name='bango.success'),
+ url(r'^error$', views.error, name='bango.error'),
+)
View
33 webpay/bango/views.py
@@ -0,0 +1,33 @@
+from django import http
+from django.conf import settings
+from django.shortcuts import render
+from django.views.decorators.http import require_GET, require_POST
+
+import commonware.log
+
+from webpay.pay.models import TRANS_STATE_COMPLETED
+
+log = commonware.log.getLogger('w.bango')
+
+
+@require_GET
+def success(request):
+ if 'trans_id' not in request.session:
+ return http.HttpResponseBadRequest()
+ # Simulate app purchase!
+ # TODO(Kumar): fixme. See bug 795143
+ if settings.FAKE_PAY_COMPLETE:
+ simulated = True
+ log.warning('Completing fake transaction without checking signature')
+ trans = Transaction.objects.get(pk=request.session['trans_id'])
+ trans.state = TRANS_STATE_COMPLETED
+ trans.save()
+ tasks.payment_notify.delay(trans.pk)
+ else:
+ simulated = False
+ return render(request, 'bango/success.html', {'simulated': simulated})
+
+
+@require_GET
+def error(request):
+ return render(request, 'bango/error.html', {})
View
13 webpay/base/helpers.py
@@ -1,6 +1,8 @@
from urllib import urlencode
import urlparse
+from django.conf import settings
+
import jinja2
from jingo import register
@@ -46,3 +48,14 @@ def media(context, url, key='MEDIA_URL'):
def static(context, url):
"""Get a STATIC_URL link with a cache buster querystring."""
return media(context, url, 'STATIC_URL')
+
+
+@register.filter
+def absolutify(url, site=None):
+ """Takes a URL and prepends the SITE_URL"""
+ if url.startswith('http'):
+ return url
+ else:
+ if site:
+ return site + url
+ return settings.SITE_URL + url
View
0 webpay/base/tests/__init__.py
No changes.
View
13 webpay/base/tests/test_helpers.py
@@ -0,0 +1,13 @@
+from django.conf import settings
+
+from mock import patch
+from nose.tools import eq_
+
+from .. import helpers
+
+
+@patch.object(settings, 'SITE_URL', 'http://somewhere')
+def test_absolutify():
+ eq_(helpers.absolutify('/woo'), settings.SITE_URL + '/woo')
+ eq_(helpers.absolutify('https://elsewhere.org'),
+ 'https://elsewhere.org')
View
4 webpay/pay/tasks.py
@@ -6,13 +6,15 @@
import urlparse
from django.conf import settings
+from django.core.urlresolvers import reverse
from django.db import transaction
from celeryutils import task
import jwt
from lib.solitude.api import client
from multidb.pinning import use_master
+from webpay.base.helpers import absolutify
from .models import (Notice, Transaction, TRANS_PAY, TRANS_REFUND,
TRANS_STATE_FAILED, TRANS_STATE_PENDING,
TRANS_STATE_READY)
@@ -67,6 +69,8 @@ def start_pay(trans_id, **kw):
trans.name, # app/product name
trans.currency,
trans.amount,
+ absolutify(reverse('bango.success')),
+ absolutify(reverse('bango.error')),
)
trans.bango_config_id = bill_id
trans.state = TRANS_STATE_READY
View
4 webpay/pay/templates/pay/fake-bango-url.html
@@ -6,9 +6,7 @@
Pretend this is a Bango payment screen for configuration ID {{ bill_config_id }}
</p>
<p>
- <form action="{{ url('pay.complete') }}" method="post">
- <input type="submit" value="Complete the payment">
- </form>
+ <a href="{{ url('bango.success') }}">Complete the payment</a>
</p>
</div>
{% endblock %}
View
5 webpay/pay/templates/pay/fakepay.html
@@ -5,8 +5,5 @@
Charge this payment to your bill (not really)
</div>
<p>
- <form action="{{ url('pay.complete') }}" method="post">
- <input type="submit" value="Complete the payment">
- </form>
+ <a href="{{ url('bango.success') }}">Complete the payment</a>
</p>
-{% endblock %}
View
1 webpay/pay/urls.py
@@ -4,7 +4,6 @@
urlpatterns = patterns('',
url(r'^$', views.lobby, name='pay.lobby'),
- url(r'^complete$', views.complete, name='pay.complete'),
url(r'^fakepay$', views.fakepay, name='pay.fakepay'),
# Be careful if you change this because it could be hard
# coded into settings. See BANGO_PAY_URL.
View
22 webpay/pay/views.py
@@ -4,7 +4,7 @@
from django import http
from django.conf import settings
from django.shortcuts import render
-from django.views.decorators.http import require_GET, require_POST
+from django.views.decorators.http import require_GET
import commonware.log
from moz_inapp_pay.exc import InvalidJWT, RequestExpired
@@ -17,8 +17,8 @@
from webpay.pin.forms import VerifyPinForm
from . import tasks
from .forms import VerifyForm
-from .models import (Issuer, Transaction, TRANS_STATE_COMPLETED,
- TRANS_STATE_PENDING, TRANS_STATE_READY)
+from .models import (Issuer, Transaction, TRANS_STATE_PENDING,
+ TRANS_STATE_READY)
log = commonware.log.getLogger('w.pay')
@@ -87,22 +87,6 @@ def lobby(request):
@anonymous_csrf_exempt
-@require_POST
-def complete(request):
- if 'trans_id' not in request.session:
- return http.HttpResponseBadRequest()
- # Simulate app purchase!
- # TODO(Kumar): fixme. See bug 795143
- if settings.FAKE_PAY_COMPLETE:
- log.warning('Completing fake transaction without checking signature')
- trans = Transaction.objects.get(pk=request.session['trans_id'])
- trans.state = TRANS_STATE_COMPLETED
- trans.save()
- tasks.payment_notify.delay(trans.pk)
- return render(request, 'pay/complete.html')
-
-
-@anonymous_csrf_exempt
@require_GET
def fakepay(request):
if not settings.FAKE_PAYMENTS:
View
1 webpay/settings/base.py
@@ -11,6 +11,7 @@
INSTALLED_APPS = list(INSTALLED_APPS) + [
'webpay.base', # Needed for global templates, etc.
+ 'webpay.bango',
'webpay.pay',
'webpay.pin',
'webpay.services',
View
1 webpay/urls.py
@@ -12,6 +12,7 @@
urlpatterns = patterns('',
(r'^mozpay/auth/', include('webpay.auth.urls')),
+ (r'^mozpay/bango/', include('webpay.bango.urls')),
(r'^mozpay/services/', include('webpay.services.urls')),
(r'^mozpay/', include('webpay.pay.urls')),
url('^mozpay/jsi18n.js$',

0 comments on commit 2c2d001

Please sign in to comment.