Skip to content

Commit

Permalink
feat(paypal): add coin order
Browse files Browse the repository at this point in the history
  • Loading branch information
Defelo committed Oct 22, 2024
1 parent a595d74 commit b505baa
Show file tree
Hide file tree
Showing 46 changed files with 2,150 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,10 @@ jobs:
cargo test -p academy_extern_impl --no-fail-fast --all-features --test vat
env:
ACADEMY_CONFIG: ${{ github.workspace }}/config.dev.toml
- name: test paypal
run: |
cargo run --bin academy-testing -- paypal &
while ! curl -s http://127.0.0.1:8005; do sleep .1; done
cargo test -p academy_extern_impl --no-fail-fast --all-features --test paypal
env:
ACADEMY_CONFIG: ${{ github.workspace }}/config.dev.toml
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ academy_core_mfa_contracts.path = "academy_core/mfa/contracts"
academy_core_mfa_impl.path = "academy_core/mfa/impl"
academy_core_oauth2_contracts.path = "academy_core/oauth2/contracts"
academy_core_oauth2_impl.path = "academy_core/oauth2/impl"
academy_core_paypal_contracts.path = "academy_core/paypal/contracts"
academy_core_paypal_impl.path = "academy_core/paypal/impl"
academy_core_session_contracts.path = "academy_core/session/contracts"
academy_core_session_impl.path = "academy_core/session/impl"
academy_core_user_contracts.path = "academy_core/user/contracts"
Expand Down
1 change: 1 addition & 0 deletions academy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ academy_core_health_impl.workspace = true
academy_core_internal_impl.workspace = true
academy_core_mfa_impl.workspace = true
academy_core_oauth2_impl.workspace = true
academy_core_paypal_impl.workspace = true
academy_core_session_impl.workspace = true
academy_core_user_contracts.workspace = true
academy_core_user_impl.workspace = true
Expand Down
21 changes: 19 additions & 2 deletions academy/src/environment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use academy_config::Config;
use academy_core_contact_impl::ContactFeatureConfig;
use academy_core_health_impl::HealthFeatureConfig;
use academy_core_oauth2_impl::OAuth2FeatureConfig;
use academy_core_paypal_impl::PaypalFeatureConfig;
use academy_core_session_impl::SessionFeatureConfig;
use academy_core_user_impl::UserFeatureConfig;
use academy_di::provider;
use academy_extern_impl::{
internal::InternalApiServiceConfig, recaptcha::RecaptchaApiServiceConfig,
vat::VatApiServiceConfig,
internal::InternalApiServiceConfig, paypal::PaypalApiServiceConfig,
recaptcha::RecaptchaApiServiceConfig, vat::VatApiServiceConfig,
};
use academy_models::oauth2::OAuth2Provider;
use academy_shared_impl::{
Expand All @@ -37,6 +38,7 @@ provider! {
InternalApiServiceConfig,
RecaptchaApiServiceConfig,
VatApiServiceConfig,
PaypalApiServiceConfig,

// Shared
CaptchaServiceConfig,
Expand All @@ -52,6 +54,7 @@ provider! {
HealthFeatureConfig,
SessionFeatureConfig,
UserFeatureConfig,
PaypalFeatureConfig,
}
}
}
Expand All @@ -78,6 +81,7 @@ provider! {
internal_api_service_config: InternalApiServiceConfig,
recaptcha_api_service_config: RecaptchaApiServiceConfig,
vat_api_service_config: VatApiServiceConfig,
paypal_api_service_config: PaypalApiServiceConfig,

// Shared
captcha_service_config: CaptchaServiceConfig,
Expand All @@ -93,6 +97,7 @@ provider! {
health_feature_config: HealthFeatureConfig,
session_feature_config: SessionFeatureConfig,
user_feature_config: UserFeatureConfig,
paypal_feature_config: PaypalFeatureConfig,
}
}

Expand Down Expand Up @@ -124,6 +129,12 @@ impl ConfigProvider {
let vat_api_service_config =
VatApiServiceConfig::new(config.vat.validate_endpoint_override.clone());

let paypal_api_service_config = PaypalApiServiceConfig::new(
config.paypal.base_url_override.clone(),
config.paypal.client_id.clone(),
config.paypal.client_secret.clone(),
);

// Shared
let captcha_service_config = match config.recaptcha.as_ref() {
Some(recaptcha) => CaptchaServiceConfig::Recaptcha(RecaptchaCaptchaServiceConfig {
Expand Down Expand Up @@ -207,6 +218,10 @@ impl ConfigProvider {
newsletter_subscription_verification_code_ttl: config.user.newsletter_code_ttl.into(),
};

let paypal_feature_config = PaypalFeatureConfig {
purchase_range: config.coin.purchase_min..=config.coin.purchase_max,
};

Ok(Self {
_cache: Default::default(),

Expand All @@ -217,6 +232,7 @@ impl ConfigProvider {
internal_api_service_config,
recaptcha_api_service_config,
vat_api_service_config,
paypal_api_service_config,

// Shared
jwt_service_config,
Expand All @@ -232,6 +248,7 @@ impl ConfigProvider {
health_feature_config,
session_feature_config,
user_feature_config,
paypal_feature_config,
})
}
}
Expand Down
13 changes: 11 additions & 2 deletions academy/src/environment/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use academy_core_oauth2_impl::{
link::OAuth2LinkServiceImpl, login::OAuth2LoginServiceImpl,
registration::OAuth2RegistrationServiceImpl, OAuth2FeatureServiceImpl,
};
use academy_core_paypal_impl::{coin_order::PaypalCoinOrderServiceImpl, PaypalFeatureServiceImpl};
use academy_core_session_impl::{
failed_auth_count::SessionFailedAuthCountServiceImpl, session::SessionServiceImpl,
SessionFeatureServiceImpl,
Expand All @@ -28,12 +29,13 @@ use academy_core_user_impl::{
};
use academy_email_impl::{template::TemplateEmailServiceImpl, EmailServiceImpl};
use academy_extern_impl::{
internal::InternalApiServiceImpl, oauth2::OAuth2ApiServiceImpl,
internal::InternalApiServiceImpl, oauth2::OAuth2ApiServiceImpl, paypal::PaypalApiServiceImpl,
recaptcha::RecaptchaApiServiceImpl, vat::VatApiServiceImpl,
};
use academy_persistence_postgres::{
coin::PostgresCoinRepository, mfa::PostgresMfaRepository, oauth2::PostgresOAuth2Repository,
session::PostgresSessionRepository, user::PostgresUserRepository, PostgresDatabase,
paypal::PostgresPaypalRepository, session::PostgresSessionRepository,
user::PostgresUserRepository, PostgresDatabase,
};
use academy_shared_impl::{
captcha::CaptchaServiceImpl, hash::HashServiceImpl, id::IdServiceImpl, jwt::JwtServiceImpl,
Expand All @@ -52,6 +54,7 @@ pub type RestServer = academy_api_rest::RestServer<
MfaFeature,
OAuth2Feature,
CoinFeature,
PaypalFeature,
Internal,
>;

Expand All @@ -70,6 +73,7 @@ pub type RecaptchaApi = RecaptchaApiServiceImpl;
pub type OAuth2Api = OAuth2ApiServiceImpl;
pub type InternalApi = InternalApiServiceImpl<AuthInternal>;
pub type VatApi = VatApiServiceImpl;
pub type PaypalApi = PaypalApiServiceImpl;

// Template
pub type Template = TemplateServiceImpl;
Expand All @@ -90,6 +94,7 @@ pub type UserRepo = PostgresUserRepository;
pub type MfaRepo = PostgresMfaRepository;
pub type OAuth2Repo = PostgresOAuth2Repository;
pub type CoinRepo = PostgresCoinRepository;
pub type PaypalRepo = PostgresPaypalRepository;

// Auth
pub type Auth =
Expand Down Expand Up @@ -167,4 +172,8 @@ pub type OAuth2Registration = OAuth2RegistrationServiceImpl<Secret, Cache>;

pub type CoinFeature = CoinFeatureServiceImpl<Database, Auth, UserRepo, CoinRepo>;

pub type PaypalFeature =
PaypalFeatureServiceImpl<Database, Auth, PaypalApi, UserRepo, PaypalRepo, PaypalCoinOrder>;
pub type PaypalCoinOrder = PaypalCoinOrderServiceImpl<Time, PaypalRepo, CoinRepo>;

pub type Internal = InternalServiceImpl<Database, AuthInternal, UserRepo>;
1 change: 1 addition & 0 deletions academy_api/rest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ academy_core_health_contracts.workspace = true
academy_core_internal_contracts.workspace = true
academy_core_mfa_contracts.workspace = true
academy_core_oauth2_contracts.workspace = true
academy_core_paypal_contracts.workspace = true
academy_core_session_contracts.workspace = true
academy_core_user_contracts.workspace = true
academy_di.workspace = true
Expand Down
11 changes: 8 additions & 3 deletions academy_api/rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use academy_core_health_contracts::HealthFeatureService;
use academy_core_internal_contracts::InternalService;
use academy_core_mfa_contracts::MfaFeatureService;
use academy_core_oauth2_contracts::OAuth2FeatureService;
use academy_core_paypal_contracts::PaypalFeatureService;
use academy_core_session_contracts::SessionFeatureService;
use academy_core_user_contracts::UserFeatureService;
use academy_di::Build;
Expand Down Expand Up @@ -37,7 +38,7 @@ mod models;
mod routes;

#[derive(Debug, Clone, Build)]
pub struct RestServer<Health, Config, User, Session, Contact, Mfa, OAuth2, Coin, Internal> {
pub struct RestServer<Health, Config, User, Session, Contact, Mfa, OAuth2, Coin, Paypal, Internal> {
_config: RestServerConfig,
health: Health,
config: Config,
Expand All @@ -47,6 +48,7 @@ pub struct RestServer<Health, Config, User, Session, Contact, Mfa, OAuth2, Coin,
mfa: Mfa,
oauth2: OAuth2,
coin: Coin,
paypal: Paypal,
internal: Internal,
}

Expand All @@ -62,8 +64,8 @@ pub struct RestServerRealIpConfig {
pub set_from: IpAddr,
}

impl<Health, Config, User, Session, Contact, Mfa, OAuth2, Coin, Internal>
RestServer<Health, Config, User, Session, Contact, Mfa, OAuth2, Coin, Internal>
impl<Health, Config, User, Session, Contact, Mfa, OAuth2, Coin, Paypal, Internal>
RestServer<Health, Config, User, Session, Contact, Mfa, OAuth2, Coin, Paypal, Internal>
where
Health: HealthFeatureService,
Config: ConfigFeatureService,
Expand All @@ -73,6 +75,7 @@ where
Mfa: MfaFeatureService,
OAuth2: OAuth2FeatureService,
Coin: CoinFeatureService,
Paypal: PaypalFeatureService,
Internal: InternalService,
{
pub async fn serve(self) -> anyhow::Result<()> {
Expand All @@ -98,6 +101,7 @@ where
routes::mfa::TAG,
routes::oauth2::TAG,
routes::coin::TAG,
routes::paypal::TAG,
routes::internal::TAG,
]
.into_iter()
Expand Down Expand Up @@ -162,6 +166,7 @@ where
.merge(routes::mfa::router(self.mfa.into()))
.merge(routes::oauth2::router(self.oauth2.into()))
.merge(routes::coin::router(self.coin.into()))
.merge(routes::paypal::router(self.paypal.into()))
.merge(routes::internal::router(self.internal.into()))
}
}
Expand Down
1 change: 1 addition & 0 deletions academy_api/rest/src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ pub mod health;
pub mod internal;
pub mod mfa;
pub mod oauth2;
pub mod paypal;
pub mod session;
pub mod user;
Loading

0 comments on commit b505baa

Please sign in to comment.