Efficient session management is essential to ensure smooth transactions and handle time-sensitive payment links in Modem Pay. You can retrieve specific sessions, list all sessions for a more comprehensive view, and manually expire sessions as needed.


Retrieve a Session

Use the retrieve method to access detailed information about a single session by its unique session ID. This is particularly useful for checking the status, customer information, amount, and other details of a specific session.

const session = await modempay.sessions.retrieve(
  "2f4145b6-5a8b-4ec7-b62a-246b4424d351"
);

This command will return the full session object, allowing you to view properties such as:

  • Session Status: Check if it’s active or expired.
  • Customer Information: View customer details if associated.
  • Payment Link: Access the direct payment URL.
  • Custom Fields and Metadata: Any additional fields or custom data stored with the session.

List All Sessions

The list method provides a summary of all sessions, allowing you to monitor and manage multiple sessions at once. This feature is helpful for tracking recent payment activity, handling session statuses, and generating reports.

const sessions = await modempay.sessions.list();

Pagination options are also available to limit the number of sessions retrieved per request and to navigate through large datasets.


Expire a Session

If a session needs to be invalidated manually, perhaps due to a canceled order or an expired offer, you can expire it immediately. Once expired, the session’s payment link becomes unusable.

const expiredSession = await modempay.sessions.expire(
    "2f4145b6-5a8b-4ec7-b62a-246b4424d351"
);

When a session is expired:

  • Status: Changes to expired.
  • Link Invalidity: The payment link becomes inactive, preventing any further actions by the customer.
  • Error Prevention: Customers attempting to access an expired link will encounter a notification that the session is no longer available.

This action can’t be undone, ensuring that expired sessions remain securely inactive.