Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
use std::time::Duration;
use common_utils::id_type;
use super::jwt;
use crate::{configs::Settings, consts, core::errors::UserResult};
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct EmbeddedToken {
pub tenant_id: id_type::TenantId,
pub org_id: id_type::OrganizationId,
pub merchant_id: id_type::MerchantId,
pub profile_id: id_type::ProfileId,
pub token_access_type: EmbeddedTokenAllowList,
exp: u64,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub enum EmbeddedTokenAllowList {
All,
}
impl EmbeddedToken {
pub async fn new_token(
tenant_id: id_type::TenantId,
org_id: id_type::OrganizationId,
merchant_id: id_type::MerchantId,
profile_id: id_type::ProfileId,
settings: &Settings,
) -> UserResult<String> {
let exp_duration = Duration::from_secs(consts::JWT_EMBEDDED_TOKEN_TIME_IN_SECS);
let exp = jwt::generate_exp(exp_duration)?.as_secs();
let token_payload = Self {
tenant_id,
org_id,
merchant_id,
profile_id,
token_access_type: EmbeddedTokenAllowList::All,
exp,
};
jwt::generate_jwt(&token_payload, settings).await
}
}