hold_invoice_self_payment_consumer.go raw
1 package transactions
2
3 import (
4 "context"
5
6 "github.com/getAlby/hub/db"
7 "github.com/getAlby/hub/events"
8 )
9
10 type holdInvoiceUpdatedConsumer struct {
11 paymentRequest string
12 settledChannel chan<- *db.Transaction
13 canceledChannel chan<- *db.Transaction
14 }
15
16 func newHoldInvoiceUpdatedConsumer(paymentRequest string, settledChannel chan<- *db.Transaction, canceledChannel chan<- *db.Transaction) *holdInvoiceUpdatedConsumer {
17 return &holdInvoiceUpdatedConsumer{
18 paymentRequest: paymentRequest,
19 settledChannel: settledChannel,
20 canceledChannel: canceledChannel,
21 }
22 }
23
24 func (consumer *holdInvoiceUpdatedConsumer) ConsumeEvent(ctx context.Context, event *events.Event, globalProperties map[string]interface{}) {
25 if event.Event == "nwc_payment_received" && event.Properties.(*db.Transaction).PaymentRequest == consumer.paymentRequest {
26 consumer.settledChannel <- event.Properties.(*db.Transaction)
27 }
28 if event.Event == "nwc_hold_invoice_canceled" && event.Properties.(*db.Transaction).PaymentRequest == consumer.paymentRequest {
29 consumer.canceledChannel <- event.Properties.(*db.Transaction)
30 }
31 }
32