adk_payments/tools/
toolset.rs1use std::sync::Arc;
2
3use adk_core::Tool;
4
5use crate::kernel::service::{InterventionService, MerchantCheckoutService, TransactionStore};
6
7use super::{
8 cancel_checkout_tool, complete_checkout_tool, continue_intervention_tool, create_checkout_tool,
9 status_lookup_tool, update_checkout_tool,
10};
11
12pub struct PaymentToolsetBuilder {
17 checkout_service: Arc<dyn MerchantCheckoutService>,
18 transaction_store: Arc<dyn TransactionStore>,
19 intervention_service: Option<Arc<dyn InterventionService>>,
20}
21
22impl PaymentToolsetBuilder {
23 #[must_use]
25 pub fn new(
26 checkout_service: Arc<dyn MerchantCheckoutService>,
27 transaction_store: Arc<dyn TransactionStore>,
28 ) -> Self {
29 Self { checkout_service, transaction_store, intervention_service: None }
30 }
31
32 #[must_use]
34 pub fn with_intervention_service(
35 mut self,
36 intervention_service: Arc<dyn InterventionService>,
37 ) -> Self {
38 self.intervention_service = Some(intervention_service);
39 self
40 }
41
42 #[must_use]
44 pub fn build(self) -> PaymentToolset {
45 let mut tools: Vec<Arc<dyn Tool>> = vec![
46 Arc::new(create_checkout_tool(self.checkout_service.clone())),
47 Arc::new(update_checkout_tool(self.checkout_service.clone())),
48 Arc::new(complete_checkout_tool(self.checkout_service.clone())),
49 Arc::new(cancel_checkout_tool(self.checkout_service.clone())),
50 Arc::new(status_lookup_tool(self.transaction_store.clone())),
51 ];
52 if let Some(intervention_service) = self.intervention_service {
53 tools.push(Arc::new(continue_intervention_tool(intervention_service)));
54 }
55 PaymentToolset { tools }
56 }
57}
58
59pub struct PaymentToolset {
61 tools: Vec<Arc<dyn Tool>>,
62}
63
64impl PaymentToolset {
65 #[must_use]
67 pub fn tools(&self) -> Vec<Arc<dyn Tool>> {
68 self.tools.clone()
69 }
70}