docs: general fixes and additions (#10876)

This commit is contained in:
Shahed Nasser
2025-01-08 16:09:48 +02:00
committed by GitHub
parent 9427f1e4af
commit a0e944a7a8
12 changed files with 235 additions and 74 deletions
@@ -10,6 +10,12 @@ This document explains how the Inventory Module is used within the Medusa applic
When a product variant is created and its `manage_inventory` property's value is `true`, the Medusa application creates an inventory item associated with that product variant.
<Note title="Tip">
This flow is implemented within the [createProductVariantsWorkflow](/references/medusa-workflows/createProductVariantsWorkflow)
</Note>
![A diagram showcasing how the Inventory Module is used in the product variant creation form](https://res.cloudinary.com/dza7lstvk/image/upload/v1709661511/Medusa%20Resources/inventory-product-create_khz2hk.jpg)
---
@@ -18,6 +24,12 @@ When a product variant is created and its `manage_inventory` property's value is
When a product variant with `manage_inventory` set to `true` is added to cart, the Medusa application checks whether there's sufficient stocked quantity. If not, an error is thrown and the product variant won't be added to the cart.
<Note title="Tip">
This flow is implemented within the [addToCartWorkflow](/references/medusa-workflows/addToCartWorkflow)
</Note>
![A diagram showcasing how the Inventory Module is used in the add to cart flow](https://res.cloudinary.com/dza7lstvk/image/upload/v1709711645/Medusa%20Resources/inventory-cart-flow_achwq9.jpg)
---
@@ -26,6 +38,12 @@ When a product variant with `manage_inventory` set to `true` is added to cart, t
When an order is placed, the Medusa application creates a reservation item for each product variant with `manage_inventory` set to `true`.
<Note title="Tip">
This flow is implemented within the [completeCartWorkflow](/references/medusa-workflows/completeCartWorkflow)
</Note>
![A diagram showcasing how the Inventory Module is used in the order placed flow](https://res.cloudinary.com/dza7lstvk/image/upload/v1709712005/Medusa%20Resources/inventory-order-placed_qdxqdn.jpg)
---
@@ -38,6 +56,12 @@ When an item in an order is fulfilled and the associated variant has its `manage
- Resets the `reserved_quantity` to `0`.
- Deletes the associated reservation item.
<Note title="Tip">
This flow is implemented within the [createOrderFulfillmentWorkflow](/references/medusa-workflows/createOrderFulfillmentWorkflow)
</Note>
![A diagram showcasing how the Inventory Module is used in the order fulfillment flow](https://res.cloudinary.com/dza7lstvk/image/upload/v1709712390/Medusa%20Resources/inventory-order-fulfillment_o9wdxh.jpg)
---
@@ -46,6 +70,12 @@ When an item in an order is fulfilled and the associated variant has its `manage
When an item in an order is returned and the associated variant has its `manage_inventory` property set to `true`, the Medusa application increments the `stocked_quantity` of the inventory item's level with the returned quantity.
<Note title="Tip">
This flow is implemented within the [confirmReturnReceiveWorkflow](/references/medusa-workflows/confirmReturnReceiveWorkflow)
</Note>
![A diagram showcasing how the Inventory Module is used in the order return flow](https://res.cloudinary.com/dza7lstvk/image/upload/v1709712457/Medusa%20Resources/inventory-order-return_ihftyk.jpg)
### Dismissed Returned Items
@@ -1,10 +1,18 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = {
title: `Accept Payment Flow`,
}
# {metadata.title}
In this document, youll learn how to implement an accept-payment flow using the Payment Module's main service.
In this document, youll learn how to implement an accept-payment flow using workflows or the Payment Module's main service.
<Note>
It's highly recommended to use Medusa's workflows to implement this flow. Use the Payment Module's main service for more complex cases.
</Note>
<Note title="Tip">
@@ -24,6 +32,25 @@ A payment collection holds all details related to a resources payment operati
For example:
<CodeTabs group="workflow-service">
<CodeTab label="Using Workflow" value="workflow">
```ts
import { createPaymentCollectionForCartWorkflow } from "@medusajs/medusa/core-flows";
// ...
await createPaymentCollectionForCartWorkflow(req.scope)
.run({
input: {
cart_id: "cart_123"
}
})
```
</CodeTab>
<CodeTab label="Using Service" value="service">
```ts
const paymentCollection =
await paymentModuleService.createPaymentCollections({
@@ -33,42 +60,8 @@ const paymentCollection =
})
```
<Note title="Tip">
Learn more about the `createPaymentCollections` method in [this reference](/references/payment/createPaymentCollections).
</Note>
Then, create a link between the payment collection and the resource it's storing payment details for, such as a cart in the Cart Module:
```ts
import {
ContainerRegistrationKeys,
Modules,
} from "@medusajs/framework/utils"
// ...
// resolve Link
const link = container.resolve(
ContainerRegistrationKeys.LINK
)
link.create({
[Modules.CART]: {
cart_id: "cart_123",
},
[Modules.PAYMENT]: {
payment_collection_id: paymentCollection.id,
},
})
```
<Note title="Tip">
Learn more about Link in [this documentation](!docs!/learn/fundamentals/module-links/link).
</Note>
</CodeTab>
</CodeTabs>
---
@@ -80,6 +73,26 @@ So, after creating the payment collection, create at least one payment session f
For example:
<CodeTabs group="workflow-service">
<CodeTab label="Using Workflow" value="workflow">
```ts
import { createPaymentSessionsWorkflow } from "@medusajs/medusa/core-flows";
// ...
const { result: paymentSesion } = await createPaymentSessionsWorkflow(req.scope)
.run({
input: {
payment_collection_id: "paycol_123",
provider_id: "stripe",
}
})
```
</CodeTab>
<CodeTab label="Using Service" value="service">
```ts
const paymentSession =
await paymentModuleService.createPaymentSession(
@@ -96,11 +109,8 @@ const paymentSession =
)
```
<Note>
Learn more about the `createPaymentSession` method in [this reference](/references/payment/createPaymentSession).
</Note>
</CodeTab>
</CodeTabs>
---
@@ -110,24 +120,43 @@ Once the customer chooses a payment session, start the authorization process. Th
For example:
<CodeTabs group="workflow-service">
<CodeTab label="Using Step" value="workflow">
```ts
const payment =
await paymentModuleService.authorizePaymentSession(
paymentSession.id,
{}
)
import { authorizePaymentSessionStep } from "@medusajs/medusa/core-flows";
// ...
authorizePaymentSessionStep({
id: "payses_123",
context: {}
})
```
</CodeTab>
<CodeTab label="Using Service" value="service">
```ts
const payment = authorizePaymentSessionStep({
id: "payses_123",
context: {}
})
```
</CodeTab>
</CodeTabs>
When the payment authorization is successful, a payment is created and returned.
### Handling Additional Action
<Note>
Learn more about the `authorizePaymentSession` method in [this reference](/references/payment/authorizePaymentSession).
If you used the `authorizePaymentSessionStep`, you don't need to implement this logic as it's implemented in the step.
</Note>
### Handling Additional Action
If the payment authorization isnt successful, whether because it requires additional action or for another reason, the method updates the payment session with the new status and throws an error.
In that case, you can catch that error and, if the session's `status` property is `requires_more`, handle the additional action, then retry the authorization.
@@ -162,7 +191,10 @@ try {
The payment flow is complete once the payment session is authorized and the payment is created.
You can then use the payment to capture the amount using the [capturePayment method](/references/payment/capturePayment). You can also refund captured amounts using the [refundPayment method](/references/payment/refundPayment).
You can then:
- Capture the payment either using the [capturePaymentWorkflow](/references/medusa-workflows/capturePaymentWorkflow) or [capturePayment method](/references/payment/capturePayment).
- Refund captured amounts using the [refundPaymentWorkflow](/references/medusa-workflows/refundPaymentWorkflow) or [refundPayment method](/references/payment/refundPayment).
<Note>