Skip to main content

Ap2Adapter

Struct Ap2Adapter 

Source
pub struct Ap2Adapter { /* private fields */ }
Available on crate features ap2 and payments only.
Expand description

AP2 alpha adapter over the canonical commerce kernel.

The adapter fails closed: until a MerchantAuthorizationVerifier and a UserAuthorizationVerifier are configured, every merchant, intent, and payment authorization artifact is rejected with Ap2Error::AuthorizationVerifierNotConfigured. Payment mandates are single-use: a mandate that reached the payment backend is refused when resubmitted, and a transaction executes at most one payment mandate.

Money movement is governed like a GovernedCheckoutService checkout: the PaymentPolicySet is evaluated before a cart mandate creates a checkout and before a payment mandate reaches the payment backend, the payment total is reserved in the spend ledger and committed once the backend authorizes it, and an optional PaymentAuditor records each decision before money moves.

§Example

ⓘ
use adk_payments::protocol::ap2::Ap2Adapter;

let adapter = Ap2Adapter::new(checkout, payments, transactions, evidence)
    .with_merchant_authorization_verifier(merchant_jws_verifier)
    .with_user_authorization_verifier(user_sd_jwt_verifier)
    .with_intervention_service(interventions);

Implementations§

Source§

impl Ap2Adapter

Source

pub fn new( checkout_service: Arc<dyn MerchantCheckoutService>, payment_service: Arc<dyn PaymentExecutionService>, transaction_store: Arc<dyn TransactionStore>, evidence_store: Arc<dyn EvidenceStore>, ) -> Ap2Adapter

Creates a new AP2 adapter bound to the canonical checkout, journal, and evidence services.

No authorization verifier is configured, so every authorization artifact is rejected until with_merchant_authorization_verifier and with_user_authorization_verifier are called. Executed payment mandates are tracked in an InMemoryPaymentMandateLedger unless with_payment_mandate_ledger replaces it. Payments are governed by [SpendLimitGuardrail::when_configured] until with_payment_policies adds further policies.

Source

pub fn with_payment_policies(self, policies: PaymentPolicySet) -> Ap2Adapter

Evaluates policies before every cart-mandate checkout creation and every payment mandate execution.

When policies has no spend guardrail, [SpendLimitGuardrail::when_configured] is added, which reserves against with_spend_ledger or the caller’s ledger.

§Example
ⓘ
use adk_payments::guardrail::{AmountThresholdGuardrail, PaymentPolicySet};

let adapter = adapter.with_payment_policies(
    PaymentPolicySet::new()
        .with(AmountThresholdGuardrail::new(Some(5_000), Some(50_000)).with_currency("USD", 2)),
);
Source

pub fn with_spend_ledger(self, ledger: Arc<dyn SpendLedger>) -> Ap2Adapter

Reserves payments against ledger, ahead of any ledger the caller supplies.

Source

pub fn with_payment_auditor(self, auditor: PaymentAuditor) -> Ap2Adapter

Records every governed decision with auditor before money moves, refusing a payment whose decision cannot be recorded.

Source

pub fn with_merchant_authorization_verifier( self, verifier: Arc<dyn MerchantAuthorizationVerifier>, ) -> Ap2Adapter

Sets the merchant authorization verifier used for cart mandates.

Source

pub fn with_user_authorization_verifier( self, verifier: Arc<dyn UserAuthorizationVerifier>, ) -> Ap2Adapter

Sets the user authorization verifier used for intent and payment mandates.

Source

pub fn allow_unverified_authorizations(self) -> Ap2Adapter

Accepts any non-empty authorization artifact where no verifier is configured.

Development only. Forged merchant signatures and user authorizations pass this check, so a payment mandate carrying any non-empty user_authorization reaches the payment backend. Verifiers configured through with_*_authorization_verifier still apply. Emits one warn! when called.

Source

pub fn with_payment_mandate_ledger( self, ledger: Arc<dyn PaymentMandateLedger>, ) -> Ap2Adapter

Replaces the ledger that records consumed payment mandate identifiers.

Use shared durable storage when several adapter instances serve one merchant, so a mandate cannot be replayed against another instance.

Source

pub fn with_intervention_service( self, intervention_service: Arc<dyn InterventionService>, ) -> Ap2Adapter

Enables canonical intervention handling for AP2 return-to-user flows.

Source

pub async fn submit_intent_mandate( &self, context: CommerceContext, intent_mandate: IntentMandate, authorization_artifact: Option<AuthorizationArtifact>, ) -> Result<TransactionRecord, AdkError>

Starts or refreshes a human-not-present transaction from an intent mandate.

§Errors

Returns an error when the intent is expired, unsigned, fails user authorization verification, or lacks explicit autonomous authority constraints.

Source

pub async fn submit_cart_mandate( &self, context: CommerceContext, cart_mandate: CartMandate, ) -> Result<TransactionRecord, AdkError>

Creates or updates canonical checkout state from a merchant cart mandate.

§Errors

Returns an error when the cart is expired, unsigned, fails merchant authorization verification, names a merchant other than the verified signer, carries invalid amounts, or violates the stored intent constraints for a human-not-present transaction.

Source

pub async fn submit_payment_mandate( &self, context: CommerceContext, payment_mandate: PaymentMandate, ) -> Result<PaymentExecutionResult, AdkError>

Executes or escalates a payment mandate against the canonical payment service.

The payment is attributed to the session’s app and the acting actor; see submit_payment_mandate_as.

§Errors

See submit_payment_mandate_as.

Source

pub async fn submit_payment_mandate_as( &self, context: CommerceContext, payment_mandate: PaymentMandate, caller: &PaymentCaller, ) -> Result<PaymentExecutionResult, AdkError>

Executes or escalates a payment mandate for caller against the canonical payment service.

The mandate’s authorization is verified first, and a verification failure refuses the payment. The payment policies are then evaluated on the stored transaction at the mandate’s total: a denial, a refused or pending escalation, a refused spend reservation, or an audit record that cannot be written stops the payment before the mandate is consumed, so the same mandate can be resubmitted once approved.

Payment mandates are single-use. The mandate identifier is consumed in the PaymentMandateLedger immediately before the payment backend is called and recorded on the transaction afterwards, so a resubmitted mandate never executes twice and a transaction never executes a second mandate. The backend receives an idempotency_key extension field: the key already on context (a payment tool supplies its call’s key), otherwise one derived from the payment mandate ID.

§Errors

Returns an error when the mandate does not match the current cart, fails user authorization verification, was already executed, targets a transaction that already executed a payment or is bound to another mandate, or the flow lacks user authorization and cannot proceed autonomously. Returns payments.policy.denied, payments.policy.approval_required, or payments.policy.approval_denied when the payment policies stop the payment, and payments.auth.audit_failed when the decision cannot be recorded.

Source

pub async fn apply_payment_receipt( &self, context: CommerceContext, payment_receipt: PaymentReceipt, ) -> Result<TransactionRecord, AdkError>

Applies a final AP2 payment receipt to canonical transaction state.

§Errors

Returns an error when the underlying transaction does not exist or the receipt references a payment mandate other than the one bound to the transaction.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Ap2Adapter

§

impl !UnwindSafe for Ap2Adapter

§

impl Forget for Ap2Adapter

§

impl Freeze for Ap2Adapter
where *const ArcInner<dyn MerchantCheckoutService> is !null: Freeze, PhantomData<ArcInner<dyn MerchantCheckoutService>>: Freeze, *const ArcInner<dyn PaymentExecutionService> is !null: Freeze, PhantomData<ArcInner<dyn PaymentExecutionService>>: Freeze, *const ArcInner<dyn TransactionStore> is !null: Freeze, PhantomData<ArcInner<dyn TransactionStore>>: Freeze, *const ArcInner<dyn EvidenceStore> is !null: Freeze, PhantomData<ArcInner<dyn EvidenceStore>>: Freeze, *const ArcInner<dyn MerchantAuthorizationVerifier> is !null: Freeze, PhantomData<ArcInner<dyn MerchantAuthorizationVerifier>>: Freeze, *const ArcInner<dyn UserAuthorizationVerifier> is !null: Freeze, PhantomData<ArcInner<dyn UserAuthorizationVerifier>>: Freeze, *const ArcInner<dyn PaymentMandateLedger> is !null: Freeze, PhantomData<ArcInner<dyn PaymentMandateLedger>>: Freeze, *const ArcInner<dyn InterventionService> is !null: Freeze, PhantomData<ArcInner<dyn InterventionService>>: Freeze, *const u8 is !null: Freeze, PhantomData<Arc<dyn PaymentPolicyGuardrail>>: Freeze, *const ArcInner<dyn SpendLedger> is !null: Freeze, PhantomData<ArcInner<dyn SpendLedger>>: Freeze, *const ArcInner<dyn AuditSink> is !null: Freeze, PhantomData<ArcInner<dyn AuditSink>>: Freeze,

§

impl Move for Ap2Adapter

§

impl Send for Ap2Adapter

§

impl Sync for Ap2Adapter

§

impl Unpin for Ap2Adapter

§

impl UnsafeUnpin for Ap2Adapter

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more