resubscribe button
This commit is contained in:
parent
ffc070ed51
commit
a5199b7d4b
@ -50,8 +50,8 @@ const addState = connect(
|
||||
return ws.sendMtxConstructSpawn(name);
|
||||
}
|
||||
|
||||
function sendSubscriptionCancel() {
|
||||
return ws.sendSubscriptionCancel();
|
||||
function sendSubscriptionEnding(enabled) {
|
||||
return ws.sendSubscriptionEnding(enabled);
|
||||
}
|
||||
|
||||
return {
|
||||
@ -63,7 +63,7 @@ const addState = connect(
|
||||
sendSetPassword,
|
||||
sendSetEmail,
|
||||
sendConstructSpawn,
|
||||
sendSubscriptionCancel,
|
||||
sendSubscriptionEnding,
|
||||
};
|
||||
},
|
||||
);
|
||||
@ -90,7 +90,7 @@ class AccountStatus extends Component {
|
||||
sendSetEmail,
|
||||
sendSetPassword,
|
||||
sendConstructSpawn,
|
||||
sendSubscriptionCancel,
|
||||
sendSubscriptionEnding,
|
||||
} = args;
|
||||
|
||||
const {
|
||||
@ -109,29 +109,34 @@ class AccountStatus extends Component {
|
||||
return !(passwordsEqual() && password && current && confirm);
|
||||
}
|
||||
|
||||
const unsub = e => {
|
||||
if (unsubState) {
|
||||
return sendSubscriptionCancel();
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
return this.setState({ unsubState: true });
|
||||
}
|
||||
|
||||
const unsubBtn = () => {
|
||||
if (!account.subscribed) return false;
|
||||
|
||||
const classes = `unsub ${unsubState ? 'confirming' : ''}`;
|
||||
const text = unsubState ? 'Confirm' : 'Unsubscribe'
|
||||
return <button class={classes} onClick={unsub}>{text}</button>
|
||||
}
|
||||
|
||||
const tlClick = e => {
|
||||
e.stopPropagation();
|
||||
return this.setState({ unsubState: false });
|
||||
}
|
||||
|
||||
const subInfo = () => {
|
||||
const unsubBtn = () => {
|
||||
if (!subscription) return false;
|
||||
|
||||
// resub button
|
||||
if (subscription.cancel_at_period_end) {
|
||||
return <button class='stripe-btn' onClick={() => sendSubscriptionEnding(false)}>Resubscribe</button>
|
||||
}
|
||||
|
||||
const classes = `unsub ${unsubState ? 'confirming' : ''}`;
|
||||
const text = unsubState ? 'Confirm' : 'Unsubscribe'
|
||||
return <button class={classes} onClick={unsub}>{text}</button>
|
||||
}
|
||||
|
||||
const unsub = e => {
|
||||
if (unsubState) {
|
||||
return sendSubscriptionEnding(true);
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
return this.setState({ unsubState: true });
|
||||
}
|
||||
|
||||
if (!subscription) return false;
|
||||
return <div>
|
||||
<h3>Subscription</h3>
|
||||
@ -141,6 +146,7 @@ class AccountStatus extends Component {
|
||||
<dt>Status</dt>
|
||||
<dd>{subscription.cancel_at_period_end ? 'Disabled' : 'Active'}</dd>
|
||||
</dl>
|
||||
{unsubBtn()}
|
||||
</div>;
|
||||
}
|
||||
|
||||
@ -211,7 +217,6 @@ class AccountStatus extends Component {
|
||||
</div>
|
||||
<div>
|
||||
{subInfo()}
|
||||
{unsubBtn()}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
|
||||
@ -54,8 +54,8 @@ function createSocket(events) {
|
||||
send(['AccountSetTeam', { ids }]);
|
||||
}
|
||||
|
||||
function sendSubscriptionCancel() {
|
||||
send(['SubscriptionCancel', { }]);
|
||||
function sendSubscriptionEnding(ending) {
|
||||
send(['SubscriptionEnding', { ending }]);
|
||||
}
|
||||
|
||||
function sendGameState(id) {
|
||||
@ -315,7 +315,6 @@ function createSocket(events) {
|
||||
sendAccountInstances,
|
||||
sendAccountSetTeam,
|
||||
|
||||
sendSubscriptionCancel,
|
||||
|
||||
sendGameState,
|
||||
sendGameReady,
|
||||
@ -338,6 +337,7 @@ function createSocket(events) {
|
||||
|
||||
sendEmailState,
|
||||
sendSubscriptionState,
|
||||
sendSubscriptionEnding,
|
||||
|
||||
sendMtxApply,
|
||||
sendMtxBuy,
|
||||
|
||||
@ -36,7 +36,7 @@ pub fn subscription_account(tx: &mut Transaction, sub: String) -> Result<Uuid, E
|
||||
Ok(row.get(0))
|
||||
}
|
||||
|
||||
pub fn subscription_cancel(tx: &mut Transaction, client: &Client, account: &Account) -> Result<Option<Subscription>, Error> {
|
||||
pub fn subscription_ending(tx: &mut Transaction, client: &Client, account: &Account, ending: bool) -> Result<Option<Subscription>, Error> {
|
||||
let query = "
|
||||
SELECT account, customer, checkout, subscription
|
||||
FROM stripe_subscriptions
|
||||
@ -55,16 +55,16 @@ pub fn subscription_cancel(tx: &mut Transaction, client: &Client, account: &Acco
|
||||
|
||||
let id = subscription.parse()?;
|
||||
let mut params = stripe::UpdateSubscription::new();
|
||||
params.cancel_at_period_end = Some(true);
|
||||
params.cancel_at_period_end = Some(ending);
|
||||
|
||||
match stripe::Subscription::update(client, &id, params) {
|
||||
Ok(s) => {
|
||||
info!("subscription cancelled account={:?} subscription={:?}", account, s);
|
||||
info!("subscription changed ending={:?} account={:?} subscription={:?}", ending, account, s);
|
||||
Ok(Some(s))
|
||||
},
|
||||
Err(e) => {
|
||||
warn!("{:?}", e);
|
||||
Err(err_msg("unable to cancel subscription"))
|
||||
Err(err_msg("unable to update subscription"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ enum RpcRequest {
|
||||
AccountConstructs {},
|
||||
AccountSetTeam { ids: Vec<Uuid> },
|
||||
|
||||
SubscriptionCancel {},
|
||||
SubscriptionEnding { ending: bool },
|
||||
SubscriptionState {},
|
||||
EmailState {},
|
||||
|
||||
@ -209,8 +209,8 @@ impl Connection {
|
||||
RpcRequest::MtxBuy { mtx } =>
|
||||
Ok(RpcMessage::AccountShop(mtx::buy(&mut tx, account, mtx)?)),
|
||||
|
||||
RpcRequest::SubscriptionCancel { } =>
|
||||
Ok(RpcMessage::SubscriptionState(payments::subscription_cancel(&mut tx, &self.stripe, account)?)),
|
||||
RpcRequest::SubscriptionEnding { ending } =>
|
||||
Ok(RpcMessage::SubscriptionState(payments::subscription_ending(&mut tx, &self.stripe, account, ending)?)),
|
||||
|
||||
_ => Err(format_err!("unknown request request={:?}", request)),
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user