@graphcommerce/docs 4.11.1 → 4.12.0-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.12.0-canary.1
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1729](https://github.com/graphcommerce-org/graphcommerce/pull/1729) [`c37187a51`](https://github.com/graphcommerce-org/graphcommerce/commit/c37187a513670ebcf09e99eb4a762c8bdb5df7e4) - Moved Magento Cart Pickup shipping method to the [GraphCommerce plugin system](https://www.graphcommerce.org/docs/framework/plugins)
8
+
9
+ Upgrade guide:
10
+
11
+ - The upgrade removes `@graphcommerce/magento-cart-pickup` package from your `package.json`, remove them for now.
12
+ - Proceed to upgrade normally
13
+ - Add back `@graphcommerce/magento-cart-pickup`, following the [GraphCommerce Magento docs](https://graphcommerce.org/docs/magento). ([@paales](https://github.com/paales))
14
+
15
+ - [#1729](https://github.com/graphcommerce-org/graphcommerce/pull/1729) [`2e68e0560`](https://github.com/graphcommerce-org/graphcommerce/commit/2e68e0560690bbf9bad6dc2b33d6e2ddb16197ce) - Adyen Payment gateway support ([@paales](https://github.com/paales))
16
+
17
+ - [#1729](https://github.com/graphcommerce-org/graphcommerce/pull/1729) [`366b05a7d`](https://github.com/graphcommerce-org/graphcommerce/commit/366b05a7da174a8a7c665b44e11422d8c873e4ed) - MultiSafePay Payment gateway support ([@paales](https://github.com/paales))
18
+
19
+ ### Patch Changes
20
+
21
+ - [#1729](https://github.com/graphcommerce-org/graphcommerce/pull/1729) [`78980b009`](https://github.com/graphcommerce-org/graphcommerce/commit/78980b009a3055006a50e0f54a4414ccf5570860) - Loosen node version constraint ([@paales](https://github.com/paales))
22
+
23
+ ## 4.12.0-canary.0
24
+
25
+ ### Minor Changes
26
+
27
+ - [#1718](https://github.com/graphcommerce-org/graphcommerce/pull/1718) [`16abc9995`](https://github.com/graphcommerce-org/graphcommerce/commit/16abc9995377f5c00032674de0a1ea3ebad88c4c) - Introducing a new **Plugin system for GraphCommerce** which allows you to extend GraphCommerce in a plug-and-play manner. [Read the documentation to learn more](https://github.com/graphcommerce-org/graphcommerce/blob/main/docs/framework/plugins.md) ([@paales](https://github.com/paales))
28
+
3
29
  ## 4.11.1
4
30
 
5
31
  ### Patch Changes
@@ -0,0 +1,174 @@
1
+ # Plugins
2
+
3
+ GraphCommerce plugin system allows you to extend GraphCommerce in a
4
+ plug-and-play manner. Install a new package and the code will be added at the
5
+ right places.
6
+
7
+ - Plug-and-play: It is be possible to install packages after which they
8
+ immediately work.
9
+ - No runtime overhead: The plugin system is fully implemented in webpack and
10
+ - Easy plugin creation: Configuration should happen in the plugin file, not a
11
+ separate configuration file.
12
+
13
+ ## What problem are we solving?
14
+
15
+ Without plugins the only way to add new functionality is by modifying the code
16
+ of your project at multiple places. We often pass props to components to
17
+ customize them, but sometimes we also place hooks at multiple places.
18
+
19
+ For example, to add a new payment method it was necessary to modify the props of
20
+ `<PaymentMethodContextProvider methods={[...braintree]}>`
21
+
22
+ This causes problems:
23
+
24
+ - Upgrades: If GraphCommerce changes something somewhere in the code where you
25
+ have already modified the code, you get an upgrade conflict which you have to
26
+ manually resolve. By using plugins you can avoid this.
27
+ - New packages: When you install a complex new package, it can happen that you
28
+ have to modify the code of your project at multiple places. This is not
29
+ necessary with plugins.
30
+
31
+ ## What is a plugin?
32
+
33
+ A plugin is a way to modify React Components by wrapping them, without having to
34
+ modify the code in `examples/magento-graphcms` or `your-project`.
35
+
36
+ For the M2 people: Think of around plugins, but without configuration files and
37
+ no performance penalty.
38
+
39
+ In the [PR](https://github.com/graphcommerce-org/graphcommerce/pull/1718) I have
40
+ made the
41
+ [`<PaymentMethodContextProvider />`](https://github.com/graphcommerce-org/graphcommerce/pull/1718/files#diff-d5b4da6c34d4b40dc8ac5d1c5967bc6f5aaa70d0d5ac79552f3a980b17a88ea9R115)
42
+ work with plugins.
43
+
44
+ The actual plugins are:
45
+
46
+ - [AddBraintreeMethods](https://github.com/graphcommerce-org/graphcommerce/pull/1718/files#diff-14391e8c8f598e720b3e99ece1248987d68eb6133d354a3a55ef82331905be5b)
47
+ - [AddIncludedMethods](https://github.com/graphcommerce-org/graphcommerce/pull/1718/files#diff-c3d57b802463ed40925b558049a56992202be975f3c86982e6a753e2830bdb9f)
48
+ - [AddPaypalMethods](https://github.com/graphcommerce-org/graphcommerce/pull/1718/files#diff-934d7a9d597b01b6da875f61ca1cdfd57e0e0817e7126ce6216fd82dc4b6f899)
49
+ - [AddMollieMethods](https://github.com/graphcommerce-org/graphcommerce/pull/1718/files#diff-76e6fc63dee67f55cbad4f13dc7b1b764da6235b88ed8d987c7044b7ef7fc942)
50
+
51
+ The result of this is that:
52
+
53
+ - The payment methods are added to the `<PaymentMethodContextProvider />` via
54
+ plugins.
55
+ - These plugins are only applied if the relevant package is installed.
56
+
57
+ ### How do I make a plugin?
58
+
59
+ In the root of my project, i've created a plugin
60
+ `examples/magento-graphcms/plugins/AddPaymentMethodEnhancer.tsx` that adds
61
+ purchaseorder to `<PaymentMethodContextProvider/>`
62
+
63
+ ```tsx
64
+ import type { PaymentMethodContextProviderProps } from '@graphcommerce/magento-cart-payment-method'
65
+ import type { PluginProps } from '@graphcommerce/next-config'
66
+ import { purchaseorder } from '../PurchaseOrder'
67
+
68
+ // Component to extend, required
69
+ export const component = 'PaymentMethodContextProvider'
70
+
71
+ // Exported location of the component that you are extending, required
72
+ export const exported = '@graphcommerce/magento-cart-payment-method'
73
+
74
+ function AddPaymentMethodEnhancer(
75
+ props: PluginProps<PaymentMethodContextProviderProps>,
76
+ ) {
77
+ const { Component, modules, ...rest } = props
78
+ return <Component {...rest} modules={{ ...modules, purchaseorder }} />
79
+ }
80
+
81
+ /** The export must be named `Plugin` and must accept a Component to render */
82
+ export const Plugin = AddIncludedMethods
83
+ ```
84
+
85
+ ### How does it work?
86
+
87
+ 1. It generates a list of all packages with `graphcommerce` in the package
88
+ `name` (All `@graphcommerce/*` packages and
89
+ `@my-company/graphcommerce-plugin-name`).
90
+ 2. It does a glob search for plugins in the plugins folders for each package:
91
+ `${packageLocation}/plugins/**/*.tsx`.
92
+ 3. Statically Analyse the plugins, check if the `component` and `exported`
93
+ exports exist and generate the plugin configuration.
94
+ 4. Generate `PaymentMethodContext.interceptor.tsx` and place it next to the
95
+ existing component
96
+
97
+ Example of generated interceptor with additional comments:
98
+
99
+ ```tsx
100
+ // All plugins are imported, which will be used to enhance the original component.
101
+ import { Plugin as AddIncludedMethods } from '@graphcommerce/magento-payment-included/plugins/AddIncludedMethods'
102
+ import { Plugin as AddPaypalMethods } from '@graphcommerce/magento-payment-paypal/plugins/AddPaypalMethods'
103
+
104
+ // This file is placed next to the original component, so it is imported with a relative path, in the Webpack plugin we
105
+ // load the original file if it is loaded from the interceptor.
106
+ import { PaymentMethodContextProvider as PaymentMethodContextProviderBase } from './PaymentMethodContext'
107
+
108
+ // All original exports are exported, if the original file exports more than we're intercepting, it will still work.
109
+ export * from './PaymentMethodContext'
110
+
111
+ type PaymentMethodContextProviderBaseProps = React.ComponentProps<
112
+ typeof PaymentMethodContextProviderBase
113
+ >
114
+
115
+ // We create new Interceptor components here, which allows us to wrap multiple plugins around the original component.
116
+ const AddIncludedMethodsInterceptor = (
117
+ props: PaymentMethodContextProviderBaseProps,
118
+ ) => (
119
+ //For the first plugin we use the original component.
120
+ <AddIncludedMethods {...props} Component={PaymentMethodContextProviderBase} />
121
+ )
122
+ const AddPaypalMethodsInterceptor = (
123
+ props: PaymentMethodContextProviderBaseProps,
124
+ ) => (
125
+ // For the next components we use the previous Interceptor component.
126
+ <AddPaypalMethods {...props} Component={AddIncludedMethodsInterceptor} />
127
+ )
128
+
129
+ // Finally we return the resulting interceptor component.
130
+ export const PaymentMethodContextProvider = AddPaypalMethodsInterceptor
131
+ ```
132
+
133
+ React profile will show that all components are nested:
134
+
135
+ ![](https://user-images.githubusercontent.com/1244416/197813853-e8aa329e-41bc-4f56-8aac-2464cc37032f.png)
136
+
137
+ ### Possible use cases
138
+
139
+ In the examples above we've extended the payment methods, but it should also
140
+ work for other things such as:
141
+
142
+ - Googletagmanager
143
+ - Googleanalytics
144
+ - Google recaptcha
145
+ - Compare functionality?
146
+ - Wishlist functionality?
147
+ - Abstraction between GraphCommerce and Backends? (Magento, BigCommerce,
148
+ CommerceTools, etc.)
149
+
150
+ ### Limitations
151
+
152
+ Work is planned to lift these limitations, but for now:
153
+
154
+ React Refresh doesn't work correctly with Plugins, it will force a page reload
155
+ on each file change and will throw an error in the console. To solve this issue,
156
+ move your actual plugin outside of the plugin file and only have the plugin be a
157
+ configuration file.
158
+
159
+ It currently isn't possible to provide a plugin sort order. The project root is
160
+ intercepting last, followed by the packages in reverse alphabetical order,
161
+ followed by dependencies' dependencies. We don't generate a proper graph at the
162
+ moment to figure out the actual dependencies but is an artifact of how we
163
+ resolve the dependencies.
164
+
165
+ There currently isn't a way for the plugin to determine if the plugin should be
166
+ activated at all. For example, the code for Google Analytics should only be
167
+ added if the user has configured it. This is currently not possible. Of if a
168
+ user wants to disable a plugin, this is currently not possible.
169
+
170
+ It is currently is only possible to extend React Components. This however sets
171
+ the foundation to allow for a more flexible plugin system in the future.
172
+
173
+ Plugins should be optional for GraphCommerce to function properly. Plugins for
174
+ mandatory packages shouldn't exist.
@@ -47,9 +47,9 @@ If you want to test a GraphCommerce storefront using a pre-configured Magento
47
47
  demo store and a pre-configured GraphCMS project with demo content, then you
48
48
  need to only install the dependencies. This is the quickest approach.
49
49
 
50
- - Install and use node 14/16: `nvm install 16` or `nvm use 16`
51
- - Install yarn: `corepack enable` (for node 16) or `npm install --global yarn`
52
- (for node 14)
50
+ - Install and use node 14/16/18: `nvm install 16` or `nvm use 16`
51
+ - Install yarn: `corepack enable` (for node 16/18) or
52
+ `npm install --global yarn` (for node 14)
53
53
 
54
54
  ## Step 1: Create a new GraphCommerce app
55
55
 
@@ -135,16 +135,6 @@ List of routes and store_codes:
135
135
  > }
136
136
  > ```
137
137
 
138
- ### Remove unused PSP's
139
-
140
- The example has Payment Service Providers integrated (Mollie, Braintree). Remove
141
- the ones your Magento backend doesn't support.
142
-
143
- - Remove Payment Service integrations from package.json:
144
- `@graphcommerce/mollie-magento-payment` and/or
145
- `@graphcommerce/magento-payment-braintree`
146
- - Remove Payment Service references from `pages/checkout/payment.tsx`
147
-
148
138
  ## Step 3: Start the development environment
149
139
 
150
140
  - `yarn` Install the dependencies
@@ -166,3 +156,4 @@ Visit the GraphQL Playground running at http://localhost:3000/api/graphql
166
156
  - [Start building a GraphCommerce custom storefront](../getting-started/start-building.md)
167
157
  by customizing text and component styles, fetching data from server
168
158
  components, and making changes to GraphQL queries.
159
+ - [Install optional Magento packages](../magento/readme.md)
@@ -0,0 +1,168 @@
1
+ # Magento payment gateway requirements
2
+
3
+ Payment gateways are the most important part of any e-commerce store. In this
4
+ section, we will discuss the requirements for implementing a payment gateway in
5
+ Magento 2 that is compatible with GraphCommerce.
6
+
7
+ There are multiple flows to handle payments.
8
+
9
+ ## Flow 1: Redirecting payment gateway
10
+
11
+ The first step is to call setPaymentMethodOnCart and placeOrder.
12
+
13
+ ```ts
14
+ const variables = {
15
+ cartId: 'currentCartId',
16
+ paymentMethod: {
17
+ code: 'my_payment_method',
18
+ my_gateway: {
19
+ return_url: 'https://my-site.com/checkout/billing?token=$TOKEN',
20
+ custom_field: 'blabla',
21
+ },
22
+ },
23
+ }
24
+ ```
25
+
26
+ ```graphql
27
+ mutation MyGatewayPaymentOptionsAndPlaceOrder(
28
+ $cartId: String!
29
+ $paymentMethod: PaymentMethodInput!
30
+ ) {
31
+ setPaymentMethodOnCart(
32
+ input: { cart_id: $cartId, payment_method: $paymentMethod }
33
+ ) {
34
+ cart {
35
+ selected_payment_method {
36
+ ...SelectedPaymentMethod
37
+ }
38
+ }
39
+ }
40
+ placeOrder(input: { cart_id: $cartId }) {
41
+ order {
42
+ order_number
43
+ my_gateway_status {
44
+ token
45
+ status # Will probably be REDIRECT_SHOPPER
46
+ redirect_url
47
+ }
48
+ }
49
+ }
50
+ }
51
+ ```
52
+
53
+ When the query succeeds the GraphCommerce payment module will redirect to the
54
+ payment_url. The customer handles it's payment on the payment gateway's website.
55
+ One of the following things can happen:
56
+
57
+ - Result 1: The customer has successfully paid and the customer is redirected
58
+ back to the `return_url` with the $TOKEN injected.
59
+ - Result 2: The customer has failed their pauyment and the customer is
60
+ redirected back to the `return_url` with the $TOKEN injected.
61
+ - Result 3: The customer presses back in their browser and we still get the
62
+ token from the `placeOrder` mutation.
63
+
64
+ GraphCommerce now needs to check if the payment has indeed succeeded by calling
65
+ the payment gateway's custom endpoint:
66
+
67
+ ```graphql
68
+ mutation MyGatewayProcessPayment($cartId: String!, $token: String!) {
69
+ myGatewayPaymentStatus(input: { cartId: $cartId, token: $string }) {
70
+ status
71
+ error_message
72
+ cart {
73
+ # it will optionally return the cart if it hasn't succeeded yet and is recovered.
74
+ id
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ After that GraphCommerce van either:
81
+
82
+ - Redirect to the success page
83
+ - Restore the cart, show the error message and let the customer checkout again.
84
+
85
+ ### The GraphQL Schema for the above example looks something like this:
86
+
87
+ ```graphql
88
+ input PaymentMethodInput {
89
+ my_gateway: MyGatewayPaymentInput
90
+ }
91
+
92
+ input MyGatewayPaymentInput {
93
+ """
94
+ The URL to redirect the customer to after the payment has been processed.
95
+
96
+ This will should be a fully qualified URL: `https://mydomain.com/checkout/payment?token=$TOKEN`
97
+ $TOKEN will be repaced with the payment gateway token.
98
+
99
+ This information should be stored in the database (encryped if required)
100
+ """
101
+ return_url: String!
102
+ """
103
+ Payment gateway can accept any custom field, for example an issuer or any additional information that can be configured in the checkout.
104
+
105
+ This information should be stored in the database (encryped if required)
106
+ """
107
+ custom_field: String
108
+ }
109
+
110
+ type Order {
111
+ my_gateway_status: MyGatewayStatus
112
+ }
113
+
114
+ type Mutation {
115
+ myGatewayPaymentStatus: MyGatewayStatus
116
+ }
117
+
118
+ type MyGatewayStatus {
119
+ """
120
+ Returns the secret token that is used to check the payment status and is understood by the external payment gateway.
121
+ """
122
+ token: String!
123
+ """
124
+ Status of the current payment.
125
+ """
126
+ status: MyGatewayStatusEnum!
127
+ """
128
+ Returned when status ERROR and there is a message to show to the customer from the gateway
129
+ """
130
+ error_message: String
131
+ """
132
+ Returned when the status is REDIRECT_SHOPPER
133
+ """
134
+ redirect_url: String
135
+ """
136
+ Retuned when when the cart has been restored on status CANCELLED, ERROR, REFUSED
137
+ """
138
+ cart: Cart
139
+ }
140
+
141
+ """
142
+ StatusEnum of the payment gateway.
143
+ Should probably look something like the following but can be extended / reduced according payment gateway's requirements.
144
+ """
145
+ enum MyGatewayStatusEnum {
146
+ """
147
+ Will be returned when the order is placed.
148
+ """
149
+ REDIRECT_SHOPPER
150
+ """
151
+ Will be returned when the customer has cancelled the payment on the external site.
152
+ Will be returned if the customer has pressed back in their browser.
153
+ """
154
+ CANCELLED
155
+ """
156
+ Will be returned if the payment hasn't succeeded, to be used in tandem with error_message
157
+ """
158
+ ERROR
159
+ """
160
+ Will be returned if the payment was rejected by the payment gateway.
161
+ """
162
+ REFUSED
163
+ """
164
+ Payment has succeeded
165
+ """
166
+ SUCCESS
167
+ }
168
+ ```
@@ -0,0 +1,17 @@
1
+ # Magento
2
+
3
+ To integrate with Magento, most of the functionality should work out-of-the box
4
+ if Magento exposes a working GraphQL API.
5
+
6
+ ## Optional packages
7
+
8
+ - [Store Pickup / MSI](https://github.com/graphcommerce-org/graphcommerce/tree/main/packages/magento-cart-pickup)
9
+
10
+ ## Payment gateways
11
+
12
+ - [PayPal](https://github.com/graphcommerce-org/graphcommerce/tree/main/packages/magento-payment-paypal)
13
+ - [Mollie](https://github.com/graphcommerce-org/graphcommerce/tree/main/packages/mollie-magento-payment)
14
+ - [Braintree](https://github.com/graphcommerce-org/graphcommerce/tree/main/packages/magento-payment-braintree)
15
+ - [Adyen](https://github.com/graphcommerce-org/graphcommerce/tree/main/packages/magento-payment-adyen)
16
+ - [MultiSafePay](https://github.com/graphcommerce-org/graphcommerce/tree/main/packages/magento-payment-multisafepay)
17
+ - [Klarna](https://github.com/graphcommerce-org/graphcommerce/tree/main/packages/magento-payment-klarna)
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/docs",
3
3
  "homepage": "https://www.graphcommerce.org/docs",
4
4
  "repository": "github:graphcommerce-org/graphcommerce/docs",
5
- "version": "4.11.1",
5
+ "version": "4.12.0-canary.1",
6
6
  "sideEffects": true,
7
7
  "devDependencies": {
8
8
  "@graphcommerce/prettier-config-pwa": "^4.0.7"