chore: move ModuleRegistrationName to utils (#7911)

This commit is contained in:
Carlos R. L. Rodrigues
2024-07-03 06:30:56 -03:00
committed by GitHub
parent 46f15b4909
commit a7844efd09
339 changed files with 7203 additions and 7620 deletions

View File

@@ -13,56 +13,57 @@ In this guide, youll find common examples of how you can use the Payment Modu
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPaymentModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPaymentModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function POST(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const paymentModuleService: IPaymentModuleService =
req.scope.resolve(ModuleRegistrationName.PAYMENT)
export async function POST(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const paymentModuleService: IPaymentModuleService = req.scope.resolve(
ModuleRegistrationName.PAYMENT
)
const paymentCollection =
await paymentModuleService.createPaymentCollections({
region_id: "reg_123",
currency_code: "usd",
amount: 4000,
})
const paymentCollection = await paymentModuleService.createPaymentCollections(
{
region_id: "reg_123",
currency_code: "usd",
amount: 4000,
}
)
res.json({
payment_collection: paymentCollection,
})
}
```
res.json({
payment_collection: paymentCollection,
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
```ts
import { NextResponse } from "next/server"
import {
initialize as initializePaymentModule,
} from "@medusajs/payment"
import { initialize as initializePaymentModule } from "@medusajs/payment"
export async function POST(request: Request) {
const paymentModuleService = await initializePaymentModule()
export async function POST(request: Request) {
const paymentModuleService = await initializePaymentModule()
const paymentCollection =
await paymentModuleService.createPaymentCollections({
region_id: "reg_123",
currency_code: "usd",
amount: 4000,
})
const paymentCollection = await paymentModuleService.createPaymentCollections(
{
region_id: "reg_123",
currency_code: "usd",
amount: 4000,
}
)
return NextResponse.json({
payment_collection: paymentCollection,
})
}
```
return NextResponse.json({
payment_collection: paymentCollection,
})
}
```
</CodeTab>
</CodeTabs>
@@ -74,64 +75,61 @@ In this guide, youll find common examples of how you can use the Payment Modu
<CodeTabs groupId="app-type" isCodeCodeTabs={true}>
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPaymentModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPaymentModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function POST(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const paymentModuleService: IPaymentModuleService =
req.scope.resolve(ModuleRegistrationName.PAYMENT)
export async function POST(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const paymentModuleService: IPaymentModuleService = req.scope.resolve(
ModuleRegistrationName.PAYMENT
)
const paymentSession =
await paymentModuleService.createPaymentSession(
"pay_col_123",
{
currency_code: "usd",
provider_id: "system",
amount: 4000,
data: {},
}
)
const paymentSession = await paymentModuleService.createPaymentSession(
"pay_col_123",
{
currency_code: "usd",
provider_id: "system",
amount: 4000,
data: {},
}
)
res.json({
payment_session: paymentSession,
})
}
```
res.json({
payment_session: paymentSession,
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
```ts
import { NextResponse } from "next/server"
import {
initialize as initializePaymentModule,
} from "@medusajs/payment"
import { initialize as initializePaymentModule } from "@medusajs/payment"
export async function POST(request: Request) {
const paymentModuleService = await initializePaymentModule()
export async function POST(request: Request) {
const paymentModuleService = await initializePaymentModule()
const paymentSession =
await paymentModuleService.createPaymentSession(
"pay_col_123",
{
currency_code: "usd",
provider_id: "system",
amount: 4000,
data: {},
}
)
const paymentSession = await paymentModuleService.createPaymentSession(
"pay_col_123",
{
currency_code: "usd",
provider_id: "system",
amount: 4000,
data: {},
}
)
return NextResponse.json({
payment_session: paymentSession,
})
}
```
return NextResponse.json({
payment_session: paymentSession,
})
}
```
</CodeTab>
</CodeTabs>
@@ -143,54 +141,49 @@ In this guide, youll find common examples of how you can use the Payment Modu
<CodeTabs groupId="app-type" isCodeCodeTabs={true}>
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPaymentModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPaymentModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const paymentModuleService: IPaymentModuleService =
req.scope.resolve(ModuleRegistrationName.PAYMENT)
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const paymentModuleService: IPaymentModuleService = req.scope.resolve(
ModuleRegistrationName.PAYMENT
)
const paymentSessions =
await paymentModuleService.listPaymentSessions({
payment_collection_id: ["pay_col_123"],
})
const paymentSessions = await paymentModuleService.listPaymentSessions({
payment_collection_id: ["pay_col_123"],
})
res.json({
payment_sessions: paymentSessions,
})
}
```
res.json({
payment_sessions: paymentSessions,
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
```ts
import { NextResponse } from "next/server"
import {
initialize as initializePaymentModule,
} from "@medusajs/payment"
import { initialize as initializePaymentModule } from "@medusajs/payment"
export async function POST(
request: Request
) {
const paymentModuleService = await initializePaymentModule()
export async function POST(request: Request) {
const paymentModuleService = await initializePaymentModule()
const paymentSessions =
await paymentModuleService.listPaymentSessions({
payment_collection_id: ["pay_col_123"],
})
const paymentSessions = await paymentModuleService.listPaymentSessions({
payment_collection_id: ["pay_col_123"],
})
return NextResponse.json({
payment_sessions: paymentSessions,
})
}
```
return NextResponse.json({
payment_sessions: paymentSessions,
})
}
```
</CodeTab>
</CodeTabs>
@@ -202,56 +195,51 @@ In this guide, youll find common examples of how you can use the Payment Modu
<CodeTabs groupId="app-type" isCodeCodeTabs={true}>
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPaymentModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPaymentModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function POST(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const paymentModuleService: IPaymentModuleService =
req.scope.resolve(ModuleRegistrationName.PAYMENT)
export async function POST(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const paymentModuleService: IPaymentModuleService = req.scope.resolve(
ModuleRegistrationName.PAYMENT
)
const payment =
await paymentModuleService.authorizePaymentSession(
"payses_123",
{}
)
const payment = await paymentModuleService.authorizePaymentSession(
"payses_123",
{}
)
res.json({
payment,
})
}
```
res.json({
payment,
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
```ts
import { NextResponse } from "next/server"
import {
initialize as initializePaymentModule,
} from "@medusajs/payment"
import { initialize as initializePaymentModule } from "@medusajs/payment"
export async function POST(
request: Request
) {
const paymentModuleService = await initializePaymentModule()
export async function POST(request: Request) {
const paymentModuleService = await initializePaymentModule()
const payment =
await paymentModuleService.authorizePaymentSession(
"payses_123",
{}
)
const payment = await paymentModuleService.authorizePaymentSession(
"payses_123",
{}
)
return NextResponse.json({
payment,
})
}
```
return NextResponse.json({
payment,
})
}
```
</CodeTab>
</CodeTabs>
@@ -263,52 +251,49 @@ In this guide, youll find common examples of how you can use the Payment Modu
<CodeTabs groupId="app-type" isCodeCodeTabs={true}>
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPaymentModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPaymentModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const paymentModuleService: IPaymentModuleService =
req.scope.resolve(ModuleRegistrationName.PAYMENT)
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const paymentModuleService: IPaymentModuleService = req.scope.resolve(
ModuleRegistrationName.PAYMENT
)
const payments = await paymentModuleService.listPayments({
session_id: "payses_123",
})
const payments = await paymentModuleService.listPayments({
session_id: "payses_123",
})
res.json({
payments,
})
}
```
res.json({
payments,
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
```ts
import { NextResponse } from "next/server"
import {
initialize as initializePaymentModule,
} from "@medusajs/payment"
import { initialize as initializePaymentModule } from "@medusajs/payment"
export async function GET(
request: Request
) {
const paymentModuleService = await initializePaymentModule()
export async function GET(request: Request) {
const paymentModuleService = await initializePaymentModule()
const payments = await paymentModuleService.listPayments({
session_id: "payses_123",
})
const payments = await paymentModuleService.listPayments({
session_id: "payses_123",
})
return NextResponse.json({
payments,
})
}
```
return NextResponse.json({
payments,
})
}
```
</CodeTab>
</CodeTabs>
@@ -320,52 +305,49 @@ In this guide, youll find common examples of how you can use the Payment Modu
<CodeTabs groupId="app-type" isCodeCodeTabs={true}>
<CodeTab label="Medusa API Router" value="medusa">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPaymentModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPaymentModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function POST(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const paymentModuleService: IPaymentModuleService =
req.scope.resolve(ModuleRegistrationName.PAYMENT)
export async function POST(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const paymentModuleService: IPaymentModuleService = req.scope.resolve(
ModuleRegistrationName.PAYMENT
)
const payment = await paymentModuleService.capturePayment({
payment_id: "pay_123",
})
const payment = await paymentModuleService.capturePayment({
payment_id: "pay_123",
})
res.json({
payment,
})
}
```
res.json({
payment,
})
}
```
</CodeTab>
<CodeTab label="Next.js App Router" value="nextjs">
```ts
import { NextResponse } from "next/server"
```ts
import { NextResponse } from "next/server"
import {
initialize as initializePaymentModule,
} from "@medusajs/payment"
import { initialize as initializePaymentModule } from "@medusajs/payment"
export async function POST(
request: Request
) {
const paymentModuleService = await initializePaymentModule()
export async function POST(request: Request) {
const paymentModuleService = await initializePaymentModule()
const payment = await paymentModuleService.capturePayment({
payment_id: "pay_123",
})
const payment = await paymentModuleService.capturePayment({
payment_id: "pay_123",
})
return NextResponse.json({
payment,
})
}
```
return NextResponse.json({
payment,
})
}
```
</CodeTab>
</CodeTabs>