fix(payments): do not send payment failure emails during subscription creation flow

fixes #6129
This commit is contained in:
Les Orchard 2020-08-10 19:18:31 -04:00
Родитель 41da2dbbdc
Коммит 5eb89ef661
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 857F1A39AA1C4902
2 изменённых файлов: 27 добавлений и 7 удалений

Просмотреть файл

@ -1027,6 +1027,10 @@ class DirectStripeRoutes {
event: Stripe.Event
) {
const invoice = event.data.object as Stripe.Invoice;
if (invoice.billing_reason !== 'subscription_cycle') {
// Send payment failure emails only when processing a subscription renewal.
return;
}
const { uid, email } = await this.sendSubscriptionPaymentFailedEmail(
invoice
);

Просмотреть файл

@ -2265,21 +2265,27 @@ describe('DirectStripeRoutes', () => {
});
describe('handleInvoicePaymentFailedEvent', () => {
it('sends email and emits a notification when an invoice payment fails', async () => {
const paymentFailedEvent = deepCopy(eventInvoicePaymentFailed);
const sendSubscriptionPaymentFailedEmailStub = sandbox
const mockSubscription = {
id: 'test1',
plan: { product: 'test2' },
};
let sendSubscriptionPaymentFailedEmailStub;
beforeEach(() => {
sendSubscriptionPaymentFailedEmailStub = sandbox
.stub(
directStripeRoutesInstance,
'sendSubscriptionPaymentFailedEmail'
)
.resolves(true);
const mockSubscription = {
id: 'test1',
plan: { product: 'test2' },
};
directStripeRoutesInstance.stripeHelper.expandResource.resolves(
mockSubscription
);
});
it('sends email and emits a notification when an invoice payment fails', async () => {
const paymentFailedEvent = deepCopy(eventInvoicePaymentFailed);
paymentFailedEvent.data.object.billing_reason = 'subscription_cycle';
await directStripeRoutesInstance.handleInvoicePaymentFailedEvent(
{},
paymentFailedEvent
@ -2290,6 +2296,16 @@ describe('DirectStripeRoutes', () => {
);
assert.notCalled(stubSendSubscriptionStatusToSqs);
});
it('does not send email during subscription creation flow', async () => {
const paymentFailedEvent = deepCopy(eventInvoicePaymentFailed);
paymentFailedEvent.data.object.billing_reason = 'subscription_create';
await directStripeRoutesInstance.handleInvoicePaymentFailedEvent(
{},
paymentFailedEvent
);
assert.notCalled(sendSubscriptionPaymentFailedEmailStub);
});
});
describe('handleSubscriptionCreatedEvent', () => {