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

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,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.0.2-canary.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [`7d5e75e`](https://github.com/graphcommerce-org/graphcommerce/commit/7d5e75ebfe93194237b8f6b6511d2bd1549d121e) - Solve issue where the Component prop would we forwarded tot the DOM element of the PaymentMethodActionCard ([@paales](https://github.com/paales))
8
+
9
+ - [`058b7bf`](https://github.com/graphcommerce-org/graphcommerce/commit/058b7bf64be29e1bc3d16551abcc1cd55b5413bd) - 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))
10
+
3
11
  ## 9.0.1
4
12
 
5
13
  ## 9.0.1-canary.1
@@ -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",
5
+ "version": "9.0.2-canary.0",
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",
16
- "@graphcommerce/eslint-config-pwa": "^9.0.1",
17
- "@graphcommerce/framer-scroller": "^9.0.1",
18
- "@graphcommerce/graphql": "^9.0.1",
19
- "@graphcommerce/image": "^9.0.1",
20
- "@graphcommerce/magento-cart": "^9.0.1",
21
- "@graphcommerce/magento-cart-shipping-address": "^9.0.1",
22
- "@graphcommerce/magento-store": "^9.0.1",
23
- "@graphcommerce/next-ui": "^9.0.1",
24
- "@graphcommerce/prettier-config-pwa": "^9.0.1",
25
- "@graphcommerce/react-hook-form": "^9.0.1",
26
- "@graphcommerce/typescript-config-pwa": "^9.0.1",
15
+ "@graphcommerce/ecommerce-ui": "^9.0.2-canary.0",
16
+ "@graphcommerce/eslint-config-pwa": "^9.0.2-canary.0",
17
+ "@graphcommerce/framer-scroller": "^9.0.2-canary.0",
18
+ "@graphcommerce/graphql": "^9.0.2-canary.0",
19
+ "@graphcommerce/image": "^9.0.2-canary.0",
20
+ "@graphcommerce/magento-cart": "^9.0.2-canary.0",
21
+ "@graphcommerce/magento-cart-shipping-address": "^9.0.2-canary.0",
22
+ "@graphcommerce/magento-store": "^9.0.2-canary.0",
23
+ "@graphcommerce/next-ui": "^9.0.2-canary.0",
24
+ "@graphcommerce/prettier-config-pwa": "^9.0.2-canary.0",
25
+ "@graphcommerce/react-hook-form": "^9.0.2-canary.0",
26
+ "@graphcommerce/typescript-config-pwa": "^9.0.2-canary.0",
27
27
  "@lingui/core": "^4.2.1",
28
28
  "@lingui/macro": "^4.2.1",
29
29
  "@lingui/react": "^4.2.1",