PaymentsService
public class PaymentsService : @unchecked Sendable
Service for querying payment operations from the Stellar Horizon API.
The PaymentsService provides methods to retrieve payment-related operations including payments, path payments, create account operations, and account merges. These are the operations that transfer value between accounts.
Example usage:
let sdk = StellarSDK()
// Get payment history for an account
let response = await sdk.payments.getPayments(
forAccount: "GACCOUNT...",
limit: 50,
order: .descending
)
switch response {
case .success(let page):
for payment in page.records {
if let paymentOp = payment as? PaymentOperationResponse {
print("Amount: \(paymentOp.amount) \(paymentOp.assetCode ?? "XLM")")
}
}
case .failure(let error):
print("Error: \(error)")
}
See also:
- Stellar developer docs
- OperationResponse for payment operation types
-
getPayments(from:Asynchronousorder: limit: includeFailed: join: ) Retrieves all payment operations that are part of validated transactions.
Declaration
Swift
open func getPayments(from cursor: String? = nil, order: Order? = nil, limit: Int? = nil, includeFailed: Bool? = nil, join: String? = nil) async -> PageResponse<OperationResponse>.ResponseEnumParameters
cursorAn optional paging token, specifying where to start returning records from.
orderThe order in which to return rows, “asc” or “desc”.
limitMaximum number of records to return. Default: 10, max: 200
includeFailedSet to true to include payments of failed transactions in results.
joinSet to “transactions” to include transaction data in response.
Return Value
PageResponse containing payment operations or error
-
Retrieves payment operations where the given account was either the sender or receiver.
Declaration
Swift
open func getPayments(forAccount accountId: String, from cursor: String? = nil, order: Order? = nil, limit: Int? = nil, includeFailed: Bool? = nil, join: String? = nil) async -> PageResponse<OperationResponse>.ResponseEnumParameters
accountIdThe Stellar account ID of the account used to constrain results.
cursorAn optional paging token, specifying where to start returning records from.
orderThe order in which to return rows, “asc” or “desc”.
limitMaximum number of records to return. Default: 10, max: 200
includeFailedSet to true to include payments of failed transactions in results.
joinSet to “transactions” to include transaction data in response.
Return Value
PageResponse containing payment operations for the account or error
-
Retrieves all payment operations that are part of valid transactions in a given ledger.
Declaration
Swift
open func getPayments(forLedger ledger: String, from cursor: String? = nil, order: Order? = nil, limit: Int? = nil, includeFailed: Bool? = nil, join: String? = nil) async -> PageResponse<OperationResponse>.ResponseEnumParameters
ledgerThe ledger sequence number used to constrain results.
cursorAn optional paging token, specifying where to start returning records from.
orderThe order in which to return rows, “asc” or “desc”.
limitMaximum number of records to return. Default: 10, max: 200
includeFailedSet to true to include payments of failed transactions in results.
joinSet to “transactions” to include transaction data in response.
Return Value
PageResponse containing payment operations for the ledger or error
-
Retrieves all payment operations that are part of a given transaction.
Declaration
Swift
open func getPayments(forTransaction hash: String, from cursor: String? = nil, order: Order? = nil, limit: Int? = nil, includeFailed: Bool? = nil, join: String? = nil) async -> PageResponse<OperationResponse>.ResponseEnumParameters
hashA transaction hash, hex-encoded.
cursorAn optional paging token, specifying where to start returning records from.
orderThe order in which to return rows, “asc” or “desc”.
limitMaximum number of records to return. Default: 10, max: 200
includeFailedSet to true to include payments of failed transactions in results.
joinSet to “transactions” to include transaction data in response.
Return Value
PageResponse containing payment operations for the transaction or error
-
getPaymentsFromUrl(url:Asynchronous) Loads payments from a given URL.
Useful for pagination with “next” or “prev” links from a PageResponse.
Declaration
Swift
open func getPaymentsFromUrl(url: String) async -> PageResponse<OperationResponse>.ResponseEnumParameters
urlThe URL to be used to load the payments.
Return Value
PageResponse containing payment operations or error
-
Streams real-time payment operation updates via Server-Sent Events from Horizon.
Declaration
Swift
open func stream(for transactionsType: PaymentsChange) -> OperationsStreamItemParameters
transactionsTypeThe filter specifying which payments to stream (all, by account, ledger, or transaction)
Return Value
OperationsStreamItem for receiving streaming payment updates
View on GitHub
Install in Dash