diff --git a/src/controller/requests/mod.rs b/src/controller/requests/mod.rs index 5b9a8b4..be99759 100644 --- a/src/controller/requests/mod.rs +++ b/src/controller/requests/mod.rs @@ -1,5 +1,7 @@ +use stq_static_resources::Currency as StqCurrency; + use models::order_v2::OrderId as Orderv2Id; -use models::{Currency, CustomerId, NewSubscription, PaymentState, StoreSubscriptionStatus, UpdateStoreSubscription}; +use models::{CreateStoreSubscription, CustomerId, NewSubscription, PaymentState, StoreSubscriptionStatus, UpdateStoreSubscription}; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct NewCustomerWithSourceRequest { @@ -35,21 +37,29 @@ pub struct CreateSubscriptionsRequest { #[derive(Debug, Clone, Deserialize)] pub struct CreateStoreSubscriptionRequest { - pub currency: Currency, + pub currency: StqCurrency, } #[derive(Debug, Clone, Deserialize)] pub struct UpdateStoreSubscriptionRequest { - pub currency: Option, + pub currency: Option, pub status: Option, } impl From for UpdateStoreSubscription { fn from(data: UpdateStoreSubscriptionRequest) -> Self { UpdateStoreSubscription { - currency: data.currency, + currency: data.currency.map(|c| c.into()), status: data.status, ..Default::default() } } } + +impl From for CreateStoreSubscription { + fn from(data: CreateStoreSubscriptionRequest) -> Self { + CreateStoreSubscription { + currency: data.currency.into(), + } + } +} diff --git a/src/controller/responses/mod.rs b/src/controller/responses/mod.rs index f15ad50..2ff54e1 100644 --- a/src/controller/responses/mod.rs +++ b/src/controller/responses/mod.rs @@ -11,8 +11,8 @@ use models::{ fee::FeeId, invoice_v2::InvoiceId, order_v2::{OrderId, RawOrder, StoreId}, - ChargeId, CustomerId, Fee, FeeStatus, PaymentIntent, PaymentIntentStatus, PaymentState, StoreSubscription, SubscriptionPayment, - SubscriptionPaymentSearchResults, SubscriptionPaymentStatus, TransactionId, WalletAddress, + ChargeId, CustomerId, Fee, FeeStatus, PaymentIntent, PaymentIntentStatus, PaymentState, StoreSubscription, StoreSubscriptionStatus, + SubscriptionPayment, SubscriptionPaymentSearchResults, SubscriptionPaymentStatus, TransactionId, WalletAddress, }; use stq_static_resources::Currency as StqCurrency; @@ -258,6 +258,7 @@ pub struct StoreSubscriptionResponse { pub trial_start_date: Option, pub created_at: NaiveDateTime, pub updated_at: NaiveDateTime, + pub status: StoreSubscriptionStatus, } impl From for StoreSubscriptionResponse { @@ -270,6 +271,7 @@ impl From for StoreSubscriptionResponse { trial_start_date: data.trial_start_date, created_at: data.created_at, updated_at: data.updated_at, + status: data.status, } } } diff --git a/src/models/currency.rs b/src/models/currency.rs index dc83af5..fe849a3 100644 --- a/src/models/currency.rs +++ b/src/models/currency.rs @@ -148,6 +148,19 @@ impl Into for Currency { } } +impl From for Currency { + fn from(stq_currency: StqCurrency) -> Currency { + match stq_currency { + StqCurrency::ETH => Currency::Eth, + StqCurrency::STQ => Currency::Stq, + StqCurrency::BTC => Currency::Btc, + StqCurrency::EUR => Currency::Eur, + StqCurrency::USD => Currency::Usd, + StqCurrency::RUB => Currency::Rub, + } + } +} + #[derive(Debug, Clone)] pub enum CurrencyChoice { Crypto(TureCurrency), diff --git a/src/models/subscription.rs b/src/models/subscription.rs index c8388a4..d252edb 100644 --- a/src/models/subscription.rs +++ b/src/models/subscription.rs @@ -89,6 +89,10 @@ pub struct NewStoreSubscription { pub trial_start_date: Option, } +pub struct CreateStoreSubscription { + pub currency: Currency, +} + #[derive(Clone, Debug, Default, Serialize, Deserialize, AsChangeset)] #[table_name = "store_subscription"] pub struct UpdateStoreSubscription { diff --git a/src/services/store_subscription.rs b/src/services/store_subscription.rs index 1f9a8aa..cf8e5f5 100644 --- a/src/services/store_subscription.rs +++ b/src/services/store_subscription.rs @@ -16,7 +16,9 @@ use client::payments::PaymentsClient; use controller::context::DynamicContext; use controller::requests::{CreateStoreSubscriptionRequest, UpdateStoreSubscriptionRequest}; use controller::responses::StoreSubscriptionResponse; -use models::{Amount, Currency, NewStoreSubscription, StoreSubscriptionSearch, TureCurrency, UpdateStoreSubscription}; +use models::{ + Amount, CreateStoreSubscription, Currency, NewStoreSubscription, StoreSubscriptionSearch, TureCurrency, UpdateStoreSubscription, +}; use repos::repo_factory::ReposFactory; use services::accounts::AccountService; use services::subscription::DEFAULT_EUR_CENTS_AMOUNT; @@ -60,6 +62,8 @@ impl< let db_pool = self.db_pool.clone(); let cpu_pool = self.cpu_pool.clone(); + let payload: CreateStoreSubscription = payload.into(); + let account_service = match self.dynamic_context.account_service.clone() { Some(account_service) => account_service, None => {