mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
stripe webhook for unpaid subs: add 3 days of remaining time
This commit is contained in:
@@ -12,6 +12,7 @@ import payments from '../../../../../website/server/libs/payments';
|
|||||||
import common from '../../../../../website/common';
|
import common from '../../../../../website/common';
|
||||||
import logger from '../../../../../website/server/libs/logger';
|
import logger from '../../../../../website/server/libs/logger';
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
const i18n = common.i18n;
|
const i18n = common.i18n;
|
||||||
|
|
||||||
@@ -878,6 +879,7 @@ describe('Stripe Payments', () => {
|
|||||||
let cancelSubscriptionOpts = payments.cancelSubscription.lastCall.args[0];
|
let cancelSubscriptionOpts = payments.cancelSubscription.lastCall.args[0];
|
||||||
expect(cancelSubscriptionOpts.user._id).to.equal(subscriber._id);
|
expect(cancelSubscriptionOpts.user._id).to.equal(subscriber._id);
|
||||||
expect(cancelSubscriptionOpts.paymentMethod).to.equal('Stripe');
|
expect(cancelSubscriptionOpts.paymentMethod).to.equal('Stripe');
|
||||||
|
expect(Math.round(moment(cancelSubscriptionOpts.nextBill).diff(new Date(), 'days', true))).to.equal(3);
|
||||||
expect(cancelSubscriptionOpts.groupId).to.be.undefined;
|
expect(cancelSubscriptionOpts.groupId).to.be.undefined;
|
||||||
|
|
||||||
stripe.events.retrieve.restore();
|
stripe.events.retrieve.restore();
|
||||||
@@ -988,6 +990,7 @@ describe('Stripe Payments', () => {
|
|||||||
let cancelSubscriptionOpts = payments.cancelSubscription.lastCall.args[0];
|
let cancelSubscriptionOpts = payments.cancelSubscription.lastCall.args[0];
|
||||||
expect(cancelSubscriptionOpts.user._id).to.equal(leader._id);
|
expect(cancelSubscriptionOpts.user._id).to.equal(leader._id);
|
||||||
expect(cancelSubscriptionOpts.paymentMethod).to.equal('Stripe');
|
expect(cancelSubscriptionOpts.paymentMethod).to.equal('Stripe');
|
||||||
|
expect(Math.round(moment(cancelSubscriptionOpts.nextBill).diff(new Date(), 'days', true))).to.equal(3);
|
||||||
expect(cancelSubscriptionOpts.groupId).to.equal(subscriber._id);
|
expect(cancelSubscriptionOpts.groupId).to.equal(subscriber._id);
|
||||||
|
|
||||||
stripe.events.retrieve.restore();
|
stripe.events.retrieve.restore();
|
||||||
|
|||||||
@@ -424,7 +424,7 @@ api.cancelSubscription = async function cancelSubscription (data) {
|
|||||||
defaultRemainingDays = 2;
|
defaultRemainingDays = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
let remaining = data.nextBill ? moment(data.nextBill).diff(new Date(), 'days') : defaultRemainingDays;
|
let remaining = data.nextBill ? moment(data.nextBill).diff(new Date(), 'days', true) : defaultRemainingDays;
|
||||||
if (plan.extraMonths < 0) plan.extraMonths = 0;
|
if (plan.extraMonths < 0) plan.extraMonths = 0;
|
||||||
let extraDays = Math.ceil(30.5 * plan.extraMonths);
|
let extraDays = Math.ceil(30.5 * plan.extraMonths);
|
||||||
let nowStr = `${now.format('MM')}/${moment(plan.dateUpdated).format('DD')}/${now.format('YYYY')}`;
|
let nowStr = `${now.format('MM')}/${moment(plan.dateUpdated).format('DD')}/${now.format('YYYY')}`;
|
||||||
|
|||||||
@@ -328,6 +328,8 @@ api.handleWebhooks = async function handleWebhooks (options, stripeInc) {
|
|||||||
user,
|
user,
|
||||||
groupId,
|
groupId,
|
||||||
paymentMethod: this.constants.PAYMENT_METHOD,
|
paymentMethod: this.constants.PAYMENT_METHOD,
|
||||||
|
// Give three extra days to allow the user to resubscribe without losing benefits
|
||||||
|
nextBill: moment().add({days: 3}).toDate(),
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user