@graphcommerce/magento-payment-paypal 4.13.3 → 4.14.0-canary.10

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,8 +1,44 @@
1
1
  # @graphcommerce/magento-payment-paypal
2
2
 
3
- ## 4.13.3
3
+ ## 4.14.0-canary.10
4
4
 
5
- ## 4.13.2
5
+ ## 4.14.0-canary.9
6
+
7
+ ## 4.14.0-canary.8
8
+
9
+ ## 4.14.0-canary.7
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1738](https://github.com/graphcommerce-org/graphcommerce/pull/1738) [`52882a63e`](https://github.com/graphcommerce-org/graphcommerce/commit/52882a63e96c0d3ba9641c3714d288fa4f420c82) - Do not forward the Prev prop in plugins ([@paales](https://github.com/paales))
14
+
15
+ ## 4.14.0-canary.6
16
+
17
+ ## 4.14.0-canary.5
18
+
19
+ ## 4.14.0-canary.4
20
+
21
+ ### Patch Changes
22
+
23
+ - [#1733](https://github.com/graphcommerce-org/graphcommerce/pull/1733) [`b2d73c726`](https://github.com/graphcommerce-org/graphcommerce/commit/b2d73c726fa123435fa6c54b4e0fd0db2df7c4ab) - Move to <Prev/> instead of <Component/> to call the plugin component ([@paales](https://github.com/paales))
24
+
25
+ - [#1733](https://github.com/graphcommerce-org/graphcommerce/pull/1733) [`be10e8cd1`](https://github.com/graphcommerce-org/graphcommerce/commit/be10e8cd1dce172a914ee9e5f65fdca4d0929fc8) - Migrated payment methods to use the new `onSuccess` method from `PaymentMethodContextProvider` instead of redirecting manually, makes sure the onSuccess method can be used by plugins. ([@paales](https://github.com/paales))
26
+
27
+ ## 4.14.0-canary.3
28
+
29
+ ### Patch Changes
30
+
31
+ - [#1729](https://github.com/graphcommerce-org/graphcommerce/pull/1729) [`4f85e4878`](https://github.com/graphcommerce-org/graphcommerce/commit/4f85e4878e4ad0dd528d60ad35826da0677059a9) - Add the ability to specificy plugins on the package name (e.g. `@graphcommerce/magento-cart-payment-method`) ([@paales](https://github.com/paales))
32
+
33
+ ## 4.14.0-canary.2
34
+
35
+ ### Minor Changes
36
+
37
+ - [#1718](https://github.com/graphcommerce-org/graphcommerce/pull/1718) [`f08bffd63`](https://github.com/graphcommerce-org/graphcommerce/commit/f08bffd63780cb626f072b25c2fd4da37543b6f7) - Add payment methods with a plugin ([@paales](https://github.com/paales))
38
+
39
+ ## 4.13.2-canary.1
40
+
41
+ ## 4.13.2-canary.0
6
42
 
7
43
  ## 4.13.1
8
44
 
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Magento Payment PayPal
2
+
3
+ Integrates GraphCommerce with the Magento PayPal module.
4
+
5
+ Note: Not yet working
6
+
7
+ ## Installation
8
+
9
+ 1. Find current version of your `@graphcommerce/magento-cart-payment-method` in
10
+ your package.json.
11
+ 2. `yarn add @graphcommerce/magento-payment-paypal@1.2.3` (replace 1.2.3 with
12
+ the version of the step above)
13
+
14
+ This package uses GraphCommerce plugin systems, so there is no code modification
15
+ required.
@@ -1,14 +1,10 @@
1
1
  import { ApolloErrorSnackbar } from '@graphcommerce/ecommerce-ui'
2
2
  import { useMutation } from '@graphcommerce/graphql'
3
+ import { useCurrentCartId } from '@graphcommerce/magento-cart'
3
4
  import {
4
- useAssignCurrentCartId,
5
- useClearCurrentCartId,
6
- useCurrentCartId,
7
- } from '@graphcommerce/magento-cart'
8
- import { PaymentHandlerProps } from '@graphcommerce/magento-cart-payment-method'
9
- import { ErrorSnackbar } from '@graphcommerce/next-ui'
10
- import { Trans } from '@lingui/react'
11
- import { FormControlLabel } from '@mui/material'
5
+ PaymentHandlerProps,
6
+ usePaymentMethodContext,
7
+ } from '@graphcommerce/magento-cart-payment-method'
12
8
  import { useRouter } from 'next/router'
13
9
  import { useEffect } from 'react'
14
10
  import { usePayPalCartLock } from '../../hooks/usePayPalCartLock'
@@ -18,7 +14,7 @@ export const PayPalPaymentHandler = (props: PaymentHandlerProps) => {
18
14
  const { code } = props
19
15
  const { push } = useRouter()
20
16
  const [lockStatus, , unlock] = usePayPalCartLock()
21
- const clearCurrentCartId = useClearCurrentCartId()
17
+ const { onSuccess } = usePaymentMethodContext()
22
18
  const { currentCartId: cartId } = useCurrentCartId()
23
19
 
24
20
  const { token, PayerID, locked, justLocked, method } = lockStatus
@@ -49,27 +45,18 @@ export const PayPalPaymentHandler = (props: PaymentHandlerProps) => {
49
45
  const fetchData = async () => {
50
46
  const res = await placeOrder()
51
47
 
52
- if (res.errors) {
48
+ if (res.errors || !res.data?.placeOrder?.order) {
53
49
  await unlock({ token: null, PayerID: null })
54
50
  return
55
51
  }
56
52
 
57
- // We're done with the current cart, we clear the current cartId.
58
- clearCurrentCartId()
59
-
60
53
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
61
- push({
62
- pathname: '/checkout/success',
63
- query: {
64
- cart_id: cartId,
65
- order_number: res.data?.placeOrder?.order.order_number,
66
- },
67
- })
54
+ onSuccess(res.data?.placeOrder?.order.order_number)
68
55
  }
69
56
 
70
57
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
71
58
  fetchData()
72
- }, [PayerID, called, cartId, clearCurrentCartId, placeOrder, push, token, unlock])
59
+ }, [PayerID, called, cartId, onSuccess, placeOrder, push, token, unlock])
73
60
 
74
61
  if (error) return <ApolloErrorSnackbar error={error} />
75
62
  return null
package/index.ts CHANGED
@@ -3,13 +3,11 @@ import { PayPalExpressActionCard } from './components/PayPalPaymentActionCard/Pa
3
3
  import { PayPalPaymentHandler } from './components/PayPalPaymentHandler/PayPalPaymentHandler'
4
4
  import { PayPalPaymentOptions } from './components/PayPalPaymentOptionsAndPlaceOrder/PayPalPaymentOptions'
5
5
 
6
- const mspModule: PaymentModule = {
7
- PaymentOptions: PayPalPaymentOptions,
8
- PaymentActionCard: PayPalExpressActionCard,
9
- PaymentHandler: PayPalPaymentHandler,
10
- PaymentPlaceOrder: () => null,
11
- }
12
-
13
6
  export const paypal: Record<string, PaymentModule> = {
14
- paypal_express: mspModule,
7
+ paypal_express: {
8
+ PaymentOptions: PayPalPaymentOptions,
9
+ PaymentActionCard: PayPalExpressActionCard,
10
+ PaymentHandler: PayPalPaymentHandler,
11
+ PaymentPlaceOrder: () => null,
12
+ },
15
13
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-payment-paypal",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "4.13.3",
5
+ "version": "4.14.0-canary.10",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -19,13 +19,13 @@
19
19
  "type-fest": "^2.12.2"
20
20
  },
21
21
  "dependencies": {
22
- "@graphcommerce/ecommerce-ui": "4.30.2",
23
- "@graphcommerce/graphql": "4.30.2",
24
- "@graphcommerce/image": "4.30.2",
25
- "@graphcommerce/magento-cart": "4.13.3",
26
- "@graphcommerce/magento-cart-payment-method": "4.13.3",
27
- "@graphcommerce/magento-store": "4.13.3",
28
- "@graphcommerce/next-ui": "4.30.2"
22
+ "@graphcommerce/ecommerce-ui": "4.31.0-canary.6",
23
+ "@graphcommerce/graphql": "4.31.0-canary.6",
24
+ "@graphcommerce/image": "4.31.0-canary.6",
25
+ "@graphcommerce/magento-cart": "4.14.0-canary.10",
26
+ "@graphcommerce/magento-cart-payment-method": "4.14.0-canary.10",
27
+ "@graphcommerce/magento-store": "4.14.0-canary.10",
28
+ "@graphcommerce/next-ui": "4.31.0-canary.6"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@lingui/react": "^3.13.2",
@@ -0,0 +1,22 @@
1
+ import type { PaymentMethodContextProviderProps } from '@graphcommerce/magento-cart-payment-method'
2
+ import type { PluginProps } from '@graphcommerce/next-config'
3
+ import { PayPalExpressActionCard } from '../components/PayPalPaymentActionCard/PayPalPaymentActionCard'
4
+ import { PayPalPaymentHandler } from '../components/PayPalPaymentHandler/PayPalPaymentHandler'
5
+ import { PayPalPaymentOptions } from '../components/PayPalPaymentOptionsAndPlaceOrder/PayPalPaymentOptions'
6
+
7
+ export const component = 'PaymentMethodContextProvider'
8
+ export const exported = '@graphcommerce/magento-cart-payment-method'
9
+
10
+ const paypal_express = {
11
+ PaymentOptions: PayPalPaymentOptions,
12
+ PaymentActionCard: PayPalExpressActionCard,
13
+ PaymentHandler: PayPalPaymentHandler,
14
+ PaymentPlaceOrder: () => null,
15
+ }
16
+
17
+ function AddPaypalMethods(props: PluginProps<PaymentMethodContextProviderProps>) {
18
+ const { modules, Prev, ...rest } = props
19
+ return <Prev {...rest} modules={{ ...modules, paypal_express }} />
20
+ }
21
+
22
+ export const Plugin = AddPaypalMethods