{"id":25716342,"url":"https://github.com/interledgerjs/hapi-web-monetization","last_synced_at":"2026-06-11T02:31:41.189Z","repository":{"id":65996768,"uuid":"126256405","full_name":"interledgerjs/hapi-web-monetization","owner":"interledgerjs","description":null,"archived":false,"fork":false,"pushed_at":"2018-11-20T19:34:29.000Z","size":109,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-19T02:02:53.931Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/interledgerjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-22T00:19:50.000Z","updated_at":"2018-11-20T19:34:28.000Z","dependencies_parsed_at":"2023-03-23T17:34:59.402Z","dependency_job_id":null,"html_url":"https://github.com/interledgerjs/hapi-web-monetization","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/interledgerjs/hapi-web-monetization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interledgerjs%2Fhapi-web-monetization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interledgerjs%2Fhapi-web-monetization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interledgerjs%2Fhapi-web-monetization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interledgerjs%2Fhapi-web-monetization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/interledgerjs","download_url":"https://codeload.github.com/interledgerjs/hapi-web-monetization/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interledgerjs%2Fhapi-web-monetization/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34180147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-25T14:53:06.208Z","updated_at":"2026-06-11T02:31:41.176Z","avatar_url":"https://github.com/interledgerjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DEPRECATED\nThis module has been deprecated in favor of [web-monetization-receiver](https://github.com/interledgerjs/web-monetization-receiver).\n\n# Hapi Web Monetization\n\u003e Charge for resources and API calls with web monetization\n\n- [Overview](#overview)\n- [Example Code](#example-code)\n- [Try it Out](#try-it-out)\n  - [Prerequisites](#prerequisites)\n  - [Install and Run](#install-and-run)\n- [API Docs](#api-docs)\n  - [Server register options](#server-register-options)\n  - [Client constructor options](#client-constructor-options)\n  - [Charging users](#charging-users)\n\n## Overview\n\nUsing [Interledger](https://interledger.org) for payments, [Web\nMonetization](https://github.com/interledger/rfcs/blob/master/0028-web-monetization/0028-web-monetization.md#web-monetization)\nallows sites to monetize their traffic without being tied to an ad network. And\nbecause payments happen instantly, they can also be tracked on the server-side\nto unlock exclusive content or paywalls.\n\n`hapi-web-monetization` makes this easy by providing middleware for your\n[Hapi](https://hapijs.com/) application. Charging your users is as easy as putting\n`request.spend(100)` in your route handler. No need to convince them to\nbuy a subscription or donate.\n\n## Example Code\n\nBelow is an example of some of the functions that you would use to create\npaywalled content. For a complete and working example, look at the next\nsection.\n\n```js\nconst Hapi = require('hapi')\n\nconst server = Hapi.server({\n  port: 8080,\n  host: 'localhost'\n})\n\nconst options = {\n  cookieOptions: {\n    isSecure: true\n  }\n}\n\nconst start = async () =\u003e {\n  await server.register(require('inert'))\n  await server.register({\n    plugin: require('hapi-web-monetization'),\n    options\n  })\n\n  server.route([\n    {\n      method: 'GET',\n      path: '/',\n      handler: function (request, reply) {\n        // Load index page\n      }\n    },\n    {\n      method: 'GET',\n      path: '/content/',\n      handler: async function (request, reply) {\n        await request.awaitBalance(100)\n        request.spend(100)\n        // Send paid content\n      }\n    },\n  ])\n\n  await server.start()\n\n  console.log('Server running at:', server.info.uri)\n}\n\nstart()\n\n```\n\nThe client side code to support this is very simple too:\n\n```html\n\u003cscript src=\"node_modules/hapi-web-monetization/client.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  var monetizerClient = new MonetizerClient();\n  monetizerClient.start()\n    .then(function() {\n      var img = document.createElement('img')\n      var container = document.getElementById('container')\n      img.src = '/content/'\n      img.width = '600'\n      container.appendChild(img)\n    })\n    .catch(function(error){\n      console.log(\"Error\", error);\n    })\n\u003c/script\u003e\n```\n\n## Try it out\n\nThis repo comes with an example server that you can run. It serves a page that has a single paywalled image on it.\nThe server waits for money to come in and then shows the image.\n\n### Prerequisites\n\n- You should be running [Moneyd](https://github.com/interledgerjs/moneyd-xrp)\n  for Interledger payments. [Local\n  mode](https://github.com/interledgerjs/moneyd-xrp#local-test-network) will work\n  fine.\n\n- Build and install the [Minute](https://github.com/sharafian/minute)\n  extension. This adds Web Monetization support to your browser.\n\n### Install and Run\n\n```sh\ngit clone https://github.com/andywong418/hapi-web-monetization.git\ncd hapi-web-monetization\nnpm install\nDEBUG=* node example/index.js\n```\n\nNow go to [http://localhost:8080](http://localhost:8080), and watch the server\nlogs.\n\nIf you configured Minute and Moneyd correctly, you'll start to see that money\nis coming in. Once the user has paid 100 units, the example image will load on\nthe page.\n\n## API Docs\n### Server register options\n\n```ts\n  server.register({\n    plugin: require('hapi-web-monetization'),\n    options : Object | void\n  })\n```\n\nRegisters a new `HapiWebMonetization` plugin which creates and sets cookie for the payer ID in the browser.\n- `options.plugin` - Supply an ILP plugin. Defaults to using Moneyd.\n- `options.maxBalance` - The maximum balance that can be associated with any user. Defaults to `Infinity`.\n- `options.receiveEndpointUrl` - The endpoint in your Hapi route configuration that specifies where a user pays streams PSK packets to your site. Defaults to `/__monetizer/{id}` where `{id}` is the server generated ID (stored in the browser as a cookie).\n- `options.cookieName` - The cookie key name for your server generated payer ID. Defaults to `__monetizer`.\n- `options.cookieOptions` - Cookie configurations for Hapi. See [Hapi server state options](https://hapijs.com/api#-serverstatename-options) for more details!\n\n### Client constructor options\n\n```ts\nnew MonetizerClient(options: Object | void): MonetizerClient\n```\nCreates a new `MonetizerClient` instance.\n\n- `options.url` - The url of the server that is registering the HapiWebMonetization plugin. Defaults to `new URL(window.location).origin`\n- `options.cookieName` - The cookie key name that will be saved in your browser. Defaults to `__monetizer`. This MUST be the same has `options.cookieName` in the server configuration.\n- `options.receiverUrl` - The endpoint where users of the site can start streaming packets via their browser extension or through the browser API. Defaults to `options.url + '__monetizer/:id'` where id is the server generated payer ID. This MUST be the same has `options.receiverEndpointUrl` in the server configuration.\n\n### Charging users\n\nThe methods `request.spend()` and `request.awaitBalance()` are available to use inside handlers.\n\n```ts\nrequest.spend(amount): Function\n```\nSpecifies how many units to charge the user.\n\n```ts\nrequest.awaitBalance(amount): Function\n```\nWaits until the user has sufficient balance to pay for specific content.\n`awaitBalance` can be useful for when a call is being done at page start.\nRather than immediately failing because the user hasn't paid, the server will\nwait until the user has paid the specified price.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterledgerjs%2Fhapi-web-monetization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finterledgerjs%2Fhapi-web-monetization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterledgerjs%2Fhapi-web-monetization/lists"}