chore: payment auto capture + remove enum from utils (#7513)
What: - handles payments session that are auto captured - removes all the enums from `@medusajs/types` - move all `@medusajs/types` to devDependencies
This commit is contained in:
committed by
GitHub
parent
2c5ba408d4
commit
f1ced57d5f
@@ -2,11 +2,14 @@ import {
|
||||
CreatePaymentProviderSession,
|
||||
PaymentProviderError,
|
||||
PaymentProviderSessionResponse,
|
||||
PaymentSessionStatus,
|
||||
ProviderWebhookPayload,
|
||||
WebhookActionResult,
|
||||
} from "@medusajs/types"
|
||||
import { AbstractPaymentProvider, PaymentActions } from "@medusajs/utils"
|
||||
import {
|
||||
AbstractPaymentProvider,
|
||||
PaymentActions,
|
||||
PaymentSessionStatus,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
export class SystemProviderService extends AbstractPaymentProvider {
|
||||
static identifier = "system"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
BigNumberInput,
|
||||
CaptureDTO,
|
||||
Context,
|
||||
CreateCaptureDTO,
|
||||
@@ -18,7 +19,6 @@ import {
|
||||
PaymentDTO,
|
||||
PaymentProviderDTO,
|
||||
PaymentSessionDTO,
|
||||
PaymentSessionStatus,
|
||||
ProviderWebhookPayload,
|
||||
RefundDTO,
|
||||
UpdatePaymentCollectionDTO,
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
ModulesSdkUtils,
|
||||
PaymentActions,
|
||||
PaymentCollectionStatus,
|
||||
PaymentSessionStatus,
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { IsolationLevel } from "@mikro-orm/core"
|
||||
@@ -417,6 +418,7 @@ export default class PaymentModuleService<
|
||||
"data",
|
||||
"provider_id",
|
||||
"amount",
|
||||
"raw_amount",
|
||||
"currency_code",
|
||||
"payment_collection_id",
|
||||
],
|
||||
@@ -434,14 +436,19 @@ export default class PaymentModuleService<
|
||||
return await this.baseRepository_.serialize(payment, { populate: true })
|
||||
}
|
||||
|
||||
const { data, status } =
|
||||
await this.paymentProviderService_.authorizePayment(
|
||||
{
|
||||
provider_id: session.provider_id,
|
||||
data: session.data,
|
||||
},
|
||||
context
|
||||
)
|
||||
let { data, status } = await this.paymentProviderService_.authorizePayment(
|
||||
{
|
||||
provider_id: session.provider_id,
|
||||
data: session.data,
|
||||
},
|
||||
context
|
||||
)
|
||||
|
||||
let autoCapture = false
|
||||
if (status === PaymentSessionStatus.CAPTURED) {
|
||||
status = PaymentSessionStatus.AUTHORIZED
|
||||
autoCapture = true
|
||||
}
|
||||
|
||||
await this.paymentSessionService_.update(
|
||||
{
|
||||
@@ -479,6 +486,13 @@ export default class PaymentModuleService<
|
||||
sharedContext
|
||||
)
|
||||
|
||||
if (autoCapture) {
|
||||
await this.capturePayment_(
|
||||
{ payment_id: payment.id, amount: session.amount as BigNumberInput },
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
|
||||
return await this.retrievePayment(
|
||||
payment.id,
|
||||
{ relations: ["payment_collection"] },
|
||||
|
||||
Reference in New Issue
Block a user