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.
brew tap homebrew/versions brew install python26 mysql swig nodejs
Clone the source:
git clone git://github.com/mozilla/webpay.git
mkvirtualenv --python=python2.6 webpay
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/local.py-dist webpay/settings/local.py
Edit that file and fill in your database credentials. Be sure to also set this so you can see errors:
VERBOSE_LOGGING = True
Sync up your database by running all the migrations:
Now you should be ready to run the test suite:
python manage.py test
If they all pass then fire up a development server:
python manage.py runserver 0.0.0.0:8000
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.
Each payment begins with a JWT (Json Web Token). You can generate one for testing on the command line like this:
python manage.py genjwt
Copy that into a URL and load it. It will look something like this:
There is no easy way to point your B2G device at your local webpay instance because it forces the server to run with https. Unless you have an https proxy to your local server it won't work. Here is how to at least set your device up to point to the dev server.
You need to edit your user.js file to add some preferences. This is found in your Firefox profile so there are a few ways to do it.
The best way is to clone Gaia and build a custom profile. Refer to the Gaia Hacking page for all the details.
You start with the source:
git clone git://github.com/mozilla-b2g/gaia.git gaia cd gaia
Then you create build/custom-prefs.js in that directory. Add this to it:
pref("dom.payment.provider.1.name", "firefoxmarketdev"); pref("dom.payment.provider.1.description", "marketplace-dev.allizom.org"); pref("dom.payment.provider.1.type", "mozilla/payments/pay/v1"); pref("dom.payment.provider.1.uri", "https://marketplace-dev.allizom.org/mozpay/?req="); pref("dom.payment.provider.1.requestMethod", "GET");
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/B2G.app/Contents/MacOS/b2g-bin -jsconsole -profile ~/dev/gaia/profile/
Starting a custom built B2G app is pretty similar. Just specify the path to the binary you built.
To sign app purchasing JWTs that will work in navigator.mozPay([yourJWT]) you can generate them like this:
python manage.py genjwt --secret 'some secret' --iss marketplace-dev.allizom.org --aud marketplace-dev.allizom.org
To get the correct value for some secret you'll have to ask someone in #marketplace on irc.freenode.net. This value should match what the dev server is configured for.
Download a nightly B2G desktop. Clone or update gaia from master:
git clone git://github.com/mozilla-b2g/gaia.git cd gaia
Inside your gaia clone, add a file at build/custom-prefs.js and add this:
pref("dom.payment.provider.1.name", "firefoxmarketdev"); pref("dom.payment.provider.1.description", "marketplace-dev.allizom.org"); pref("dom.payment.provider.1.type", "mozilla/payments/pay/v1"); pref("dom.payment.provider.1.uri", "https://marketplace-dev.allizom.org/mozpay/?req="); pref("dom.payment.provider.1.requestMethod", "GET"); pref("dom.identity.enabled", true); pref("toolkit.identity.debug", true);
Now make a profile to use:
Next, start up the custom B2G desktop app up with that profile:
/Applications/B2G.app/Contents/MacOS/b2g-bin -jsconsole -profile ~/src/gaia/profile/
You are now ready to install the Marketplace app on B2G to test with. You can load this in the B2G browser for convenience: http://people.mozilla.com/~kmcmillan/mktdev.html Click the Install Marketplace altdev button since that is currently configured to work.
Launch the shiny Marketplace app and make a purchase. Search for a paid app (e.g. CHIRP Radio) and try to make a purchase. If everything worked you should be connecting to the dev version of webpay at https://marketplace-dev.allizom.org/mozpay/
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'
Start up your local server exactly like this:
./manage.py --settings=settings_local_mkt runserver 0.0.0.0:8001
You might 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.