@visa/cli 4.1.0-rc.164 → 4.1.0-rc.166

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,9 +10,32 @@ export { minorFromDecimal, pageCurrency } from './amount.js';
10
10
  export type CheckoutMode = 'dry-run' | 'submit';
11
11
  export type CheckoutOutcome = 'reviewed-dry-run'
12
12
  /** Historical receipt value from the credential-disclosing dry-run. */
13
- | 'filled-dry-run' | 'partial-fill' | 'adapter-required' | 'confirmed' | 'declined' | 'action-required' | 'cancelled' | 'blocked-by-mandate' | 'failed';
13
+ | 'filled-dry-run' | 'partial-fill' | 'adapter-required' | 'confirmed' | 'declined' | 'action-required' | 'cancelled' | 'blocked-by-mandate'
14
+ /**
15
+ * KNOWN-NOT-CHARGED. Every `failed` path ends before the pay control was
16
+ * clicked (or before a credential existed at all), so a caller may retry it
17
+ * without risking a second charge.
18
+ */
19
+ | 'failed'
20
+ /**
21
+ * SUBMITTED, OUTCOME UNKNOWN — the pay control WAS clicked and neither a
22
+ * confirmation nor a decline was observed before the deadline. The charge may
23
+ * have captured. NEVER retry this automatically.
24
+ *
25
+ * This case used to be reported as `failed`, and the difference is not
26
+ * academic: on 2026-08-17 a whop.com checkout returned `failed` here, the
27
+ * caller read that as "nothing happened" and re-ran the purchase, and the
28
+ * second run drew a second $5 against the owner's mandate. `outcome.ts`
29
+ * already treats an unrecognized post-submit page as the SAFE direction
30
+ * ('unknown' → operator verification); collapsing it into `failed` at the
31
+ * boundary is what threw that safety away. The distinction has to survive all
32
+ * the way to the value consumers branch on.
33
+ */
34
+ | 'unverified';
14
35
  /** Stable machine-readable cause for an expected terminal checkout result. */
15
- export type CheckoutFailureCode = 'card-number-field-unavailable' | 'human-action-required' | 'mandate-blocked';
36
+ export type CheckoutFailureCode = 'card-number-field-unavailable' | 'human-action-required' | 'mandate-blocked'
37
+ /** A detected, visible field we held a value for refused every fill attempt. */
38
+ | 'required-field-unfillable';
16
39
  export type CredentialLifecycle = 'not-requested' | 'minted-not-exposed' | 'partially-exposed' | 'fully-filled';
17
40
  export type CredentialTiming = {
18
41
  approvedAt?: string;
@@ -1116,9 +1116,30 @@ export async function submitApprovedCheckout(reviewId, opts, store = defaultPrep
1116
1116
  ? []
1117
1117
  : ['expiry']),
1118
1118
  ];
1119
+ // Roles the adapter TRIED to fill and never landed, across every reveal
1120
+ // attempt. A job only exists when the field was detected, was visible, and
1121
+ // we held a value for it (see `add()` in adapters/generic.ts) — so a failure
1122
+ // here is never "the page didn't ask for it". It means the page asked, we
1123
+ // answered, and the element refused.
1124
+ //
1125
+ // Roles that failed on an early attempt and succeeded after a reveal are
1126
+ // excluded: `successfulRoles` spans all four attempts, same as above.
1127
+ const failedFillRoles = [
1128
+ ...new Set(evidence
1129
+ .getSteps()
1130
+ .filter((step) => step.type === 'field-fill' && step.data.ok === false)
1131
+ .map((step) => String(step.data.role))),
1132
+ ]
1133
+ .filter((role) => !successfulRoles.has(role))
1134
+ .sort();
1119
1135
  evidence.step('fill-complete', {
1120
- ok: missingCredentialRoles.length === 0,
1136
+ // "Ready to submit", not "the card fields landed". Before 2026-08-17 this
1137
+ // read only the credential roles, so a whop.com run whose city/state/
1138
+ // postalCode all timed out recorded `ok: true` and clicked Get access on
1139
+ // a form it knew was incomplete.
1140
+ ok: missingCredentialRoles.length === 0 && failedFillRoles.length === 0,
1121
1141
  missingCredentialRoles,
1142
+ failedFillRoles,
1122
1143
  });
1123
1144
  if (options.debugShotsDir) {
1124
1145
  await captureDebugShot(page, options.debugShotsDir, checkout.review.id, '2-filled', evidence, state.fields);
@@ -1177,6 +1198,20 @@ export async function submitApprovedCheckout(reviewId, opts, store = defaultPrep
1177
1198
  evidence.setSnapshotSummary(await snapshotSummary(page));
1178
1199
  return makeResult('failed', state.fields, evidence, requiresAdapter, `credential fill incomplete: missing ${missingCredentialRoles.join(', ')}`);
1179
1200
  }
1201
+ // STOP BEFORE THE CLICK when any field we tried to fill refused. Submitting
1202
+ // a form we know is incomplete is how a PSP ends up holding a charge we
1203
+ // cannot then confirm or account for: the 2026-08-17 whop.com run filled the
1204
+ // card into Basis Theory iframes, watched city/state/postalCode time out at
1205
+ // 5s each, clicked Get access anyway, and could never observe an outcome.
1206
+ //
1207
+ // This refusal happens BEFORE the submit click, so nothing can be charged by
1208
+ // it — the safe direction, and the reason it is allowed to be strict. A
1209
+ // merchant whose address widget we cannot drive now fails cleanly and
1210
+ // retryably instead of dangerously.
1211
+ if (failedFillRoles.length > 0) {
1212
+ evidence.setSnapshotSummary(await snapshotSummary(page));
1213
+ return makeResult('partial-fill', state.fields, evidence, requiresAdapter, `required field fill failed: ${failedFillRoles.join(', ')} — not submitting an incomplete form. Nothing was charged.`, undefined, 'required-field-unfillable');
1214
+ }
1180
1215
  if (!submit) {
1181
1216
  evidence.setSnapshotSummary(await snapshotSummary(page));
1182
1217
  return makeResult('failed', state.fields, evidence, requiresAdapter, 'no submit control detected');
@@ -1337,19 +1372,35 @@ export async function submitApprovedCheckout(reviewId, opts, store = defaultPrep
1337
1372
  });
1338
1373
  return makeResult('confirmed', state.fields, evidence, requiresAdapter, undefined, confirmationRef);
1339
1374
  }
1375
+ // The pay control was clicked and the observer reached its deadline with no
1376
+ // definitive answer. This is NOT a failure — it is the absence of an answer,
1377
+ // and the charge may well have captured. Reporting it as `failed` is what
1378
+ // let a caller re-run the 2026-08-17 whop.com purchase and draw a second $5.
1340
1379
  evidence.step('outcome', {
1341
- outcome: 'failed',
1380
+ outcome: 'unverified',
1342
1381
  reason: 'no confirmation or decline signal',
1343
1382
  lastSeen: observed.lastSeen,
1344
1383
  attempts: observed.attempts,
1345
1384
  elapsedMs: observed.elapsedMs,
1346
1385
  });
1347
- return makeResult('failed', state.fields, evidence, requiresAdapter, observed.lastSeen === 'processing'
1348
- ? 'submitted but outcome unknown (page still processing at deadline)'
1349
- : 'submitted but outcome unknown');
1386
+ return makeResult('unverified', state.fields, evidence, requiresAdapter, observed.lastSeen === 'processing'
1387
+ ? 'submitted but outcome unknown (page still processing at deadline) — the charge may have gone through; verify with the merchant before any retry'
1388
+ : 'submitted but outcome unknown — the charge may have gone through; verify with the merchant before any retry');
1350
1389
  }
1351
1390
  catch (err) {
1352
1391
  const detail = err.message;
1392
+ // A throw AFTER the pay control was clicked (browser teardown, navigation
1393
+ // race, evidence I/O) leaves the same open question as the deadline path: we
1394
+ // clicked, and we do not know what happened. It must not report `failed`
1395
+ // either. A throw before the click never disclosed a payable form, so it
1396
+ // stays a clean, retry-safe failure.
1397
+ const submitted = evidence
1398
+ .getSteps()
1399
+ .some((step) => step.type === 'submit' && step.data.clicked === true);
1400
+ if (submitted) {
1401
+ evidence.step('outcome', { outcome: 'unverified', error: detail });
1402
+ return makeResult('unverified', state.fields, evidence, requiresAdapter, `${detail} — the pay control was already clicked; the charge may have gone through, so verify with the merchant before any retry`);
1403
+ }
1353
1404
  evidence.step('outcome', { outcome: 'failed', error: detail });
1354
1405
  return makeResult('failed', state.fields, evidence, requiresAdapter, detail);
1355
1406
  }
@@ -28,5 +28,10 @@ export declare function isRunSuccess(mode: CheckoutMode, outcome: CheckoutOutcom
28
28
  * so no charge can exist until it is completed — the double-charge warning
29
29
  * would misdirect the operator, and the runner prints the challenge-specific
30
30
  * notice instead.
31
+ *
32
+ * The executor now NAMES this state in the outcome itself ('unverified'), so
33
+ * the two agree by construction. This predicate stays the broader guard: it
34
+ * also catches a post-click throw or any future outcome that leaves the same
35
+ * question open, and it is what the receipt's reconciliation list reads.
31
36
  */
32
37
  export declare function submitClickedWithoutConfirmation(result: CheckoutResult): boolean;
@@ -60,6 +60,11 @@ export function isRunSuccess(mode, outcome) {
60
60
  * so no charge can exist until it is completed — the double-charge warning
61
61
  * would misdirect the operator, and the runner prints the challenge-specific
62
62
  * notice instead.
63
+ *
64
+ * The executor now NAMES this state in the outcome itself ('unverified'), so
65
+ * the two agree by construction. This predicate stays the broader guard: it
66
+ * also catches a post-click throw or any future outcome that leaves the same
67
+ * question open, and it is what the receipt's reconciliation list reads.
63
68
  */
64
69
  export function submitClickedWithoutConfirmation(result) {
65
70
  if (result.outcome === 'confirmed' ||
@@ -37,7 +37,15 @@ export function buildReceipt(input) {
37
37
  ? 'No action needed.'
38
38
  : result.outcome === 'declined'
39
39
  ? 'Review the decline before trying again.'
40
- : 'Review this outcome before retrying.';
40
+ : result.outcome === 'unverified'
41
+ ? // Defensive: reconciliationFor() already pushes the richer
42
+ // submit-clicked reason for this outcome, so this line is only
43
+ // reached if that ever stops firing. It must still not invite a
44
+ // retry.
45
+ 'The charge may have gone through. Confirm with the merchant before retrying.'
46
+ : result.outcome === 'partial-fill'
47
+ ? 'Nothing was submitted and nothing was charged. Safe to try again once the checkout can be filled.'
48
+ : 'Review this outcome before retrying.';
41
49
  const recoveryActions = reconciliation.reasons.length > 0 ? reconciliation.reasons : [fallbackAction];
42
50
  const cardLast4 = input.cardLast4 && /^\d{4}$/.test(input.cardLast4) ? input.cardLast4 : null;
43
51
  const checkoutUrl = input.merchant.url && KNOWN_MERCHANT_IDENTITIES[input.merchant.url] ? input.merchant.url : null;