fix: Updates to medusa payments provider (#13914)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/payment": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Minor fixes to medusa payments provider
|
||||||
@@ -155,12 +155,24 @@ export class MedusaPaymentsProvider extends AbstractPaymentProvider<MedusaPaymen
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleStripeError(error: CloudServiceError): HandledErrorType {
|
handleStripeError(error: CloudServiceError): HandledErrorType {
|
||||||
|
let medusaPayment: MedusaPayment | undefined
|
||||||
|
|
||||||
switch (error.type) {
|
switch (error.type) {
|
||||||
case "MedusaCardError":
|
case "MedusaCardError":
|
||||||
// Medusa has created a payment but it failed
|
// Medusa has created a payment but it failed
|
||||||
// Extract and return payment object to be stored in payment_session
|
// Extract and return payment object to be stored in payment_session
|
||||||
// Allows for reference to the failed intent and potential webhook reconciliation
|
// Allows for reference to the failed intent and potential webhook reconciliation
|
||||||
const medusaPayment = error.data as MedusaPayment | undefined
|
medusaPayment = error.data as MedusaPayment | undefined
|
||||||
|
if (medusaPayment) {
|
||||||
|
return {
|
||||||
|
retry: false,
|
||||||
|
data: medusaPayment,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
case "MedusaPaymentUnexpectedStateError":
|
||||||
|
medusaPayment = error.data as MedusaPayment | undefined
|
||||||
if (medusaPayment) {
|
if (medusaPayment) {
|
||||||
return {
|
return {
|
||||||
retry: false,
|
retry: false,
|
||||||
@@ -169,7 +181,6 @@ export class MedusaPaymentsProvider extends AbstractPaymentProvider<MedusaPaymen
|
|||||||
} else {
|
} else {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
case "MedusaConnectionError":
|
case "MedusaConnectionError":
|
||||||
case "MedusaRateLimitError":
|
case "MedusaRateLimitError":
|
||||||
// Connection or rate limit errors indicate an uncertain result
|
// Connection or rate limit errors indicate an uncertain result
|
||||||
@@ -239,11 +250,11 @@ export class MedusaPaymentsProvider extends AbstractPaymentProvider<MedusaPaymen
|
|||||||
}
|
}
|
||||||
|
|
||||||
const payment = await this.retrievePayment({ data: { id } })
|
const payment = await this.retrievePayment({ data: { id } })
|
||||||
|
const statusResponse = this.getStatus(
|
||||||
|
payment.data as unknown as MedusaPayment
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return statusResponse
|
||||||
status: payment.data?.status as PaymentSessionStatus,
|
|
||||||
data: payment.data,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async initiatePayment({
|
async initiatePayment({
|
||||||
@@ -307,6 +318,13 @@ export class MedusaPaymentsProvider extends AbstractPaymentProvider<MedusaPaymen
|
|||||||
}).then((data) => data.payment)
|
}).then((data) => data.payment)
|
||||||
})) as MedusaPayment
|
})) as MedusaPayment
|
||||||
|
|
||||||
|
const status = this.getStatus(intent)
|
||||||
|
if (status.status !== PaymentSessionStatus.CANCELED) {
|
||||||
|
throw new Error(
|
||||||
|
`Payment with id ${id} could not be canceled. Status: ${status.status}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return { data: intent as unknown as Record<string, unknown> }
|
return { data: intent as unknown as Record<string, unknown> }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,6 +343,13 @@ export class MedusaPaymentsProvider extends AbstractPaymentProvider<MedusaPaymen
|
|||||||
}).then((data) => data.payment)
|
}).then((data) => data.payment)
|
||||||
})) as MedusaPayment
|
})) as MedusaPayment
|
||||||
|
|
||||||
|
const status = this.getStatus(intent)
|
||||||
|
if (status.status !== PaymentSessionStatus.CAPTURED) {
|
||||||
|
throw new Error(
|
||||||
|
`Payment with id ${id} could not be captured. Status: ${status.status}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return { data: intent as unknown as Record<string, unknown> }
|
return { data: intent as unknown as Record<string, unknown> }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user