pub struct ProtocolCorrelator { /* private fields */ }payments only.Expand description
Cross-protocol correlator that routes ACP and AP2 adapters through the same canonical transaction ID and journal model.
The correlator enforces three rules:
- Both protocols share one canonical
TransactionIdper transaction. - Protocol-specific identifiers are correlated in
ProtocolRefswithout assuming they are interchangeable. - Direct protocol-to-protocol conversion is refused when it would lose semantics or accountability evidence.
Implementations§
Source§impl ProtocolCorrelator
impl ProtocolCorrelator
Sourcepub fn new(transaction_store: Arc<dyn TransactionStore>) -> ProtocolCorrelator
pub fn new(transaction_store: Arc<dyn TransactionStore>) -> ProtocolCorrelator
Creates a new correlator backed by the canonical transaction store.
Sourcepub async fn get_transaction(
&self,
lookup: TransactionLookup,
) -> Result<Option<TransactionRecord>, AdkError>
pub async fn get_transaction( &self, lookup: TransactionLookup, ) -> Result<Option<TransactionRecord>, AdkError>
Looks up a canonical transaction by its internal ID.
Sourcepub async fn find_by_acp_checkout_session_id(
&self,
session_identity: Option<AdkIdentity>,
acp_checkout_session_id: &str,
) -> Result<Option<TransactionRecord>, AdkError>
pub async fn find_by_acp_checkout_session_id( &self, session_identity: Option<AdkIdentity>, acp_checkout_session_id: &str, ) -> Result<Option<TransactionRecord>, AdkError>
Looks up a canonical transaction by an ACP checkout session ID.
Scans unresolved transactions for a matching protocol_refs.acp_checkout_session_id.
For production use, a dedicated index would be more efficient.
Sourcepub async fn find_by_ap2_mandate_id(
&self,
session_identity: Option<AdkIdentity>,
mandate_id: &str,
) -> Result<Option<TransactionRecord>, AdkError>
pub async fn find_by_ap2_mandate_id( &self, session_identity: Option<AdkIdentity>, mandate_id: &str, ) -> Result<Option<TransactionRecord>, AdkError>
Looks up a canonical transaction by an AP2 mandate ID (intent, cart, or payment).
Sourcepub fn attach_protocol_ref(
record: &mut TransactionRecord,
kind: ProtocolRefKind,
value: String,
) -> Result<(), PaymentsKernelError>
pub fn attach_protocol_ref( record: &mut TransactionRecord, kind: ProtocolRefKind, value: String, ) -> Result<(), PaymentsKernelError>
Attaches a protocol-specific reference to an existing transaction record.
This is the canonical way to correlate ACP and AP2 identifiers under one transaction. The correlator never overwrites an existing reference slot with a different value.
§Errors
Returns an error if the slot is already occupied by a different value.
Returns all protocol identifiers correlated to one canonical transaction.
Sourcepub fn contributing_protocols(record: &TransactionRecord) -> Vec<String>
pub fn contributing_protocols(record: &TransactionRecord) -> Vec<String>
Returns the set of protocol names that have contributed evidence to this transaction.
Sourcepub fn is_dual_protocol(record: &TransactionRecord) -> bool
pub fn is_dual_protocol(record: &TransactionRecord) -> bool
Returns true when both ACP and AP2 have contributed to this transaction.
Source§impl ProtocolCorrelator
Best-effort canonical projections where ACP or AP2 data can be mapped
safely without semantic loss.
impl ProtocolCorrelator
Best-effort canonical projections where ACP or AP2 data can be mapped safely without semantic loss.
These projections are intentionally one-directional: protocol data is projected into canonical kernel types. The kernel never projects canonical data back into a different protocol’s wire format because that would fabricate provenance.
Sourcepub fn project_acp_cart_to_canonical(
record: &TransactionRecord,
) -> ProjectionResult<Cart>
pub fn project_acp_cart_to_canonical( record: &TransactionRecord, ) -> ProjectionResult<Cart>
Projects an ACP cart (line items + totals) into the canonical cart model.
This projection is safe because ACP line items, totals, and currency map
directly to canonical Cart fields without losing structure.
Sourcepub fn project_ap2_cart_to_canonical(
record: &TransactionRecord,
) -> ProjectionResult<Cart>
pub fn project_ap2_cart_to_canonical( record: &TransactionRecord, ) -> ProjectionResult<Cart>
Projects an AP2 cart mandate’s payment details into the canonical cart model.
This projection is safe because AP2 PaymentRequest.details.displayItems
and total map to canonical CartLine and Cart.total without losing
the item-level structure.
Sourcepub fn project_order_to_canonical(
record: &TransactionRecord,
) -> ProjectionResult<OrderSnapshot>
pub fn project_order_to_canonical( record: &TransactionRecord, ) -> ProjectionResult<OrderSnapshot>
Projects ACP or AP2 order updates into the canonical order snapshot.
Both protocols produce order state that maps to the canonical
OrderSnapshot without semantic loss.
Sourcepub fn project_settlement_state(
record: &TransactionRecord,
) -> ProjectionResult<TransactionState>
pub fn project_settlement_state( record: &TransactionRecord, ) -> ProjectionResult<TransactionState>
Projects the canonical transaction state into a protocol-neutral settlement summary.
Both ACP order updates and AP2 payment receipts can update canonical settlement state, so this projection is safe in both directions.
Sourcepub fn project_fulfillment_to_canonical(
record: &TransactionRecord,
) -> ProjectionResult<FulfillmentSelection>
pub fn project_fulfillment_to_canonical( record: &TransactionRecord, ) -> ProjectionResult<FulfillmentSelection>
Projects the canonical fulfillment selection.
Both ACP fulfillment options and AP2 shipping options map to the
canonical FulfillmentSelection without semantic loss.
Sourcepub fn project_payment_method(
record: &TransactionRecord,
) -> ProjectionResult<PaymentMethodSelection>
pub fn project_payment_method( record: &TransactionRecord, ) -> ProjectionResult<PaymentMethodSelection>
Projects the canonical payment method selection.
Both ACP payment handlers and AP2 payment response method names map to
the canonical PaymentMethodSelection without semantic loss.
Source§impl ProtocolCorrelator
Guards against unsafe direct protocol-to-protocol conversions.
impl ProtocolCorrelator
Guards against unsafe direct protocol-to-protocol conversions.
The kernel mediates all cross-protocol operations. These guards return explicit errors when a direct ACP-to-AP2 or AP2-to-ACP conversion would lose semantics or accountability evidence.
Refuses direct conversion of an ACP delegated payment token to an AP2 user authorization credential.
ACP delegated payment tokens are scoped PSP credentials with merchant and amount constraints. AP2 user authorization artifacts are cryptographic proofs of user consent. Converting one to the other would fabricate provenance.
Refuses direct conversion of an AP2 signed user authorization to an ACP delegated payment token.
AP2 user authorization presentations prove user consent through cryptographic signatures. ACP delegated payment tokens are PSP-issued scoped credentials. Converting one to the other would lose the cryptographic accountability chain.
Sourcepub fn refuse_acp_session_to_ap2_mandate(
field: &str,
) -> Result<(), PaymentsKernelError>
pub fn refuse_acp_session_to_ap2_mandate( field: &str, ) -> Result<(), PaymentsKernelError>
Refuses direct conversion of ACP checkout session state to AP2 mandate state.
ACP checkout sessions are merchant-facing HTTP resources with server-managed lifecycle. AP2 mandates are signed authorization artifacts with explicit role separation. The state models are not equivalent.
Sourcepub fn refuse_ap2_mandate_to_acp_session(
field: &str,
) -> Result<(), PaymentsKernelError>
pub fn refuse_ap2_mandate_to_acp_session( field: &str, ) -> Result<(), PaymentsKernelError>
Refuses direct conversion of AP2 mandate state to ACP checkout session state.
AP2 mandates carry cryptographic authorization chains and role-separated provenance. ACP checkout sessions are server-managed merchant resources. Direct conversion would discard the mandate’s authorization evidence.
Sourcepub fn require_kernel_mediation(
record: &TransactionRecord,
source: ProtocolOrigin,
target: ProtocolOrigin,
operation: &str,
) -> Result<(), PaymentsKernelError>
pub fn require_kernel_mediation( record: &TransactionRecord, source: ProtocolOrigin, target: ProtocolOrigin, operation: &str, ) -> Result<(), PaymentsKernelError>
Validates that a cross-protocol operation goes through the kernel rather than attempting direct protocol-to-protocol transcoding.
Returns Ok(()) when the operation is kernel-mediated (both sides use
the canonical transaction). Returns an error when the caller attempts
to bypass the kernel.
Auto Trait Implementations§
impl Freeze for ProtocolCorrelator
impl !RefUnwindSafe for ProtocolCorrelator
impl Send for ProtocolCorrelator
impl Sync for ProtocolCorrelator
impl Unpin for ProtocolCorrelator
impl UnsafeUnpin for ProtocolCorrelator
impl !UnwindSafe for ProtocolCorrelator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request