GithubHelp home page GithubHelp logo

mozilla / fxpay Goto Github PK

View Code? Open in Web Editor NEW
20.0 16.0 11.0 12.96 MB

JavaScript library for Firefox Marketplace payments

License: BSD 3-Clause "New" or "Revised" License

CSS 1.15% JavaScript 97.80% HTML 1.05%

fxpay's Introduction

fxpay

JavaScript library to support Firefox Marketplace payments in a web application.

Build Status Bower Version devDependency Status

Usage

This is a complete guide to fxpay usage on MDN

Examples

You can find working code in the example directory of this repository

FxPay Developers

To hack on this library you need NodeJS and npm installed. After cloning the source, cd to the root and install all dependencies:

npm install

To execute scripts, you should add the local .bin directory to your $PATH:

PATH="./node_modules/.bin:${PATH}"
export PATH

This is pretty standard for any Node project so you you might already have it.

To test that you have your path set up, type which grunt and make sure you see a path to the executable.

Before going any further, you'll need to install the bower components used for development. Run this:

grunt bower

Compression

To build yourself a compressed version of fxpay.js, run this:

grunt compress

The compressed source file will appear in the build directory as fxpay.min.js. You'll also get a source map file in the same directory as fxpay.min.js.map.

IMPORTANT: To use this library in a web page you have to compress it first because the source code spans multiple files. The usage instructions above explain how to install public releases from Bower which is of course easier.

Running Tests

From a source checkout, run all tests and lint checks like this:

grunt test

To run the JavaScript unit tests continuously while you are developing, type:

grunt karma:dev

This opens a web browser and will report test results to your console. As you edit a code file, it will re-run the tests. NOTE: this can be buggy sometimes.

To fire off a single test run with a browser and see the results, type:

grunt karma:run

Here's how to run a specific test file:

grunt karma:run --tests tests/test-get-products.js

You can also use grep patterns to match files:

grunt karma:run --tests 'tests/test-get-*'

If you want to run a specific test function, you can use a grep pattern to match the name in the describe() or it() definition. For example, run all tests under describe('fxpay.purchase()') like this:

grunt karma:run --grep='fxpay.purchase()'

or run a test defined as it('should open a payment window on the web') like this:

grunt karma:run --grep='should open a payment window on the web'

If you should need to change the karma log-level (default is ERROR) you can do so as follows:

grunt test --log-level=DEBUG

Check For Lint

To check for syntax errors (lint), run:

grunt jshint

Create A Release

You have to do a couple things to create a release:

  • Run grunt release. This compresses the files and copies them to the dist dir.

    • Commit and push your changes to master.
  • Publish the pending github release (or create one) which will tag master at the version string.

    • Make sure all release notes in the draft are up to date.
    • If no release exists yet, create one and title it as the pending version number. For example: 0.0.1.
    • Alternatively, you could manually tag the release with git by running git tag 0.0.1 && git push upstream 0.0.1.
  • Bump the version for the next release. Library version numbers are managed in multiple files. To increment the version number and update all files at once, run grunt bump.

    • Commit and push your changes.

Build the docs

To build the JSDoc API docs locally run grunt docs. The built docs can be found in build/docs.

For anyone with the commit bit that wants to publish the docs to the gh-pages branch of this repo run: grunt publish-docs.

The current API docs are available here: FxPay API Docs (Note: they are currently under development).

Changelog

See the release page

fxpay's People

Contributors

clouserw avatar jaredlockhart avatar kumar303 avatar muffinresearch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fxpay's Issues

Fix-up the ignores

Installing fxpay via bower gives this directory structure:

1__vim

I think we can trim everything from this aside from the license and the min js file.

fxpay.purchase() not working on Android: PAY_REQUEST_ERROR_NO_VALID_REQUEST_FOUND

I am getting the following error when i try to purchase an item on my hosted app pathuku on my andriod phone.

The fxpay.getProducts() is returning the correct product, when i try to purchase it i get a PAY_REQUEST_ERROR_NO_VALID_REQUEST_FOUND error.

I've been unable to solve the problem

App details:
https://marketplace.firefox.com/app/pathuku
https://marketplace.firefox.com/api/v1/apps/app/pathuku/
https://www.pathuku.com/manifest.webapp

Console output:

"creating default adapter" fxpay.min.js:1:25830
"configuring Firefox Marketplace In-App adapter" fxpay.min.js:1:23063
"using adapter:" "<FxInappAdapter at https://marketplace.firefox.com>" fxpay.min.js:1:25909
"(re)configuration completed; fxpay version:" "0.0.16" fxpay.min.js:1:25959
"building a product->receipt map" fxpay.min.js:1:19983
"got appSelf from mozApps.getSelf()" fxpay.min.js:1:13047
"receipts fetched from mozApps:" 0 fxpay.min.js:1:17395
"receipts fetched from localStorage:" 0 fxpay.min.js:1:17442
"about to fetch real products for app" "https%3A%2F%2Fwww.pathuku.com" fxpay.min.js:1:21079
"opening" "GET" "to" "https://marketplace.firefox.com/api/v1/payments/https%3A%2F%2Fwww.pathuku.com/in-app/?active=1" fxpay.min.js:1:4761
"XHR load: GOT response:" "{"meta":{"next":null,"previous":null,"total_count":1,"offset":0,"limit":25},"objects":[{"active":true,"guid":"2116b44b-70c3-4bf4-9918-4dcee15141fe","app":"pathuku","price_id":2,"name":"Level Pack 1","default_locale":"en-us","logo_url":"https://www.pathuku.com/images/LevelPack164x64.png"}]}" fxpay.min.js:1:4368
"total products fetched:" 1 fxpay.min.js:1:21326

"starting purchase for product" "2116b44b-70c3-4bf4-9918-4dcee15141fe" fxpay.min.js:2:1302
"opening" "POST" "to" "https://marketplace.firefox.com/api/v1/webpay/inapp/prepare/" fxpay.min.js:1:4761
"XHR load: GOT response:" "{"contribStatusURL":"/api/v1/webpay/status/fc0b8dff-0c16-4bbb-a742-f4aec591b2a2/","webpayJWT":"eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJhdWQiOiAibWFya2V0cGxhY2UuZmlyZWZveC5jb20iLCAiaXNzIjogIm1hcmtldHBsYWNlLmZpcmVmb3guY29tIiwgInJlcXVlc3QiOiB7ImNoYXJnZWJhY2tVUkwiOiAiaHR0cHM6Ly9tYXJrZXRwbGFjZS5maXJlZm94LmNvbS9zZXJ2aWNlcy93ZWJwYXkvY2hhcmdlYmFjayIsICJuYW1lIjogIkxldmVsIFBhY2sgMSIsICJwcm9kdWN0RGF0YSI6ICJhZGRvbl9pZD0zOTc1NTQmcHVibGljX2lkPWNjMjA2YWQyLWUyYTEtNDc0Yy04MjAxLWJhYmUwOWM4ZWRkOCZhcHBsaWNhdGlvbl9zaXplPU5vbmUmaW5hcHBfaWQ9MTA4JmNvbnRyaWJfdXVpZD1mYzBiOGRmZi0wYzE2LTRiYmItYTc0Mi1mNGFlYzU5MWIyYTIiLCAiaWNvbnMiOiB7IjY0IjogImh0dHBzOi8vd3d3LnBhdGh1a3UuY29tL2ltYWdlcy9MZXZlbFBhY2sxNjR4NjQucG5nIn0sICJkZWZhdWx0TG9jYWxlIjogbnVsbCwgInByaWNlUG9pbnQiOiAiMjAiLCAicG9zdGJhY2tVUkwiOiAiaHR0cHM6Ly9tYXJrZXRwbGFjZS5maXJlZm94LmNvbS9zZXJ2aWNlcy93ZWJwYXkvcG9zdGJhY2siLCAiaWQiOiAiaW5hcHAubWFya2V0cGxhY2U6MTA4IiwgImxvY2FsZXMiOiB7fSwgImRlc2NyaXB0aW9uIjogIlBhdGh1a3UgLSBDb25uZWN0IHRoZSBsaW5lcy5cblxuQ29tcGxldGUga    nVzdCA1IGxldmVscyBhbmQgeW91IHdpbGwgYmUgYWRkaWN0ZWQhXG5cblBhdGh1a3UgaXMgYSBmcmVlIEV1bGVyaWFuIHB1enpsZSBnYW1lIGluIHdoaWNoIHlvdSBoYXZlIHRvIGNvbm5lY3QgdXAgYWxsIHRoZSBkb3RzLCBidXQgYmUgY2FyZWZ1bCBiZWNhdXNlIHlvdSBjYW5ub3QgY3Jvc3MgYSBwYXRoIHR3aWNlLiBBbHNvIGRvbid0IGdvIHRvbyBzbG93IG9yIHRoZSBjaGFzZXIgd2lsbCBjYXRjaCB5b3UgdXAgYW5kIHlvdSB3aWxsIGhhdmUgdG8gcmVzdGFydCB0aGUgbGV2ZWwuXG5cbjYwIExldmVscyJ9LCAiZXhwIjogMTQzMzM3MTE1MSwgImlhdCI6IDE0MzMzNjc1NTEsICJ0eXAiOiAibW96aWxsYS9wYXltZW50cy9wYXkvdjEifQ.agd4HChFOoLxDfRNhT0Y_ovd8hLqsTqyWsHIGI64elA"}" fxpay.min.js:1:4368
"requested JWT for " "2116b44b-70c3-4bf4-9918-4dcee15141fe" "from API; got:" Object { contribStatusURL: "/api/v1/webpay/status/fc0b8dff-0c16…", webpayJWT: "ey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YW1lIGluIHdoaWNoIHlvdSBoYXZlIHRvIGNvbm5lY3QgdXAgYWxsIHRoZSBkb3RzLCBidXQgYmUgY2FyZWZ1bCBiZWNhdXNlIHlvdSBjYW5ub3QgY3Jvc3MgYSBwYXRoIHR3aWNlLiBBbHNvIGRvbid0IGdvIHRvbyBzbG93IG9yIHRoZSBjaGFzZXIgd2lsbCBjYXRjaCB5b3UgdXAgYW5kIHlvdSB3aWxsIGhhdmUgdG8gcmVzdGFydCB0aGUgbGV2ZWwuXG5cbjYwIExldmVscyJ9LCAiZXhwIjogMTQzMzM3MTE1MSwgImlhdCI6IDE0MzMzNjc1NTEsICJ0eXAiOiAibW96aWxsYS9wYXltZW50cy9wYXkvdjEifQ.agd4HChFOoLxDfRNhT0Y_ovd8hLqsTqyWsHIGI64elA" fxpay.min.js:1:29480
"mozPay: received onerror():" "PAY_REQUEST_ERROR_NO_VALID_REQUEST_FOUND" fxpay.min.js:1:29578

"PayPlatformError: mozPay error: PAY_REQUEST_ERROR_NO_VALID_REQUEST_FOUND {code: PAY_REQUEST_ERROR_NO_VALID_REQUEST_FOUND}" fxpay.min.js:1:26477

"error purchasing:PayPlatformError: mozPay error: PAY_REQUEST_ERROR_NO_VALID_REQUEST_FOUND {code: PAY_REQUEST_ERROR_NO_VALID_REQUEST_FOUND}" main.js:1:10798

I've run out of things to try.

Consider removing circular deps to enable us to use amdclean

We now have everything as AMD modules which is then built into a combined file. Given we have no dynamic deps it would be nice to be able to remove the amd wrappers in the built file and then just wrap that in UMD. Unfortunately amdclean doesn't handle circular deps so the module order gets out of whack and TypeErrors are thrown for undefined modules.

Given the file size is pretty good uglified we may not need to worry about this.

Add tests to cover all the variants of UMD

We are currently running tests that use requirejs in the tests to pull in the various modules. This validates the AMD layout. It would be nice to have some tests that cover all the various ways one can utilise the lib via the UMD wrapper.

Allow installation via npm

React and other packages can be pulled into a project via npm and included via webpack/browserify.

fxpay is private and can't be included.

fxpay "XHR error event" error

I have added FireFox Marketplace in-app payments to my game pathuku using fxPay.

Everything seems to be working when i use the fakeProducts setting below:

fxpay.configure({fakeProducts: true});

When i try to use fxPay in Live i get the following in my console:

ok
23:30:46.305 "opening" "GET" "to" "https://marketplace.firefox.com/api/v1/payments/https%3A%2F%2Fwww.pathuku.com/in-app/?active=1"1 fxpay.min.js:1:476

error
23:30:46.681 "XHR error event:" error { target: XMLHttpRequest, isTrusted: true, lengthComputable: false, loaded: 0, total: 0, currentTarget: XMLHttpRequest, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1432593046679000 }1 fxpay.min.js:1:4078

error
23:30:46.690 "Error getting products:ApiRequestError: received XHR error for path: /payments/https%3A%2F%2Fwww.pathuku.com/in-app/?active=1"1 main.js:1:10765
 _eo/b.e5.fxpay.checkForPurcs/<() main.js:1
z() fxpay.min.js:1
A() fxpay.min.js:1
x() fxpay.min.js:1
t() fxpay.min.js:1
j() fxpay.min.js:1

A http OPTIONS request is made to
https://marketplace.firefox.com/api/v1/payments/https%3A%2F%2Fwww.pathuku.com/in-app/?active=1

The url seems to be working, but i don't understand why only a OPTIONS request is being made?

My game urls are
https://marketplace.firefox.com/app/pathuku/
https://www.pathuku.com/manifest.webapp
https://www.pathuku.com

Do i need a "type" in my manifest? Ideally i want the in-app payments to work from any platform not just FireFox OS.

Any help would be very welcome

Reconfigure adapter when `fxpay.configure` is called.

Currently the defaultAdapter is running with the default settings which means that if you configure the baseApiUrl to be stage, when it gets to doing preparing the tranasaction it uses the default baseApiUrl e.g. prod.

Move logging into its own module.

Currently logging is part of settings. It should be its own module.

Any changes to logging need to ensure the correct lines are reported.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.