moz_inapp_pay

Python module to work with Mozilla Marketplace in-app payments
Download

moz_inapp_pay Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Kumar McMillan
  • Publisher web site:
  • http://farmdev.com/

moz_inapp_pay Tags


moz_inapp_pay Description

moz_inapp_pay is a Python module to work with Mozilla Marketplace in-app payments.You can read all about how in-app payments work in the developer docs.Mozilla's in-app payments allow you to operate an app that accepts payments for digital goods. As payments are completed, the Mozilla Marketplace needs to communicate the transaction ID to your app. You can use this library to validate the signature of that communication.InstallationWith pip or easy_install, run:pip install moz_inapp_payOr install it from source (recommended):pip install git+git://github.com/kumar303/moz_inapp_pay.gitVerify a postbackimport loggingfrom moz_inapp_pay import InvalidJWT, process_postbacktry: data = process_postback(signed_request, app_key, app_secret) print dataexcept InvalidJWT: loggging.exception('in postback')Verify a chargebackimport loggingfrom moz_inapp_pay import InvalidJWT, process_chargebacktry: data = process_chargeback(signed_request, app_key, app_secret) print data print dataexcept InvalidJWT: logging.exception('in chargeback')Use It With DjangoIf you use the Django framework, there's an app you can plug right into your urls.py.Add the app in your settings.py file:INSTALLED_APPS = Add your key and secret that was granted by the Mozilla Marketplace to your local settings.py file:MOZ_APP_KEY = '< from marketplace.mozilla.org >'MOZ_APP_SECRET = '< from marketplace.mozilla.org >'Do not commit your secret to a public repo. Always keep it secure on your serverAdd the postback / chargeback URLs to your urls.py file:from django.conf.urls.defaults import patterns, includeurlpatterns = patterns('', ('^moz/', include('moz_inapp_pay.djangoapp.urls')),)This will add /moz/postback and /moz/chargeback to your URLs. You'll enter these callback URLs into the in-app payment config screen on the Mozilla Marketplace.If you want to do further processing on the postbacks, you can connect to a few signals. Here is an example of code to go in your app (probably in models.py):import loggingfrom django.dispatch import receiverfrom moz_inapp_pay.djangoapp.signals import (moz_inapp_postback, moz_inapp_chargeback)@receiver(moz_inapp_postback)def mozmarket_postback(request, jwt_data, **kwargs): logging.info('transaction ID %s processed ok' % jwt_data)@receiver(moz_inapp_chargeback)def mozmarket_chargeback(request, jwt_data, **kwargs): logging.info('transaction ID %s charged back; reason: %r' % (jwt_data, jwt_data))Exceptions are logged to the channel moz_inapp_pay.djangoapp.views so be sure to add the appropriate handlers to that.When an InvalidJWT exception occurs, a 400 Bad Request is returned.Product's homepage


moz_inapp_pay Related Software