Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 12 additions & 28 deletions ap2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

from absl.testing import absltest
import integration_test_utils
from ucp_sdk.models.schemas.shopping import fulfillment_resp as checkout
from ucp_sdk.models.schemas.shopping.ap2_mandate import Ap2CompleteRequest
from ucp_sdk.models.schemas.shopping import checkout
from ucp_sdk.models.schemas.shopping.ap2_mandate import Ap2WithCheckoutMandate
from ucp_sdk.models.schemas.shopping.ap2_mandate import CheckoutMandate
from ucp_sdk.models.schemas.shopping.payment_resp import (
PaymentResponse as Payment,
from ucp_sdk.models.schemas.shopping.payment import (
Payment,
)
from ucp_sdk.models.schemas.shopping.types import card_payment_instrument
from ucp_sdk.models.schemas.shopping.types import payment_instrument
from ucp_sdk.models.schemas.shopping.types import token_credential_resp
from ucp_sdk.models.schemas.shopping.types import token_credential as token_credential_resp


# Rebuild models to resolve forward references
checkout.Checkout.model_rebuild(_types_namespace={"PaymentResponse": Payment})
checkout.Checkout.model_rebuild(_types_namespace={"Payment": Payment})


class Ap2MandateTest(integration_test_utils.IntegrationTestBase):
Expand All @@ -48,32 +48,16 @@ def test_ap2_mandate_completion(self) -> None:
response_json = self.create_checkout_session()
checkout_id = checkout.Checkout(**response_json).id

credential = token_credential_resp.TokenCredentialResponse(
type="token", token="success_token"
)
instr = payment_instrument.PaymentInstrument(
root=card_payment_instrument.CardPaymentInstrument(
id="instr_1",
brand="visa",
last_digits="4242",
handler_id="mock_payment_handler",
handler_name="mock_payment_handler",
type="card",
credential=credential,
)
)
payment_data = instr.root.model_dump(mode="json", exclude_none=True)

# SD-JWT+kb pattern:
# ^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+(~[A-Za-z0-9_-]+)*$
mandate = CheckoutMandate(root="header.payload.signature~kb_signature")
ap2_data = Ap2CompleteRequest(checkout_mandate=mandate)
ap2_data = Ap2WithCheckoutMandate(checkout_mandate=mandate)

payment_payload = {
"payment_data": payment_data,
"risk_signals": {},
"ap2": ap2_data.model_dump(mode="json", exclude_none=True),
}
# Use the standard valid payment payload and add AP2 data
payment_payload = integration_test_utils.get_valid_payment_payload()
payment_payload["ap2"] = ap2_data.model_dump(
mode="json", exclude_none=True
)

response = self.client.post(
self.get_shopping_url(f"/checkout-sessions/{checkout_id}/complete"),
Expand Down
40 changes: 10 additions & 30 deletions binding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

from absl.testing import absltest
import integration_test_utils
from ucp_sdk.models.schemas.shopping import fulfillment_resp as checkout
from ucp_sdk.models.schemas.shopping.payment_resp import (
PaymentResponse as Payment,
from ucp_sdk.models.schemas.shopping import checkout
from ucp_sdk.models.schemas.shopping.payment import (
Payment,
)
from ucp_sdk.models.schemas.shopping.types import binding
from ucp_sdk.models.schemas.shopping.types import card_payment_instrument
from ucp_sdk.models.schemas.shopping.types import payment_identity
from ucp_sdk.models.schemas.shopping.types import payment_instrument
from ucp_sdk.models.schemas.shopping.types import token_credential_resp
from ucp_sdk.models.schemas.shopping.types import token_credential as token_credential_resp


# Rebuild models to resolve forward references
checkout.Checkout.model_rebuild(_types_namespace={"PaymentResponse": Payment})
checkout.Checkout.model_rebuild(_types_namespace={"Payment": Payment})


class TokenBindingTest(integration_test_utils.IntegrationTestBase):
Expand All @@ -48,31 +48,11 @@ def test_token_binding_completion(self) -> None:
response_json = self.create_checkout_session()
checkout_id = checkout.Checkout(**response_json).id

identity = payment_identity.PaymentIdentity(
access_token="user_access_token"
)
token_binding = binding.Binding(checkout_id=checkout_id, identity=identity)

# TokenCredentialResponse allows extra fields
credential = token_credential_resp.TokenCredentialResponse(
type="stripe_token", token="success_token", binding=token_binding
)

instr = payment_instrument.PaymentInstrument(
root=card_payment_instrument.CardPaymentInstrument(
id="instr_1",
brand="visa",
last_digits="4242",
handler_id="mock_payment_handler",
handler_name="mock_payment_handler",
type="card",
credential=credential,
)
)
payment_data = instr.root.model_dump(mode="json", exclude_none=True)
payment_payload = {
"payment_data": payment_data,
"risk_signals": {},
# Use the standard valid payment payload and add binding data
payment_payload = integration_test_utils.get_valid_payment_payload()
payment_payload["payment_data"]["credential"]["binding"] = {
"checkout_id": checkout_id,
"identity": {"access_token": "user_access_token"},
}

response = self.client.post(
Expand Down
23 changes: 12 additions & 11 deletions business_logic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@

from absl.testing import absltest
import integration_test_utils
from ucp_sdk.models.schemas.shopping import buyer_consent_resp as buyer_consent
from ucp_sdk.models.schemas.shopping import checkout_update_req
from ucp_sdk.models.schemas.shopping import discount_resp as discount
from ucp_sdk.models.schemas.shopping import fulfillment_resp as checkout
from ucp_sdk.models.schemas.shopping import payment_update_req
from ucp_sdk.models.schemas.shopping.payment_resp import (
PaymentResponse as Payment,
from ucp_sdk.models.schemas.shopping import buyer_consent
from ucp_sdk.models.schemas.shopping import checkout_update_request as checkout_update_req
from ucp_sdk.models.schemas.shopping import discount
from ucp_sdk.models.schemas.shopping import checkout
from ucp_sdk.models.schemas.shopping import payment_update_request as payment_update_req
from ucp_sdk.models.schemas.shopping.payment import (
Payment,
)
from ucp_sdk.models.schemas.shopping.types import buyer
from ucp_sdk.models.schemas.shopping.types import item_update_req
from ucp_sdk.models.schemas.shopping.types import line_item_update_req
from ucp_sdk.models.schemas.shopping.types import buyer_update_request
from ucp_sdk.models.schemas.shopping.types import item_update_request as item_update_req
from ucp_sdk.models.schemas.shopping.types import line_item_update_request as line_item_update_req

# Rebuild models to resolve forward references
checkout.Checkout.model_rebuild(_types_namespace={"PaymentResponse": Payment})
checkout.Checkout.model_rebuild(_types_namespace={"Payment": Payment})


class BusinessLogicTest(integration_test_utils.IntegrationTestBase):
Expand Down Expand Up @@ -515,7 +516,7 @@ def test_buyer_info_persistence(self):
currency=checkout_obj.currency,
line_items=[line_item_update],
payment=payment_update,
buyer=buyer.Buyer(
buyer=buyer_update_request.BuyerUpdateRequest(
email="test@example.com",
first_name="Test",
last_name="User",
Expand Down
26 changes: 9 additions & 17 deletions card_credential_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

from absl.testing import absltest
import integration_test_utils
from ucp_sdk.models.schemas.shopping import fulfillment_resp as checkout
from ucp_sdk.models.schemas.shopping.payment_resp import (
PaymentResponse as Payment,
from ucp_sdk.models.schemas.shopping import checkout
from ucp_sdk.models.schemas.shopping.payment import (
Payment,
)
from ucp_sdk.models.schemas.shopping.types import card_credential
from ucp_sdk.models.schemas.shopping.types import card_payment_instrument


# Rebuild models to resolve forward references
checkout.Checkout.model_rebuild(_types_namespace={"PaymentResponse": Payment})
checkout.Checkout.model_rebuild(_types_namespace={"Payment": Payment})


class CardCredentialTest(integration_test_utils.IntegrationTestBase):
Expand Down Expand Up @@ -54,20 +54,12 @@ def test_card_credential_payment(self) -> None:
cvc="123",
name="John Doe",
)
instr = card_payment_instrument.CardPaymentInstrument(
id="instr_card",
handler_id="mock_payment_handler",
handler_name="mock_payment_handler",
type="card",
brand="Visa",
last_digits="1111",
credential=credential,

# Use the standard valid payment payload and override credential
payment_payload = integration_test_utils.get_valid_payment_payload()
payment_payload["payment_data"]["credential"] = credential.model_dump(
mode="json", exclude_none=True
)
payment_data = instr.model_dump(mode="json", exclude_none=True)
payment_payload = {
"payment_data": payment_data,
"risk_signals": {},
}

response = self.client.post(
self.get_shopping_url(f"/checkout-sessions/{checkout_id}/complete"),
Expand Down
16 changes: 8 additions & 8 deletions checkout_lifecycle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

from absl.testing import absltest
import integration_test_utils
from ucp_sdk.models.schemas.shopping import checkout_update_req
from ucp_sdk.models.schemas.shopping import fulfillment_resp as checkout
from ucp_sdk.models.schemas.shopping import payment_update_req
from ucp_sdk.models.schemas.shopping.payment_resp import (
PaymentResponse as Payment,
from ucp_sdk.models.schemas.shopping import checkout_update_request as checkout_update_req
from ucp_sdk.models.schemas.shopping import checkout
from ucp_sdk.models.schemas.shopping import payment_update_request as payment_update_req
from ucp_sdk.models.schemas.shopping.payment import (
Payment,
)
from ucp_sdk.models.schemas.shopping.types import item_update_req
from ucp_sdk.models.schemas.shopping.types import line_item_update_req
from ucp_sdk.models.schemas.shopping.types import item_update_request as item_update_req
from ucp_sdk.models.schemas.shopping.types import line_item_update_request as line_item_update_req

# Rebuild models to resolve forward references
checkout.Checkout.model_rebuild(_types_namespace={"PaymentResponse": Payment})
checkout.Checkout.model_rebuild(_types_namespace={"Payment": Payment})


class CheckoutLifecycleTest(integration_test_utils.IntegrationTestBase):
Expand Down
Loading