From fd10bbc286388ad8311872529456cd266fe20562 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Fri, 12 Jan 2024 10:17:29 +0100 Subject: [PATCH] Consolidate "receive payment" snippets, expose invoice --- snippets/csharp/ReceivePayment.cs | 4 +++- snippets/dart_snippets/lib/receive_payment.dart | 7 ++++--- snippets/go/receive_payment.go | 2 +- .../kotlin/com/example/kotlinmpplib/ReceivePayment.kt | 4 +++- snippets/python/src/receive_payment.py | 8 +++++--- snippets/react-native/receive_payment.ts | 6 ++++-- snippets/rust/src/receive_payment.rs | 4 +++- .../swift/BreezSDKExamples/Sources/ReceivePayment.swift | 8 +++++--- 8 files changed, 28 insertions(+), 15 deletions(-) diff --git a/snippets/csharp/ReceivePayment.cs b/snippets/csharp/ReceivePayment.cs index 52c2845c..a9856339 100644 --- a/snippets/csharp/ReceivePayment.cs +++ b/snippets/csharp/ReceivePayment.cs @@ -7,8 +7,10 @@ public void ReceivePayment(BlockingBreezServices sdk) // ANCHOR: receive-payment try { - var invoice = sdk.ReceivePayment( + var receivePaymentResponse = sdk.ReceivePayment( new ReceivePaymentRequest(3_000_000, "Invoice for 3000 sats")); + + var invoice = receivePaymentResponse.lnInvoice; } catch (Exception) { diff --git a/snippets/dart_snippets/lib/receive_payment.dart b/snippets/dart_snippets/lib/receive_payment.dart index 75edfc09..144c3d13 100644 --- a/snippets/dart_snippets/lib/receive_payment.dart +++ b/snippets/dart_snippets/lib/receive_payment.dart @@ -7,8 +7,9 @@ Future receivePayment() async { amountMsat: 3000000, description: "Invoice for 3000 sats", ); - ReceivePaymentResponse resp = await BreezSDK().receivePayment(req: req); - print(resp.lnInvoice); + ReceivePaymentResponse receivePaymentResponse = await BreezSDK().receivePayment(req: req); + + print(receivePaymentResponse.lnInvoice); // ANCHOR_END: receive-payment - return resp; + return receivePaymentResponse; } diff --git a/snippets/go/receive_payment.go b/snippets/go/receive_payment.go index 8733ab53..1c86163a 100644 --- a/snippets/go/receive_payment.go +++ b/snippets/go/receive_payment.go @@ -13,7 +13,7 @@ func ReceivePayment() { Description: "Invoice for 3000 sats", } if receivePaymentResponse, err := sdk.ReceivePayment(receivePaymentRequest); err == nil { - log.Printf("%#v", receivePaymentResponse) + log.Printf("Invoice: %#v", receivePaymentResponse.LnInvoice) } // ANCHOR_END: receive-payment } diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceivePayment.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceivePayment.kt index 946ef7a9..b3c52831 100644 --- a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceivePayment.kt +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceivePayment.kt @@ -5,10 +5,12 @@ class ReceivePayment { fun receive_payment(sdk: BlockingBreezServices) { // ANCHOR: receive-payment try { - val invoice = sdk.receivePayment(ReceivePaymentRequest( + val receivePaymentResponse = sdk.receivePayment(ReceivePaymentRequest( 3_000_000.toULong(), "Invoice for 3000 sats", )) + + val invoice = receivePaymentResponse.lnInvoice; } catch (e: Exception) { // handle error } diff --git a/snippets/python/src/receive_payment.py b/snippets/python/src/receive_payment.py index 3bcd7dd0..2439180e 100644 --- a/snippets/python/src/receive_payment.py +++ b/snippets/python/src/receive_payment.py @@ -6,10 +6,12 @@ def receive_payment(sdk_services): # ANCHOR: receive-payment req = breez_sdk.ReceivePaymentRequest( amount_msat=3000000, - description="Invoice for 3 000 000 sats") - result = sdk_services.receive_payment(req) + description="Invoice for 3 000 sats") + receive_payment_response = sdk_services.receive_payment(req) + + invoice = receive_payment_response.ln_invoice # ANCHOR_END: receive-payment - return result + return receive_payment_response except Exception as error: print(error) raise \ No newline at end of file diff --git a/snippets/react-native/receive_payment.ts b/snippets/react-native/receive_payment.ts index 3675c2b9..6324e3e6 100644 --- a/snippets/react-native/receive_payment.ts +++ b/snippets/react-native/receive_payment.ts @@ -2,9 +2,11 @@ import { receivePayment } from '@breeztech/react-native-breez-sdk' const exampleReceiveLightningPayment = async () => { // ANCHOR: receive-payment - const invoice = await receivePayment({ - amountMsat: 3000000, + const receivePaymentResponse = await receivePayment({ + amountMsat: 3_000_000, description: 'Invoice for 3000 sats' }) + + const invoice = receivePaymentResponse.lnInvoice // ANCHOR_END: receive-payment } diff --git a/snippets/rust/src/receive_payment.rs b/snippets/rust/src/receive_payment.rs index bede251e..22a9112a 100644 --- a/snippets/rust/src/receive_payment.rs +++ b/snippets/rust/src/receive_payment.rs @@ -5,13 +5,15 @@ use breez_sdk_core::*; async fn receive_payment(sdk: Arc) -> Result<()> { // ANCHOR: receive-payment - let res = sdk + let receive_payment_response = sdk .receive_payment(ReceivePaymentRequest { amount_msat: 3_000_000, description: "Invoice for 3000 sats".into(), ..Default::default() }) .await?; + + let invoice = receive_payment_response.ln_invoice; // ANCHOR_END: receive-payment Ok(()) diff --git a/snippets/swift/BreezSDKExamples/Sources/ReceivePayment.swift b/snippets/swift/BreezSDKExamples/Sources/ReceivePayment.swift index a8e1bc78..494dbed7 100644 --- a/snippets/swift/BreezSDKExamples/Sources/ReceivePayment.swift +++ b/snippets/swift/BreezSDKExamples/Sources/ReceivePayment.swift @@ -9,10 +9,12 @@ import BreezSDK func receivePayment(sdk: BlockingBreezServices) -> ReceivePaymentResponse? { // ANCHOR: receive-payment - let repsonse = try? sdk.receivePayment( + let receivePaymentResponse = try? sdk.receivePayment( req: ReceivePaymentRequest( amountMsat: 3_000_000, - description: "Invoice for 3 000 000 sats")) + description: "Invoice for 3 000 sats")) + + let invoice = receivePaymentResponse?.lnInvoice; // ANCHOR_END: receive-payment - return repsonse + return receivePaymentResponse }