docs: fixes in shipping, payment, and other documentations

* added integration

* add segment for API reference

* updated frontend checkout flow

* added paypal documentation

* Improve storefront quickstart documents

* added documentation for entities

* docs: disable running tests for docs

* added docs contribution guidelines

* Use npm2yarn where missing

* added additional steps section

* added notification overview

* Added guidelines for sidebar labels

* added how to create notification provider

* fixes

* fixes for payment provider

* fixes

* chore(deps): bump sqlite3 from 5.0.2 to 5.0.3 (#1453)

Bumps [sqlite3](https://github.com/TryGhost/node-sqlite3) from 5.0.2 to 5.0.3.
- [Release notes](https://github.com/TryGhost/node-sqlite3/releases)
- [Changelog](https://github.com/TryGhost/node-sqlite3/blob/master/CHANGELOG.md)
- [Commits](https://github.com/TryGhost/node-sqlite3/compare/v5.0.2...v5.0.3)

* fix: Issue with cache in CI pipeline

* Use npm2yarn where missing

* added integration

* add segment for API reference

* fix double segment

* updated frontend checkout flow

* added documentation for entities

* added docs contribution guidelines

* Added guidelines for sidebar labels

* added additional steps section

* added notification overview

* added how to create notification provider

* chore: Add issue template for bug reports (#1676)

* chore: Add issue template for feature requests (#1679)

* fixes

* fixes for payment provider

* fixes

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Shahed Nasser
2022-06-17 11:31:05 +03:00
committed by GitHub
parent 2c266302c8
commit 0bfdaab34e
9 changed files with 71 additions and 77 deletions

View File

@@ -1,8 +1,4 @@
---
title: Add Endpoint for Admin
---
# Add Endpoint for Admin
# Create Endpoint for Admin
In this document, youll learn how to add a custom endpoint in the Backend that you can use from the Admin.

View File

@@ -1,8 +1,4 @@
---
title: Add Endpoint for Storefront
---
# Add Endpoint for Storefront
# Create Endpoint for Storefront
In this document, youll learn how to add a custom endpoint in the Backend that you can use from the Storefront.

View File

@@ -70,7 +70,7 @@ Following the naming convention of Services, the name of the file should be the
As mentioned in the overview, Payment Providers should have a static `identifier` property.
The `PaymentProvider` model has 2 properties: `identifier` and `is_installed`. The value of the `identifier` property in the class will be used when the Payment Provider is created in the database.
The `PaymentProvider` entity has 2 properties: `identifier` and `is_installed`. The value of the `identifier` property in the class will be used when the Payment Provider is created in the database.
The value of this property will also be used to reference the Payment Provider throughout the Medusa server. For example, the identifier is used when a [Payment Session in a cart is selected on checkout](https://docs.medusajs.com/api/store/cart/select-a-payment-session).

View File

@@ -1,4 +1,4 @@
# Architecture Overview
# Payment Architecture Overview
In this document, youll learn about the payment architecture in Medusa, specifically its 3 main components and the idempotency key.
@@ -16,15 +16,13 @@ An important part in the Payment architecture to understand is the **Idempotency
## Payment Provider
### Overview
A Payment Provider in Medusa is a method to handle payments in selected regions. It is not associated with a cart, customer, or order in particular. It provides the necessary implementation to create Payment Sessions and Payments, as well as authorize and capture payments, among other functionalities.
Payment Providers can be integrated with third-party services that handle payment operations such as capturing a payment. An example of a Payment Provider is Stripe.
Payment Providers can also be related to a custom way of handling payment operations. An example of that is cash on delivery (COD) payment methods or Medusas [manual payment provider plugin](https://github.com/medusajs/medusa/tree/master/packages/medusa-payment-manual) which provides a minimal implementation of a payment provider and allows store operators to manually handle order payments.
### How it is Created
### How Payment Provider is Created
A Payment Provider is essentially a Medusa [service](../services/create-service.md) with a unique identifier, and it extends the `PaymentService` provided by the `medusa-interfaces` package. It can be created as part of a [plugin](../../../guides/plugins.md), or it can be created just as a service file in your Medusa server.
@@ -40,21 +38,19 @@ Its important to choose a payment provider in the list of payment providers i
:::
### Model Overview
### PaymentProvider Entity Overview
The `PaymentProvider` model only has 2 attributes: `is_installed` to indicate if the payment provider is installed and its value is a boolean; and `id` which is the unique identifier that you define in the Payment Provider service.
The `PaymentProvider` entity only has 2 attributes: `is_installed` to indicate if the payment provider is installed and its value is a boolean; and `id` which is the unique identifier that you define in the Payment Provider service.
## Payment Session
### Overview
Payment Sessions are linked to a customers cart. Each Payment Session is associated with a payment provider that is available in the customer carts region.
They hold the status of the payment flow throughout the checkout process which can be used to indicate different statuses such as an authorized payment or payment that requires more actions from the customer.
After the checkout process is completed and the Payment Session has been authorized successfully, a Payment instance will be created to be associated with the customers order and will be used for further actions related to that order.
### How it is Created
### How Payment Session is Created
After the customer adds products to the cart, proceeds with the checkout flow, and reaches the payment method section, Payment Sessions are created for each Payment Provider available in that region.
@@ -64,15 +60,15 @@ Payment Sessions can hold data that is necessary for the customer to complete th
Among the Payment Sessions available only one will be selected based on the customers payment provider choice. For example, if the customer sees that they can pay with Stripe or PayPal and chooses Stripe, Stripes Payment Session will be the selected Payment Session of that cart.
### Model Overview
### PaymentSession Entity Overview
The `PaymentSession` model belongs to a `Cart`. This is the customers cart that was used for checkout which lead to the creation of the Payment Session.
The `PaymentSession` entity belongs to a `Cart`. This is the customers cart that was used for checkout which lead to the creation of the Payment Session.
The `PaymentSession` also belongs to a `PaymentProvider`. This is the Payment Provider that was used to create the Payment Session and that controls it for further actions like authorizing the payment.
The `data` attribute is an object that holds any data required for the Payment Provider to perform payment operations like authorizing or capturing payment. For example, when a Stripe payment session is initialized, the `data` object will hold the payment intent among other data necessary to authorize the payment.
The `is_selected` attribute in the `PaymentSession` model is a boolean value that indicates whether this Payment Session was selected by the customer to pay for their purchase. Going back to the previous example of having Stripe and PayPal as the available Payment Providers, when the customer chooses Stripe, Stripes Payment Session will have `is_selected` set to true whereas PayPals Payment Session will have `is_selected` set to false.
The `is_selected` attribute in the `PaymentSession` entity is a boolean value that indicates whether this Payment Session was selected by the customer to pay for their purchase. Going back to the previous example of having Stripe and PayPal as the available Payment Providers, when the customer chooses Stripe, Stripes Payment Session will have `is_selected` set to true whereas PayPals Payment Session will have `is_selected` set to false.
The `status` attributes indicates the current status of the Payment Session. It can be one of the following values:
@@ -86,21 +82,19 @@ These statuses are important in the checkout flow to determine the current step
## Payment
### Overview
A Payment is used to represent the amount authorized for a customers purchase. It is associated with the order placed by the customer and will be used after that for all operations related to the orders payment such as capturing or refunding the payment.
Payments are generally created using data from the Payment Session and it holds any data that can be necessary to perform later payment operations.
### How it is Created
### How Payment is Created
Once the customer completes their purchase and the payment has been authorized, a Payment instance will be created from the Payment Session. The Payment is associated first with the cart and then with the order once its created and placed.
When the store operator then chooses to capture the order from the Medusa Admin, the Payment is used by the Payment Provider to capture the payment. This is the same case for refunding the amount, canceling the order, or creating a swap.
### Model Overview
### Payment Entity Overview
The `Payment` model belongs to the `Cart` that it was originally created from when the customers payment was authorized. It also belongs to an `Order` once its placed. Additionally, it belongs to a `PaymentProvider` which is the payment provider that the customer chose on checkout.
The `Payment` entity belongs to the `Cart` that it was originally created from when the customers payment was authorized. It also belongs to an `Order` once its placed. Additionally, it belongs to a `PaymentProvider` which is the payment provider that the customer chose on checkout.
In case a `Swap` is created for an order, `Payment` will be associated with that swap to handle payment operations related to it.

View File

@@ -1,6 +1,6 @@
# How to Add a Fulfillment Provider
In this document, youll learn how to add a fulfillment provider to a Medusa server. If youre unfamiliar with the Shipping architecture in Medusa, make sure to [check out the overview first](https://docs.medusajs.com/advanced/backend/shipping/overview/).
In this document, youll learn how to add a fulfillment provider to a Medusa server. If youre unfamiliar with the Shipping architecture in Medusa, make sure to [check out the overview first](overview.md).
## Overview
@@ -45,7 +45,7 @@ Following the naming convention of Services, the name of the file should be the
As mentioned in the overview, fulfillment providers should have a static `identifier` property.
The `FulfillmentProvider` model has 2 properties: `identifier` and `is_installed`. The `identifier` property in the class will be used when the fulfillment provider is created in the database.
The `FulfillmentProvider` entity has 2 properties: `identifier` and `is_installed`. The `identifier` property in the class will be used when the fulfillment provider is created in the database.
The value of this property will also be used to reference the fulfillment provider throughout Medusa. For example, it is used to [add a fulfillment provider](https://docs.medusajs.com/api/admin/region/add-fulfillment-provider) to a region.

View File

@@ -1,46 +1,57 @@
---
# Shipping Architecture Overview
title: Shipping Architecture Overview
---
# Architecture Overview
This document gives an overview of the shipping architecture and its 3 most important components.
This document gives an overview of the shipping architecture and its 4 most important components.
## Introduction
In Medusa, the Shipping architecture relies on 3 components: **Shipping Profiles**, **Shipping Options**, and **Shipping Methods**.
In Medusa, the Shipping architecture relies on 4 components: **Fulfillment Provider**, **Shipping Profiles**, **Shipping Options**, and **Shipping Methods**.
The distinction between the 3 is important. It has been carefully planned and put together to support all the different ecommerce use cases and shipping providers that can be integrated.
The distinction between the 4 is important. It has been carefully planned and put together to support all the different ecommerce use cases and shipping providers that can be integrated.
Its also constructed to support multiple regions, provide different shipment configurations and options for different product types, provide promotional shipments for your customers, and much more.
## Summary
- **Shipping Profiles:** created by the admin. They are used to group products that should be shipped in a different manner than the default. Shipping profiles can have multiple shipping options.
- S**hipping Options:** created by the admin and belong to a shipping profile. They are specific to certain regions and can have cart conditions. They use an underlying fulfillment provider. Once a customer checks out, they can choose the shipping option thats available and most relevant to them.
- **Shipping Method:** created when the customer chooses a shipping option on checkout. The shipping method is basically a copy of the shipping option, but with values specific to the customer and the cart its associated with. When the order is placed, the shipping method will then be associated with the order and fulfilled based on the integration with the fulfillment provider.
- **Fulfillment Provider:** Fulfillment providers are plugins or [Services](../services/create-service.md) used to ship the products to your customers, whether physically or virtually. An example of a fulfillment provider would be FedEx.
- **Shipping Profiles:** created by the admin. They are used to group products that should be shipped in a different manner than the default. Shipping profiles can have multiple shipping options.
- **Shipping Options:** created by the admin and belong to a shipping profile. They are specific to certain regions and can have cart conditions. They use an underlying fulfillment provider. Once a customer checks out, they can choose the shipping option thats available and most relevant to them.
- **Shipping Method:** created when the customer chooses a shipping option on checkout. The shipping method is basically a copy of the shipping option, but with values specific to the customer and the cart its associated with. When the order is placed, the shipping method will then be associated with the order and fulfilled based on the integration with the fulfillment provider.
:::note
![Shipping Architecture](https://i.imgur.com/QII2Hvn.png)
Fulfillment providers are used to ship the products to your customers, whether physically or virtually. An example of a fulfillment provider would be FedEx.
## Fulfillment Provider
:::
A Fulfillment Provider in Medusa is a method to handle shipping products in selected regions. It is not associated with a cart, customer, or order in particular.
![Shipping.png](https://i.imgur.com/RnC2esy.png)
It provides the necessary implementation to create Fulfillments for orders and ship items to customers. They can also be used for order returns and swaps.
Fulfillment Providers can be integrated with third-party services that handle the actual shipment of products. An example of a Fulfillment Provider is FedEx.
Fulfillment Providers can also be related to a custom way of handling fulfillment operations. An example of that is Medusas [manual fulfillment provider plugin](https://github.com/medusajs/medusa/tree/master/packages/medusa-fulfillment-manual) which provides a minimal implementation of a fulfillment provider and allows store operators to manually handle order fulfillments.
### How Fulfillment Provider is Created
A Fulfillment Provider is essentially a Medusa [Service](../services/create-service.md) with a unique identifier, and it extends the `FulfillmentService` provided by the `medusa-interfaces` package. It can be created as part of a [plugin](../../../guides/plugins.md), or it can be created just as a Service file in your Medusa server.
As a developer, you will mainly work with the Fulfillment Provider when integrating a fulfillment method in Medusa.
When you run your Medusa server, the Fulfillment Provider will be registered on your server if it hasnt been already.
Once the Fulfillment Provider is added to the server, the store operator will be able to associate on the [Medusa Admin](../../../quickstart/quick-start.md) the Fulfillment Provider with shipping options.
### FulfillmentProvider Entity Overview
The `FulfillmentProvider` entity only has 2 attributes: `is_installed` to indicate if the fulfillment provider is installed and its value is a boolean; and `id` which is the unique identifier that you define in the Fulfillment Provider Service.
## Shipping Profile
### Overview
Shipping profiles are the highest in the hierarchy in the shipping architecture.
Shipping profiles are created by the admin. The admin can specify the name of the shipping profile which will be a name that the customer can see.
A shipping profile is not associated with any fulfillment providers. It has multiple shipping options that can be associated with different providers.
### Purpose
### Purpose of Shipping Profile
Shipping profiles are used to group products that can be shipped in the same manner.
@@ -50,18 +61,16 @@ Although this might be the general case, there are still some use cases where yo
For example, shipping heavy items might be more expensive than others, which would enforce different price rates. In that case, you can create a new shipping profile that groups together heavy products. This would allow you to give these products more suitable price rates when creating their shipping options.
### Model Overview
### ShippingProfile Entity Overview
The `ShippingProfile` model can have a set of `Product` instances. These would be the products the shipping profile is providing shipping options for.
The `ShippingProfile` entity can have a set of `Product` instances. These would be the products the shipping profile is providing shipping options for.
The `ShippingProfile` has a `type` attribute that can be `default`, `gift_card`, or `custom`.
The `ShippingProfile` model also has an array of `ShippingOption` instances.
The `ShippingProfile` entity also has an array of `ShippingOption` instances.
## Shipping Option
### Overview
After the admin adds a shipping profile, they can add shipping options that belong to that shipping profile from the admin dashboard.
Shipping options have a set of conditions like the region theyre available in or cart-specific conditions. For example, if your company operates in the United States as well as Germany, you might use a different shipping option for each of the two countries.
@@ -70,7 +79,7 @@ Among the configurations that the admin has to set when creating a shipping opti
Shipping options are only shown to a customer during checkout if their cart satisfies the options conditions. Also, as they belong to a shipping profile, theyre only shown when products that belong to the same shipping profile are in the cart.
### Purpose
### Purpose of Shipping Option
The first purpose that a shipping option has is showing the customer during checkout what shipping options are available for them.
@@ -78,17 +87,17 @@ Then, once the customer chooses a shipping option, that shipping option is used
Think of a shipping option as a template defined by the admin that indicates what data and values the shipping method should have when its chosen by the customer during checkout.
### Model Overview
### ShippingOption Entity Overview
The `ShippingOption` model belongs to the `ShippingProfile` model.
The `ShippingOption` entity belongs to the `ShippingProfile` entity.
The `ShippingOption` model also belongs to a `FulfillmentProvider`. This can be either a custom third-party provider or one of Medusas default fulfillment providers.
The `ShippingOption` entity also belongs to a `FulfillmentProvider`. This can be either a custom third-party provider or one of Medusas default fulfillment providers.
It has the `price_type` attribute to indicate whether the shipping options rate is `calculated` by the provider or a fixed `flat_rate` price. It also has the `amount` attribute to set an amount for the shipping option if the `price_type` is `flat_rate`.
`ShippingOption` also belongs to a `Region`, which resembles one or more countries. This defines where the shipping option is available.
`ShippingOption` has a set of `ShippingOptionRequirement` instances. The `ShippingOptionRequirement` model allows defining cart rules which determine whether the shipping option will be available or not for a customer during checkout. For example, you can set a minimum subtotal amount for a shipping option to be available for a customers cart.
`ShippingOption` has a set of `ShippingOptionRequirement` instances. The `ShippingOptionRequirement` entity allows defining cart rules which determine whether the shipping option will be available or not for a customer during checkout. For example, you can set a minimum subtotal amount for a shipping option to be available for a customers cart.
The `is_return` attribute is used to indicate whether the shipping option is used for shipping orders or returning orders. Shipping options can only be used for one or the other.
@@ -98,15 +107,13 @@ The `data` attribute does not have any specific format. Its up to you to choo
## Shipping Method
### Overview
Unlike the previous two components, a shipping method is not created by the admin. Its created when a `POST` request is sent to `/store/carts/:id/shipping-methods` after the customer chooses a shipping option.
The shipping method will be created based on the chosen shipping option and itll be associated with the customers cart. Then, when the order is placed, the shipping method is associated with the order.
A shipping method can be fulfilled automatically or manually through the admin dashboard. This is based on the fulfillment provider associated with the shipping option the shipping method is based on.
### Purpose
### Shipping Method Purpose
Its important to understand the distinction between shipping methods and shipping options. Shipping options are templates created by the admin to indicate what shipping options should be shown to a customer. This provides customization capabilities in a store, as an admin is free to specify configurations for that option such as what fulfillment provider it uses or what are its rates.
@@ -114,17 +121,17 @@ When handling the order and fulfilling it, you, as a developer, will be mostly i
This separation allows for developers to implement the custom integration with third-party fulfillment providers as necessary while also ensuring that the admin has full control of their store.
## Model Overview
## ShippingMethod Entity Overview
A lot of the shipping methods attributes are similar to the shipping options attribute.
The `ShippingMethod` model belongs to a `ShippingOption`.
The `ShippingMethod` entity belongs to a `ShippingOption`.
Similar to the `data` attribute explained for the `ShippingOption` model, a `ShippingMethod` has a similar `data` attribute that includes all the data to be sent to the fulfillment provider when fulfilling the order.
Similar to the `data` attribute explained for the `ShippingOption` entity, a `ShippingMethod` has a similar `data` attribute that includes all the data to be sent to the fulfillment provider when fulfilling the order.
The `ShippingMethod` belongs to a `Cart`. This is the cart the customer is checking out with.
The `ShippingMethod` also belongs to the `Order` model. This association is accomplished when the order is placed.
The `ShippingMethod` also belongs to the `Order` entity. This association is accomplished when the order is placed.
The `ShippingMethod` instance holds a `price` attribute, which will either be the flat rate price or the calculated price.

View File

@@ -167,7 +167,7 @@ Triggered when a cart and data associated with it (payment sessions, shipping me
</td>
<td>
The entire cart as an object. You can refer to the [Cart model](https://github.com/medusajs/medusa/blob/master/packages/medusa/src/models/cart.ts) for an idea of what fields to expect.
The entire cart as an object. You can refer to the [Cart entity](https://github.com/medusajs/medusa/blob/master/packages/medusa/src/models/cart.ts) for an idea of what fields to expect.
</td>
</tr>
@@ -476,7 +476,7 @@ Triggered when a customer is created.
</td>
<td>
The entire customer passed as an object. You can refer to the [Customer model](https://github.com/medusajs/medusa/blob/master/packages/medusa/src/models/customer.ts) for an idea of what fields to expect.
The entire customer passed as an object. You can refer to the [Customer entity](https://github.com/medusajs/medusa/blob/master/packages/medusa/src/models/customer.ts) for an idea of what fields to expect.
</td>
</tr>
@@ -494,7 +494,7 @@ Triggered when a customer is updated including their information or password, or
</td>
<td>
The entire customer passed as an object. You can refer to the [Customer model](https://github.com/medusajs/medusa/blob/master/packages/medusa/src/models/customer.ts) for an idea of what fields to expect.
The entire customer passed as an object. You can refer to the [Customer entity](https://github.com/medusajs/medusa/blob/master/packages/medusa/src/models/customer.ts) for an idea of what fields to expect.
</td>
</tr>
@@ -1338,7 +1338,7 @@ Triggered when a product and data associated with it (options, variant orders, e
</td>
<td>
The entire product passed as an object. You can refer to the [Product model](https://github.com/medusajs/medusa/blob/master/packages/medusa/src/models/product.ts) for an idea of what fields to expect.
The entire product passed as an object. You can refer to the [Product entity](https://github.com/medusajs/medusa/blob/master/packages/medusa/src/models/product.ts) for an idea of what fields to expect.
</td>
</tr>

View File

@@ -58,7 +58,7 @@ const dotenv = require('dotenv')
This new version of Medusa allows store operators to adjust line items in an order or a swap which provides more customization capabilities.
It introduces a new model `LineItemAdjustment` which gives more flexibility to adjust the pricing of line items in a cart, order, or swap. A discount can be added, removed, or modified and the price will reflect on the total calculation of the cart, order, or swap.
It introduces a new entity `LineItemAdjustment` which gives more flexibility to adjust the pricing of line items in a cart, order, or swap. A discount can be added, removed, or modified and the price will reflect on the total calculation of the cart, order, or swap.
This also introduces an optimization to the calculation of totals, as it is no longer necessary to calculate the discounts every time the totals are retrieved.
@@ -76,7 +76,7 @@ node ./node_modules/@medusajs/medusa/dist/scripts/line-item-adjustment-migration
This new version of Medusa holds advanced promotions functionalities to provide store operators with even more customization capabilities when creating discounts. You can now add even more conditions to your discounts to make them specific for a set of products, collections, customer groups, and more.
This change required creating a new model `DiscountCondition` which belongs to `DiscountRule` and includes a few relationships with other models to make the aforementioned feature possible.
This change required creating a new entity `DiscountCondition` which belongs to `DiscountRule` and includes a few relationships with other entities to make the aforementioned feature possible.
### Actions Required

View File

@@ -112,12 +112,12 @@ module.exports = {
{
type: "doc",
id: "advanced/backend/endpoints/add-storefront",
label: "Add Endpoint for Storefront"
label: "Create Endpoint for Storefront"
},
{
type: "doc",
id: "advanced/backend/endpoints/add-admin",
label: "Add Endpoint for Admin"
label: "Create Endpoint for Admin"
},
]
},
@@ -129,7 +129,7 @@ module.exports = {
{
type: "category",
label: 'Subscribers',
collapsed: false,
collapsed: true,
items: [
{
type: "doc",
@@ -161,7 +161,7 @@ module.exports = {
{
type: "doc",
id: "advanced/backend/shipping/add-fulfillment-provider",
label: "Add Fulfillment Provider"
label: "Create a Fulfillment Provider"
}
]
},
@@ -178,6 +178,7 @@ module.exports = {
{
type: "doc",
id: "advanced/backend/payment/how-to-create-payment-provider",
label: "Create a Payment Provider"
},
]
},