diff --git a/packages/cli/src/commands/mpp/index.tsx b/packages/cli/src/commands/mpp/index.tsx index 1b09a6cf..a075f578 100644 --- a/packages/cli/src/commands/mpp/index.tsx +++ b/packages/cli/src/commands/mpp/index.tsx @@ -3,7 +3,6 @@ import type { ISpendRequestResource, } from '@stripe/link-sdk'; import { Cli, z } from 'incur'; -import React from 'react'; import type { CliAuthStorage } from '../../auth/storage'; import { renderInteractive } from '../../utils/render-interactive'; import { requireAuth } from '../../utils/require-auth'; @@ -16,12 +15,24 @@ import { type PayResult, probeMppRequest, readPayResult, - runMppPayFullFlow, runMppPayWithSpendRequest, } from './pay'; import { createMppRequest } from './request'; import { decodeOptions, payOptions } from './schema'; +export function resolveInteractivePayResult( + result: PayResult | null | undefined, +): PayResult | undefined { + if (result === undefined) { + throw new Error('Component exited without producing a result'); + } + if (result === null) { + process.exitCode = 1; + return undefined; + } + return result; +} + export function createMppCli( repository: ISpendRequestResource, paymentMethodsFactory: () => IPaymentMethodsResource, @@ -50,7 +61,7 @@ export function createMppCli( const headers = opts.header?.length ? opts.header : undefined; if (!c.agent && !c.formatExplicit) { - let capturedResult: PayResult | null = null; + let capturedResult: PayResult | null | undefined; return renderInteractive( , - () => { - if (!capturedResult) - throw new Error('Component exited without producing a result'); - return capturedResult; - }, + () => resolveInteractivePayResult(capturedResult), ); }