Skip to content

Commit 888e8a2

Browse files
feat: Read Shop Pay card status one read at a time and report outcome details
Stainless-Generated-From: dd6b6b03f72c1649efbd6b4b8b7271c44ccb2981
1 parent e5e6b25 commit 888e8a2

8 files changed

Lines changed: 125 additions & 5 deletions

‎src/kernel/resources/vaults/items.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,9 @@ def perform_operation(
615615
"PURCHASE", "AUTHORIZATION", "CAPTURE", "REFUND", "REVERSAL", "VERIFICATION", "CHARGEBACK", "FRAUD"
616616
],
617617
type: Literal["confirm_transaction"],
618+
failure_code: str | Omit = omit,
619+
order_id: str | Omit = omit,
620+
order_url: str | Omit = omit,
618621
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
619622
# The extra values given here take precedence over values defined on the client or passed to this method.
620623
extra_headers: Headers | None = None,
@@ -662,6 +665,17 @@ def perform_operation(
662665
663666
occurred_at: Time the merchant outcome was observed.
664667
668+
failure_code: Why the purchase did not succeed, for any other outcome, such as 3ds_challenge,
669+
captcha, login_required, timeout or site_error. payment_declined goes only with
670+
DECLINED, which takes no other code. Shop Pay reports it; other providers ignore
671+
it.
672+
673+
order_id: The merchant's order number, for an APPROVED outcome. Shop Pay reports it; other
674+
providers ignore it.
675+
676+
order_url: The merchant's https order page, for an APPROVED outcome. Shop Pay reports it;
677+
other providers ignore it.
678+
665679
extra_headers: Send extra headers
666680
667681
extra_query: Add additional query parameters to the request
@@ -1655,6 +1669,9 @@ def perform_operation(
16551669
"PURCHASE", "AUTHORIZATION", "CAPTURE", "REFUND", "REVERSAL", "VERIFICATION", "CHARGEBACK", "FRAUD"
16561670
]
16571671
| Omit = omit,
1672+
failure_code: str | Omit = omit,
1673+
order_id: str | Omit = omit,
1674+
order_url: str | Omit = omit,
16581675
checkout: VaultCheckoutContextParam | Omit = omit,
16591676
fields: Iterable[VaultFillFieldParam] | Omit = omit,
16601677
timeout_ms: int | Omit = omit,
@@ -1698,6 +1715,9 @@ def perform_operation(
16981715
"occurred_at": occurred_at,
16991716
"status": status,
17001717
"transaction_type": transaction_type,
1718+
"failure_code": failure_code,
1719+
"order_id": order_id,
1720+
"order_url": order_url,
17011721
"checkout": checkout,
17021722
"fields": fields,
17031723
"timeout_ms": timeout_ms,
@@ -2600,6 +2620,9 @@ async def perform_operation(
26002620
"PURCHASE", "AUTHORIZATION", "CAPTURE", "REFUND", "REVERSAL", "VERIFICATION", "CHARGEBACK", "FRAUD"
26012621
],
26022622
type: Literal["confirm_transaction"],
2623+
failure_code: str | Omit = omit,
2624+
order_id: str | Omit = omit,
2625+
order_url: str | Omit = omit,
26032626
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
26042627
# The extra values given here take precedence over values defined on the client or passed to this method.
26052628
extra_headers: Headers | None = None,
@@ -2647,6 +2670,17 @@ async def perform_operation(
26472670
26482671
occurred_at: Time the merchant outcome was observed.
26492672
2673+
failure_code: Why the purchase did not succeed, for any other outcome, such as 3ds_challenge,
2674+
captcha, login_required, timeout or site_error. payment_declined goes only with
2675+
DECLINED, which takes no other code. Shop Pay reports it; other providers ignore
2676+
it.
2677+
2678+
order_id: The merchant's order number, for an APPROVED outcome. Shop Pay reports it; other
2679+
providers ignore it.
2680+
2681+
order_url: The merchant's https order page, for an APPROVED outcome. Shop Pay reports it;
2682+
other providers ignore it.
2683+
26502684
extra_headers: Send extra headers
26512685
26522686
extra_query: Add additional query parameters to the request
@@ -3640,6 +3674,9 @@ async def perform_operation(
36403674
"PURCHASE", "AUTHORIZATION", "CAPTURE", "REFUND", "REVERSAL", "VERIFICATION", "CHARGEBACK", "FRAUD"
36413675
]
36423676
| Omit = omit,
3677+
failure_code: str | Omit = omit,
3678+
order_id: str | Omit = omit,
3679+
order_url: str | Omit = omit,
36433680
checkout: VaultCheckoutContextParam | Omit = omit,
36443681
fields: Iterable[VaultFillFieldParam] | Omit = omit,
36453682
timeout_ms: int | Omit = omit,
@@ -3683,6 +3720,9 @@ async def perform_operation(
36833720
"occurred_at": occurred_at,
36843721
"status": status,
36853722
"transaction_type": transaction_type,
3723+
"failure_code": failure_code,
3724+
"order_id": order_id,
3725+
"order_url": order_url,
36863726
"checkout": checkout,
36873727
"fields": fields,
36883728
"timeout_ms": timeout_ms,

‎src/kernel/types/vaults/authorize_vault_item_operation_request_param.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class AuthorizeVaultItemOperationRequestParam(TypedDict, total=False):
1111
"""
12-
Authorize a Link, Kernel or Shop Pay card using its existing purchase specification. Use only after explicit user approval and when the item advertises authorize; follow the advertised operation's description. For a Link card, pass browser_id and page_url together while the browser is on the final checkout page: Kernel inspects that checkout, chooses how the credential is delivered, and limits fill to that checkout's origin in any browser with this vault attached. Omitting both issues a virtual card that fills any page on the merchant origin. Once approval has been requested, browser_id and page_url are ignored and authorize only re-checks the request. Browser and checkout inspection errors occur before any provider request and can be retried once the browser is on the checkout page. Kernel and Shop Pay cards do not accept browser_id or page_url.
12+
Authorize a Link, Kernel or Shop Pay card using its existing purchase specification. Use only after explicit user approval and when the item advertises authorize; follow the advertised operation's description. For a Link or Shop Pay card, pass browser_id and page_url together while the browser is on the final checkout page: Kernel confirms that checkout is open, sends it to the provider as the merchant, and limits fill to that checkout's origin in any browser with this vault attached. For Link it also chooses how the credential is delivered. Omitting both issues a virtual card that fills any page on the merchant origin. Once approval has been requested, browser_id and page_url are ignored and authorize only re-checks the request. Browser and checkout inspection errors occur before any provider request and can be retried once the browser is on the checkout page. Kernel cards do not accept browser_id or page_url.
1313
"""
1414

1515
type: Required[Literal["authorize"]]

‎src/kernel/types/vaults/confirm_transaction_vault_item_operation_request_param.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,23 @@ class ConfirmTransactionVaultItemOperationRequestParam(TypedDict, total=False):
3232
]
3333

3434
type: Required[Literal["confirm_transaction"]]
35+
36+
failure_code: str
37+
"""
38+
Why the purchase did not succeed, for any other outcome, such as 3ds_challenge,
39+
captcha, login_required, timeout or site_error. payment_declined goes only with
40+
DECLINED, which takes no other code. Shop Pay reports it; other providers ignore
41+
it.
42+
"""
43+
44+
order_id: str
45+
"""The merchant's order number, for an APPROVED outcome.
46+
47+
Shop Pay reports it; other providers ignore it.
48+
"""
49+
50+
order_url: str
51+
"""The merchant's https order page, for an APPROVED outcome.
52+
53+
Shop Pay reports it; other providers ignore it.
54+
"""

‎src/kernel/types/vaults/item_perform_operation_params.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ class ConfirmTransactionVaultItemOperationRequest(TypedDict, total=False):
7575

7676
type: Required[Literal["confirm_transaction"]]
7777

78+
failure_code: str
79+
"""
80+
Why the purchase did not succeed, for any other outcome, such as 3ds_challenge,
81+
captcha, login_required, timeout or site_error. payment_declined goes only with
82+
DECLINED, which takes no other code. Shop Pay reports it; other providers ignore
83+
it.
84+
"""
85+
86+
order_id: str
87+
"""The merchant's order number, for an APPROVED outcome.
88+
89+
Shop Pay reports it; other providers ignore it.
90+
"""
91+
92+
order_url: str
93+
"""The merchant's https order page, for an APPROVED outcome.
94+
95+
Shop Pay reports it; other providers ignore it.
96+
"""
97+
7898

7999
class CollectVaultItemOperationRequest(TypedDict, total=False):
80100
id_or_name: Required[str]

‎src/kernel/types/vaults/shop_pay_card_state.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class ShopPayCardState(BaseModel):
4141
]
4242
"""declined covers a request the shopper declined or that was cancelled.
4343
44+
consumed means the transaction outcome was reported with confirm_transaction;
45+
the card is no longer stored and cannot be filled again, whatever the outcome.
4446
recovery_required means a provider operation has an unresolved outcome and the
4547
card cannot be used. When status_reason says the provider refused retrieval
4648
before acceptance, no card was issued and a later read retries. Otherwise follow

‎src/kernel/types/vaults/shop_pay_card_vault_item_spec.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ class LineItem(BaseModel):
2828
class ShopPayCardVaultItemSpec(BaseModel):
2929
"""Shop Pay purchase.
3030
31-
amount is the limit the shopper approves; totals must include exactly one positive total no higher than it. context is shown to the shopper when they approve. Authorize without checkout context: authorize returns an approval action for the shopper, who approves the purchase in Shop. Share its URL unchanged when present. Once approved, the card becomes ready and fills checkouts on the merchant_url origin. Report the merchant outcome with confirm_transaction.
31+
amount is the limit the shopper approves; totals must include exactly one positive total no higher than it. context is shown to the shopper when they approve. Authorize it with the browser at final checkout: Kernel sends that page to Shop as the merchant and the card fills only on its origin. Without browser_id and page_url it authorizes for merchant_url. authorize returns an approval action for the shopper, who approves the purchase in Shop; share its URL unchanged when present. Report the merchant outcome with confirm_transaction, which ends the card.
3232
"""
3333

3434
amount: int
35-
"""Approval limit in minor currency units."""
35+
"""Approval limit in minor currency units, at most 1000000."""
3636

3737
context: str
3838
"""What is being bought and why, written for the shopper."""
3939

4040
currency: str
41+
"""Shop accepts USD spend requests only."""
4142

4243
merchant_name: str
4344

‎src/kernel/types/vaults/shop_pay_card_vault_item_spec_param.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ class LineItem(TypedDict, total=False):
2828
class ShopPayCardVaultItemSpecParam(TypedDict, total=False):
2929
"""Shop Pay purchase.
3030
31-
amount is the limit the shopper approves; totals must include exactly one positive total no higher than it. context is shown to the shopper when they approve. Authorize without checkout context: authorize returns an approval action for the shopper, who approves the purchase in Shop. Share its URL unchanged when present. Once approved, the card becomes ready and fills checkouts on the merchant_url origin. Report the merchant outcome with confirm_transaction.
31+
amount is the limit the shopper approves; totals must include exactly one positive total no higher than it. context is shown to the shopper when they approve. Authorize it with the browser at final checkout: Kernel sends that page to Shop as the merchant and the card fills only on its origin. Without browser_id and page_url it authorizes for merchant_url. authorize returns an approval action for the shopper, who approves the purchase in Shop; share its URL unchanged when present. Report the merchant outcome with confirm_transaction, which ends the card.
3232
"""
3333

3434
amount: Required[int]
35-
"""Approval limit in minor currency units."""
35+
"""Approval limit in minor currency units, at most 1000000."""
3636

3737
context: Required[str]
3838
"""What is being bought and why, written for the shopper."""
3939

4040
currency: Required[str]
41+
"""Shop accepts USD spend requests only."""
4142

4243
merchant_name: Required[str]
4344

‎tests/api_resources/vaults/test_items.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,24 @@ def test_method_perform_operation_overload_3(self, client: Kernel) -> None:
793793
)
794794
assert_matches_type(VaultItemOperationResponse, item, path=["response"])
795795

796+
@pytest.mark.skip(reason="Mock server tests are disabled")
797+
@parametrize
798+
def test_method_perform_operation_with_all_params_overload_3(self, client: Kernel) -> None:
799+
item = client.vaults.items.perform_operation(
800+
key="key",
801+
id_or_name="id_or_name",
802+
amount=0,
803+
currency="SEW",
804+
occurred_at=parse_datetime("2019-12-27T18:11:19.117Z"),
805+
status="APPROVED",
806+
transaction_type="PURCHASE",
807+
type="confirm_transaction",
808+
failure_code="failure_code",
809+
order_id="x",
810+
order_url="https://example.com",
811+
)
812+
assert_matches_type(VaultItemOperationResponse, item, path=["response"])
813+
796814
@pytest.mark.skip(reason="Mock server tests are disabled")
797815
@parametrize
798816
def test_raw_response_perform_operation_overload_3(self, client: Kernel) -> None:
@@ -3396,6 +3414,24 @@ async def test_method_perform_operation_overload_3(self, async_client: AsyncKern
33963414
)
33973415
assert_matches_type(VaultItemOperationResponse, item, path=["response"])
33983416

3417+
@pytest.mark.skip(reason="Mock server tests are disabled")
3418+
@parametrize
3419+
async def test_method_perform_operation_with_all_params_overload_3(self, async_client: AsyncKernel) -> None:
3420+
item = await async_client.vaults.items.perform_operation(
3421+
key="key",
3422+
id_or_name="id_or_name",
3423+
amount=0,
3424+
currency="SEW",
3425+
occurred_at=parse_datetime("2019-12-27T18:11:19.117Z"),
3426+
status="APPROVED",
3427+
transaction_type="PURCHASE",
3428+
type="confirm_transaction",
3429+
failure_code="failure_code",
3430+
order_id="x",
3431+
order_url="https://example.com",
3432+
)
3433+
assert_matches_type(VaultItemOperationResponse, item, path=["response"])
3434+
33993435
@pytest.mark.skip(reason="Mock server tests are disabled")
34003436
@parametrize
34013437
async def test_raw_response_perform_operation_overload_3(self, async_client: AsyncKernel) -> None:

0 commit comments

Comments
 (0)