diff --git a/snippets/csharp/ServiceStatus.cs b/snippets/csharp/ServiceStatus.cs index 839131d..c35c11f 100644 --- a/snippets/csharp/ServiceStatus.cs +++ b/snippets/csharp/ServiceStatus.cs @@ -8,7 +8,7 @@ public class ServiceStatusSnippets try { var healthCheck = sdk.ServiceHealthCheck(); - Console.WriteLine($"Current service status is: {healthCheck.status}"); + Console.WriteLine($"Current service status is: {healthCheck.status}"); } catch (Exception) { diff --git a/snippets/csharp/Webhook.cs b/snippets/csharp/Webhook.cs new file mode 100644 index 0000000..6c9b9e7 --- /dev/null +++ b/snippets/csharp/Webhook.cs @@ -0,0 +1,32 @@ +using Breez.Sdk; + +public class ServiceStatusSnippets +{ + public void Webhook(BlockingBreezServices sdk) + { + // ANCHOR: register-webook + try + { + sdk.RegisterWebhook("https://yourapplication.com"); + } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: register-webook + } + + public void PaymentWebhook(BlockingBreezServices sdk) + { + // ANCHOR: register-payment-webook + try + { + sdk.RegisterWebhook("https://your-nds-service.com/notify?platform=ios&token="); + } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: register-payment-webook + } +} diff --git a/snippets/dart_snippets/lib/webhook.dart b/snippets/dart_snippets/lib/webhook.dart new file mode 100644 index 0000000..aec46ff --- /dev/null +++ b/snippets/dart_snippets/lib/webhook.dart @@ -0,0 +1,14 @@ +import 'package:breez_sdk/breez_sdk.dart'; +import 'package:breez_sdk/bridge_generated.dart'; + +Future webhook() async { + // ANCHOR: register-webook + await BreezSDK().registerWebhook("https://yourapplication.com"); + // ANCHOR_END: register-webook +} + +Future paymentWebhook({required String paymentHash}) async { + // ANCHOR: register-payment-webook + await BreezSDK().registerWebhook("https://your-nds-service.com/notify?platform=ios&token="); + // ANCHOR_END: register-payment-webook +} diff --git a/snippets/go/webhook.go b/snippets/go/webhook.go new file mode 100644 index 0000000..a63f8dd --- /dev/null +++ b/snippets/go/webhook.go @@ -0,0 +1,21 @@ +package example + +import ( + "log" +) + +func Webhook() { + // ANCHOR: register-webook + if err := sdk.RegisterWebhook("https://yourapplication.com"); err != nil { + log.Printf("Webhook registration failed: %v", err) + } + // ANCHOR_END: register-webook +} + +func PaymentWebhook() { + // ANCHOR: register-payment-webook + if err := sdk.RegisterWebhook("https://your-nds-service.com/notify?platform=ios&token="); err != nil { + log.Printf("Webhook registration failed: %v", err) + } + // ANCHOR_END: register-payment-webook +} diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/Webhook.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/Webhook.kt new file mode 100644 index 0000000..f9bc6af --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/Webhook.kt @@ -0,0 +1,24 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class ServiceStatus { + fun Webhook(sdk: BlockingBreezServices) { + // ANCHOR: register-webook + try { + sdk.registerWebhook("https://yourapplication.com") + } catch (e: Exception) { + // Handle error + } + // ANCHOR_END: register-webook + } + + fun paymentWebhook(sdk: BlockingBreezServices) { + // ANCHOR: register-payment-webook + try { + sdk.registerWebhook("https://your-nds-service.com/notify?platform=ios&token=") + } catch (e: Exception) { + // Handle error + } + // ANCHOR_END: register-payment-webook + } +} \ No newline at end of file diff --git a/snippets/python/src/webhook.py b/snippets/python/src/webhook.py new file mode 100644 index 0000000..ea92f25 --- /dev/null +++ b/snippets/python/src/webhook.py @@ -0,0 +1,19 @@ +import breez_sdk + +def webhook(sdk_services): + try: + # ANCHOR: register-webook + sdk_services.registerWebhook("https://yourapplication.com") + # ANCHOR_END: register-webook + except Exception as error: + print(error) + raise + +def paymentWebhook(sdk_services): + try: + # ANCHOR: register-payment-webook + sdk_services.registerWebhook("https://your-nds-service.com/notify?platform=ios&token=") + # ANCHOR_END: register-payment-webook + except Exception as error: + print(error) + raise diff --git a/snippets/react-native/webhook.ts b/snippets/react-native/webhook.ts new file mode 100644 index 0000000..363e259 --- /dev/null +++ b/snippets/react-native/webhook.ts @@ -0,0 +1,13 @@ +import { registerWebhook } from '@breeztech/react-native-breez-sdk' + +const webhook = async () => { + // ANCHOR: register-webook + await registerWebhook("https://yourapplication.com") + // ANCHOR_END: register-webook +} + +const paymentWebhook = async () => { + // ANCHOR: register-payment-webook + await registerWebhook('https://your-nds-service.com/notify?platform=ios&token=') + // ANCHOR_END: register-payment-webook +} diff --git a/snippets/rust/src/webhook.rs b/snippets/rust/src/webhook.rs index 0e99e9a..fd4c1a1 100644 --- a/snippets/rust/src/webhook.rs +++ b/snippets/rust/src/webhook.rs @@ -6,7 +6,7 @@ use breez_sdk_core::*; async fn webhook(sdk: Arc) -> Result<()> { // ANCHOR: register-webook - sdk.register_webhook("https://yourapplication.com").await? + sdk.register_webhook("https://yourapplication.com").await? // ANCHOR_END: register-webook Ok(()) diff --git a/snippets/swift/BreezSDKExamples/Sources/Webhook.swift b/snippets/swift/BreezSDKExamples/Sources/Webhook.swift new file mode 100644 index 0000000..6d6a9d4 --- /dev/null +++ b/snippets/swift/BreezSDKExamples/Sources/Webhook.swift @@ -0,0 +1,20 @@ +// +// ServiceStatus.swift +// +// +// + +import Foundation +import BreezSDK + +func webhook(sdk: BlockingBreezServices) throws { + // ANCHOR: register-webook + sdk.registerWebhook("https://yourapplication.com") + // ANCHOR_END: register-webook +} + +func paymentWebhook(sdk: BlockingBreezServices) { + // ANCHOR: register-payment-webook + sdk.registerWebhook("https://your-nds-service.com/notify?platform=ios&token=").await? + // ANCHOR_END: register-payment-webook +} diff --git a/src/guide/payment_notification.md b/src/guide/payment_notification.md index 7ba3e43..319a25b 100644 --- a/src/guide/payment_notification.md +++ b/src/guide/payment_notification.md @@ -20,6 +20,63 @@ Next, register this URL with the Breez SDK. This step involves calling a specifi {{#include ../../snippets/rust/src/webhook.rs:register-webook}} ``` + +
Swift
+
+ +```swift,ignore +{{#include ../../snippets/swift/BreezSDKExamples/Sources/Webhook.swift:register-webook}} +``` +
+ +
Kotlin
+
+ +```kotlin,ignore +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/Webhook.kt:register-webook}} +``` +
+ +
React Native
+
+ +```typescript +{{#include ../../snippets/react-native/webhook.ts:register-webook}} +``` +
+ +
Dart
+
+ +```dart,ignore +{{#include ../../snippets/dart_snippets/lib/webhook.dart:register-webook}} +``` +
+ +
Python
+
+ +```python,ignore +{{#include ../../snippets/python/src/webhook.py:register-webook}} +``` +
+ +
Go
+
+ +```go,ignore +{{#include ../../snippets/go/webhook.go:register-webook}} +``` +
+ +
C#
+
+ +```cs,ignore +{{#include ../../snippets/csharp/Webhook.cs:register-webook}} +``` +
+ ## Handling Incoming Notifications @@ -71,6 +128,63 @@ Register the constructed URL with the Breez SDK By calling an SDK function. {{#include ../../snippets/rust/src/webhook.rs:register-payment-webook}} ``` + +
Swift
+
+ +```swift,ignore +{{#include ../../snippets/swift/BreezSDKExamples/Sources/Webhook.swift:register-payment-webook}} +``` +
+ +
Kotlin
+
+ +```kotlin,ignore +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/Webhook.kt:register-payment-webook}} +``` +
+ +
React Native
+
+ +```typescript +{{#include ../../snippets/react-native/webhook.ts:register-payment-webook}} +``` +
+ +
Dart
+
+ +```dart,ignore +{{#include ../../snippets/dart_snippets/lib/webhook.dart:register-payment-webook}} +``` +
+ +
Python
+
+ +```python,ignore +{{#include ../../snippets/python/src/webhook.py:register-payment-webook}} +``` +
+ +
Go
+
+ +```go,ignore +{{#include ../../snippets/go/webhook.go:register-payment-webook}} +``` +
+ +
C#
+
+ +```cs,ignore +{{#include ../../snippets/csharp/Webhook.cs:register-payment-webook}} +``` +
+ ## Step 4: Handling Notifications When the App is Not Running