Use lndhub.go v2 endpoint for invoice creation

This commit is contained in:
2024-04-21 10:01:18 +02:00
parent 5685e1b7bc
commit 596ed7fccc
3 changed files with 39 additions and 28 deletions

View File

@@ -71,11 +71,7 @@ class LnurlpayController < ApplicationController
end
def metadata(address)
"[[\"text/identifier\", \"#{address}\"], [\"text/plain\", \"Send sats, receive thanks.\"]]"
end
def zap_metadata(event)
"[[\"application/json\", #{event.to_json}]]"
"[[\"text/identifier\",\"#{address}\"],[\"text/plain\",\"Sats for #{address}\"]]"
end
def valid_amount?(amount_in_sats)
@@ -92,14 +88,14 @@ class LnurlpayController < ApplicationController
return
end
memo = "To #{address}"
memo = "#{memo}: \"#{comment}\"" if comment.present?
desc = "To #{address}"
desc = "#{desc}: \"#{comment}\"" if comment.present?
payment_request = LndhubManager::CreateUserInvoice.call(
invoice = LndhubManager::CreateUserInvoice.call(
user: @user, payload: {
amount: amount, # sats
memo: memo,
description_hash: Digest::SHA2.hexdigest(metadata(address)),
description: desc,
description_hash: Digest::SHA256.hexdigest(metadata(address)),
}
)
@@ -110,7 +106,7 @@ class LnurlpayController < ApplicationController
message: "Sats received. Thank you!"
},
routes: [],
pr: payment_request
pr: invoice["payment_request"]
}
end
@@ -135,15 +131,14 @@ class LnurlpayController < ApplicationController
return
end
payment_request = LndhubManager::CreateUserInvoice.call(
invoice = LndhubManager::CreateUserInvoice.call(
user: @user, payload: {
amount: amount, # sats
# TODO should be npub instead of address?
memo: "Zapped #{@user.address} on Nostr", # TODO include event ID if given
description_hash: Digest::SHA2.hexdigest(zap_metadata(event)),
description: event.to_json,
description_hash: Digest::SHA256.hexdigest(event.to_json),
}
)
render json: { status: "OK", pr: payment_request }
render json: { status: "OK", pr: invoice["payment_request"] }
end
end