File tree Expand file tree Collapse file tree
phoenix-shared/src/commonMain/kotlin/fr.acinq.phoenix/managers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -789,16 +789,14 @@ class BusinessManager {
789789 case . abortHandledElsewhere( _) :
790790 log. warning ( " handleCardReqeust: abort: handled elsewhere " )
791791
792- case . continueAndSendPayment( _ , _, _) :
792+ case . continueAndSendPayment( let card , _, _) :
793793 log. debug ( " handleCardReqeust: continue: send payment " )
794794
795- guard let peer = business. peerManager. peerStateValue ( ) else {
796- log. error ( " handleCardReqeust: peer is nil " )
797- return
798- }
799-
800795 do {
801- try await peer. payUnsolicitedInvoice ( invoice: cardRequest. invoice)
796+ try await business. sendManager. payUnsolicitedInvoice (
797+ invoice: cardRequest. invoice,
798+ metadata: WalletPaymentMetadata . withCard ( card. id)
799+ )
802800 } catch {
803801 log. error ( " peer.payUnsolicitedInvoice(): error: \( error) " )
804802 }
Original file line number Diff line number Diff line change @@ -553,23 +553,20 @@ class NotificationService: UNNotificationServiceExtension {
553553 case . abortHandledElsewhere( _) :
554554 log. warning ( " handleCardReqeust: abort: handled elsewhere " )
555555
556- case . continueAndSendPayment( _ , _, _) :
556+ case . continueAndSendPayment( let card , _, _) :
557557 log. debug ( " handleCardReqeust: continue: send payment " )
558558
559- guard let peer = business. peerManager. peerStateValue ( ) else {
560- log. error ( " handleCardReqeust: peer is nil " )
561- return
562- }
563-
564559 // Send the payment
565560 do {
566- try await peer. payUnsolicitedInvoice ( invoice: cardRequest. invoice)
561+ try await business. sendManager. payUnsolicitedInvoice (
562+ invoice: cardRequest. invoice,
563+ metadata: WalletPaymentMetadata . withCard ( card. id)
564+ )
567565 } catch {
568566 log. error ( " peer.payUnsolicitedInvoice(): error: \( error) " )
569567 }
570568
571569 // Wait for the outgoing payment to complete
572- let paymentHash = cardRequest. invoice. paymentHash
573570 business. paymentsManager. lastCompletedPaymentPublisher ( ) . sink { payment in
574571 if let lnPayment = payment as? Lightning_kmpLightningOutgoingPayment {
575572 if lnPayment. details. paymentHash == cardRequest. invoice. paymentHash {
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import fr.acinq.lightning.MilliSatoshi
99import fr.acinq.lightning.TrampolineFees
1010import fr.acinq.lightning.db.LightningOutgoingPayment
1111import fr.acinq.lightning.io.PayInvoice
12+ import fr.acinq.lightning.io.SendPaymentResult
1213import fr.acinq.lightning.logging.LoggerFactory
1314import fr.acinq.lightning.logging.debug
1415import fr.acinq.lightning.logging.error
@@ -477,6 +478,21 @@ class SendManager(
477478 )
478479 }
479480
481+ suspend fun payUnsolicitedInvoice (
482+ invoice : Bolt12Invoice ,
483+ metadata : WalletPaymentMetadata ?
484+ ): SendPaymentResult {
485+ val paymentId: UUID = UUID .randomUUID()
486+ val peer = peerManager.getPeer()
487+
488+ // save card metadata if any
489+ metadata?.let { row ->
490+ databaseManager.metadataQueue.enqueue(row = row, id = paymentId)
491+ }
492+
493+ return peer.payUnsolicitedInvoice(invoice, paymentId)
494+ }
495+
480496 /* *
481497 * Step 1 of 2:
482498 * First call this function to convert the LnurlPay.Intent into a LnurlPay.Invoice.
You can’t perform that action at this time.
0 commit comments