Move lndhub invoice creation to service
This commit is contained in:
@@ -95,11 +95,13 @@ class LnurlpayController < ApplicationController
|
||||
memo = "To #{address}"
|
||||
memo = "#{memo}: \"#{comment}\"" if comment.present?
|
||||
|
||||
payment_request = @user.ln_create_invoice({
|
||||
amount: amount, # sats
|
||||
memo: memo,
|
||||
description_hash: Digest::SHA2.hexdigest(metadata(address)),
|
||||
})
|
||||
payment_request = LndhubManager::CreateUserInvoice.call(
|
||||
user: @user, payload: {
|
||||
amount: amount, # sats
|
||||
memo: memo,
|
||||
description_hash: Digest::SHA2.hexdigest(metadata(address)),
|
||||
}
|
||||
)
|
||||
|
||||
render json: {
|
||||
status: "OK",
|
||||
@@ -133,15 +135,14 @@ class LnurlpayController < ApplicationController
|
||||
return
|
||||
end
|
||||
|
||||
# TODO
|
||||
# raise zap_metadata(event).inspect
|
||||
|
||||
payment_request = @user.ln_create_invoice({
|
||||
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)),
|
||||
})
|
||||
payment_request = 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)),
|
||||
}
|
||||
)
|
||||
|
||||
render json: { status: "OK", pr: payment_request }
|
||||
end
|
||||
|
||||
@@ -143,12 +143,6 @@ class User < ApplicationRecord
|
||||
enable_service Setting.default_services
|
||||
end
|
||||
|
||||
def ln_create_invoice(payload)
|
||||
lndhub = Lndhub.new
|
||||
lndhub.authenticate self
|
||||
lndhub.addinvoice payload
|
||||
end
|
||||
|
||||
def dn
|
||||
return @dn if defined?(@dn)
|
||||
@dn = Devise::LDAP::Adapter.get_dn(self.cn)
|
||||
|
||||
13
app/services/lndhub_manager/create_user_invoice.rb
Normal file
13
app/services/lndhub_manager/create_user_invoice.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module LndhubManager
|
||||
class CreateUserInvoice < Lndhub
|
||||
def initialize(user:, payload:)
|
||||
@user = user
|
||||
@payload = payload
|
||||
end
|
||||
|
||||
def call
|
||||
authenticate @user
|
||||
addinvoice @payload
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user