Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle HTTP 402 payment required responses #46

Open
bumi opened this issue Nov 27, 2018 · 6 comments
Open

Handle HTTP 402 payment required responses #46

bumi opened this issue Nov 27, 2018 · 6 comments

Comments

@bumi
Copy link
Contributor

bumi commented Nov 27, 2018

I am wondering what your thoughts are on trying to handle HTTP 402 responses to request payments:
If a server responds with a 402 HTTP status and a lightning invoice the extension could prompt the user to confirm the payment and "refresh" the page with a proof of payment.
(if auto-payments are enabled for the domain the payment could be done automatically.)

From what I've seen so far it might be tricky to get this working with the available extensions APIs, but I've looked into the chrome.webRequest.onBeforeSendHeaders which allows to check the response headers and to block/redirect the request... maybe it can somehow be hacked.

I've lately experimented with a similar flow for API requests (blog post) also ln-paywall is pretty cool.

Would love to see this to pay for content :)

@wbobeirne
Copy link
Member

wbobeirne commented Nov 27, 2018

This is a really interesting concept! The extension webRequest API could definitely jump in here, but I feel like it would result in a much better user experience if the application handled the 402 error, and presented the user with a BOLT-11 link to make the payment (or a webln.sendPayment call to trigger the payment prompt.)

I'm definitely open to this though, if there comes to be a standard around using the 402 response (ln-paywall looks promising.) However, I'm sure everyone will implement it slightly differently (plaintext bolt-11 string, JSON object with the bolt-11 string as a key, etc.)

@bumi
Copy link
Contributor Author

bumi commented Nov 28, 2018

ahhh...hmmm. so you mean rendering the 402 as a page with a BOLT-11 link that triggers the payment?
that's probably easier to implement.
my motivation somehow is to make it as frictionless as possible to pay/tip for content - ideally with hardly any user interaction (on trusted sites).

regarding the standard: yep, indeed that's a problem. my ruby implementation and the go implementation are compatible. I guess it is the time right now to experiment with what works best and encourage adoption.

Also have you looked at the W3C payment request API? (I think @cdecker is part of the working group) - that's a bit of a different topic/issue though.

@JASchilz
Copy link

JASchilz commented Nov 29, 2018

Another idea for placing a Bolt-11 invoice in a 402 response: in a header.

A header would require the least coupling between client and server. If the invoice is in a header rather than the body, then the client doesn't have to know to look for the invoice under a particular JSON key, or inside of an XML tag with a particular ID, etc.

On the other hand, defining a new header or using an existing one might be stepping on the toes of the HTTP protocol group.

@wbobeirne
Copy link
Member

It looks like that's exactly how ln-paywall functions: https://github.com/philippgille/ln-paywall/blob/master/README.md#how-it-works

@JASchilz
Copy link

If I'm reading it correctly, it looks like the client returns the payment preimage in a header, but the payment request itself is in the body. But putting it alone in the body seems like a fairly de-coupled solution as well!

@bumi
Copy link
Contributor Author

bumi commented Nov 29, 2018

yep, ln-paywall and rack-lightning are both using the body for the lightning invoice (content type application/vnd.lightning.bolt11)

I like the idea of using a header. The content type then can be HTML and a normal page can be returned for browsers without the extension.
The extension could listen for HTTP 402 responses and prompt the user to pay the payment request from the header.

wbobeirne pushed a commit that referenced this issue Oct 13, 2020
…r-dom-5.1.5

Upgrade @types/react-router-dom: 4.3.5 → 5.1.5 (major)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants