mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-03 00:09:41 +00:00
stripe webhook: fix handling of automatic requests
(cherry picked from commit c4463f991b)
This commit is contained in:
parent
0ecb95a294
commit
4c121fba19
2 changed files with 8 additions and 3 deletions
|
|
@ -810,7 +810,7 @@ describe('Stripe Payments', () => {
|
||||||
sinon.stub(stripe.events, 'retrieve').returnsPromise().resolves({
|
sinon.stub(stripe.events, 'retrieve').returnsPromise().resolves({
|
||||||
id: 123,
|
id: 123,
|
||||||
type: eventType,
|
type: eventType,
|
||||||
request: null,
|
request: 123,
|
||||||
});
|
});
|
||||||
|
|
||||||
await stripePayments.handleWebhooks({requestBody: {}}, stripe);
|
await stripePayments.handleWebhooks({requestBody: {}}, stripe);
|
||||||
|
|
@ -835,6 +835,7 @@ describe('Stripe Payments', () => {
|
||||||
customer: customerId,
|
customer: customerId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
request: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(stripePayments.handleWebhooks({requestBody: {}}, stripe)).to.eventually.be.rejectedWith({
|
await expect(stripePayments.handleWebhooks({requestBody: {}}, stripe)).to.eventually.be.rejectedWith({
|
||||||
|
|
@ -868,6 +869,7 @@ describe('Stripe Payments', () => {
|
||||||
customer: customerId,
|
customer: customerId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
request: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
await stripePayments.handleWebhooks({requestBody: {}}, stripe);
|
await stripePayments.handleWebhooks({requestBody: {}}, stripe);
|
||||||
|
|
@ -900,6 +902,7 @@ describe('Stripe Payments', () => {
|
||||||
customer: customerId,
|
customer: customerId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
request: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(stripePayments.handleWebhooks({requestBody: {}}, stripe)).to.eventually.be.rejectedWith({
|
await expect(stripePayments.handleWebhooks({requestBody: {}}, stripe)).to.eventually.be.rejectedWith({
|
||||||
|
|
@ -938,6 +941,7 @@ describe('Stripe Payments', () => {
|
||||||
customer: customerId,
|
customer: customerId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
request: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(stripePayments.handleWebhooks({requestBody: {}}, stripe)).to.eventually.be.rejectedWith({
|
await expect(stripePayments.handleWebhooks({requestBody: {}}, stripe)).to.eventually.be.rejectedWith({
|
||||||
|
|
@ -979,6 +983,7 @@ describe('Stripe Payments', () => {
|
||||||
customer: customerId,
|
customer: customerId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
request: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
await stripePayments.handleWebhooks({requestBody: {}}, stripe);
|
await stripePayments.handleWebhooks({requestBody: {}}, stripe);
|
||||||
|
|
|
||||||
|
|
@ -291,9 +291,9 @@ api.handleWebhooks = async function handleWebhooks (options, stripeInc) {
|
||||||
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case 'customer.subscription.deleted': {
|
case 'customer.subscription.deleted': {
|
||||||
// event.request === null means that the user itself cancelled the subscrioption,
|
// event.request !== null means that the user itself cancelled the subscrioption,
|
||||||
// the cancellation on our side has been already handled
|
// the cancellation on our side has been already handled
|
||||||
if (event.request === null) break;
|
if (event.request !== null) break;
|
||||||
|
|
||||||
const subscription = event.data.object;
|
const subscription = event.data.object;
|
||||||
const customerId = subscription.customer;
|
const customerId = subscription.customer;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue