@akinon/pz-apple-pay 2.0.0-beta.8 → 2.0.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,39 +1,149 @@
1
1
  # @akinon/pz-apple-pay
2
2
 
3
- ## 2.0.0-beta.8
3
+ ## 2.0.0
4
4
 
5
- ## 2.0.0-beta.7
5
+ ## 2.0.0-beta.27
6
6
 
7
- ## 2.0.0-beta.6
7
+ ## 2.0.0-beta.26
8
+
9
+ ## 2.0.0-beta.25
10
+
11
+ ## 2.0.0-beta.24
12
+
13
+ ## 2.0.0-beta.23
14
+
15
+ ## 2.0.0-beta.22
16
+
17
+ ## 2.0.0-beta.21
18
+
19
+ ## 2.0.0-beta.20
20
+
21
+ ## 1.126.0
22
+
23
+ ## 1.125.2
24
+
25
+ ## 1.125.1
26
+
27
+ ## 1.125.0
28
+
29
+ ## 1.124.0
30
+
31
+ ## 1.123.0
32
+
33
+ ## 1.122.0
34
+
35
+ ## 1.121.0
36
+
37
+ ## 1.120.0
8
38
 
9
39
  ### Minor Changes
10
40
 
11
- - 8f05f9b: ZERO-3250: Beta branch synchronized with Main branch
41
+ - 6ad72e8d: ZERO-4032: Add loading state management for payment submissions across multiple components and add safe guarding
12
42
 
13
- ## 2.0.0-beta.5
43
+ ## 1.119.0
14
44
 
15
- ## 2.0.0-beta.4
45
+ ## 1.118.0
16
46
 
17
- ## 2.0.0-beta.3
47
+ ## 1.117.0
18
48
 
19
- ## 2.0.0-beta.2
49
+ ## 1.116.0
50
+
51
+ ## 1.115.0
52
+
53
+ ## 1.114.0
54
+
55
+ ## 1.113.0
56
+
57
+ ## 1.112.0
58
+
59
+ ## 1.111.0
60
+
61
+ ## 1.110.0
62
+
63
+ ## 1.109.0
64
+
65
+ ## 1.108.0
20
66
 
21
67
  ### Minor Changes
22
68
 
23
- - a006015: ZERO-3116: Add not-found page and update default middleware.
24
- - 1eeb3d8: ZERO-3116: Add not found page
69
+ - d8883ce6: ZERO-3640: Refactor wallet completion handling to accept additional parameters; update related API calls
70
+ - 31a2d35a: ZERO-3640: Refactor checkout API call to include useFormData option; update FlowPayment component for improved error handling and code readability
71
+
72
+ ## 1.107.0
73
+
74
+ ## 1.106.0
75
+
76
+ ## 1.105.0
77
+
78
+ ## 1.104.0
79
+
80
+ ## 1.103.0
81
+
82
+ ## 1.102.0
25
83
 
26
- ## 2.0.0-beta.1
84
+ ## 1.101.0
85
+
86
+ ## 1.100.0
87
+
88
+ ## 1.99.0
89
+
90
+ ### Minor Changes
91
+
92
+ - d58538b: ZERO-3638: Enhance RC pipeline: add fetch, merge, and pre-release setup with conditional commit
93
+
94
+ ## 1.98.0
95
+
96
+ ## 1.97.0
97
+
98
+ ## 1.96.0
99
+
100
+ ## 1.95.0
101
+
102
+ ## 1.94.0
103
+
104
+ ## 1.93.0
105
+
106
+ ## 1.92.0
107
+
108
+ ## 1.91.0
109
+
110
+ ## 1.90.0
27
111
 
28
112
  ### Minor Changes
29
113
 
30
- - ZERO-3091: Upgrade Next.js to v15 and React to v19
114
+ - f2e9d1d: ZERO-3383: Add custom UI rendering option for apple pay
115
+
116
+ ## 1.89.0
117
+
118
+ ## 1.88.0
119
+
120
+ ## 1.87.0
121
+
122
+ ## 1.86.0
123
+
124
+ ## 1.85.0
125
+
126
+ ## 1.84.0
127
+
128
+ ### Minor Changes
129
+
130
+ - 624a4eb: ZERO-3276: Update installation instructions across multiple README files to standardize format and improve clarity
131
+
132
+ ## 1.83.0
133
+
134
+ ## 1.82.0
135
+
136
+ ## 1.81.0
137
+
138
+ ## 1.80.0
139
+
140
+ ## 1.79.0
31
141
 
32
- ## 2.0.0-beta.0
142
+ ## 1.78.0
33
143
 
34
- ### Major Changes
144
+ ## 1.77.0
35
145
 
36
- - be6c09d: ZERO-3114: Create beta version.
146
+ ## 1.76.0
37
147
 
38
148
  ## 1.75.0
39
149
 
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@akinon/pz-apple-pay",
3
- "version": "2.0.0-beta.8",
3
+ "version": "2.0.0",
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>