зеркало из https://github.com/mozilla/fxa.git
fix(payments): do not send payment failure emails during subscription creation flow
fixes #6129
This commit is contained in:
Родитель
41da2dbbdc
Коммит
5eb89ef661
|
@ -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', () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче