diff --git a/payment/integrations/__init__.py b/payment/integrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/payment/integrations/fps_integration.py b/payment/integrations/fps_integration.py new file mode 100644 index 00000000..809a0bb4 --- /dev/null +++ b/payment/integrations/fps_integration.py @@ -0,0 +1,25 @@ +""" +https://github.com/agiliq/merchant/blob/master/example/app/integrations/fps_integration.py +""" + +from billing.integrations.amazon_fps_integration import AmazonFpsIntegration as Integration +from django.core.urlresolvers import reverse +from django.http import HttpResponseRedirect +import urlparse + +class FpsIntegration(Integration): + def transaction(self, request): + """Ideally at this method, you will check the + caller reference against a user id or uniquely + identifiable attribute (if you are already not + using it as the caller reference) and the type + of transaction (either pay, reserve etc). For + the sake of the example, we assume all the users + get charged $100""" + request_url = request.build_absolute_uri() + parsed_url = urlparse.urlparse(request_url) + query = parsed_url.query + dd = dict(map(lambda x: x.split("="), query.split("&"))) + resp = self.purchase(100, dd) + return HttpResponseRedirect("%s?status=%s" %(reverse("app_offsite_amazon_fps"), + resp["status"])) \ No newline at end of file diff --git a/payment/templates/amazon_fps.html b/payment/templates/amazon_fps.html new file mode 100644 index 00000000..f60d3d67 --- /dev/null +++ b/payment/templates/amazon_fps.html @@ -0,0 +1,14 @@ +{% load amazon_fps_tags %} + +{% block content %} +
+

You are going to be charged $100 in the + Amazon FPS Sandbox.

+

{% amazon_fps fps_obj %}

+
+
+

(Recurring payments) You are going to be charged $100 every hour in the + Amazon FPS Sandbox.

+

{% amazon_fps fps_recur_obj %}

+
+{% endblock %} \ No newline at end of file diff --git a/payment/templatetags/__init__.py b/payment/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/payment/templatetags/amazon_fps_tags.py b/payment/templatetags/amazon_fps_tags.py new file mode 100644 index 00000000..96389ddc --- /dev/null +++ b/payment/templatetags/amazon_fps_tags.py @@ -0,0 +1,8 @@ +""" +Template tags for amazon_fps +""" +from django import template +from billing.templatetags.amazon_fps_tags import amazon_fps +register = template.Library() + +register.tag(amazon_fps) \ No newline at end of file diff --git a/payment/urls.py b/payment/urls.py index 0bf59487..6da83b17 100644 --- a/payment/urls.py +++ b/payment/urls.py @@ -1,6 +1,12 @@ from django.conf.urls.defaults import * from django.conf import settings +# django-merchant integration +from billing import get_integration + +amazon_fps_obj = get_integration("fps") +fps_recur_obj = get_integration("fps") + urlpatterns = patterns( "regluit.payment.views", url(r"^paypalipn", "paypalIPN", name="PayPalIPN"), @@ -19,5 +25,9 @@ if not settings.IS_PREVIEW: url(r"^checkstatus", "checkStatus"), url(r"^testfinish", "testFinish"), url(r"^testrefund", "testRefund"), - url(r"^testmodify", "testModify"), -) + url(r"^testmodify", "testModify"), + url(r"^testfps", "testfps"), + ) + urlpatterns += patterns('', + (r'^fps/', include(amazon_fps_obj.urls)), + ) diff --git a/payment/views.py b/payment/views.py index a3225076..bb974abf 100644 --- a/payment/views.py +++ b/payment/views.py @@ -3,13 +3,19 @@ from regluit.payment.paypal import IPN from regluit.payment.models import Transaction from regluit.core.models import Campaign, Wishlist from django.conf import settings +from django.core.urlresolvers import reverse +from django.shortcuts import render_to_response from django.contrib.auth.models import User +from django.contrib.sites.models import RequestSite from regluit.payment.parameters import * from django.http import HttpResponse, HttpRequest, HttpResponseRedirect from django.views.decorators.csrf import csrf_exempt from django.test.utils import setup_test_environment +from django.template import RequestContext + from unittest import TestResult from regluit.payment.tests import PledgeTest, AuthorizeTest +from regluit.payment.urls import amazon_fps_obj, fps_recur_obj import traceback import logging @@ -305,7 +311,37 @@ def checkStatus(request): return HttpResponse(error_data, mimetype="text/xml") +# https://raw.github.com/agiliq/merchant/master/example/app/views.py +def _render(request, template, template_vars={}): + return render_to_response(template, template_vars, RequestContext(request)) +def testfps(request): + url_scheme = "http" + if request.is_secure(): + url_scheme = "https" + fields = {"transactionAmount": "100", + "pipelineName": "SingleUse", + "paymentReason": "Merchant Test", + "paymentPage": request.build_absolute_uri(), + "returnURL": "%s://%s%s" % (url_scheme, + RequestSite(request).domain, + reverse("fps_return_url")) + } + # Save the fps.fields["callerReference"] in the db along with + # the amount to be charged or use the user's unique id as + # the callerReference so that the amount to be charged is known + # Or save the callerReference in the session and send the user + # to FPS and then use the session value when the user is back. + amazon_fps_obj.add_fields(fields) + fields.update({"transactionAmount": "100", + "pipelineName": "Recurring", + "recurringPeriod": "1 Hour", + }) + fps_recur_obj.add_fields(fields) + template_vars = {'title': 'Amazon Flexible Payment Service', + "fps_recur_obj": fps_recur_obj, + "fps_obj": amazon_fps_obj} + return _render(request, 'amazon_fps.html', template_vars) \ No newline at end of file diff --git a/settings/common.py b/settings/common.py index 4e26f209..0b1b7c42 100644 --- a/settings/common.py +++ b/settings/common.py @@ -98,7 +98,7 @@ TEMPLATE_DIRS = ( INSTALLED_APPS = ( 'django.contrib.auth', - 'django.contrib.contenttypes', + 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', @@ -118,7 +118,9 @@ INSTALLED_APPS = ( 'endless_pagination', 'selectable', 'regluit.frontend.templatetags', + 'regluit.payment.templatetags', 'notification', + 'billing', # this must appear *after* django.frontend or else it overrides the # registration templates in frontend/templates/registration