зеркало из https://github.com/mozilla/fxa.git
fix(auth-server): Capture error in updateStripeNameFromBA if billing agreement was cancelled
This commit is contained in:
Родитель
3351a003e7
Коммит
93f31f97ae
|
@ -410,6 +410,11 @@ export class PayPalHelper {
|
|||
const agreementDetails = await this.agreementDetails({
|
||||
billingAgreementId,
|
||||
});
|
||||
if (agreementDetails.status === 'cancelled') {
|
||||
throw error.internalValidationError('updateStripeNameFromBA', {
|
||||
message: 'Billing agreement was cancelled.',
|
||||
});
|
||||
}
|
||||
const name = `${agreementDetails.firstName} ${agreementDetails.lastName}`;
|
||||
return this.stripeHelper.updateCustomerBillingAddress({
|
||||
customerId: customer.id,
|
||||
|
|
|
@ -541,10 +541,24 @@ export class StripeWebhookHandler extends StripeHandler {
|
|||
this.stripeHelper.getCustomerPaypalAgreement(customer);
|
||||
// The customer needs to be updated for their name.
|
||||
if (billingAgreementId) {
|
||||
await this.paypalHelper.updateStripeNameFromBA(
|
||||
customer,
|
||||
billingAgreementId
|
||||
);
|
||||
try {
|
||||
await this.paypalHelper.updateStripeNameFromBA(
|
||||
customer,
|
||||
billingAgreementId
|
||||
);
|
||||
} catch (err) {
|
||||
if (err.errno === error.ERRNO.INTERNAL_VALIDATION_ERROR) {
|
||||
this.log.error(
|
||||
`handleInvoiceCreatedEvent - Billing agreement (id: ${billingAgreementId}) was cancelled.`,
|
||||
{
|
||||
request,
|
||||
customer,
|
||||
}
|
||||
);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -627,6 +627,30 @@ describe('PayPalHelper', () => {
|
|||
);
|
||||
sinon.assert.calledOnce(paypalHelper.metrics.increment);
|
||||
});
|
||||
|
||||
it('throws error if billing agreement status is cancelled', async () => {
|
||||
mockStripeHelper.updateCustomerBillingAddress = sinon.fake.resolves({});
|
||||
paypalHelper.agreementDetails = sinon.fake.resolves({
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
status: 'cancelled',
|
||||
});
|
||||
|
||||
try {
|
||||
await paypalHelper.updateStripeNameFromBA(
|
||||
mockCustomer,
|
||||
'mock-agreement-id'
|
||||
);
|
||||
assert.fail('Error should throw billing agreement was cancelled.');
|
||||
} catch (err) {
|
||||
assert.deepEqual(
|
||||
err,
|
||||
error.internalValidationError('updateStripeNameFromBA', {
|
||||
message: 'Billing agreement was cancelled.',
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('processZeroInvoice', () => {
|
||||
|
|
|
@ -1175,6 +1175,55 @@ describe('StripeWebhookHandler', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('logs if the billing agreement was cancelled', async () => {
|
||||
const invoiceCreatedEvent = deepCopy(eventInvoiceCreated);
|
||||
invoiceCreatedEvent.data.object.status = 'draft';
|
||||
StripeWebhookHandlerInstance.stripeHelper.invoicePayableWithPaypal.resolves(
|
||||
true
|
||||
);
|
||||
StripeWebhookHandlerInstance.stripeHelper.finalizeInvoice.resolves({});
|
||||
StripeWebhookHandlerInstance.stripeHelper.getCustomerPaypalAgreement.returns(
|
||||
'test-ba'
|
||||
);
|
||||
StripeWebhookHandlerInstance.paypalHelper.updateStripeNameFromBA.rejects(
|
||||
{
|
||||
errno: 998,
|
||||
}
|
||||
);
|
||||
StripeWebhookHandlerInstance.log.error = sinon.fake.returns({});
|
||||
const result =
|
||||
await StripeWebhookHandlerInstance.handleInvoiceCreatedEvent(
|
||||
{},
|
||||
invoiceCreatedEvent
|
||||
);
|
||||
assert.deepEqual(result, {});
|
||||
assert.calledOnceWithExactly(
|
||||
StripeWebhookHandlerInstance.log.error,
|
||||
`handleInvoiceCreatedEvent - Billing agreement (id: test-ba) was cancelled.`,
|
||||
{
|
||||
request: {},
|
||||
customer: {},
|
||||
}
|
||||
);
|
||||
assert.calledWith(
|
||||
StripeWebhookHandlerInstance.stripeHelper.invoicePayableWithPaypal,
|
||||
invoiceCreatedEvent.data.object
|
||||
);
|
||||
assert.calledWith(
|
||||
StripeWebhookHandlerInstance.stripeHelper.finalizeInvoice,
|
||||
invoiceCreatedEvent.data.object
|
||||
);
|
||||
assert.calledWith(
|
||||
StripeWebhookHandlerInstance.paypalHelper.updateStripeNameFromBA,
|
||||
{},
|
||||
'test-ba'
|
||||
);
|
||||
assert.calledWith(
|
||||
StripeWebhookHandlerInstance.stripeHelper.getCustomerPaypalAgreement,
|
||||
{}
|
||||
);
|
||||
});
|
||||
|
||||
it('finalizes invoices for invoice subscriptions', async () => {
|
||||
const invoiceCreatedEvent = deepCopy(eventInvoiceCreated);
|
||||
invoiceCreatedEvent.data.object.status = 'draft';
|
||||
|
|
Загрузка…
Ссылка в новой задаче