Move lndhub invoice creation to service
This commit is contained in:
parent
c3b82fc2a9
commit
5685e1b7bc
@ -95,11 +95,13 @@ class LnurlpayController < ApplicationController
|
|||||||
memo = "To #{address}"
|
memo = "To #{address}"
|
||||||
memo = "#{memo}: \"#{comment}\"" if comment.present?
|
memo = "#{memo}: \"#{comment}\"" if comment.present?
|
||||||
|
|
||||||
payment_request = @user.ln_create_invoice({
|
payment_request = LndhubManager::CreateUserInvoice.call(
|
||||||
amount: amount, # sats
|
user: @user, payload: {
|
||||||
memo: memo,
|
amount: amount, # sats
|
||||||
description_hash: Digest::SHA2.hexdigest(metadata(address)),
|
memo: memo,
|
||||||
})
|
description_hash: Digest::SHA2.hexdigest(metadata(address)),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
status: "OK",
|
status: "OK",
|
||||||
@ -133,15 +135,14 @@ class LnurlpayController < ApplicationController
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO
|
payment_request = LndhubManager::CreateUserInvoice.call(
|
||||||
# raise zap_metadata(event).inspect
|
user: @user, payload: {
|
||||||
|
amount: amount, # sats
|
||||||
payment_request = @user.ln_create_invoice({
|
# TODO should be npub instead of address?
|
||||||
amount: amount, # sats
|
memo: "Zapped #{@user.address} on Nostr", # TODO include event ID if given
|
||||||
# TODO should be npub instead of address?
|
description_hash: Digest::SHA2.hexdigest(zap_metadata(event)),
|
||||||
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 }
|
render json: { status: "OK", pr: payment_request }
|
||||||
end
|
end
|
||||||
|
@ -143,12 +143,6 @@ class User < ApplicationRecord
|
|||||||
enable_service Setting.default_services
|
enable_service Setting.default_services
|
||||||
end
|
end
|
||||||
|
|
||||||
def ln_create_invoice(payload)
|
|
||||||
lndhub = Lndhub.new
|
|
||||||
lndhub.authenticate self
|
|
||||||
lndhub.addinvoice payload
|
|
||||||
end
|
|
||||||
|
|
||||||
def dn
|
def dn
|
||||||
return @dn if defined?(@dn)
|
return @dn if defined?(@dn)
|
||||||
@dn = Devise::LDAP::Adapter.get_dn(self.cn)
|
@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
|
@ -49,7 +49,8 @@ RSpec.describe "/lnurlpay", type: :request do
|
|||||||
|
|
||||||
describe "GET /lnurlpay/:username/invoice" do
|
describe "GET /lnurlpay/:username/invoice" do
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(User).to receive(:ln_create_invoice).and_return("lnbc50u1p3lwgknpp52g78gqya5euvzjc53fc6hkmlm2rfjhcd305tcmc0g9gaestav48sdq4gdhkven9v5sx6mmwv4ujzcqzpgxqyz5vqsp5skkz4jlqr6tkvv2g9739ygrjupc4rkqd94mc7dfpj3pgx3f6w7qs9qyyssq7mf3fzcuxlmkr9nqatcch3u8uf4gjyawe052tejz8e9fqxu4pncqk3qklt8g6ylpshg09xyjquyrgtc72vcw5cp0dzcf406apyua7dgpnfn7an")
|
allow(LndhubManager::CreateUserInvoice).to receive(:call)
|
||||||
|
.and_return("lnbc50u1p3lwgknpp52g78gqya5euvzjc53fc6hkmlm2rfjhcd305tcmc0g9gaestav48sdq4gdhkven9v5sx6mmwv4ujzcqzpgxqyz5vqsp5skkz4jlqr6tkvv2g9739ygrjupc4rkqd94mc7dfpj3pgx3f6w7qs9qyyssq7mf3fzcuxlmkr9nqatcch3u8uf4gjyawe052tejz8e9fqxu4pncqk3qklt8g6ylpshg09xyjquyrgtc72vcw5cp0dzcf406apyua7dgpnfn7an")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a formatted lnurlpay response" do
|
it "returns a formatted lnurlpay response" do
|
||||||
@ -123,12 +124,12 @@ RSpec.describe "/lnurlpay", type: :request do
|
|||||||
}
|
}
|
||||||
|
|
||||||
it "returns an invoice" do
|
it "returns an invoice" do
|
||||||
expect_any_instance_of(User).to receive(:ln_create_invoice)
|
expect(LndhubManager::CreateUserInvoice).to receive(:call)
|
||||||
.with(
|
.with(user: user, payload: {
|
||||||
amount: 2100,
|
amount: 2100,
|
||||||
memo: "Zapped satoshi@kosmos.org on Nostr",
|
memo: "Zapped satoshi@kosmos.org on Nostr",
|
||||||
description_hash: "540279cd9da15279c8299d6d9ff1ab2a79eb259ee218adf3de393e1abe723077"
|
description_hash: "540279cd9da15279c8299d6d9ff1ab2a79eb259ee218adf3de393e1abe723077"
|
||||||
)
|
})
|
||||||
.and_return("lnbc50u1p3lwgknpp52g78gqya5euvzjc53fc6hkmlm2rfjhcd305tcmc0g9gaestav48sdq4gdhkven9v5sx6mmwv4ujzcqzpgxqyz5vqsp5skkz4jlqr6tkvv2g9739ygrjupc4rkqd94mc7dfpj3pgx3f6w7qs9qyyssq7mf3fzcuxlmkr9nqatcch3u8uf4gjyawe052tejz8e9fqxu4pncqk3qklt8g6ylpshg09xyjquyrgtc72vcw5cp0dzcf406apyua7dgpnfn7an")
|
.and_return("lnbc50u1p3lwgknpp52g78gqya5euvzjc53fc6hkmlm2rfjhcd305tcmc0g9gaestav48sdq4gdhkven9v5sx6mmwv4ujzcqzpgxqyz5vqsp5skkz4jlqr6tkvv2g9739ygrjupc4rkqd94mc7dfpj3pgx3f6w7qs9qyyssq7mf3fzcuxlmkr9nqatcch3u8uf4gjyawe052tejz8e9fqxu4pncqk3qklt8g6ylpshg09xyjquyrgtc72vcw5cp0dzcf406apyua7dgpnfn7an")
|
||||||
|
|
||||||
get lnurlpay_invoice_path(username: "satoshi", params: {
|
get lnurlpay_invoice_path(username: "satoshi", params: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user