Skip to main content

adk_payments/kernel/
service.rs

1use adk_core::Result;
2use async_trait::async_trait;
3
4use crate::domain::TransactionRecord;
5use crate::kernel::commands::{
6    BeginInterventionCommand, CancelCheckoutCommand, CompleteCheckoutCommand,
7    ContinueInterventionCommand, CreateCheckoutCommand, DelegatePaymentCommand,
8    DelegatedPaymentResult, EvidenceLookup, ExecutePaymentCommand,
9    ListUnresolvedTransactionsRequest, OrderUpdateCommand, PaymentExecutionResult,
10    StoreEvidenceCommand, StoredEvidence, SyncPaymentOutcomeCommand, TransactionLookup,
11    UpdateCheckoutCommand,
12};
13
14/// Backend-facing checkout operations shared by ACP and AP2 adapters.
15#[async_trait]
16pub trait MerchantCheckoutService: Send + Sync {
17    async fn create_checkout(&self, command: CreateCheckoutCommand) -> Result<TransactionRecord>;
18    async fn update_checkout(&self, command: UpdateCheckoutCommand) -> Result<TransactionRecord>;
19    async fn get_checkout(&self, lookup: TransactionLookup) -> Result<Option<TransactionRecord>>;
20    async fn complete_checkout(
21        &self,
22        command: CompleteCheckoutCommand,
23    ) -> Result<TransactionRecord>;
24    async fn cancel_checkout(&self, command: CancelCheckoutCommand) -> Result<TransactionRecord>;
25    async fn apply_order_update(&self, command: OrderUpdateCommand) -> Result<TransactionRecord>;
26}
27
28/// Backend-facing payment execution operations shared by ACP and AP2 adapters.
29#[async_trait]
30pub trait PaymentExecutionService: Send + Sync {
31    async fn execute_payment(
32        &self,
33        command: ExecutePaymentCommand,
34    ) -> Result<PaymentExecutionResult>;
35
36    async fn sync_payment_outcome(
37        &self,
38        command: SyncPaymentOutcomeCommand,
39    ) -> Result<TransactionRecord>;
40}
41
42/// Backend-facing delegated-payment tokenization operations.
43#[async_trait]
44pub trait DelegatedPaymentService: Send + Sync {
45    async fn delegate_payment(
46        &self,
47        command: DelegatePaymentCommand,
48    ) -> Result<DelegatedPaymentResult>;
49}
50
51/// Backend-facing intervention lifecycle operations.
52#[async_trait]
53pub trait InterventionService: Send + Sync {
54    async fn begin_intervention(
55        &self,
56        command: BeginInterventionCommand,
57    ) -> Result<TransactionRecord>;
58
59    async fn continue_intervention(
60        &self,
61        command: ContinueInterventionCommand,
62    ) -> Result<TransactionRecord>;
63}
64
65/// Durable structured transaction storage keyed by canonical transaction ID.
66#[async_trait]
67pub trait TransactionStore: Send + Sync {
68    async fn upsert(&self, record: TransactionRecord) -> Result<()>;
69    async fn get(&self, lookup: TransactionLookup) -> Result<Option<TransactionRecord>>;
70    async fn list_unresolved(
71        &self,
72        request: ListUnresolvedTransactionsRequest,
73    ) -> Result<Vec<TransactionRecord>>;
74}
75
76/// Raw evidence storage used to preserve immutable protocol artifacts.
77#[async_trait]
78pub trait EvidenceStore: Send + Sync {
79    async fn store(&self, command: StoreEvidenceCommand) -> Result<StoredEvidence>;
80    async fn load(&self, lookup: EvidenceLookup) -> Result<Option<StoredEvidence>>;
81}