Skip to content

Commit c439359

Browse files
feat: Add single-use AgentCard prepare_checkout for Square
Stainless-Generated-From: 0c1e767db4c047801717ec350cd4b40cd7eace0c
1 parent 3927c96 commit c439359

12 files changed

Lines changed: 513 additions & 50 deletions

api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,16 @@ Types:
525525
```python
526526
from kernel.types.vaults import (
527527
AgentcardCheckoutAuthorization,
528+
AgentcardCheckoutPreparation,
529+
AuthorizeVaultItemOperationRequest,
528530
CardVaultItemSpec,
529531
CardVaultItemState,
530532
FillVaultItemOperationRequest,
531533
FillVaultItemOperationResult,
534+
PrepareCheckoutVaultItemOperationRequest,
532535
VaultCardAliases,
533536
VaultCardFillField,
537+
VaultCheckoutContext,
534538
VaultFillFieldResult,
535539
VaultItem,
536540
VaultItemAction,

src/kernel/resources/vaults/items.py

Lines changed: 157 additions & 28 deletions
Large diffs are not rendered by default.

src/kernel/types/vaults/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@
2020
from .wallet_vault_item_state import WalletVaultItemState as WalletVaultItemState
2121
from .card_vault_item_spec_param import CardVaultItemSpecParam as CardVaultItemSpecParam
2222
from .vault_card_fill_field_param import VaultCardFillFieldParam as VaultCardFillFieldParam
23+
from .vault_checkout_context_param import VaultCheckoutContextParam as VaultCheckoutContextParam
2324
from .item_perform_operation_params import ItemPerformOperationParams as ItemPerformOperationParams
2425
from .vault_item_operation_response import VaultItemOperationResponse as VaultItemOperationResponse
26+
from .agentcard_checkout_preparation import AgentcardCheckoutPreparation as AgentcardCheckoutPreparation
2527
from .agentcard_checkout_authorization import AgentcardCheckoutAuthorization as AgentcardCheckoutAuthorization
2628
from .fill_vault_item_operation_result import FillVaultItemOperationResult as FillVaultItemOperationResult
2729
from .fill_vault_item_operation_request_param import (
2830
FillVaultItemOperationRequestParam as FillVaultItemOperationRequestParam,
2931
)
32+
from .authorize_vault_item_operation_request_param import (
33+
AuthorizeVaultItemOperationRequestParam as AuthorizeVaultItemOperationRequestParam,
34+
)
35+
from .prepare_checkout_vault_item_operation_request_param import (
36+
PrepareCheckoutVaultItemOperationRequestParam as PrepareCheckoutVaultItemOperationRequestParam,
37+
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Optional
4+
from datetime import datetime
5+
from typing_extensions import Literal
6+
7+
from ..._models import BaseModel
8+
9+
__all__ = ["AgentcardCheckoutPreparation"]
10+
11+
12+
class AgentcardCheckoutPreparation(BaseModel):
13+
"""One-use Square checkout preparation.
14+
15+
Keep the approval page open through token handoff. The amount is display-only and does not constrain the merchant's eventual charge.
16+
"""
17+
18+
browser_id: str
19+
20+
created_at: datetime
21+
22+
environment: Literal["production", "sandbox"]
23+
24+
merchant_origin: str
25+
26+
status: Literal["creating", "awaiting_approval", "ready", "consumed", "cancelled", "expired", "unknown"]
27+
"""
28+
Preparation consumed means egress claimed the preparation and it cannot be
29+
reused. It does not mean the attempt settled. Use the enclosing item's status as
30+
the lifecycle indicator; item consumed means the attempt settled, not that an
31+
order or charge succeeded.
32+
"""
33+
34+
id: Optional[str] = None
35+
36+
approval_url: Optional[str] = None
37+
38+
expires_at: Optional[datetime] = None
39+
"""
40+
When ready, the absolute deadline to submit the first native request; no later
41+
than provider readiness expiry or 30 seconds after Kernel first observes
42+
readiness. Polling never extends this deadline.
43+
"""
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Literal, Required, TypedDict
6+
7+
__all__ = ["AuthorizeVaultItemOperationRequestParam"]
8+
9+
10+
class AuthorizeVaultItemOperationRequestParam(TypedDict, total=False):
11+
"""Authorize a Link card using its existing purchase specification.
12+
13+
Use only after explicit user approval and when the item advertises authorize. Do not automatically retry provider failures or indeterminate outcomes. Checkout context is not accepted.
14+
"""
15+
16+
type: Required[Literal["authorize"]]

src/kernel/types/vaults/card_vault_item_state.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ..._utils import PropertyInfo
99
from ..._models import BaseModel
1010
from .vault_card_aliases import VaultCardAliases
11+
from .agentcard_checkout_preparation import AgentcardCheckoutPreparation
1112
from .agentcard_checkout_authorization import AgentcardCheckoutAuthorization
1213

1314
__all__ = ["CardVaultItemState", "LinkCardState", "LinkCardStateMasks", "AgentCardCardState", "AgentCardCardStateMasks"]
@@ -76,14 +77,28 @@ def __getattr__(self, attr: str) -> str: ...
7677
class AgentCardCardState(BaseModel):
7778
provider: Literal["agentcard"]
7879

79-
status: Literal["requested", "ready", "pending_approval", "degraded", "recovery_required"]
80-
"""recovery_required means the original checkout outcome is unresolved.
81-
82-
Automatic reuse is blocked. Known authorization IDs must be reconciled through
83-
provider observations or support. When no authorization ID was returned, an
84-
explicitly confirmed item deletion may abandon the unresolved attempt so the
85-
caller can create a replacement; deletion does not prove that the original
86-
attempt failed. It does not mean declined or expired.
80+
status: Literal[
81+
"requested",
82+
"ready",
83+
"preparing",
84+
"ready_to_submit",
85+
"pending_approval",
86+
"consumed",
87+
"stopped",
88+
"outcome_unknown",
89+
"degraded",
90+
"recovery_required",
91+
]
92+
"""ready_to_submit is device readiness for at most 30 seconds.
93+
94+
consumed means the prepared attempt has settled, not that an order succeeded.
95+
stopped cannot be reused. outcome_unknown requires merchant reconciliation and
96+
blocks new requests. recovery_required means the original checkout outcome is
97+
unresolved. Automatic reuse is blocked. Known authorization IDs must be
98+
reconciled through provider observations or support. When no authorization ID
99+
was returned, an explicitly confirmed item deletion may abandon the unresolved
100+
attempt so the caller can create a replacement; deletion does not prove that the
101+
original attempt failed. It does not mean declined or expired.
87102
"""
88103

89104
aliases: Optional[VaultCardAliases] = None
@@ -96,6 +111,13 @@ class AgentCardCardState(BaseModel):
96111

97112
masks: Optional[AgentCardCardStateMasks] = None
98113

114+
preparation: Optional[AgentcardCheckoutPreparation] = None
115+
"""One-use Square checkout preparation.
116+
117+
Keep the approval page open through token handoff. The amount is display-only
118+
and does not constrain the merchant's eventual charge.
119+
"""
120+
99121
status_reason: Optional[str] = None
100122

101123

src/kernel/types/vaults/item_perform_operation_params.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
from typing_extensions import Literal, Required, TypeAlias, TypedDict
77

88
from .vault_card_fill_field_param import VaultCardFillFieldParam
9+
from .vault_checkout_context_param import VaultCheckoutContextParam
910

10-
__all__ = ["ItemPerformOperationParams", "AuthorizeVaultItemOperationRequest", "FillVaultItemOperationRequest"]
11+
__all__ = [
12+
"ItemPerformOperationParams",
13+
"AuthorizeVaultItemOperationRequest",
14+
"PrepareCheckoutVaultItemOperationRequest",
15+
"FillVaultItemOperationRequest",
16+
]
1117

1218

1319
class AuthorizeVaultItemOperationRequest(TypedDict, total=False):
@@ -16,6 +22,21 @@ class AuthorizeVaultItemOperationRequest(TypedDict, total=False):
1622
type: Required[Literal["authorize"]]
1723

1824

25+
class PrepareCheckoutVaultItemOperationRequest(TypedDict, total=False):
26+
id_or_name: Required[str]
27+
28+
checkout: Required[VaultCheckoutContextParam]
29+
"""Required when preparing an unused AgentCard card for Square.
30+
31+
Consent is bound to this browser and declared merchant origin, not a tab. Wait
32+
for the item's ready_to_submit status before native Pay and submit within its
33+
readiness deadline. Unused preparations expire automatically; every preparation
34+
is single-use, including after failure or expiry.
35+
"""
36+
37+
type: Required[Literal["prepare_checkout"]]
38+
39+
1940
class FillVaultItemOperationRequest(TypedDict, total=False):
2041
id_or_name: Required[str]
2142

@@ -38,4 +59,6 @@ class FillVaultItemOperationRequest(TypedDict, total=False):
3859
"""Total operation deadline in milliseconds, not a per-field timeout."""
3960

4061

41-
ItemPerformOperationParams: TypeAlias = Union[AuthorizeVaultItemOperationRequest, FillVaultItemOperationRequest]
62+
ItemPerformOperationParams: TypeAlias = Union[
63+
AuthorizeVaultItemOperationRequest, PrepareCheckoutVaultItemOperationRequest, FillVaultItemOperationRequest
64+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Literal, Required, TypedDict
6+
7+
from .vault_checkout_context_param import VaultCheckoutContextParam
8+
9+
__all__ = ["PrepareCheckoutVaultItemOperationRequestParam"]
10+
11+
12+
class PrepareCheckoutVaultItemOperationRequestParam(TypedDict, total=False):
13+
"""Prepare an unused AgentCard card for Square checkout.
14+
15+
Deliver the returned approval URL and keep the approval page open. Poll the item until ready_to_submit, then submit native Pay before preparation.expires_at. Readiness lasts at most 30 seconds. Unused preparations expire automatically. Preparations are single-use even after failure or expiry; do not automatically retry and reconcile uncertain outcomes with the merchant.
16+
"""
17+
18+
checkout: Required[VaultCheckoutContextParam]
19+
"""Required when preparing an unused AgentCard card for Square.
20+
21+
Consent is bound to this browser and declared merchant origin, not a tab. Wait
22+
for the item's ready_to_submit status before native Pay and submit within its
23+
readiness deadline. Unused preparations expire automatically; every preparation
24+
is single-use, including after failure or expiry.
25+
"""
26+
27+
type: Required[Literal["prepare_checkout"]]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Literal, Required, TypedDict
6+
7+
__all__ = ["VaultCheckoutContextParam"]
8+
9+
10+
class VaultCheckoutContextParam(TypedDict, total=False):
11+
"""Required when preparing an unused AgentCard card for Square.
12+
13+
Consent is bound to this browser and declared merchant origin, not a tab. Wait for the item's ready_to_submit status before native Pay and submit within its readiness deadline. Unused preparations expire automatically; every preparation is single-use, including after failure or expiry.
14+
"""
15+
16+
browser_id: Required[str]
17+
"""Active browser session with this vault bound to it."""
18+
19+
environment: Required[Literal["production", "sandbox"]]
20+
"""Square environment, independent of the AgentCard credential mode."""
21+
22+
merchant_origin: Required[str]
23+
"""Canonical HTTPS origin of the top-level merchant document, not the Square
24+
iframe.
25+
26+
HTTP localhost is accepted for tests.
27+
"""

src/kernel/types/vaults/vault_item.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class WalletVaultItemAvailableOperation(BaseModel):
4343

4444
description: str
4545

46-
type: Literal["authorize", "fill"]
46+
type: Literal["authorize", "prepare_checkout", "fill"]
4747

4848

4949
class WalletVaultItemExpanded(BaseModel):
@@ -107,7 +107,7 @@ class CardVaultItemAvailableOperation(BaseModel):
107107

108108
description: str
109109

110-
type: Literal["authorize", "fill"]
110+
type: Literal["authorize", "prepare_checkout", "fill"]
111111

112112

113113
class CardVaultItem(BaseModel):

0 commit comments

Comments
 (0)