Skip to content

Commit

Permalink
Merge pull request #215 from StoriqaTeam/feature/subscription
Browse files Browse the repository at this point in the history
subscriptions
  • Loading branch information
busarovalex authored Mar 5, 2019
2 parents c5ac672 + 42bc20b commit d57d57c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
18 changes: 14 additions & 4 deletions src/controller/requests/mod.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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<Currency>,
pub currency: Option<StqCurrency>,
pub status: Option<StoreSubscriptionStatus>,
}

impl From<UpdateStoreSubscriptionRequest> 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<CreateStoreSubscriptionRequest> for CreateStoreSubscription {
fn from(data: CreateStoreSubscriptionRequest) -> Self {
CreateStoreSubscription {
currency: data.currency.into(),
}
}
}
6 changes: 4 additions & 2 deletions src/controller/responses/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -258,6 +258,7 @@ pub struct StoreSubscriptionResponse {
pub trial_start_date: Option<NaiveDateTime>,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
pub status: StoreSubscriptionStatus,
}

impl From<StoreSubscription> for StoreSubscriptionResponse {
Expand All @@ -270,6 +271,7 @@ impl From<StoreSubscription> for StoreSubscriptionResponse {
trial_start_date: data.trial_start_date,
created_at: data.created_at,
updated_at: data.updated_at,
status: data.status,
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/models/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ impl Into<StqCurrency> for Currency {
}
}

impl From<StqCurrency> 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),
Expand Down
4 changes: 4 additions & 0 deletions src/models/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ pub struct NewStoreSubscription {
pub trial_start_date: Option<NaiveDateTime>,
}

pub struct CreateStoreSubscription {
pub currency: Currency,
}

#[derive(Clone, Debug, Default, Serialize, Deserialize, AsChangeset)]
#[table_name = "store_subscription"]
pub struct UpdateStoreSubscription {
Expand Down
6 changes: 5 additions & 1 deletion src/services/store_subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit d57d57c

Please sign in to comment.