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:

  • Retrieves all payment operations that are part of validated transactions.

    See: Stellar developer docs

    Declaration

    Swift

    open func getPayments(from cursor: String? = nil, order: Order? = nil, limit: Int? = nil, includeFailed: Bool? = nil, join: String? = nil) async -> PageResponse<OperationResponse>.ResponseEnum

    Parameters

    cursor

    An optional paging token, specifying where to start returning records from.

    order

    The order in which to return rows, “asc” or “desc”.

    limit

    Maximum number of records to return. Default: 10, max: 200

    includeFailed

    Set to true to include payments of failed transactions in results.

    join

    Set 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.

    See: Stellar developer docs

    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>.ResponseEnum

    Parameters

    accountId

    The Stellar account ID of the account used to constrain results.

    cursor

    An optional paging token, specifying where to start returning records from.

    order

    The order in which to return rows, “asc” or “desc”.

    limit

    Maximum number of records to return. Default: 10, max: 200

    includeFailed

    Set to true to include payments of failed transactions in results.

    join

    Set 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.

    See: Stellar developer docs

    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>.ResponseEnum

    Parameters

    ledger

    The ledger sequence number used to constrain results.

    cursor

    An optional paging token, specifying where to start returning records from.

    order

    The order in which to return rows, “asc” or “desc”.

    limit

    Maximum number of records to return. Default: 10, max: 200

    includeFailed

    Set to true to include payments of failed transactions in results.

    join

    Set 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.

    See: Stellar developer docs

    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>.ResponseEnum

    Parameters

    hash

    A transaction hash, hex-encoded.

    cursor

    An optional paging token, specifying where to start returning records from.

    order

    The order in which to return rows, “asc” or “desc”.

    limit

    Maximum number of records to return. Default: 10, max: 200

    includeFailed

    Set to true to include payments of failed transactions in results.

    join

    Set to “transactions” to include transaction data in response.

    Return Value

    PageResponse containing payment operations for the transaction or error

  • 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>.ResponseEnum

    Parameters

    url

    The 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) -> OperationsStreamItem

    Parameters

    transactionsType

    The filter specifying which payments to stream (all, by account, ledger, or transaction)

    Return Value

    OperationsStreamItem for receiving streaming payment updates