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

Add subscription/recurring donation option on Damus website #1754

Closed
alltheseas opened this issue Nov 21, 2023 · 23 comments
Closed

Add subscription/recurring donation option on Damus website #1754

alltheseas opened this issue Nov 21, 2023 · 23 comments
Assignees
Labels
purple Damus purple membership website zaps
Milestone

Comments

@alltheseas
Copy link
Collaborator

alltheseas commented Nov 21, 2023

user story

As a satisfied Damus user who would like to support the Damus team, I would like a way to "subscribe" on the Damus website with sats, so that I can support the Damus team in app maintenance & development.

acceptance criteria

  1. On the Damus.io website, I can find and click on a "subscribe" button
  2. I can see subscribe, and see fiat amountpreset subscription amounts: $5, $10, $20, $30, $50, $100 in both USD, and sats (see satsperusd https://bitbo.io/)
  3. I can set a custom subscription amount
  4. I can optionally provide my npub , or choose to donate anonymously
  5. For Damus internal records it should be clear that the donation originated from website subscriptions

future consideration/how might we

Subscribers could get access to subscriber premium features #659

context

One time donation capability exists #1753

@alltheseas alltheseas changed the title Add recurring donation on Damus website Add recurring donation option on Damus website Nov 21, 2023
@jb55
Copy link
Collaborator

jb55 commented Nov 21, 2023 via email

@alltheseas
Copy link
Collaborator Author

Isn't this just Damus purple?

Damus purple can be a follow on (e.g. multi-account log-ins, long-term storage on damus relay etc). We can add something simpler than Damus purple #659: There can simply be a donation subscription option. My gut feel is that folks would be happy to subscribe to this without purple.

If we want to go the previous zap splits route, we could simply re-add the ⭐️ to Damus donators/subscribers as a way to acknowledge and thank subscribers.

Most people will want to subscribe in app.

You are probably right. Apple will want their cut in app. How might we process sats in app, and pay the apple toll in fiat?

Signal has both in app, and website subscription options.

https://www.signal.org/donate/
Screenshot 2023-11-21 at 12 06 11 PM

image

@alltheseas alltheseas changed the title Add recurring donation option on Damus website Add subscription/recurring donation option on Damus website Nov 21, 2023
@danieldaquino danieldaquino self-assigned this Dec 30, 2023
@danieldaquino
Copy link
Contributor

@jb55, is this the library you mentioned that allows us to integrate lightning payments into the web page?

https://github.com/jb55/lnsocket

@jb55
Copy link
Collaborator

jb55 commented Dec 30, 2023 via email

@danieldaquino
Copy link
Contributor

Thank you @jb55. Quick question on LNSocket, do you know if anyone was able to make it work on an ES5+ javascript/typescript environment (e.g. React)?

I tried several strategies for importing it, but no matter how I try to import it, I get this error:

./node_modules/lnsocket/dist/js/lnsocket.js:46:0
Module not found: Can't resolve 'net'

Looking at LNSocket source code, I believe it is being caused the WebSocket object being undefined from that context (for some reason), and the initializer believing it is inside a node.js context.

I saw this issue in LNSocket: jb55/lnsocket#4. Do you know if there is an easy way for us to get around this issue (perhaps using the WASM module?), or would you recommend me to try using https://github.com/aaronbarnardsound/lnmessage (which seems to be a fork of LNSocket made for this type of javascript environment)

@danieldaquino
Copy link
Contributor

@jb55, nevermind, I found a way that seems to be partially working!

I found a way to import it vanilla JS style (direct <script> tag) and call it from React. I am getting a different error, I will look into it

@jb55
Copy link
Collaborator

jb55 commented Jan 6, 2024 via email

@danieldaquino
Copy link
Contributor

@jb55, no worries, I was able to make the bolt11 invoice generation work with pure lnsocket by importing the code plain JS style (<script> tag), and using it inside of React.

I am currently working on the payment verification with the server. I am researching for the best way to do it, and I am thinking of the following:

  1. Moving the invoice generation code from the client-side page to Purple server and use lnsocket there
  2. Use the waitinvoice rpc from the server-side (similar to how lnlink is using it through the wait_for_invoice function) to wait for payment confirmation (or failure).
  3. Use a Rest API or websockets to communicate between the client and server side and sync the state of payment and to communicate the bolt11 invoice.

If I generate the bolt11 invoice from the server side, and use the waitinvoice rpc call (using lnsocket on both instances) would that be considered a secure lightning payment verification? (Sorry if this is a newbie lightning/lnsocket question)

@danieldaquino
Copy link
Contributor

Sent a draft of the server code changes via email to double-check if my approach seems correct: https://groups.google.com/a/damus.io/g/patches/c/liM3fBWcZG0.

Please let me know if you think this is on the right track, or if you have suggestions! Thanks!

@jb55
Copy link
Collaborator

jb55 commented Jan 6, 2024 via email

@danieldaquino
Copy link
Contributor

Updates for today:

  1. Organized my commits on the server-side changes
  2. Added unit tests to check various important aspects of the invoicing flow.
  3. Fixed several issues with the draft arising from test failures
  4. Created part of the UI flow (with design) on the checkout page. The UX flow is as follows:
    1. Enter npub
    2. The web page will pull up the user's username and picture, as a confirmation mechanism
    3. User presses "pay", which generates the invoice and shows the QR code and lightning link

I am getting close to being able to film a video demo, but I need to work on it a bit more.

I am making the UI and testing it with the server simultaneously. Currently, I am debugging an error I am getting with the Websocket connection during invoice generation.

@danieldaquino
Copy link
Contributor

@jb55, I am having an issue with the node.js version of LNSocket

When I make the first connection to the LN node (connect_and_init specifically), that function times out trying to connect to the LN node.

This timeout seems to only happen on the Node.js version of LNSocket. The browser version seems to work well. Here is what I already checked:

  1. I checked that the nodeid and address arguments being passed are exactly the same as your working LNLink example
  2. With a debugger, I checked that none of the 3 Websocket event handlers from handle_connect are being called. After 15 seconds, the timer just calls setTimeout
  3. My connection code is very similar to the LNLink implementation:
const LNSocket = require('lnsocket')

(...)

class PurpleInvoiceManager {

  (...)

  // Connects and initializes this invoice manager
  async connect_and_init() {
    this.ln = await LNSocket()
    this.ln.genkey()
    console.log(`Connecting to LN node. Node ID: ${this.nodeid}, Address: ${this.address};`)
    await this.ln.connect_and_init(this.nodeid, this.address)
    // Purge old invoices every 10 minutes
    if (PURGE_OLD_INVOICES) {
      this.purging_interval_timer = setInterval(() => this.purge_old_invoices(), 10 * 60 * 1000)
    }
    this.continue_monitoring_invoices()
  }
  
  (...)

}

Have you encountered this type of issue before, and do you happen to know possible causes for this (Perhaps a missing init call, parameter, or dependency)?

@danieldaquino
Copy link
Contributor

@jb55, I believe I found the root cause. There seems to be an inconsistency in API between the browser version and Node.js version of LNSocket. They seem to parse Websocket URLs differently

Image 2024-01-10 at 12 03

I removed the ws:// prefix from the url, and the timeout no longer occurs.

@danieldaquino
Copy link
Contributor

However, sending RPC commands to the LN node does not seem to be working on the node.js version

Debugging reveals that it stays stuck on recv functions. I debugged it all the way down to here:

LNSocket.prototype.queue_recv = function() {
		let self = this
		return new Promise((resolve, reject) => {
			const checker = setInterval(() => {
				const val = self.queue.shift()
				if (val) {
					clearInterval(checker)
					resolve(val)
				} else if (!self.connected) {
					clearInterval(checker)
					reject()
				}
			}, 5);
		})
	}

It seems to be checking and checking, but val stays undefined.

@jb55
Copy link
Collaborator

jb55 commented Jan 10, 2024 via email

@danieldaquino
Copy link
Contributor

Can you send me the connection parameters and code you are using so I
can see what's up?

Sure, thank you!

I sent the current code draft, as well as my .env parameters via email to [email protected] (https://groups.google.com/a/damus.io/g/patches/c/b4vRvTklTuY)

Please let me know if you need more info!

@alltheseas
Copy link
Collaborator Author

Suggest to add a copy "Lightning Invoice" button that copies alphanumeric invoice string

@danieldaquino
Copy link
Contributor

I will continue conversation about this on #1827

@danieldaquino
Copy link
Contributor

The patches for the initial Lightning payment flow were pushed in #1827.

@alltheseas, since the work pushed deviated a bit from what is written in the description, can you please check if this ticket can be closed, or if we need to open other tickets to address remaining items here?

@alltheseas
Copy link
Collaborator Author

Thank you - I just revised. Is there a USD/fiat equivalent displayed in the subscribe to Purple flow?

@danieldaquino
Copy link
Contributor

Thank you - I just revised. Is there a USD/fiat equivalent displayed in the subscribe to Purple flow?

@alltheseas, not yet, but I can add one. Would it be a good idea to add it to #1893 and close this ticket?

@alltheseas
Copy link
Collaborator Author

Yes, added

@danieldaquino
Copy link
Contributor

Thanks @alltheseas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
purple Damus purple membership website zaps
Projects
Archived in project
Development

No branches or pull requests

3 participants