@graphcommerce/magento-cart-payment-method 9.0.1-canary.0 → 9.0.1-canary.2

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,88 +1,32 @@
1
1
  # Change Log
2
2
 
3
- ## 9.0.1-canary.0
4
-
5
- ## 9.0.0
3
+ ## 9.0.1-canary.2
6
4
 
7
5
  ### Patch Changes
8
6
 
9
- - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`43bd04a`](https://github.com/graphcommerce-org/graphcommerce/commit/43bd04a777c5800cc7e01bee1e123a5aad82f194) - Use the non resolved payment methods as a placeholder for the actual payment methods ([@FrankHarland](https://github.com/FrankHarland))
10
-
11
- - [#2277](https://github.com/graphcommerce-org/graphcommerce/pull/2277) [`f9199f7`](https://github.com/graphcommerce-org/graphcommerce/commit/f9199f798583138a68dd641ea6637375c487f29b) - Solve issue where Braintree wouldn't place the order after successfully validating a Credit Card. ([@paales](https://github.com/paales))
12
-
13
- - [#2247](https://github.com/graphcommerce-org/graphcommerce/pull/2247) [`d345474`](https://github.com/graphcommerce-org/graphcommerce/commit/d345474fb190d158629cd5fd5e68a78724fa2fb6) - Due to a cyclic dependency the actual `<PaymentMethodPlaceOrder />` button would sometimes be undefined. ([@paales](https://github.com/paales))
14
-
15
- - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`530076e`](https://github.com/graphcommerce-org/graphcommerce/commit/530076e3664703cb8b577b7fcf1998a420819f60) - Moved all usages of `useFormPersist` to the `<FormPersist/>` component to prevent rerenders. ([@FrankHarland](https://github.com/FrankHarland))
16
-
17
- - [#2305](https://github.com/graphcommerce-org/graphcommerce/pull/2305) [`77e8297`](https://github.com/graphcommerce-org/graphcommerce/commit/77e82976816994336c616208a651cb18ce9ea270) - Fix bug with persist not applying saved changes by moving `<FromPersist/>` below the form components. ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
18
-
19
- - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`43bd04a`](https://github.com/graphcommerce-org/graphcommerce/commit/43bd04a777c5800cc7e01bee1e123a5aad82f194) - Prevent the `<BillingPage />` query from rerunning on each mutation. ([@FrankHarland](https://github.com/FrankHarland))
20
-
21
- ## 9.0.0-canary.118
22
-
23
- ## 9.0.0-canary.117
24
-
25
- ## 9.0.0-canary.116
26
-
27
- ## 9.0.0-canary.115
28
-
29
- ## 9.0.0-canary.114
30
-
31
- ## 9.0.0-canary.113
32
-
33
- ## 9.0.0-canary.112
34
-
35
- ## 9.0.0-canary.111
36
-
37
- ## 9.0.0-canary.110
38
-
39
- ## 9.0.0-canary.109
40
-
41
- ## 9.0.0-canary.108
7
+ - [#2465](https://github.com/graphcommerce-org/graphcommerce/pull/2465) [`e77d1c4`](https://github.com/graphcommerce-org/graphcommerce/commit/e77d1c42307d4bfb188d89f30a62055d4d511bf4) - Solve issue where the Component prop would we forwarded tot the DOM element of the PaymentMethodActionCard ([@paales](https://github.com/paales))
42
8
 
43
- ## 9.0.0-canary.107
9
+ - [#2465](https://github.com/graphcommerce-org/graphcommerce/pull/2465) [`22b9111`](https://github.com/graphcommerce-org/graphcommerce/commit/22b9111b93bbfaa4d323c183b8c5a1e72b807725) - Support Magento 2.4.7 placeOrder.errors field to handle possible errors while placing the order. An `assertOrderPlaced` method was created to assert a valid placed order. ([@paales](https://github.com/paales))
44
10
 
45
- ## 9.0.0-canary.106
11
+ ## 9.0.1-canary.1
46
12
 
47
- ## 9.0.0-canary.105
48
-
49
- ## 9.0.0-canary.104
13
+ ## 9.0.0
50
14
 
51
- ## 9.0.0-canary.103
15
+ ### Major Changes
52
16
 
53
- ## 8.1.0-canary.38
17
+ - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`530076e`](https://github.com/graphcommerce-org/graphcommerce/commit/530076e3664703cb8b577b7fcf1998a420819f60) - INP improvements: Moved all usages of `useFormPersist` to the `<FormPersist/>` component to prevent rerenders. ([@FrankHarland](https://github.com/FrankHarland))
54
18
 
55
19
  ### Patch Changes
56
20
 
57
- - [#2305](https://github.com/graphcommerce-org/graphcommerce/pull/2305) [`77e8297`](https://github.com/graphcommerce-org/graphcommerce/commit/77e82976816994336c616208a651cb18ce9ea270) - Fix bug with persist not applying saved changes by moving <FromPersist/> below the form components ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
58
-
59
- ## 8.1.0-canary.18
60
-
61
- ### Patch Changes
21
+ - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`43bd04a`](https://github.com/graphcommerce-org/graphcommerce/commit/43bd04a777c5800cc7e01bee1e123a5aad82f194) - Use the non resolved payment methods as a placeholder for the actual payment methods ([@FrankHarland](https://github.com/FrankHarland))
62
22
 
63
23
  - [#2277](https://github.com/graphcommerce-org/graphcommerce/pull/2277) [`f9199f7`](https://github.com/graphcommerce-org/graphcommerce/commit/f9199f798583138a68dd641ea6637375c487f29b) - Solve issue where Braintree wouldn't place the order after successfully validating a Credit Card. ([@paales](https://github.com/paales))
64
24
 
65
- ## 8.1.0-canary.14
66
-
67
- ### Patch Changes
68
-
69
- - [`831d7cd`](https://github.com/graphcommerce-org/graphcommerce/commit/831d7cd64a40b7b58748fd9637199b88938e75b7) - Compatibility with Magento 2.4.7 ([@paales](https://github.com/paales))
70
-
71
- ## 8.1.0-canary.8
72
-
73
- ### Patch Changes
74
-
75
- - [#2247](https://github.com/graphcommerce-org/graphcommerce/pull/2247) [`d345474`](https://github.com/graphcommerce-org/graphcommerce/commit/d345474fb190d158629cd5fd5e68a78724fa2fb6) - Due to a cyclic dependency the actual PaymentMethodPlaceOrder button would sometimes be undefined. ([@paales](https://github.com/paales))
76
-
77
- ## 8.0.6-canary.2
78
-
79
- ### Patch Changes
80
-
81
- - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`43bd04a`](https://github.com/graphcommerce-org/graphcommerce/commit/43bd04a777c5800cc7e01bee1e123a5aad82f194) - Use the non resolved payment methods as a placeholder for the actual payment methods ([@FrankHarland](https://github.com/FrankHarland))
25
+ - [#2247](https://github.com/graphcommerce-org/graphcommerce/pull/2247) [`d345474`](https://github.com/graphcommerce-org/graphcommerce/commit/d345474fb190d158629cd5fd5e68a78724fa2fb6) - Due to a cyclic dependency the actual `<PaymentMethodPlaceOrder />` button would sometimes be undefined. ([@paales](https://github.com/paales))
82
26
 
83
- - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`530076e`](https://github.com/graphcommerce-org/graphcommerce/commit/530076e3664703cb8b577b7fcf1998a420819f60) - Moved all usages of useFormPersist to the <FormPersist/> component to prevent rerenders. ([@FrankHarland](https://github.com/FrankHarland))
27
+ - [#2305](https://github.com/graphcommerce-org/graphcommerce/pull/2305) [`77e8297`](https://github.com/graphcommerce-org/graphcommerce/commit/77e82976816994336c616208a651cb18ce9ea270) - Fix bug with persist not applying saved changes by moving `<FromPersist/>` below the form components. ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
84
28
 
85
- - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`43bd04a`](https://github.com/graphcommerce-org/graphcommerce/commit/43bd04a777c5800cc7e01bee1e123a5aad82f194) - Prevent BillingPage query from rerunning on each mutation ([@FrankHarland](https://github.com/FrankHarland))
29
+ - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`43bd04a`](https://github.com/graphcommerce-org/graphcommerce/commit/43bd04a777c5800cc7e01bee1e123a5aad82f194) - Prevent the `<BillingPage />` query from rerunning on each mutation. ([@FrankHarland](https://github.com/FrankHarland))
86
30
 
87
31
  ## 8.0.0
88
32
 
@@ -9,15 +9,15 @@ import { Trans } from '@lingui/react'
9
9
  import type { SxProps, Theme } from '@mui/material'
10
10
  import { useEffect } from 'react'
11
11
  import type { PaymentOptionsProps } from '../Api/PaymentMethod'
12
- import { usePaymentMethodContext } from '../PaymentMethodContext/paymentMethodContextType'
13
12
  import { useCartLock } from '../hooks'
13
+ import { usePaymentMethodContext } from '../PaymentMethodContext/paymentMethodContextType'
14
14
 
15
15
  function PaymentMethodActionCard(
16
16
  props: ActionCardItemRenderProps<PaymentOptionsProps> & {
17
17
  sx?: SxProps<Theme>
18
18
  },
19
19
  ) {
20
- const { onReset, code, step, child, Container, sx = [] } = props
20
+ const { onReset, code, step, child, Container, sx = [], ...rest } = props
21
21
  const { selectedMethod, selectedModule, modules } = usePaymentMethodContext()
22
22
 
23
23
  const selectedAndOptions =
@@ -29,6 +29,8 @@ function PaymentMethodActionCard(
29
29
 
30
30
  return (
31
31
  <Card
32
+ code={code}
33
+ child={child}
32
34
  sx={[
33
35
  {
34
36
  '& .ActionCard-title': { typography: 'h6' },
@@ -52,7 +54,7 @@ function PaymentMethodActionCard(
52
54
  <selectedModule.PaymentOptions {...selectedMethod} step={step} Container={Container} />
53
55
  )
54
56
  }
55
- {...props}
57
+ {...rest}
56
58
  />
57
59
  )
58
60
  }
@@ -1,5 +1,10 @@
1
1
  mutation PaymentMethodPlaceOrderNoop($cartId: String!) {
2
2
  placeOrder(input: { cart_id: $cartId }) {
3
+ errors {
4
+ code
5
+ message
6
+ }
7
+
3
8
  order {
4
9
  order_number
5
10
  }
@@ -3,6 +3,7 @@ import { useFormCompose } from '@graphcommerce/react-hook-form'
3
3
  import { t } from '@lingui/macro'
4
4
  import type { PaymentPlaceOrderProps } from '../Api/PaymentMethod'
5
5
  import { usePaymentMethodContext } from '../PaymentMethodContext/paymentMethodContextType'
6
+ import { assertOrderPlaced } from './assertOrderPlaced'
6
7
  import { PaymentMethodPlaceOrderNoopDocument } from './PaymentMethodPlaceOrderNoop.gql'
7
8
 
8
9
  export function PaymentMethodPlaceOrderNoop(props: PaymentPlaceOrderProps) {
@@ -11,11 +12,8 @@ export function PaymentMethodPlaceOrderNoop(props: PaymentPlaceOrderProps) {
11
12
 
12
13
  const form = useFormGqlMutationCart(PaymentMethodPlaceOrderNoopDocument, {
13
14
  onComplete: async (result) => {
14
- if (!result.data?.placeOrder?.order)
15
- throw Error(
16
- t`An error occurred while processing your payment. Please contact the store owner`,
17
- )
18
-
15
+ assertOrderPlaced(result)
16
+ console.log('result', result)
19
17
  await onSuccess(result.data.placeOrder.order.order_number)
20
18
  },
21
19
  submitWhileLocked: true,
@@ -0,0 +1,44 @@
1
+ import type { FetchResult } from '@graphcommerce/graphql'
2
+ import { ApolloError } from '@graphcommerce/graphql'
3
+ import { t } from '@lingui/macro'
4
+ import type { PaymentMethodPlaceOrderNoopMutation } from './PaymentMethodPlaceOrderNoop.gql'
5
+
6
+ export type PlacedOrder<T extends FetchResult<PaymentMethodPlaceOrderNoopMutation>> = NonNullable<
7
+ NonNullable<NonNullable<T['data']>['placeOrder']>['order']
8
+ >
9
+
10
+ export type AssertedOrderPlaced<T extends FetchResult<PaymentMethodPlaceOrderNoopMutation>> = T & {
11
+ data: {
12
+ placeOrder: { order: PlacedOrder<T> }
13
+ }
14
+ }
15
+
16
+ export function throwGenericPlaceOrderError() {
17
+ throw new ApolloError({
18
+ graphQLErrors: [
19
+ {
20
+ message: t`An error occurred while processing your payment. Please contact the store owner`,
21
+ },
22
+ ],
23
+ })
24
+ }
25
+
26
+ /** Assert that the order was place successfully. */
27
+ export function assertOrderPlaced<T extends FetchResult<PaymentMethodPlaceOrderNoopMutation>>(
28
+ result: T,
29
+ ): asserts result is AssertedOrderPlaced<T> {
30
+ if (result.errors && result.errors.length > 0) {
31
+ const graphQLErrors = result.errors.filter((e) => e !== null)
32
+ throw new ApolloError({ graphQLErrors })
33
+ }
34
+
35
+ if (result.data?.placeOrder?.errors && result.data.placeOrder.errors.length > 0) {
36
+ const graphQLErrors = result.data.placeOrder.errors.filter((e) => e !== null)
37
+ throw new ApolloError({ graphQLErrors })
38
+ }
39
+
40
+ if (!result.data?.placeOrder?.order?.order_number) {
41
+ console.info('Error while placing order', result)
42
+ throwGenericPlaceOrderError()
43
+ }
44
+ }
package/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './Api/PaymentMethod'
2
2
  export * from './hooks'
3
+ export * from './PaymentMethodActionCardList/PaymentMethodActionCardListForm'
3
4
  export * from './PaymentMethodButton/PaymentMethodButton'
4
5
  export * from './PaymentMethodContext/PaymentMethodContext'
5
6
  export * from './PaymentMethodContext/paymentMethodContextType'
@@ -7,6 +8,7 @@ export * from './PaymentMethodOptions/PaymentMethodOptions'
7
8
  export * from './PaymentMethodOptionsNoop/PaymentMethodOptionsNoop'
8
9
  export * from './PaymentMethodOptionsNoop/PaymentMethodOptionsNoop.gql'
9
10
  export * from './PaymentMethodPlaceOrder/PaymentMethodPlaceOrder'
11
+ export * from './PaymentMethodPlaceOrderNoop/assertOrderPlaced'
10
12
  export * from './PaymentMethodPlaceOrderNoop/PaymentMethodPlaceOrderNoop'
13
+ export * from './PaymentMethodPlaceOrderNoop/PaymentMethodPlaceOrderNoop.gql'
11
14
  export * from './PaymentMethodToggles/PaymentMethodToggles'
12
- export * from './PaymentMethodActionCardList/PaymentMethodActionCardListForm'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-cart-payment-method",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "9.0.1-canary.0",
5
+ "version": "9.0.1-canary.2",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,18 +12,18 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@graphcommerce/ecommerce-ui": "^9.0.1-canary.0",
16
- "@graphcommerce/eslint-config-pwa": "^9.0.1-canary.0",
17
- "@graphcommerce/framer-scroller": "^9.0.1-canary.0",
18
- "@graphcommerce/graphql": "^9.0.1-canary.0",
19
- "@graphcommerce/image": "^9.0.1-canary.0",
20
- "@graphcommerce/magento-cart": "^9.0.1-canary.0",
21
- "@graphcommerce/magento-cart-shipping-address": "^9.0.1-canary.0",
22
- "@graphcommerce/magento-store": "^9.0.1-canary.0",
23
- "@graphcommerce/next-ui": "^9.0.1-canary.0",
24
- "@graphcommerce/prettier-config-pwa": "^9.0.1-canary.0",
25
- "@graphcommerce/react-hook-form": "^9.0.1-canary.0",
26
- "@graphcommerce/typescript-config-pwa": "^9.0.1-canary.0",
15
+ "@graphcommerce/ecommerce-ui": "^9.0.1-canary.2",
16
+ "@graphcommerce/eslint-config-pwa": "^9.0.1-canary.2",
17
+ "@graphcommerce/framer-scroller": "^9.0.1-canary.2",
18
+ "@graphcommerce/graphql": "^9.0.1-canary.2",
19
+ "@graphcommerce/image": "^9.0.1-canary.2",
20
+ "@graphcommerce/magento-cart": "^9.0.1-canary.2",
21
+ "@graphcommerce/magento-cart-shipping-address": "^9.0.1-canary.2",
22
+ "@graphcommerce/magento-store": "^9.0.1-canary.2",
23
+ "@graphcommerce/next-ui": "^9.0.1-canary.2",
24
+ "@graphcommerce/prettier-config-pwa": "^9.0.1-canary.2",
25
+ "@graphcommerce/react-hook-form": "^9.0.1-canary.2",
26
+ "@graphcommerce/typescript-config-pwa": "^9.0.1-canary.2",
27
27
  "@lingui/core": "^4.2.1",
28
28
  "@lingui/macro": "^4.2.1",
29
29
  "@lingui/react": "^4.2.1",