Skip to content
Webpay is an implementation of the WebPaymentProvider spec
Python Shell Other
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Webpay is an implementation of the WebPaymentProvider spec. It hosts the payment flow inside navigator.mozPay() when making app purchases or in-app payments on Firefox OS.


You need Python 2.6, and MySQL, and a few NodeJS commands like less for minifying JS/CSS. Install system requirements with homebrew (Mac OS X):

brew tap homebrew/versions
brew install python26 mysql swig nodejs

To develop locally you also need an instance of the Solitude payment API running. If you run it with mock services (such as BANGO_MOCK=True) then things will still work. You can configure webpay with SOLITUDE_URL pointing at your localhost.

Let's install webpay! Clone the source:

git clone git://

Install all Python dependencies. You probably want to do this within a virtualenv. If you use virtualenvwrapper (recommended) set yourself up with:

mkvirtualenv --python=python2.6 webpay

Install with:

pip install --no-deps -r requirements/dev.txt

Create a database to work in:

mysql -u root -e 'create database webpay'

Install compressor scripts with npm for node.js. You'll probably want to install them globally in your common node modules, like this:

npm install -g less clean-css uglify-js

Make sure you see a valid path when you type:

which lessc
which cleancss
which uglifyjs

Make yourself a local settings file:

cp webpay/settings/ webpay/settings/

Edit that file and fill in your database credentials. Be sure to also set this so you can see errors:


Sync up your database by running all the migrations:

schematic ./migrations

Now you should be ready to run the test suite:

python test

If they all pass then fire up a development server:

python runserver

Try it out at http://localhost:8000/mozpay/ . If you see a form error about a missing JWT then you are successfully up and running.

If you can't log in with Persona check the value of SITE_URL in your local settings. It must match the URL bar of how you run your dev server exactly.

Using JWTs for development

Each payment begins with a JWT (Json Web Token). You can generate one for testing on the command line like this:

python genjwt

Copy that into a URL and load it. It will look something like this:


Setting Up Your B2G Device

Here is how to set up a device (or B2G desktop) to point to a dev server of webpay. The easiest thing is to use the nightly desktop B2G build.

Start by cloning Gaia and building a custom profile. Refer to the Gaia Hacking page for all the details.

git clone git:// gaia
cd gaia

Create build/custom-prefs.js in that directory. Add this to it:

pref("dom.payment.skipHTTPSCheck", true);
pref("", "firefoxmarketdev");
pref("dom.payment.provider.1.description", "");
pref("dom.payment.provider.1.uri", "http://localhost:8000/mozpay/?req=");
pref("dom.payment.provider.1.type", "mozilla/payments/pay/v1");
pref("dom.payment.provider.1.requestMethod", "GET");
pref("dom.identity.enabled", true);
pref("toolkit.identity.debug", true);

This will access your local webpay server as the payment provider. You may need to bind it to an IP address (or set up port forwarding) if you are working with an actual phone. If you want to work with the Marketplace dev server, change the URI to something like this:

pref("dom.payment.provider.1.uri", "");

Now, when you make or make profile it will create a profile/user.js file with those extra prefs:


If you are using the nightly desktop B2G build then just start it with your custom profile. Here is an example of launching with a custom profile on Mac OS X:

/Applications/ -jsconsole -profile ~/dev/gaia/profile/

IMPORTANT: Use b2g-bin not b2g on Mac OS X.

Starting a custom built B2G app is pretty similar. Just specify the path to the binary you built.

That's it! You should be ready to purchase apps from a properly configured Marketplace app on your B2G.

Configuring Marketplace

To sign app purchasing JWTs that will work in navigator.mozPay([yourJWT]) you can generate them like this:

python genjwt --secret 'some secret' --iss --aud

To get the correct value for some secret you'll have to ask someone in #marketplace on This value should match what the dev server is configured for.

If you want to install your localhost Marketplace app instead of altdev then you'll need to tweak some settings:

APP_PURCHASE_SECRET = 'dev secret'
SITE_URL = 'http://localhost:8001'

These settings will tell Marketplace to sign JWTs for purchase in a similar manner to the genjwt command (above).

Start up your local server exactly like this:

./ --settings=settings_local_mkt  runserver

You'll need to submit an app locally to make sure it is paid. You can also edit one of your apps to make it paid. Make sure your waffle switch disable-payments is not active. That is, switch it off.

Something went wrong with that request. Please try again.