Participant exit
****************

The plans that PsyNet records when a participant finishes, fails,
declines consent, leaves early or hits a fatal error. To change the
**Leave** confirmation, override "plan_exit()"; see
"show_early_exit_button" in Configuration.

Domain models for participant exit planning.

Every terminal participant outcome has the same core concerns: PsyNet
records why the session ended, recruiters choose a platform handoff,
and payment is planned before any external transfer occurs.  This
module contains the value objects shared by normal completion,
unsuccessful completion, voluntary Leave, and fatal-error recovery.
Timeline and error-page code remain responsible for presenting those
outcomes appropriately.

class psynet.exit.EarlyExitConfirmation(title, message, confirm_label, cancel_label)

   Bases: "object"

   Participant-facing copy for a voluntary Leave offer.

   cancel_label: str

   confirm_label: str

   message: str

   title: str

class psynet.exit.ErrorRecoveryPresentation(message, action_instruction=None, failure_message=None, researcher_contact_message=None, button_label=None, preparation_post_url=None, preparation_post_data=<factory>, action_post_url=None, action_post_data=<factory>, destination_url=None, auto_redirect_delay_ms=None)

   Bases: "object"

   Recruiter-specific copy and handoff for an error page.

   Whether tracked fatal recovery *shows* this page is recruiter
   policy ("shows_error_recovery_page"), not an inference from
   "button_label". "action_instruction" is an optional second
   paragraph before the button.

   action_instruction: str | None = None

   action_post_data: dict[str, str]

   action_post_url: str | None = None

   auto_redirect_delay_ms: int | None = None

   button_label: str | None = None

   destination_url: str | None = None

   failure_message: str | None = None

   message: str

   preparation_post_data: dict[str, str]

   preparation_post_url: str | None = None

   researcher_contact_message: str | None = None

   without_handoff()

      Return a copy that explains the error without a participant
      action.

      Return type:
         "ErrorRecoveryPresentation"

class psynet.exit.ExitContext(*values)

   Bases: "StrEnum"

   Reason that a participant is leaving the experiment.

   ERROR_RECOVERY = 'error_recovery'

   REJECTED_CONSENT = 'rejected_consent'

   SUCCESSFUL = 'successful'

   UNSUCCESSFUL = 'unsuccessful'

   VOLUNTARY = 'voluntary'

class psynet.exit.ExitPath(*values)

   Bases: "StrEnum"

   Recruiter handoff selected for a participant exit.

   END_SESSION = 'end_session'

   RETURN_FOR_BONUS = 'return_for_bonus'

   RETURN_WITHOUT_PAYMENT = 'return_without_payment'

   SCREEN_OUT = 'screen_out'

   TERMINATE_PANEL_SESSION = 'terminate_panel_session'

class psynet.exit.ExitPlan(plan_id, context, path, status, payment, currency, confirmation=None, payment_state=PaymentState.PLANNED, source_page_uuid=None)

   Bases: "object"

   Server-owned plan for one participant's terminal outcome.

   "payment_state" distinguishes recruiters that do not pay through
   PsyNet from error-recovery plans whose final amount must be
   calculated later.

   confirmation: EarlyExitConfirmation | None = None

   context: ExitContext

   classmethod create(*, context, path, payment, confirmation=None, payment_state=None, currency='$', source_page_uuid=None)

      Create a prepared exit plan.

      Return type:
         "ExitPlan"

   currency: str

   for_source_page(page_uuid)

      Bind a prepared voluntary plan to the page that displays it.

      Return type:
         "ExitPlan"

   classmethod from_dict(data)

      Restore an exit plan from participant storage.

      Return type:
         "ExitPlan"

   mark_committed()

      Return a committed copy of this plan.

      Return type:
         "ExitPlan"

   path: ExitPath

   payment: PaymentDecision | None

   payment_state: PaymentState = 'planned'

   plan_id: str

   source_page_uuid: str | None = None

   status: ExitPlanStatus

   to_dict()

      Return primitive data suitable for participant storage.

      Return type:
         "dict"

class psynet.exit.ExitPlanStatus(*values)

   Bases: "StrEnum"

   Lifecycle state of a stored exit plan.

   COMMITTED = 'committed'

   PREPARED = 'prepared'

class psynet.exit.PaymentDecision(status, platform_base, bonus)

   Bases: "object"

   Describe intended participant payment before spend caps or
   transfer.

   Parameters:
      * **status** ("str") -- Recruitment-platform outcome, such as
        "approved" or "screened_out".

      * **platform_base** ("float") -- Amount supplied by the
        recruitment platform.

      * **bonus** ("float") -- Additional amount PsyNet intends to
        transfer.

   bonus: float

   classmethod from_dict(data)

      Restore a payment decision from primitive participant data.

      Return type:
         "PaymentDecision"

   platform_base: float

   status: str

class psynet.exit.PaymentState(*values)

   Bases: "StrEnum"

   Completeness of the payment information in an exit plan.

   DEFERRED = 'deferred'

   NOT_APPLICABLE = 'not_applicable'

   PLANNED = 'planned'
