First pass at trying to integrate Amazon fps
parent
57bf9b8852
commit
00511e4730
|
@ -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"]))
|
|
@ -0,0 +1,14 @@
|
|||
{% load amazon_fps_tags %}
|
||||
|
||||
{% block content %}
|
||||
<div>
|
||||
<p>You are going to be charged $100 in the
|
||||
<a href="https://payments.amazon.com/sdui/sdui/helpTab/Amazon-Flexible-Payments-Service/Technical-Resources/Amazon-FPS-Sandbox">Amazon FPS Sandbox</a>.</p>
|
||||
<p>{% amazon_fps fps_obj %}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p>(Recurring payments) You are going to be charged $100 every hour in the
|
||||
<a href="https://payments.amazon.com/sdui/sdui/helpTab/Amazon-Flexible-Payments-Service/Technical-Resources/Amazon-FPS-Sandbox">Amazon FPS Sandbox</a>.</p>
|
||||
<p>{% amazon_fps fps_recur_obj %}</p>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -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)
|
|
@ -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)),
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue