Merge pull request #6182 from mozilla/6129-too-many-payment-failed-emails

fix(payments): do not send payment failure emails during subscription creation flow
This commit is contained in:
Les Orchard 2020-08-13 01:30:18 -07:00 коммит произвёл GitHub
Родитель 91ccfae5d6 5eb89ef661
Коммит ef378f951b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 27 добавлений и 7 удалений

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

@ -998,6 +998,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
);

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

@ -2269,21 +2269,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
@ -2294,6 +2300,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', () => {