Add settled_at to zaps, scope by settlement status
This commit is contained in:
@@ -8,12 +8,13 @@ class WebhooksController < ApplicationController
|
||||
@user = User.find_by!(ln_account: @payload[:user_login])
|
||||
|
||||
if @zap = @user.zaps.find_by(payment_request: @payload[:payment_request])
|
||||
settled_at = Time.parse(@payload[:settled_at])
|
||||
zap_receipt = NostrManager::CreateZapReceipt.call(
|
||||
zap: @zap,
|
||||
paid_at: Time.parse(@payload[:settled_at]).to_i,
|
||||
paid_at: settled_at.to_i,
|
||||
preimage: @payload[:preimage]
|
||||
)
|
||||
@zap.update! receipt: zap_receipt.to_h
|
||||
@zap.update! settled_at: settled_at, receipt: zap_receipt.to_h
|
||||
NostrManager::PublishZapReceipt.call(zap: @zap)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
class Zap < ApplicationRecord
|
||||
belongs_to :user
|
||||
|
||||
scope :settled, -> { where.not(settled_at: nil) }
|
||||
scope :unpaid, -> { where(settled_at: nil) }
|
||||
|
||||
def request_event
|
||||
nostr_event_from_hash(request)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user