{account.name}
- Subscription
- - {account.subscribed ? 'some date' : 'unsubscribed'}
+ - {account.subscribed ? 'Active' : 'Unsubscribed'}
-
+ {unsubBtn()}
+
@@ -116,11 +152,11 @@ class AccountStatus extends Component {
class="login-input"
type="email"
name="email"
- value={this.state.email}
- onInput={linkState(this, 'email')}
+ value={emailState}
+ onInput={linkState(this, 'emailState')}
placeholder="recovery@email.tld"
/>
-
+
@@ -128,29 +164,29 @@ class AccountStatus extends Component {
class="login-input"
type="password"
name="current"
- value={this.state.setPassword.current}
- onInput={linkState(this, 'setPassword.current')}
+ value={passwordState.current}
+ onInput={linkState(this, 'passwordState.current')}
placeholder="current"
/>
diff --git a/client/src/components/stripe.buttons.jsx b/client/src/components/stripe.buttons.jsx
index e660e4a9..7d15770e 100644
--- a/client/src/components/stripe.buttons.jsx
+++ b/client/src/components/stripe.buttons.jsx
@@ -8,7 +8,7 @@ function BitsBtn(args) {
} = args;
function subscribeClick() {
stripe.redirectToCheckout({
- items: [{ plan: 'plan_FGmRwawcOJJ7Nv', quantity: 1 }],
+ items: [{ plan: 'plan_Fhl9r7UdMadjGi', quantity: 1 }],
successUrl: 'http://localhost',
cancelUrl: 'http://localhost',
clientReferenceId: account.id,
diff --git a/client/src/events.jsx b/client/src/events.jsx
index 15f9f35b..04a4e6f6 100644
--- a/client/src/events.jsx
+++ b/client/src/events.jsx
@@ -3,6 +3,7 @@ const eachSeries = require('async/eachSeries');
const actions = require('./actions');
const { TIMES } = require('./constants');
const animations = require('./animations.utils');
+const { infoToast, errorToast } = require('./utils');
function registerEvents(store) {
function setPing(ping) {
@@ -170,6 +171,10 @@ function registerEvents(store) {
return store.dispatch(actions.setItemInfo(v));
}
+ function notify(msg) {
+ return infoToast(msg);
+ }
+
// events.on('SET_PLAYER', setInstance);
// events.on('SEND_SKILL', function skillActive(gameId, constructId, targetConstructId, skill) {
@@ -223,6 +228,8 @@ function registerEvents(store) {
setShop,
setTeam,
setWs,
+
+ notify,
};
}
diff --git a/client/src/socket.jsx b/client/src/socket.jsx
index 4fe78845..02c1735d 100644
--- a/client/src/socket.jsx
+++ b/client/src/socket.jsx
@@ -54,6 +54,10 @@ function createSocket(events) {
send(['AccountSetTeam', { ids }]);
}
+ function sendSubscriptionCancel() {
+ send(['SubscriptionCancel', { }]);
+ }
+
function sendGameState(id) {
send(['GameState', { id }]);
}
@@ -166,6 +170,10 @@ function createSocket(events) {
events.setTeam(constructs);
}
+ function onAccountSubscription() {
+ events.notify('Your account has been set to cancelled. You will no longer be billed. Thanks for playing.');
+ }
+
function onConstructSpawn(construct) {
events.setNewConstruct(construct);
}
@@ -200,6 +208,7 @@ function createSocket(events) {
AccountTeam: onAccountTeam,
AccountInstances: onAccountInstances,
AccountShop: onAccountShop,
+ AccountSubscription: onAccountSubscription,
ConstructSpawn: onConstructSpawn,
GameState: onGameState,
EmailState: onEmailState,
@@ -296,6 +305,8 @@ function createSocket(events) {
sendAccountInstances,
sendAccountSetTeam,
+ sendSubscriptionCancel,
+
sendGameState,
sendGameReady,
sendGameSkill,
diff --git a/etc/mnml/gs.SAMPLE.conf b/etc/mnml/gs.conf
similarity index 83%
rename from etc/mnml/gs.SAMPLE.conf
rename to etc/mnml/gs.conf
index 20435945..6fafaf6d 100644
--- a/etc/mnml/gs.SAMPLE.conf
+++ b/etc/mnml/gs.conf
@@ -3,3 +3,5 @@ DATABASE_URL=postgres://mnml:password@somewhere/mnml
MAIL_ADDRESS=machines@mnml.gg
MAIL_DOMAIN=vinyl.mnml.gg
MAIL_PASSWORD=mmmmmmmmmmmmmmmm
+
+STRIPE_SECRET=shhhhhhhhhh
diff --git a/server/Cargo.toml b/server/Cargo.toml
index f66c0f87..ab043db4 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -38,4 +38,5 @@ ws = "0.8"
lettre = "0.9"
lettre_email = "0.9"
-stripe-rust = { version = "0.10.4", features = ["webhooks"] }
+stripe-rust = "0.10"
+# stripe-rust = { path = "/home/ntr/code/stripe-rs" }
diff --git a/server/src/main.rs b/server/src/main.rs
index b452f137..cad0c1f7 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -146,6 +146,8 @@ fn main() {
let pg_pool = pool.clone();
let mailer = mail::listen(mail_rx);
+ let stripe = payments::stripe_client();
+
spawn(move || http::start(http_pool, mailer));
spawn(move || warden.listen());
spawn(move || warden::upkeep_tick(warden_tick_tx));
@@ -154,5 +156,5 @@ fn main() {
// the main thread becomes this ws listener
let rpc_pool = pool.clone();
- rpc::start(rpc_pool, rpc_events_tx);
+ rpc::start(rpc_pool, rpc_events_tx, stripe);
}
diff --git a/server/src/payments.rs b/server/src/payments.rs
index 7f02388c..c1a56597 100644
--- a/server/src/payments.rs
+++ b/server/src/payments.rs
@@ -1,3 +1,4 @@
+use std::env;
use std::io::Read;
use http::State;
@@ -12,15 +13,16 @@ use postgres::transaction::Transaction;
use failure::Error;
use failure::err_msg;
-use stripe::{Event, EventObject, CheckoutSession, SubscriptionStatus};
+use stripe::{Client, Event, EventObject, CheckoutSession, SubscriptionStatus};
use http::{MnmlHttpError};
use pg::{PgPool};
use account;
+use account::Account;
pub fn subscription_account(tx: &mut Transaction, sub: String) -> Result {
let query = "
- SELECT account
+ SELECT account, customer, checkout, subscription
FROM stripe_subscriptions
WHERE subscription = $1;
";
@@ -34,6 +36,41 @@ pub fn subscription_account(tx: &mut Transaction, sub: String) -> Result Result