The `Transaction` model in the Quicksilver SDK is an active record object that encapsulates the data and behavior of a financial transaction within the Quicksilver Engine. Unlike a passive data struct
The Transaction model in the Quicksilver SDK is an active record object that encapsulates the data and behavior of a financial transaction within the Quicksilver Engine. Unlike a passive data structure, a Transaction object provides fluent methods to interact with and manage the transaction's lifecycle, execute conditional logic, handle streaming payments, and integrate with real-time events.
Each Transaction instance is created either by the QuicksilverClient directly (e.g., via client.transactions.create() or client.createTransaction()) or fluently from an Account object (e.g., account.transaction()).
new Transaction(data, http)data: TransactionData - The raw data representing a transaction as returned by the API.http: HttpClient - An instance of HttpClient used for making API requests.Description: Initializes a new instance of the Transaction active record model. This constructor is typically called internally by the SDK when creating a transaction via client.transactions.create() or account.transaction(), or when retrieving existing transaction data.
These properties provide direct access to the transaction's underlying data.
id: stringtransactionType: stringamount: numbercurrency: stringfrom: stringto: string | nullnull if not applicable (e.g., for some internal fund movements).state: stringstatus: stringstate property, providing consistency.parentId: string | nullnull.meta: Record<string, any>createdAt: stringupdatedAt: stringexecutedAt: string | nullnull if not yet executed.children: string[]The Transaction object provides a rich set of methods that encapsulate transactional behavior, allowing for a more object-oriented approach to programmable money.
execute(gatewayId?: string): Promise<this>gatewayId is provided, it attempts to execute through a specific payment gateway.
Parameters:
gatewayId?: string (optional) - The ID of the payment gateway to use for execution.
Returns: Promise<this> - A promise that resolves with the updated Transaction object after execution.
Behavior: Updates the transaction's state and may trigger fund movements.
Usage:cancel(): Promise<this>Promise<this> - A promise that resolves with the updated Transaction object after cancellation.
Behavior: Marks the transaction as 'Cancelled' and prevents further processing.triggerEvent(event: string, context?: any): Promise<this>event: string - The name of the event to trigger (e.g., QuickSilverEvent.MilestoneApproved).context?: any (optional) - Additional data related to the event, which can be used by conditional predicates.
Returns: Promise<this> - A promise that resolves with the updated Transaction object after the event is processed.
Behavior: Evaluates any linked conditions and executes corresponding actions.
Usage:refund(amount?: number): Promise<this>amount?: number (optional) - The specific amount to refund. If not provided, the full transaction amount will be refunded.
Returns: Promise<this> - A promise that resolves with the updated Transaction object after the refund.
Behavior: Creates a refund transaction and updates the status of the original transaction.getCost(): Promise<number>Promise<number> - A promise that resolves with the numerical cost.
Behavior: For simple payments, it's the amount. For streams, it might query accumulated charges.refresh(): Promise<this>Promise<this> - A promise that resolves with the updated Transaction object.
Behavior: Ensures the local Transaction object reflects the most current state on the server.isFinal(): booleanboolean - true if final, false otherwise.
Behavior: Provides a quick way to determine if further lifecycle actions are possible.isPending(): booleanboolean - true if pending/draft, false otherwise.isCompleted(): booleanboolean - true if completed, false otherwise.isFailed(): booleanboolean - true if failed, false otherwise.getStatus(): stringstring - The transaction's status.getMeta(): Record<string, any>Record<string, any> - An object containing the transaction's metadata.getMetadata(): Record<string, any>getMeta().
Parameters: None
Returns: Record<string, any> - An object containing the transaction's metadata.getChildren(): Promise<Transaction[]>Promise<Transaction[]> - A promise that resolves with an array of Transaction objects representing the children.getStreams(): Promise<any[]>Promise<any[]> - A promise that resolves with an array of streaming transaction objects.getConditions(): anyany - The conditions object or array configured for the transaction.toJSON(): TransactionDataTransaction object into a plain JavaScript object, suitable for API submission or logging.
Parameters: None
Returns: TransactionData - The raw transaction data.toString(): stringstring - A string like Transaction(txn_123, 100 USD, pending).update(updates: Partial<TransactionData>): Promise<this>updates: Partial<TransactionData> - An object containing the fields to update.
Returns: Promise<this> - A promise that resolves with the updated Transaction object.delete(): Promise<void>Promise<void> - A promise that resolves when the deletion is successful.withConditions(conditionBuilder: ConditionBuilder): thisconditionBuilder: ConditionBuilder - An instance of ConditionBuilder containing the desired conditional logic.
Returns: this - The Transaction object itself, allowing for method chaining.
Behavior: Populates the conditions field of the transaction's meta data.withCondition(condition: ConditionBuilder): thiswithConditions().
Parameters:
condition: ConditionBuilder - An instance of ConditionBuilder.
Returns: this - The Transaction object itself.updateMeta(meta: Record<string, any>): Promise<this>meta: Record<string, any> - An object containing metadata fields to update.
Returns: Promise<this> - A promise that resolves with the updated Transaction object.withMetadata(metadata: Record<string, any>): thismetadata: Record<string, any> - An object containing metadata fields to add or update.
Returns: this - The Transaction object itself.executeGateway(gatewayId: string): Promise<this>execute() but explicitly specifies the gateway.
Parameters:
gatewayId: string - The ID of the payment gateway.
Returns: Promise<this> - A promise that resolves with the updated Transaction object.toStream(options: { rate: number; rate_unit: string }): Promise<any>options: object - Configuration for the stream.
rate: number - The rate of the stream.rate_unit: string - The unit for the rate (e.g., 'per_second', 'per_word').
Returns: Promise<any> - A promise that resolves with the streaming transaction data.startStreaming(rate: number, unit: string): Promise<any>rate: number - The rate of the stream.unit: string - The unit for the rate (e.g., 'per_second', 'per_word').
Returns: Promise<any> - A promise that resolves with the streaming transaction data.
Usage:stream(options: { rate?: number; rateUnit?: string; rate_unit?: string; endTime?: string }): Promise<any>endTime.
Parameters:
options: object - Configuration for the stream.
rate?: number (optional) - The rate of the stream.rateUnit?: string (optional) - The unit for the rate (e.g., 'per_second', 'per_minute').rate_unit?: string (optional) - Alias for rateUnit.endTime?: string (optional) - The ISO 8601 timestamp when the stream should automatically end.
Returns: Promise<any> - A promise that resolves with the streaming transaction data.subscribe(): StreamConnectionStreamConnection - An EventEmitter-like object that emits events such as 'stream_event' and 'batch_created'.
Behavior: Allows building responsive, event-driven interfaces.
Usage: