# Upgrading to 0.42.0

Upgrade from the complete 0.41.0 package set using the [upgrade procedure](README.md).
This development-preview minor set adds Platform APIs and three native SQL
migrations. Core and Outbox republish unchanged runtime, exports and SQL; Core's
reader guide adds these upgrade notes. Pin all selected `@openlup/*` packages to
0.42.0 together. Package installation and imports apply no SQL or provider setup.

## Apply the native schema migrations

Before composing the new payment ports, apply the complete selected catalogue,
including its predecessors and these ordered forwards:

| Registry slot | Migration | Purpose |
| --- | --- | --- |
| 42 | `20261114100000_payment_provider_attempt_store.sql` | Durable provider attempts, immutable verified ingress and exact-attempt replay receipts. |
| 43 | `20261114110000_payment_method_refs.sql` | Recorded reusable payment methods, health, repair and frozen recovery authority. |
| 44 | `20261114120000_payment_reconciliation_refund_evidence.sql` | Reconciliation, attributed dunning handoff and cumulative refund evidence. |

Follow [Upgrade the database](database-migrations.md): keep the installation
selection that owns your existing history, construct
`createPlatformPostgresMigrationRunner` from `@openlup/platform/migrations`,
inspect `status()`, review `apply({ dryRun: true })`, then explicitly call
`apply()` and confirm that `status()` has no pending paths. On a matching
installation the runner applies only the pending suffix in catalogue order;
it refuses a mismatched prefix. Preserve applied SQL and ledger identities.
Module descriptors are sparse projections, not standalone installation chains.
An application with its own chain must prepare compatible forwards against its
actual schema and history rather than overlaying an unrelated package baseline.

## Register payment-method evidence

Migration: install the complete selected native chain through `20261114110000_payment_method_refs.sql` before composing collection or recorded-method readers. For host-composed native subscriptions without recorded refs and with real-provider history, retry, recovery, reactivation, auto-resume and upcoming reminders refuse or remain ineligible until the host records refs with `payment_method_ref_upsert` from verified evidence. Original renewal charging retains its previous method and mandate evidence behavior when no recorded reference exists, even with real-provider history. Once any reference row exists, every reader uses strict recorded authority, regardless of its status or active state. Account-support health follows the lifecycle classification even without a reference. Explicit sandbox subscriptions retain their behavior. Existing labels and token rows are not backfilled; obtain a new authorized token when recovery context is absent, select a host-authenticated setup lane and preserve outstanding retry authority. Setup callers must retain one trimmed 8–180 character idempotency key; formerly accepted short or oversized keys now refuse before ownership lookup or provider I/O.

For example, reactivation without chargeable recorded authority returns
`subscription_command_payment_blocked`; the recorded-method reader reports
`{ kind: "unavailable", reason: "method_ref_not_recorded" }` when no recorded
reference is available. Upcoming reminders remain ineligible. A historical
healthy label or mirror string does not supply reusable provider evidence.
Register verified references through the host-authorized service lane, retain
consent and provider identity, and recheck readiness before enabling lifecycle
work. Do not reconstruct references or tokens from historical labels.

## Compose native payment execution

The durable provider store commits preparation before provider execution and
acknowledges the same attempt afterward. Immutable ingress and separate payment
identities preserve exact attribution; unresolved or superseded attribution
refuses before settlement effects. Uncertain and replayed attempts do not
redispatch. Unpaid-order cancellation terminalizes provider payment authority;
response-loss replay reads its durable transition without new method context.

Reconciliation applies canonical observations atomically to the exact attempt.
A correlated failed webhook hands off attributed dunning even when a direct
result committed first: it reuses that attempt's original failure receipt,
without another financial transition, retry rung, recovery authority or notice.
Historical unattributed attempts and cases retain named refusals. Absence
auto-reopen stays off; a later dispatch requires explicit due-reopen consumption.

Refund evidence preserves original settlement money, subscription service and
paid-cycle history. `commerce.order.refunded` remains status-only. Financial
customer messaging uses `commerce.order.refund_processed`, gated by accepted
same-currency evidence; cumulative snapshots use their maximum. Recording a
refund neither creates a provider refund nor pauses or cancels a subscription.

Explicitly select `createPostgresProviderPaymentRail` and
`createPostgresProviderRenewalBinding` with the matching webhook control,
renewal lifecycle and retry ports together. The card reference provider composes
these native owners additively; its composition adds no further SQL beyond the
three forwards above. Preserve provider occurrence time separately from first
receipt; untimestamped card readback remains ambiguous. Host authentication,
verified ingress, provider configuration and live activation remain host-owned.
See the [payment owner](https://github.com/openlup/openlup/blob/openlup-core-v1.4.0/packages/platform/README.md#payments-prepared-attempts)
for the ports and their limits.

## Known limits

The native rail supports the two reference payment providers; a third provider needs the provider-profile refactor. The second reference provider's portable composition and the provider-profile refactor are deferred to a later set. Provider qualification is limited to fake-client proof; no live provider qualification is claimed. The starter still selects sandbox payments by default.

The offline adapter kit proves only its supplied fixtures, without certifying a
provider account, durable host behavior or real-money operation. Experimental
services remain inert until explicitly selected and composed.

## API changes

These are declaration-report changes, including referenced declaration files.
They do not imply that every listed name is exported by every listed subpath.
The repeated contract changes in provider and testing reports follow their
shared payment-contract references.

### `packages/platform/api/payments-contracts.api.md`

Added declarations:

```ts nocheck
// API report diff: not compiled.
export type VerifiedReusableMethod = {
export type { PaymentRefundObservation, RefundEvidencePolicy, VerifiedPaymentEvidence, VerifiedMethodEvidence, VerifiedReusableMethod, PaymentVerifyNormalizePort, ProviderReadPurpose, PaymentAbsenceEnvelope, PaymentReadbackEnvelope, PaymentMoney, PaymentAttemptIdentity, PaymentReadbackPort, PaymentAbsencePort, } from "./evidence.js";
```

Removed declarations:

```ts nocheck
// API report diff: not compiled.
export type { PaymentRefundObservation, RefundEvidencePolicy, VerifiedPaymentEvidence, VerifiedMethodEvidence, PaymentVerifyNormalizePort, ProviderReadPurpose, PaymentAbsenceEnvelope, PaymentReadbackEnvelope, PaymentMoney, PaymentAttemptIdentity, PaymentReadbackPort, PaymentAbsencePort, } from "./evidence.js";
```

Changed declarations:

```ts nocheck
// API report diff: not compiled.
export interface PaymentExecutionEnvelope {
export interface PaymentAttemptPort {
export interface PaymentAdapter {
export type VerifiedPaymentEvidence = VerifiedIdentity & {
export type VerifiedMethodEvidence = VerifiedIdentity & {
export interface PaymentProviderReconciliationPort {
```

### Reference provider adapter subpaths

Both reference provider adapter subpaths' API reports have the same shared
payment-contract diff shown above: 2 added declaration lines, 1 replaced type
re-export line and 6 changed declaration blocks. No provider-specific declaration
changed: the card reference provider retains its 48 top-level declaration lines,
and the second reference provider retains its 85.

### `packages/platform/api/payments-testing.api.md`

Added declarations:

```ts nocheck
// API report diff: not compiled.
export type VerifiedReusableMethod = {
export type { PaymentRefundObservation, RefundEvidencePolicy, VerifiedPaymentEvidence, VerifiedMethodEvidence, VerifiedReusableMethod, PaymentVerifyNormalizePort, ProviderReadPurpose, PaymentAbsenceEnvelope, PaymentReadbackEnvelope, PaymentMoney, PaymentAttemptIdentity, PaymentReadbackPort, PaymentAbsencePort, } from "./evidence.js";
```

Removed declarations:

```ts nocheck
// API report diff: not compiled.
export type { PaymentRefundObservation, RefundEvidencePolicy, VerifiedPaymentEvidence, VerifiedMethodEvidence, PaymentVerifyNormalizePort, ProviderReadPurpose, PaymentAbsenceEnvelope, PaymentReadbackEnvelope, PaymentMoney, PaymentAttemptIdentity, PaymentReadbackPort, PaymentAbsencePort, } from "./evidence.js";
```

Changed declarations:

```ts nocheck
// API report diff: not compiled.
export interface PaymentExecutionEnvelope {
export interface PaymentAttemptPort {
export interface PaymentAdapter {
export type VerifiedPaymentEvidence = VerifiedIdentity & {
export type VerifiedMethodEvidence = VerifiedIdentity & {
export interface PaymentProviderReconciliationPort {
```

### `packages/platform/api/payments.api.md`

Added declarations:

```ts nocheck
// API report diff: not compiled.
export type VerifiedReusableMethod = {
export type { PaymentRefundObservation, RefundEvidencePolicy, VerifiedPaymentEvidence, VerifiedMethodEvidence, VerifiedReusableMethod, PaymentVerifyNormalizePort, ProviderReadPurpose, PaymentAbsenceEnvelope, PaymentReadbackEnvelope, PaymentMoney, PaymentAttemptIdentity, PaymentReadbackPort, PaymentAbsencePort, } from "./evidence.js";
export { createPostgresPreparedAttemptPersistencePort } from "./postgresPreparedAttempt.js";
export { createPostgresPaymentWebhookControlPort } from "./postgresProviderWebhook.js";
export { createPostgresProviderPaymentControlPort } from "./postgresProviderControl.js";
export { createPostgresProviderPaymentRecoveryGuidancePort, createPostgresProviderExpiredCheckoutSafety } from "./providerRecoveryReaders.js";
export { createPostgresProviderCheckoutRecoveryAttemptPort, createPostgresProviderInlineRecoveryAttemptPort } from "./providerRecoveryAttempts.js";
export type { ProviderCheckoutMethod } from "./providerRecoveryAttempts.js";
export type { ProviderPaymentIntentInput, ProviderPaymentAttemptInput, ProviderPaymentResultInput } from "./postgresProviderControl.js";
export { createPostgresPaymentMethodStore, createPostgresPaymentWebhookMethodRefPort, applyPostgresPaymentMethodLifecycleEvent, schedulePostgresRetryOnDurableMethodUpdate, consumePostgresPaymentMethodDelivery } from "./postgresPaymentMethods.js";
export { createPostgresPaymentMethodSetup } from "./postgresMethodSetup.js";
export { createPostgresRecordedSubscriptionMethodReader } from "./postgresSubscriptionMethod.js";
export { createPostgresPaymentProviderReconciliationPort } from "./postgresPaymentProviderReconciliation.js";
export { createPostgresProviderPaymentRail } from "./postgresProviderRail.js";
export type { PostgresProviderPaymentRail, PostgresProviderAttemptSnapshot } from "./postgresProviderRail.js";
export declare function createPostgresPaymentMethodSetup(db: PaymentProviderExecutor, input: {
declare const methodSchema: z.ZodObject<{
type StoredMethod = z.infer<typeof methodSchema>;
export declare function createPostgresPaymentMethodStore(db: PaymentProviderExecutor): {
export declare function createPostgresPaymentWebhookMethodRefPort(db: PaymentProviderExecutor): PaymentWebhookMethodRefPort;
export declare function applyPostgresPaymentMethodLifecycleEvent(db: PaymentProviderExecutor, event: PaymentMethodLifecycleEvent): Promise<{
export declare function schedulePostgresRetryOnDurableMethodUpdate(db: PaymentProviderExecutor, event: NormalizedProviderPaymentWebhook): Promise<{
export declare function consumePostgresPaymentMethodDelivery(db: PaymentProviderExecutor, event: NormalizedProviderPaymentWebhook): Promise<void>;
export declare function createPostgresPaymentProviderReconciliationPort(db: PaymentProviderExecutor, options: PostgresPaymentTruthOptions): InteractivePreparedAttemptManualReconciliationPort;
export interface PaymentProviderExecutor {
export declare function createPostgresPreparedAttemptPersistencePort(db: PaymentProviderExecutor): PreparedAttemptPersistencePort;
export declare function decodeProviderAttempt(value: unknown): {
export interface ProviderPaymentIntentInput {
export interface ProviderPaymentAttemptInput {
export interface ProviderPaymentResultInput {
export declare function createPostgresProviderPaymentControlPort(db: PaymentProviderExecutor, options: PostgresPaymentTruthOptions): {
export interface PostgresProviderAttemptSnapshot {
export interface PostgresProviderPaymentRail {
export declare function createPostgresProviderPaymentRail(input: {
export declare function createPostgresPaymentWebhookControlPort(db: PaymentProviderExecutor, options: PostgresPaymentTruthOptions): PaymentWebhookControlPort;
export declare function createPostgresRecordedSubscriptionMethodReader(db: PaymentProviderExecutor): {
export type ProviderCheckoutMethod = Omit<PreparedAttemptPrepareInput, "idempotencyKey" | "paymentIntentId">;
export declare function createPostgresProviderCheckoutRecoveryAttemptPort(db: PaymentProviderExecutor, now?: () => Date): {
export declare function createPostgresProviderInlineRecoveryAttemptPort(db: PaymentProviderExecutor, methodKeyFor: (request: Record<string, unknown>) => string | null, now?: () => Date): {
export declare function createPostgresProviderPaymentRecoveryGuidancePort(db: PaymentProviderExecutor, normalize: (input: {
export declare function createPostgresProviderExpiredCheckoutSafety(db: PaymentProviderExecutor): {
```

Removed declarations:

```ts nocheck
// API report diff: not compiled.
export type { PaymentRefundObservation, RefundEvidencePolicy, VerifiedPaymentEvidence, VerifiedMethodEvidence, PaymentVerifyNormalizePort, ProviderReadPurpose, PaymentAbsenceEnvelope, PaymentReadbackEnvelope, PaymentMoney, PaymentAttemptIdentity, PaymentReadbackPort, PaymentAbsencePort, } from "./evidence.js";
```

Changed declarations:

```ts nocheck
// API report diff: not compiled.
export interface PaymentExecutionEnvelope {
export interface PaymentAttemptPort {
export interface PaymentAdapter {
export type VerifiedPaymentEvidence = VerifiedIdentity & {
export type VerifiedMethodEvidence = VerifiedIdentity & {
export interface PaymentProviderReconciliationPort {
export declare const paymentSchemaDescriptor: {
export interface NormalizedProviderPaymentWebhook {
export declare function createVerifiedPaymentIngress({ provider, verifyPort, paymentControlPort, methodRefPort, afterProcessed, createPorts, resolveMethodOwner, resolveSavedMethodOwner, refundEvidencePolicy, operationalEvents, }: {
```

### `packages/platform/api/subscriptions.api.md`

Added declarations:

```ts nocheck
// API report diff: not compiled.
export { createPostgresProviderRenewalBinding } from "./postgresProviderRenewalBinding.js";
export type { PostgresProviderRenewalBinding, ProviderRenewalPaymentPorts, ProviderRenewalResultInput } from "./postgresProviderRenewalBinding.js";
export interface ProviderRenewalResultInput {
type ProviderRenewalWebhookIngest = (input: ProviderRenewalWebhook & {
type ProviderRenewalWebhookControl = {
type ProviderRenewalWebhook = {
type ProviderRenewalAttempt = {
export interface ProviderRenewalPaymentPorts {
export interface PostgresProviderRenewalBinding {
export declare function createPostgresProviderRenewalBinding(input: {
```

Changed declarations:

```ts nocheck
// API report diff: not compiled.
export interface NativeRenewalPurchaseFacts {
export declare function createNativeSubscriptionBinding(input: {
```
