@wearejh/m2-pwa-adyen 0.23.2 → 0.26.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
@@ -3,6 +3,30 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.26.0](https://github.com/WeareJH/mage-mono/compare/v0.25.0...v0.26.0) (2024-07-15)
7
+
8
+ **Note:** Version bump only for package @wearejh/m2-pwa-adyen
9
+
10
+
11
+
12
+
13
+
14
+ # [0.25.0](https://github.com/WeareJH/mage-mono/compare/v0.23.2...v0.25.0) (2024-06-13)
15
+
16
+ **Note:** Version bump only for package @wearejh/m2-pwa-adyen
17
+
18
+
19
+
20
+
21
+
22
+ # [0.24.0](https://github.com/WeareJH/mage-mono/compare/v0.23.2...v0.24.0) (2024-06-13)
23
+
24
+ **Note:** Version bump only for package @wearejh/m2-pwa-adyen
25
+
26
+
27
+
28
+
29
+
6
30
  ## [0.23.2](https://github.com/WeareJH/mage-mono/compare/v0.23.1...v0.23.2) (2024-04-10)
7
31
 
8
32
  **Note:** Version bump only for package @wearejh/m2-pwa-adyen
@@ -118,10 +118,16 @@ export function AdyenProvider(props: AdyenProviderProps) {
118
118
 
119
119
  const dispatch = useDispatch();
120
120
 
121
- const { action, checkoutConfig, orderId, selectedPaymentMethod, step, supportedPaymentMethods } = useSelector(
122
- getAdyenStateFromStore,
123
- shallowEqual,
124
- );
121
+ const {
122
+ action,
123
+ checkoutConfig,
124
+ cartId,
125
+ cartVariant,
126
+ orderId,
127
+ selectedPaymentMethod,
128
+ step,
129
+ supportedPaymentMethods,
130
+ } = useSelector(getAdyenStateFromStore, shallowEqual);
125
131
 
126
132
  const checkoutTotalsState = useSelector(getCheckoutTotalsStateFromStore, shallowEqual);
127
133
 
@@ -269,6 +275,8 @@ export function AdyenProvider(props: AdyenProviderProps) {
269
275
  action,
270
276
  adyenCheckout,
271
277
  attemptPayment,
278
+ cartId,
279
+ cartVariant,
272
280
  checkoutConfig: adyenCheckoutConfig,
273
281
  orderId,
274
282
  paymentFormSubmit,
@@ -284,6 +292,8 @@ export function AdyenProvider(props: AdyenProviderProps) {
284
292
  adyenCheckoutConfig,
285
293
  attemptPayment,
286
294
  availiablePaymentMethods,
295
+ cartId,
296
+ cartVariant,
287
297
  orderId,
288
298
  paymentFormSubmit,
289
299
  paymentFormSubmitted,
@@ -5,11 +5,13 @@ import { ActionTypes, AdyenMessage } from './adyen.actions';
5
5
  import { AdyenRedirectParams, AdyenSteps } from './adyen.types';
6
6
  import { useAdyen } from './AdyenProvider';
7
7
 
8
+ type AdyenRedirectProps = Omit<AdyenRedirectParams, 'orderId' | 'cartId' | 'cartVariant'>;
9
+
8
10
  /**
9
11
  * React component for for processing the the payment provider
10
12
  * redirection response.
11
13
  */
12
- export function AdyenRedirect(props: Omit<AdyenRedirectParams, 'orderId'>) {
14
+ export function AdyenRedirect(props: AdyenRedirectProps) {
13
15
  const { redirectResult } = props;
14
16
 
15
17
  const { step } = useAdyen();
@@ -102,6 +102,8 @@ export function reducer(state = initialState, action: Actions): Store {
102
102
 
103
103
  case ActionTypes.ProcessRedirect:
104
104
  newState.orderId = action.payload.orderId;
105
+ newState.cartId = action.payload.cartId;
106
+ newState.cartVariant = action.payload.cartVariant;
105
107
  newState.step = AdyenSteps.ProcessRedirect;
106
108
  break;
107
109
 
@@ -83,6 +83,8 @@ export interface AdyenPaymentAction extends PaymentAction {
83
83
  }
84
84
 
85
85
  export interface AdyenRedirectParams {
86
+ cartId?: string;
87
+ cartVariant?: string;
86
88
  merchantReference?: string;
87
89
  orderId?: string;
88
90
  payload?: string;
@@ -130,6 +132,8 @@ export type AdyenSubmitParams = {
130
132
 
131
133
  export enum AdyenStorageKey {
132
134
  OrderId = 'adyen.orderid',
135
+ CartId = 'adyen.cartid',
136
+ CartVariant = 'adyen.cartvariant',
133
137
  }
134
138
 
135
139
  /**
@@ -306,6 +310,10 @@ export interface Store {
306
310
 
307
311
  messages: Message[];
308
312
 
313
+ cartId?: string;
314
+
315
+ cartVariant?: string;
316
+
309
317
  orderId?: string;
310
318
 
311
319
  /**
@@ -1,4 +1,3 @@
1
- import { cartVariantAndId } from '@wearejh/m2-pwa-cart/lib/utils/stateObservables';
2
1
  import { CartVariant } from '@wearejh/m2-pwa-cart/lib/cart.reducer';
3
2
  import { AppendState, CheckoutActions, CheckoutMsg, State, TypeMap as CheckoutTypes } from '@wearejh/m2-pwa-checkout';
4
3
  import { EpicDeps } from '@wearejh/m2-pwa-engine/lib/types';
@@ -13,6 +12,7 @@ import { Actions, AdyenMessage, ActionTypes, TypeMap } from '../adyen.actions';
13
12
  import { AdyenPayload, AdyenResponseParams } from '../adyen.types';
14
13
 
15
14
  import { processAdyenResponse } from './utils/processAdyenResponse';
15
+ import { getAdyenCart } from './utils/getAdyenCart';
16
16
 
17
17
  function getOrderStatus({ cartVariant, orderId, cartId }, deps: EpicDeps) {
18
18
  if (cartVariant === CartVariant.Account) {
@@ -29,6 +29,11 @@ function getOrderStatus({ cartVariant, orderId, cartId }, deps: EpicDeps) {
29
29
  export function adyenPayment(action$: Observable<any>, state$: Observable<any>, deps: EpicDeps): Observable<any> {
30
30
  const pendingPayment$ = state$.pipe(pluck<AppendState, 'checkout', 'pendingPayment'>('checkout', 'pendingPayment'));
31
31
 
32
+ /**
33
+ * Get checkout cart variant and id from the store.
34
+ */
35
+ const adyenCart$ = getAdyenCart(state$);
36
+
32
37
  return action$.pipe(
33
38
  /**
34
39
  * Listern for the event to be triggered
@@ -36,7 +41,7 @@ export function adyenPayment(action$: Observable<any>, state$: Observable<any>,
36
41
  */
37
42
  ofType<Actions, TypeMap[ActionTypes.PaymentSubmit]>(ActionTypes.PaymentSubmit),
38
43
 
39
- withLatestFrom(pendingPayment$, cartVariantAndId(state$)),
44
+ withLatestFrom(pendingPayment$, adyenCart$),
40
45
 
41
46
  switchMap(([{ payload }, pendingPayment, [cartVariant, cartId]]) => {
42
47
  if (!pendingPayment) {
@@ -92,7 +97,15 @@ export function adyenPayment(action$: Observable<any>, state$: Observable<any>,
92
97
  cartId,
93
98
  },
94
99
  deps,
95
- ).pipe(mergeMap((response) => processAdyenResponse(response, orderId))),
100
+ ).pipe(
101
+ mergeMap((response) =>
102
+ processAdyenResponse(response, {
103
+ cartId,
104
+ cartVariant,
105
+ orderId,
106
+ }),
107
+ ),
108
+ ),
96
109
  ),
97
110
  ),
98
111
 
@@ -1,4 +1,4 @@
1
- import { cartTotals, cartVariantAndId } from '@wearejh/m2-pwa-cart/lib/utils/stateObservables';
1
+ import { cartTotals } from '@wearejh/m2-pwa-cart/lib/utils/stateObservables';
2
2
  import { CheckoutActions } from '@wearejh/m2-pwa-checkout/lib/checkout.actions';
3
3
  import { CartVariant } from '@wearejh/m2-pwa-cart/lib/cart.reducer';
4
4
  import { EpicDeps } from '@wearejh/m2-pwa-engine/lib/types';
@@ -18,6 +18,8 @@ import {
18
18
  PaymentMethodTypes,
19
19
  } from '../adyen.types';
20
20
 
21
+ import { getAdyenCart } from './utils/getAdyenCart';
22
+
21
23
  /**
22
24
  * API url for Adyen Web Components.
23
25
  *
@@ -58,6 +60,11 @@ export function getAdyenConfig(action$: Observable<any>, state$: Observable<any>
58
60
  */
59
61
  const shippingAddress$ = state$.pipe(pluck('checkout', 'shippingAddress'));
60
62
 
63
+ /**
64
+ * Get checkout cart variant and id from the store.
65
+ */
66
+ const adyenCart$ = getAdyenCart(state$);
67
+
61
68
  return action$.pipe(
62
69
  /**
63
70
  * Listern for the event to be triggered
@@ -77,7 +84,7 @@ export function getAdyenConfig(action$: Observable<any>, state$: Observable<any>
77
84
  */
78
85
  withLatestFrom(
79
86
  cartTotals(state$),
80
- cartVariantAndId(state$),
87
+ adyenCart$,
81
88
  shippingAddress$,
82
89
  deps.window$.pipe(map((win) => Boolean((win as any).Cypress))),
83
90
  ),
@@ -20,10 +20,22 @@ export function getRedirectData(action$: Observable<any>, _state$: Observable<an
20
20
 
21
21
  mergeMap(() => {
22
22
  const orderId = deps.storage.get(AdyenStorageKey.OrderId);
23
+ const cartId = deps.storage.get(AdyenStorageKey.CartId);
24
+ const cartVariant = deps.storage.get(AdyenStorageKey.CartVariant);
23
25
 
24
- if (orderId) {
26
+ const hasRequiredOrderData =
27
+ orderId !== undefined &&
28
+ orderId !== null &&
29
+ cartId !== undefined &&
30
+ cartId !== null &&
31
+ cartVariant !== undefined &&
32
+ cartVariant !== null;
33
+
34
+ if (hasRequiredOrderData) {
25
35
  return of(
26
36
  AdyenMessage(ActionTypes.ProcessRedirect, {
37
+ cartId,
38
+ cartVariant,
27
39
  orderId,
28
40
  }),
29
41
  );
@@ -32,7 +44,7 @@ export function getRedirectData(action$: Observable<any>, _state$: Observable<an
32
44
  return of(
33
45
  AdyenMessage(ActionTypes.Error, {
34
46
  cancelPayment: true,
35
- message: 'Cannot proceed without an order id',
47
+ message: 'Cannot proceed without order information',
36
48
  }),
37
49
  );
38
50
  }),
@@ -1,4 +1,3 @@
1
- import { cartVariantAndId } from '@wearejh/m2-pwa-cart/lib/utils/stateObservables';
2
1
  import { CartVariant } from '@wearejh/m2-pwa-cart/lib/cart.reducer';
3
2
  import { EpicDeps } from '@wearejh/m2-pwa-engine/lib/types';
4
3
  import { extractErrorAndCode } from '@wearejh/swagger-rxjs/utils/ajax-helpers';
@@ -12,6 +11,7 @@ import { execute as getUserAdyenPaymentDetailsQuery } from '../rest/AdyenPayment
12
11
  import { execute as getGuestAdyenPaymentDetailsQuery } from '../rest/AdyenPaymentGuestAdyenThreeDS2ProcessV1InitiatePost';
13
12
 
14
13
  import { processAdyenResponse } from './utils/processAdyenResponse';
14
+ import { getAdyenCart } from './utils/getAdyenCart';
15
15
 
16
16
  /**
17
17
  * Process Adyen payment details.
@@ -26,6 +26,11 @@ export function paymentDetails(
26
26
  */
27
27
  const orderId$ = state$.pipe(pluck<AdyenStore, 'adyen', 'orderId'>('adyen', 'orderId'));
28
28
 
29
+ /**
30
+ * Get checkout cart variant and id from the store.
31
+ */
32
+ const adyenCart$ = getAdyenCart(state$);
33
+
29
34
  return action$.pipe(
30
35
  /**
31
36
  * Listern for the event to be triggered
@@ -37,12 +42,20 @@ export function paymentDetails(
37
42
  * Get the latest data from the Store
38
43
  * before proceeding.
39
44
  */
40
- withLatestFrom(orderId$, cartVariantAndId(state$)),
45
+ withLatestFrom(orderId$, adyenCart$),
41
46
 
42
47
  switchMap(([{ payload }, orderId, [cartVariant, cartId]]) => {
43
48
  const process$ = (() => {
44
- if (!orderId) {
45
- return throwError(new Error(`cannot continue without an order id`));
49
+ const hasRequiredOrderData =
50
+ orderId !== undefined &&
51
+ orderId !== null &&
52
+ cartId !== undefined &&
53
+ cartId !== null &&
54
+ cartVariant !== undefined &&
55
+ cartVariant !== null;
56
+
57
+ if (!hasRequiredOrderData) {
58
+ return throwError(new Error(`Cannot proceed without order information`));
46
59
  }
47
60
 
48
61
  const outgoing = JSON.stringify({
@@ -71,7 +84,13 @@ export function paymentDetails(
71
84
  /**
72
85
  * Handle the JSON response.
73
86
  */
74
- mergeMap((response: any) => processAdyenResponse(response, orderId)),
87
+ mergeMap((response: any) =>
88
+ processAdyenResponse(response, {
89
+ cartId,
90
+ cartVariant,
91
+ orderId,
92
+ }),
93
+ ),
75
94
 
76
95
  catchError((errorResponse) => {
77
96
  const { error } = extractErrorAndCode(errorResponse);
@@ -1,8 +1,9 @@
1
+ import { StorageActions, StorageMsg } from '@wearejh/m2-pwa-engine/lib/storage';
1
2
  import { CheckoutMsg } from '@wearejh/m2-pwa-checkout';
2
- import { concat, of } from 'rxjs';
3
+ import { of } from 'rxjs';
3
4
 
4
5
  import { ActionTypes, AdyenMessage } from '../../adyen.actions';
5
- import { AdyenSteps } from '../../adyen.types';
6
+ import { AdyenSteps, AdyenStorageKey } from '../../adyen.types';
6
7
 
7
8
  /**
8
9
  * Let `m2-pwa-checkout` know that Adyen
@@ -17,10 +18,12 @@ export function completeAdyen(orderId: string) {
17
18
 
18
19
  const paymentProviderComplete = CheckoutMsg('Checkout.PaymentProviderComplete');
19
20
 
20
- return concat(
21
- of(AdyenMessage(ActionTypes.SetStep, AdyenSteps.Complete)),
22
- of(paymentProviderSuccess),
23
- of(paymentProviderComplete),
24
- of(AdyenMessage(ActionTypes.SetStep, AdyenSteps.Init)),
21
+ return of(
22
+ StorageMsg(StorageActions.Delete, AdyenStorageKey.OrderId),
23
+ StorageMsg(StorageActions.Delete, AdyenStorageKey.CartId),
24
+ StorageMsg(StorageActions.Delete, AdyenStorageKey.CartVariant),
25
+ AdyenMessage(ActionTypes.SetStep, AdyenSteps.Complete),
26
+ paymentProviderSuccess,
27
+ paymentProviderComplete,
25
28
  );
26
29
  }
@@ -0,0 +1,32 @@
1
+ import { cartVariantAndId } from '@wearejh/m2-pwa-cart/lib/utils/stateObservables';
2
+ import { combineLatest, Observable } from 'rxjs';
3
+ import { map, pluck, switchMap } from 'rxjs/operators';
4
+
5
+ import { AppendAdyenState, AppendState as AdyenStore } from '../../adyen.types';
6
+
7
+ type GetAdyenCartState = Observable<AppendAdyenState<AdyenStore>>;
8
+
9
+ /**
10
+ * Get checkout cart variant and id from the store.
11
+ */
12
+ export function getAdyenCart(state$: GetAdyenCartState) {
13
+ const cartId$ = cartVariantAndId(state$).pipe(
14
+ switchMap((cartState) =>
15
+ state$.pipe(
16
+ pluck<AdyenStore, 'adyen', 'cartId'>('adyen', 'cartId'),
17
+ map((cartId) => cartId ?? cartState[1]),
18
+ ),
19
+ ),
20
+ );
21
+
22
+ const cartVariant$ = cartVariantAndId(state$).pipe(
23
+ switchMap((cartState) =>
24
+ state$.pipe(
25
+ pluck<AdyenStore, 'adyen', 'cartVariant'>('adyen', 'cartVariant'),
26
+ map((cartVariant) => cartVariant ?? cartState[0]),
27
+ ),
28
+ ),
29
+ );
30
+
31
+ return combineLatest([cartVariant$, cartId$]);
32
+ }
@@ -17,7 +17,15 @@ import { completeAdyen } from './completeAdyen';
17
17
  // One day (24 hours) in milliseconds.
18
18
  const ONE_DAY = 60 * 60 * 24 * 1000;
19
19
 
20
- export function processAdyenResponse(response?: AdyenResponseParams, orderId?: string) {
20
+ type ProcessAdyenResponseConfig = {
21
+ cartId?: string;
22
+ cartVariant?: string;
23
+ orderId?: string;
24
+ };
25
+
26
+ export function processAdyenResponse(response?: AdyenResponseParams, config?: ProcessAdyenResponseConfig) {
27
+ const { orderId, cartId, cartVariant } = config || {};
28
+
21
29
  if (!orderId) {
22
30
  return throwError(new Error(`cannot continue without an orderid`));
23
31
  }
@@ -57,6 +65,7 @@ export function processAdyenResponse(response?: AdyenResponseParams, orderId?: s
57
65
  switch (action.type) {
58
66
  case AdyenActionTypes.Redirect:
59
67
  const paymentMethodType = action?.paymentMethodType;
68
+ const storageExpiry = new Date().getTime() + ONE_DAY;
60
69
 
61
70
  switch (paymentMethodType) {
62
71
  case PaymentMethodTypes.Giftcard:
@@ -68,10 +77,20 @@ export function processAdyenResponse(response?: AdyenResponseParams, orderId?: s
68
77
  * the user is returned to the site.
69
78
  */
70
79
  StorageMsg(StorageActions.Set, {
71
- expiry: new Date().getTime() + ONE_DAY,
80
+ expiry: storageExpiry,
72
81
  key: AdyenStorageKey.OrderId,
73
82
  value: orderId,
74
83
  }),
84
+ StorageMsg(StorageActions.Set, {
85
+ expiry: storageExpiry,
86
+ key: AdyenStorageKey.CartId,
87
+ value: cartId,
88
+ }),
89
+ StorageMsg(StorageActions.Set, {
90
+ expiry: storageExpiry,
91
+ key: AdyenStorageKey.CartVariant,
92
+ value: cartVariant,
93
+ }),
75
94
  AdyenMessage(ActionTypes.ActionGiftCardRedirect, action),
76
95
  );
77
96
 
@@ -85,10 +104,20 @@ export function processAdyenResponse(response?: AdyenResponseParams, orderId?: s
85
104
  * the user is returned to the site.
86
105
  */
87
106
  StorageMsg(StorageActions.Set, {
88
- expiry: new Date().getTime() + ONE_DAY,
107
+ expiry: storageExpiry,
89
108
  key: AdyenStorageKey.OrderId,
90
109
  value: orderId,
91
110
  }),
111
+ StorageMsg(StorageActions.Set, {
112
+ expiry: storageExpiry,
113
+ key: AdyenStorageKey.CartId,
114
+ value: cartId,
115
+ }),
116
+ StorageMsg(StorageActions.Set, {
117
+ expiry: storageExpiry,
118
+ key: AdyenStorageKey.CartVariant,
119
+ value: cartVariant,
120
+ }),
92
121
  AdyenMessage(ActionTypes.ActionKlarnaRedirect, action),
93
122
  );
94
123
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wearejh/m2-pwa-adyen",
3
- "version": "0.23.2",
3
+ "version": "0.26.0",
4
4
  "description": "> TODO: description",
5
5
  "author": "Shane Osbourne <shane.osbourne8@gmail.com>",
6
6
  "homepage": "",
@@ -22,13 +22,13 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@adyen/adyen-web": "5.59.0",
25
- "@wearejh/m2-pwa-cart": "^0.23.2",
26
- "@wearejh/m2-pwa-checkout": "^0.23.2",
27
- "@wearejh/m2-pwa-engine": "^0.23.2",
28
- "@wearejh/react-hooks": "^0.23.2",
29
- "@wearejh/rx-form": "^0.23.2",
30
- "@wearejh/swagger-rxjs": "^0.23.2",
25
+ "@wearejh/m2-pwa-cart": "^0.26.0",
26
+ "@wearejh/m2-pwa-checkout": "^0.26.0",
27
+ "@wearejh/m2-pwa-engine": "^0.26.0",
28
+ "@wearejh/react-hooks": "^0.26.0",
29
+ "@wearejh/rx-form": "^0.26.0",
30
+ "@wearejh/swagger-rxjs": "^0.26.0",
31
31
  "load-js": "^3.0.3"
32
32
  },
33
- "gitHead": "855a4624619460e9528cef62566b8a278456ed20"
33
+ "gitHead": "d626f346da72a5ee0fe293d4f57f70e12c4cccf5"
34
34
  }