RFC: Add orderToken to checkout queries and mutation to be more stateless
See original GitHub issueIs your feature request related to a problem? Please describe. Currently all queries and mutations that are related to the checkout are only working with the active order of a customer. So the active order is basically resolved via the session token. This behaviour leads to following problems:
- Sharing a checkout URL inside an organization is not possible (B2B eCommerce)
- Abandoned cart/checkout emails are a hassle because there is no definite URL for every checkout
- …
Other established eCommerce systems are using the checkout or cart token in the checkout URL for that reason. For example the Shopify Checkout is pretty much stateless because there is the checkoutToken as a parameter in the URL.
Describe the solution you’d like
Basically introduce an orderToken
property for every checkout-related query and mutation.
The business logic in the background should use the orderToken if given. If not it should fall back to the active order of the customer. Also there should be an service, that determines if the currently authenticated customer is eligible to access the order.
By default it should check if the authenticated customer is the same as the customer of the order. The service that is doing that eligibility check should be designed like the OrderByCodeAccessStrategy
(https://www.vendure.io/docs/typescript-api/orders/order-by-code-access-strategy/) so that you can easily override it.
Describe alternatives you’ve considered There are no alternatives than rewriting every checkout-related mutation and query, which is basically nonesense because 95% of the code would stay the same.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top GitHub Comments
Some initial thoughts on design:
Affected operations
The following operations of the Shop API are affected by this change:
Proposal:
ActiveOrderStrategy
A strategy interface which defines how the active order is determined when executing the affected operations
The default strategy, which implements the existing behaviour, would look like this:
Supplying an order token
The first question that arises is how do we supply an order token to these operations?
ActiveOrderInput
which can then be extended by the developer to include whatever fields they need, e.g. We would then need to add this as an optional argument to each of the affected operations, e.g.ctx
object in the strategy. The downsides to this approach are that it is not type-safe, less expressive than a GraphQL input, and feels slightly hacky IMO.Example orderToken implementation
Let’s assume we go with the GraphQL input method of supplying the token. What would a more-or-less complete implementation look like?
Feedback wanted
This is quite a significant change but could unlock lots of new use-cases! I’d love to get feedback on my ideas outlined above. Please leave any comments down below 👍
Good feature Graphql input is best