Overview
In the architecture of a payment API, the payment session and payment object are distinct but related concepts that manage the complete lifecycle of a transaction. This separation is particularly important when interacting with hardware terminal devices, where timing and state management are critical. The system provides both apayment_session_id and a payment_id in responses, creating a structured approach that manages:
- The initial user interaction and preparation phase
- The subsequent financial transaction execution
- State transitions and error handling
- Terminal device coordination
The Payment Session
What is a Payment Session?
A payment session is a temporary and secure context that holds all the necessary information about a potential transaction. Think of it as a digital workspace or preparation area for a specific payment interaction. The payment session acts as an intermediary layer between your application and the terminal hardware, managing the complex coordination required for secure payment processing.Key Characteristics
Payment sessions have a limited lifetime and are designed to handle the preparation phase before actual financial transactions occur.
Data Aggregation
Purpose: Gathers and validates all preliminary transaction details before processing begins.Details Collected:
- Transaction amount and currency
- Items being purchased (line items)
- Terminal device identification
- Customer reference information
- Payment method preferences
State Management
Purpose: Tracks the complete lifecycle of the payment preparation process.States Include:
ACTIVE- Ready for payment processingCOMPLETED- Payment successfully processedFAILED- Error during payment attemptCANCELED- Session terminated before completion
Security
Purpose: Provides a secure boundary for handling sensitive transaction data.Security Features:
- Isolated data environment
- Secure session identifier reference
- Controlled data access patterns
- Reduced sensitive data transmission
payment_session_id serves as a secure token for all session operations.Terminal Abstraction
Purpose: Manages terminal device preparation and coordination.Terminal Operations:
- Device initialization and configuration
- Payment method setup
- Transaction parameter loading
- Hardware status monitoring
Session Identifier
Thepayment_session_id is the unique identifier for this entire preparatory phase. This identifier serves several critical functions:
- Reference: Retrieve or update session details as needed
- Tracking: Monitor session progress and state changes
- Security: Acts as an authentication token for session operations
- Audit: Provides traceability for transaction preparation
You can use the
payment_session_id to query session status, update transaction details, or cancel the session before payment completion.The Payment Object
What is a Payment Object?
A payment object represents the successful completion of a financial transaction. It is the authoritative, immutable record created after the payment system confirms that funds have been successfully captured or transferred. Unlike the payment session which handles preparation, the payment object is created only after a transaction has been successfully processed through the payment network.Key Characteristics
Payment objects are permanent records of completed financial transactions and serve as the legal and audit trail for money movement.
Transaction Record
Purpose: Creates an immutable record of successful financial transactions.Creation Process:
- Triggered by successful payment processing
- Generated after payment gateway confirmation
- Contains complete transaction details
- Serves as official receipt and audit trail
- Customer initiates payment (card tap, QR scan, etc.)
- Payment gateway processes the transaction
- Upon approval, payment object is created
- Funds are captured or authorized
The payment object is not the trigger for the transaction—it’s the result of a successful one.
Financial Operations
Purpose: Enables post-transaction financial operations on completed payments.Available Operations:
- Voiding: Cancel transactions before settlement
- Refunds: Return funds after settlement
- Partial Refunds: Return portion of payment amount
- Captures: Complete authorized transactions
- Pre-settlement: Transactions can be voided
- Post-settlement: Transactions can be refunded
- Settlement Window: Typically 24-48 hours after processing
Payment States
Payment objects have specific states that reflect their current status in the payment lifecycle:SUCCEEDED
The transaction has been successfully processed and funds have been captured or authorized. This is the most common end state for successful payments.
VOIDED
The transaction has been canceled before settlement. Funds are returned to the customer, and no settlement will occur. This can only happen within the void window (typically before end-of-day processing).
Key Differences
Understanding the fundamental differences between payment sessions and payment objects is crucial for proper API usage and transaction management.Payment Session Characteristics
Lifecycle Stage: Preparation and setup phaseCreation Timing: Created before any payment attempt beginsPrimary States:
ACTIVE- Ready for payment processingCOMPLETED- Successfully transitioned to paymentFAILED- Error during preparationCANCELED- Terminated before completion
- Transaction data collection and validation
- Terminal device preparation and setup
- Session state monitoring and management
- Error handling during preparation phase
Payment Object Characteristics
Lifecycle Stage: Transaction completion and post-processingCreation Timing: Created after successful payment completionPrimary States:
SUCCEEDED- Transaction successfully processedVOIDED- Transaction canceled before settlementFAILED- Transaction processing error
- Voiding transactions before settlement
- Processing refunds after settlement
- Transaction history and audit trails
- Financial reconciliation and reporting
Decision Framework
When to Use Payment Session ID
When to Use Payment Session ID
Choose
payment_session_id when you need to:- Check preparation status before payment
- Update transaction details before processing
- Cancel a session before payment begins
- Monitor terminal readiness
- Handle errors during setup phase
When to Use Payment ID
When to Use Payment ID
Choose
payment_id when you need to:- Void a transaction before settlement
- Process refunds after settlement
- Retrieve transaction history
- Perform financial reconciliation
- Generate receipts or invoices
Error Handling Scenarios
Session Creation Fails
Session Creation Fails
Common Causes:
- Invalid terminal ID
- Insufficient permissions
- Network connectivity issues
- Invalid transaction parameters
Terminal Unavailable
Terminal Unavailable
Payment Processing Fails
Payment Processing Fails
Common Causes:
- Card declined by issuer
- Insufficient funds
- Expired card
- Network timeout