feat: adding docs for payment metadata (#124)

Co-authored-by: vacwmX <vacwm01@gmail.com>
Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
This commit is contained in:
yse
2024-02-29 23:32:59 +01:00
committed by GitHub
parent 09265637bf
commit 6254560488
10 changed files with 845 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
//
// Metadata.swift
//
//
//
import Foundation
import BreezSDK
func SetPaymentMetadata(sdk: BlockingBreezServices) throws {
// ANCHOR: set-payment-metadata
try sdk.setPaymentMetadata(hash: "target-payment-hash", metadata: #"{"myCustomValue":true}"#)
// ANCHOR_END: set-payment-metadata
}
func FilterPaymentMetadata(sdk: BlockingBreezServices) -> [Payment]? {
// ANCHOR: filter-payment-metadata
let metadataFilters = [
MetadataFilter(
jsonPath: "myCustomValue",
jsonValue: "true"
)
]
let payments = try? sdk.listPayments(
req: ListPaymentsRequest(
metadataFilters: metadataFilters
)
)
// ANCHOR_END: filter-payment-metadata
return payments
}
func FilterPaymentMetadataString(sdk: BlockingBreezServices) -> [Payment]? {
// ANCHOR: filter-payment-metadata-string
let metadataFilters = [
MetadataFilter(
jsonPath: "myCustomValue",
jsonValue: #""true""#
)
]
// ANCHOR_END: filter-payment-metadata-string
return try? sdk.listPayments(
req: ListPaymentsRequest(
metadataFilters: metadataFilters
)
)
}
func FilterPaymentMetadataObject(sdk: BlockingBreezServices) -> [Payment]? {
// ANCHOR: filter-payment-metadata-object
// This will *NOT* work
var metadataFilters = [
MetadataFilter(
jsonPath: "myCustomValue",
jsonValue: #"[1, 2, 3]"#
)
]
// Any of these will work
metadataFilters = [
MetadataFilter(
jsonPath: "myCustomValue",
jsonValue: #"[1,2,3]"#
)
]
// ANCHOR_END: filter-payment-metadata-object
return try? sdk.listPayments(
req: ListPaymentsRequest(
metadataFilters: metadataFilters
)
)
}