fix(medusa-payment-stripe): Catch on idempotency key retrieve if not found (#4025)

**What**
In case the idempotency key is not found, an error will be thrown. We actually want to catch this error and create the key if it does not exists
This commit is contained in:
Adrien de Peretti
2023-05-05 16:54:38 +02:00
committed by GitHub
parent ff37cd190f
commit cff54d7325
3 changed files with 14 additions and 6 deletions

View File

@@ -0,0 +1,6 @@
---
"medusa-payment-stripe": patch
"@medusajs/medusa": patch
---
fix(medusa-payment-stripe): Catch on idempotency key retrieve if not found

View File

@@ -35,8 +35,8 @@ container.register(
withTransaction: function () {
return this
},
retrieve: jest.fn().mockReturnValue(undefined),
create: jest.fn().mockReturnValue({}),
retrieve: jest.fn().mockImplementation(async () => undefined),
create: jest.fn().mockImplementation(async () => ({})),
})
)

View File

@@ -226,10 +226,12 @@ async function completeCartIfNecessary({
const idempotencyKeyServiceTx =
idempotencyKeyService.withTransaction(transactionManager)
let idempotencyKey = await idempotencyKeyServiceTx.retrieve({
request_path: "/stripe/hooks",
idempotency_key: eventId,
})
let idempotencyKey = await idempotencyKeyServiceTx
.retrieve({
request_path: "/stripe/hooks",
idempotency_key: eventId,
})
.catch(() => undefined)
if (!idempotencyKey) {
idempotencyKey = await idempotencyKeyService