mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2025-12-24 01:14:22 +01:00
BOLT12 receive (#882)
* Add BOLT12 receive payment handling * Handle BOLT12 invoice requests via WS * Fix invoice request subscription on stream initialisation * Store the BOLT12 offer used to receive a payment * Address review feedback * Separate into create BOLT12 invoice fn * Update all BOLT12 offers when webhook URL changes * Deprecate Lightning for Bolt11Invoice
This commit is contained in:
@@ -59,3 +59,50 @@ extension TaskProtocol {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ReplyableTask : TaskProtocol {
|
||||
var payload: String
|
||||
var contentHandler: ((UNNotificationContent) -> Void)?
|
||||
var bestAttemptContent: UNMutableNotificationContent?
|
||||
var logger: ServiceLogger
|
||||
var successNotificationTitle: String
|
||||
var failNotificationTitle: String
|
||||
|
||||
init(payload: String, logger: ServiceLogger, contentHandler: ((UNNotificationContent) -> Void)? = nil, bestAttemptContent: UNMutableNotificationContent? = nil, successNotificationTitle: String, failNotificationTitle: String) {
|
||||
self.payload = payload
|
||||
self.contentHandler = contentHandler
|
||||
self.bestAttemptContent = bestAttemptContent
|
||||
self.logger = logger
|
||||
self.successNotificationTitle = successNotificationTitle;
|
||||
self.failNotificationTitle = failNotificationTitle;
|
||||
}
|
||||
|
||||
func start(liquidSDK: BindingLiquidSdk) throws {}
|
||||
|
||||
public func onEvent(e: SdkEvent) {}
|
||||
|
||||
func onShutdown() {
|
||||
displayPushNotification(title: self.failNotificationTitle, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_REPLACEABLE)
|
||||
}
|
||||
|
||||
func replyServer(encodable: Encodable, replyURL: String) {
|
||||
guard let serverReplyURL = URL(string: replyURL) else {
|
||||
self.displayPushNotification(title: self.failNotificationTitle, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_REPLACEABLE)
|
||||
return
|
||||
}
|
||||
var request = URLRequest(url: serverReplyURL)
|
||||
request.httpMethod = "POST"
|
||||
request.httpBody = try! JSONEncoder().encode(encodable)
|
||||
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
||||
let statusCode = (response as! HTTPURLResponse).statusCode
|
||||
|
||||
if statusCode == 200 {
|
||||
self.displayPushNotification(title: self.successNotificationTitle, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_REPLACEABLE)
|
||||
} else {
|
||||
self.displayPushNotification(title: self.failNotificationTitle, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_REPLACEABLE)
|
||||
return
|
||||
}
|
||||
}
|
||||
task.resume()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user