Merge branch 'ry' of github.com:Gluejar/regluit

pull/1/head
Raymond Yee 2012-05-03 18:41:21 +00:00
commit a62d988249
6 changed files with 17 additions and 391 deletions

View File

@ -1,108 +0,0 @@
"""
https://github.com/agiliq/merchant/blob/master/example/app/integrations/fps_integration.py
"""
import billing
from billing.integrations.amazon_fps_integration import AmazonFpsIntegration as Integration
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse
import urlparse
import logging
logger = logging.getLogger(__name__)
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("&")))
logger.info("dd: {0}".format(dd))
logger.info("self.fps_connection.host: {0}".format(self.fps_connection.host))
# dd: {'status': 'SC', 'signatureVersion': '2',
# 'tokenID': 'CLDITXQAX2DM82CT184S5CDNKYDXEPXETZ5QJFKB8AX4V9ZD34BGGJ6IDNFZDSUU',
# 'certificateUrl': 'https%3A%2F%2Ffps.sandbox.amazonaws.com%2Fcerts%2F090911%2FPKICert.pem%3FrequestId%3Dbjzj0zgbg2uf2j46a1iq123b9rwzl694mvpstlw1p5il426x7ap',
# 'expiry': '10%2F2017', 'signatureMethod': 'RSA-SHA1', 'callerReference': '5e0f7b0d-5cc5-4a55-a646-c6e420dd0f11',
# 'signature': 'Cc64A8DP7VclFBrhFEDXr2yhP8LaJpaLC6n%2F5oXiAhhD%2BnjJH9jQRhwPgB%2BuRvdcObMmZTD9we9G%0AvmEAkd5NkVULESdipsW%2B4i62mtD0DseuAtotMzjqObEeekzkaz4Vo0X9xcdlytLR04aEb4xqsLtg%0AJU%2Fysy7KStRivTqKzug%3D'}
# need to act based on status
# getting status=SC, which doesn't seem to be in the documentation -- the docs say "SR":
# http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/CBUIapiMerchant.html
# status = SC/SR, A, CE, NP, NM
if dd.get('status') in ['SC', 'SR']:
# check to see whether we recognize this transaction -- correlate by callerReference
callerReference = dd.get('callerReference')
if callerReference is not None:
try:
trans = billing.models.AmazonFPSResponse.objects.get(callerReference=callerReference)
except billing.models.AmazonFPSResponse.DoesNotExist:
return HttpResponse('callerReference not recognized')
except Exception, e:
logger.exception("Error: {0}".format(e))
return HttpResponse('Error: {0}'.format(e))
else:
logger.warning('no callerReference included')
return HttpResponse('no callerReference included')
try:
transactionAmount = trans.transactionAmount
# should also have stored in the database that this is a purchase....
logger.info('transactionAmount: {0}; dd:{1}'.format(transactionAmount, dd))
resp = self.purchase(transactionAmount, dd)
except Exception, e:
logger.exception("Error: {0}".format(e))
return HttpResponse('Error: {0}'.format(e))
# resp: status representing the status and response representing the response as described by boto.fps.response.FPSResponse.
# mystery stuff with https://github.com/boto/boto/blob/develop/boto/resultset.py and
# https://github.com/boto/boto/blob/develop/boto/fps/response.py
#In [17]: resp['response'].RequestId
#Out[17]: u'1f7b74a5-977a-4ffe-9436-d3c0203a6a85:0'
#
#In [18]: resp['response'].TransactionId
#Out[18]: u'16QVZ98TK48G3AK2QR1N1JJN8TLPE41R3NU'
#
#In [19]: resp['response'].TransactionStatus
#Out[19]: u'Pending'
#
#In [20]: resp['status']
#Out[20]: u'Pending'
#
#In [21]: resp['response'].PayResult
#Out[21]: ''
#
#In [22]: resp['response'].PayResponse
#Out[22]: ''
#
#In [23]: resp['response'].connection
#Out[23]: FPSConnection:fps.sandbox.amazonaws.com
# Now process the response
trans.transactionId = resp['response'].TransactionId
trans.transactionStatus = resp['response'].TransactionStatus
trans.save()
logger.debug("transactionId: {0}, transactionStatus: {1}".format(trans.transactionId, trans.transactionStatus ))
return HttpResponseRedirect("%s?status=%s" %(reverse("testfps"),
resp["status"]))
elif dd.get('status') == 'A':
return HttpResponse('You cancelled the transaction')
else:
return HttpResponse('An unexpected status code: {0}'.format(dd.get('status')))

View File

@ -1,11 +1,6 @@
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", options={'host':'fps.sandbox.amazonaws.com'})
fps_recur_obj = get_integration("fps", options={'host':'fps.sandbox.amazonaws.com'})
urlpatterns = patterns(
"regluit.payment.views",
@ -34,10 +29,5 @@ if not settings.IS_PREVIEW:
url(r"^testrefund", "testRefund"),
url(r"^testmodify", "testModify"),
)
urlpatterns += patterns('',
(r'^fps/', include(amazon_fps_obj.urls)),
url(r'^testfps/$', 'regluit.payment.views.testfps', name='testfps'),
)

View File

@ -15,8 +15,6 @@ 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 billing
import uuid
from decimal import Decimal as D
@ -324,54 +322,5 @@ def checkStatus(request):
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"
# generate a callerReference to use in our call
callerReference = str(uuid.uuid4())
# model stores TransactionAmount as string! We won't be doing this in our long-term model
transactionAmount = str(D(100.00))
fields = {"transactionAmount": transactionAmount,
"pipelineName": "SingleUse",
"paymentReason": "Merchant Test",
"paymentPage": request.build_absolute_uri(),
"callerReference": callerReference,
"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)
# let's save this object to the model that django-merchant has set up for amazon transactions
# billing.models.AmazonFPSResponse.objects.all()
fps_transaction = billing.models.AmazonFPSResponse()
fps_transaction.transactionDate = now()
fps_transaction.transactionAmount = 100.00
fps_transaction.callerReference = callerReference
# force a calculation of the link_url so that callerReference gets calculated
logger.info("amazon_fps_obj.link_url: {0}".format(amazon_fps_obj.link_url))
fps_transaction.save()
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)

View File

@ -120,7 +120,6 @@ INSTALLED_APPS = (
'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
@ -270,4 +269,4 @@ AMAZON_FPS_HOST = "fps.sandbox.amazonaws.com"
#AMAZON_FPS_HOST = "fps.amazonaws.com"
# amazon or paypal for now.
PAYMENT_PROCESSOR = 'amazon'
PAYMENT_PROCESSOR = 'amazon'

File diff suppressed because one or more lines are too long