use dodo_payments::{
DodoPayments,
client::DodoPaymentsConfigBuilder,
operations::common::structs::{AggregationType, Conjunction, MeterAggregation, MeterFilter},
};
use std::env;
#[tokio::main]
async fn main() {
let bearer_token = env::var("DODO_PAYMENTS_BEARER_TOKEN")
.expect("DODO_PAYMENTS_BEARER_TOKEN must be set in env variables");
let client = DodoPayments::new(
DodoPaymentsConfigBuilder::new()
.bearer_token(&bearer_token)
.environment("test_mode"),
);
let aggregation = MeterAggregation {
aggregation_type: AggregationType::Count,
key: None,
};
let response = client
.create_meter(
"API Requests".to_string(),
"api_request".to_string(),
aggregation,
"requests".to_string(),
)
.description("Track API requests".to_string())
.send()
.await;
println!("Response: {:#?}", response);
let sum_aggregation = MeterAggregation {
aggregation_type: AggregationType::Sum,
key: Some("amount".to_string()),
};
let filter_json = serde_json::json!({
"conjunction": "and",
"clauses": [
{
"key": "user_type",
"operator": "equals",
"value": "premium"
}
]
});
let filter = MeterFilter {
conjunction: Conjunction::And,
clauses: vec![filter_json],
};
let response2 = client
.create_meter(
"Premium Revenue".to_string(),
"payment_processed".to_string(),
sum_aggregation,
"usd_cents".to_string(),
)
.description("Track revenue from premium users".to_string())
.filter(filter)
.send()
.await;
println!("Response 2: {:#?}", response2);
}