@akinon/pz-apple-pay 2.0.0-beta.9 → 2.0.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,45 +1,151 @@
1
1
  # @akinon/pz-apple-pay
2
2
 
3
- ## 2.0.0-beta.9
3
+ ## 2.0.1
4
+
5
+ ## 2.0.0
6
+
7
+ ## 2.0.0-beta.27
8
+
9
+ ## 2.0.0-beta.26
10
+
11
+ ## 2.0.0-beta.25
12
+
13
+ ## 2.0.0-beta.24
14
+
15
+ ## 2.0.0-beta.23
16
+
17
+ ## 2.0.0-beta.22
18
+
19
+ ## 2.0.0-beta.21
20
+
21
+ ## 2.0.0-beta.20
22
+
23
+ ## 1.126.0
24
+
25
+ ## 1.125.2
26
+
27
+ ## 1.125.1
28
+
29
+ ## 1.125.0
30
+
31
+ ## 1.124.0
32
+
33
+ ## 1.123.0
34
+
35
+ ## 1.122.0
36
+
37
+ ## 1.121.0
38
+
39
+ ## 1.120.0
40
+
41
+ ### Minor Changes
42
+
43
+ - 6ad72e8d: ZERO-4032: Add loading state management for payment submissions across multiple components and add safe guarding
44
+
45
+ ## 1.119.0
46
+
47
+ ## 1.118.0
48
+
49
+ ## 1.117.0
50
+
51
+ ## 1.116.0
52
+
53
+ ## 1.115.0
54
+
55
+ ## 1.114.0
56
+
57
+ ## 1.113.0
58
+
59
+ ## 1.112.0
60
+
61
+ ## 1.111.0
62
+
63
+ ## 1.110.0
64
+
65
+ ## 1.109.0
66
+
67
+ ## 1.108.0
4
68
 
5
69
  ### Minor Changes
6
70
 
7
- - 0fe7711: ZERO-3387: Upgrade nextjs, eslint-config-next
71
+ - d8883ce6: ZERO-3640: Refactor wallet completion handling to accept additional parameters; update related API calls
72
+ - 31a2d35a: ZERO-3640: Refactor checkout API call to include useFormData option; update FlowPayment component for improved error handling and code readability
73
+
74
+ ## 1.107.0
8
75
 
9
- ## 2.0.0-beta.8
76
+ ## 1.106.0
10
77
 
11
- ## 2.0.0-beta.7
78
+ ## 1.105.0
12
79
 
13
- ## 2.0.0-beta.6
80
+ ## 1.104.0
81
+
82
+ ## 1.103.0
83
+
84
+ ## 1.102.0
85
+
86
+ ## 1.101.0
87
+
88
+ ## 1.100.0
89
+
90
+ ## 1.99.0
14
91
 
15
92
  ### Minor Changes
16
93
 
17
- - 8f05f9b: ZERO-3250: Beta branch synchronized with Main branch
94
+ - d58538b: ZERO-3638: Enhance RC pipeline: add fetch, merge, and pre-release setup with conditional commit
95
+
96
+ ## 1.98.0
97
+
98
+ ## 1.97.0
18
99
 
19
- ## 2.0.0-beta.5
100
+ ## 1.96.0
20
101
 
21
- ## 2.0.0-beta.4
102
+ ## 1.95.0
22
103
 
23
- ## 2.0.0-beta.3
104
+ ## 1.94.0
24
105
 
25
- ## 2.0.0-beta.2
106
+ ## 1.93.0
107
+
108
+ ## 1.92.0
109
+
110
+ ## 1.91.0
111
+
112
+ ## 1.90.0
26
113
 
27
114
  ### Minor Changes
28
115
 
29
- - a006015: ZERO-3116: Add not-found page and update default middleware.
30
- - 1eeb3d8: ZERO-3116: Add not found page
116
+ - f2e9d1d: ZERO-3383: Add custom UI rendering option for apple pay
117
+
118
+ ## 1.89.0
119
+
120
+ ## 1.88.0
121
+
122
+ ## 1.87.0
123
+
124
+ ## 1.86.0
31
125
 
32
- ## 2.0.0-beta.1
126
+ ## 1.85.0
127
+
128
+ ## 1.84.0
33
129
 
34
130
  ### Minor Changes
35
131
 
36
- - ZERO-3091: Upgrade Next.js to v15 and React to v19
132
+ - 624a4eb: ZERO-3276: Update installation instructions across multiple README files to standardize format and improve clarity
133
+
134
+ ## 1.83.0
135
+
136
+ ## 1.82.0
137
+
138
+ ## 1.81.0
139
+
140
+ ## 1.80.0
141
+
142
+ ## 1.79.0
37
143
 
38
- ## 2.0.0-beta.0
144
+ ## 1.78.0
39
145
 
40
- ### Major Changes
146
+ ## 1.77.0
41
147
 
42
- - be6c09d: ZERO-3114: Create beta version.
148
+ ## 1.76.0
43
149
 
44
150
  ## 1.75.0
45
151
 
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@akinon/pz-apple-pay",
3
- "version": "2.0.0-beta.9",
3
+ "version": "2.0.1",
4
4
  "license": "MIT",
5
5
  "main": "src/index.tsx",
6
6
  "peerDependencies": {
7
- "react": "^19.0.0",
8
- "react-dom": "^19.0.0"
7
+ "react": "^18.0.0 || ^19.0.0",
8
+ "react-dom": "^18.0.0 || ^19.0.0"
9
9
  },
10
10
  "devDependencies": {
11
- "@types/node": "^22.10.2",
12
- "@types/react": "^19.0.2",
13
- "@types/react-dom": "^19.0.2",
14
- "prettier": "^3.4.2",
15
- "react": "^19.0.0",
16
- "react-dom": "^19.0.0",
17
- "typescript": "^5.7.2"
11
+ "@types/node": "^18.7.8",
12
+ "@types/react": "^18.0.17",
13
+ "@types/react-dom": "^18.0.6",
14
+ "prettier": "^3.0.3",
15
+ "react": "19.2.5",
16
+ "react-dom": "19.2.5",
17
+ "typescript": "^5.2.2"
18
18
  }
19
19
  }
@@ -3,6 +3,7 @@ import { useAppSelector, useAppDispatch } from '@akinon/next/redux/hooks';
3
3
  import { getCookie } from '@akinon/next/utils';
4
4
  import { getUrlPathWithLocale } from '@akinon/next/utils/localization';
5
5
  import { RootState } from '@theme/redux/store';
6
+ import { useLocalization } from '@akinon/next/hooks';
6
7
  import { useState, useMemo } from 'react';
7
8
 
8
9
  export default function useApplePay() {
@@ -10,7 +11,9 @@ export default function useApplePay() {
10
11
  (state: RootState) => state.checkout
11
12
  );
12
13
  const dispatch = useAppDispatch();
14
+ const { t } = useLocalization();
13
15
  const [errors, setErrors] = useState(null);
16
+ const [isProcessing, setIsProcessing] = useState(false);
14
17
 
15
18
  const paymentErrors = useMemo(() => {
16
19
  if (typeof errors === 'string') {
@@ -79,58 +82,70 @@ export default function useApplePay() {
79
82
  }, [walletPaymentData]);
80
83
 
81
84
  const initPaymentRequest = async () => {
82
- setErrors(null);
83
-
84
- const request = paymentRequest;
85
- const paymentRequestResponse = await request.show();
85
+ if (isProcessing) return;
86
86
 
87
- if (paymentRequestResponse.details?.token?.paymentData) {
88
- const paymentData = paymentRequestResponse.details.token.paymentData;
87
+ setIsProcessing(true);
88
+ setErrors(null);
89
89
 
90
- const walletPaymentPageResponse = await dispatch(
91
- checkoutApi.endpoints.setWalletPaymentPage.initiate({
92
- payment_token: JSON.stringify(paymentData)
93
- })
94
- ).unwrap();
90
+ try {
91
+ const request = paymentRequest;
92
+ const paymentRequestResponse = await request.show();
95
93
 
96
- if (walletPaymentPageResponse.errors) {
97
- setErrors(walletPaymentPageResponse.errors);
98
- }
94
+ if (paymentRequestResponse.details?.token?.paymentData) {
95
+ const paymentData = paymentRequestResponse.details.token.paymentData;
99
96
 
100
- if (
101
- walletPaymentPageResponse.context_list.find(
102
- (c) => c.page_name === 'WalletCompletePage'
103
- )
104
- ) {
105
- const paymentCompleteResponse = await dispatch(
106
- checkoutApi.endpoints.setWalletCompletePage.initiate(true)
97
+ const walletPaymentPageResponse = await dispatch(
98
+ checkoutApi.endpoints.setWalletPaymentPage.initiate({
99
+ payment_token: JSON.stringify(paymentData)
100
+ })
107
101
  ).unwrap();
108
102
 
109
- if (paymentCompleteResponse.errors) {
110
- setErrors(paymentCompleteResponse.errors);
103
+ if (walletPaymentPageResponse.errors) {
104
+ setErrors(walletPaymentPageResponse.errors);
111
105
  }
112
106
 
113
107
  if (
114
- paymentCompleteResponse.context_list.find(
115
- (c) => c.page_name === 'ThankYouPage'
108
+ walletPaymentPageResponse.context_list.find(
109
+ (c) => c.page_name === 'WalletCompletePage'
116
110
  )
117
111
  ) {
118
- const redirectUrl = paymentCompleteResponse.context_list.find(
119
- (c) => c.page_name === 'ThankYouPage'
120
- )?.page_context.context_data.redirect_url;
121
-
122
- const redirectUrlWithLocale = `${
123
- window.location.origin
124
- }${getUrlPathWithLocale(redirectUrl, getCookie('pz-locale'))}`;
125
-
126
- await paymentRequestResponse.complete('success');
127
- window.location.href = redirectUrlWithLocale;
112
+ const paymentCompleteResponse = await dispatch(
113
+ checkoutApi.endpoints.setWalletCompletePage.initiate({
114
+ success: true
115
+ })
116
+ ).unwrap();
117
+
118
+ if (paymentCompleteResponse.errors) {
119
+ setErrors(paymentCompleteResponse.errors);
120
+ }
121
+
122
+ if (
123
+ paymentCompleteResponse.context_list.find(
124
+ (c) => c.page_name === 'ThankYouPage'
125
+ )
126
+ ) {
127
+ const redirectUrl = paymentCompleteResponse.context_list.find(
128
+ (c) => c.page_name === 'ThankYouPage'
129
+ )?.page_context.context_data.redirect_url;
130
+
131
+ const redirectUrlWithLocale = `${
132
+ window.location.origin
133
+ }${getUrlPathWithLocale(redirectUrl, getCookie('pz-locale'))}`;
134
+
135
+ await paymentRequestResponse.complete('success');
136
+ window.location.href = redirectUrlWithLocale;
137
+ } else {
138
+ await paymentRequestResponse.complete('fail');
139
+ }
128
140
  } else {
129
141
  await paymentRequestResponse.complete('fail');
130
142
  }
131
- } else {
132
- await paymentRequestResponse.complete('fail');
133
143
  }
144
+ } catch (error) {
145
+ console.error('Apple Pay error:', error);
146
+ setErrors(error?.message || t('checkout.apple_pay.payment_failed'));
147
+ } finally {
148
+ setIsProcessing(false);
134
149
  }
135
150
  };
136
151
 
@@ -139,6 +154,7 @@ export default function useApplePay() {
139
154
  paymentErrors,
140
155
  setPaymentErrors: setErrors,
141
156
  onMerchantValidation,
142
- initPaymentRequest
157
+ initPaymentRequest,
158
+ isProcessing
143
159
  };
144
160
  }
@@ -1,22 +1,41 @@
1
1
  'use client';
2
2
 
3
+ import { JSX } from 'react';
3
4
  import { useAppSelector } from '@akinon/next/redux/hooks';
5
+ import { useLocalization } from '@akinon/next/hooks';
4
6
  import { RootState } from '@theme/redux/store';
5
7
  import useApplePay from '../hooks/use-apple-pay';
6
8
 
7
- export default function ApplePay() {
9
+ export interface ApplePayProps {
10
+ customUIRender?: (props: {
11
+ initPaymentRequest?: () => void;
12
+ paymentErrors?: string | null;
13
+ }) => JSX.Element | null;
14
+ }
15
+
16
+ export default function ApplePay({ customUIRender }: ApplePayProps) {
8
17
  const { walletPaymentData } = useAppSelector(
9
18
  (state: RootState) => state.checkout
10
19
  );
11
- const { paymentErrors, initPaymentRequest } = useApplePay();
20
+ const { t } = useLocalization();
21
+ const { paymentErrors, initPaymentRequest, isProcessing } = useApplePay();
12
22
 
13
23
  if (!walletPaymentData) {
14
24
  return null;
15
25
  }
16
26
 
27
+ if (customUIRender) {
28
+ return customUIRender({
29
+ initPaymentRequest,
30
+ paymentErrors
31
+ });
32
+ }
33
+
17
34
  return (
18
35
  <div>
19
- <button onClick={initPaymentRequest}>Pay with Apple Pay</button>
36
+ <button onClick={initPaymentRequest} disabled={isProcessing}>
37
+ {isProcessing ? t('checkout.apple_pay.processing') : t('checkout.apple_pay.pay_button')}
38
+ </button>
20
39
 
21
40
  {paymentErrors?.length > 0 && (
22
41
  <div className="text-error-100 text-xs mt-5">{paymentErrors}</div>