Skip to content

Commit

Permalink
Merge pull request #120 from breez/ok300-retrieve-invoice-receive-pay…
Browse files Browse the repository at this point in the history
…ment

Consolidate "receive payment" snippets
  • Loading branch information
ok300 authored Jan 13, 2024
2 parents 464a298 + fd10bbc commit 89ab58f
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 15 deletions.
4 changes: 3 additions & 1 deletion snippets/csharp/ReceivePayment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 4 additions & 3 deletions snippets/dart_snippets/lib/receive_payment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Future<ReceivePaymentResponse> 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;
}
2 changes: 1 addition & 1 deletion snippets/go/receive_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 5 additions & 3 deletions snippets/python/src/receive_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions snippets/react-native/receive_payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion snippets/rust/src/receive_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ use breez_sdk_core::*;

async fn receive_payment(sdk: Arc<BreezServices>) -> 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(())
Expand Down
8 changes: 5 additions & 3 deletions snippets/swift/BreezSDKExamples/Sources/ReceivePayment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 89ab58f

Please sign in to comment.