@akinon/pz-apple-pay 2.0.0-beta.2 → 2.0.0-beta.20

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,18 +1,127 @@
1
1
  # @akinon/pz-apple-pay
2
2
 
3
- ## 2.0.0-beta.2
3
+ ## 2.0.0-beta.20
4
4
 
5
- ## 2.0.0-beta.1
5
+ ## 1.125.0
6
+
7
+ ## 1.124.0
8
+
9
+ ## 1.123.0
10
+
11
+ ## 1.122.0
12
+
13
+ ## 1.121.0
14
+
15
+ ## 1.120.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 6ad72e8d: ZERO-4032: Add loading state management for payment submissions across multiple components and add safe guarding
20
+
21
+ ## 1.119.0
22
+
23
+ ## 1.118.0
24
+
25
+ ## 1.117.0
26
+
27
+ ## 1.116.0
28
+
29
+ ## 1.115.0
30
+
31
+ ## 1.114.0
32
+
33
+ ## 1.113.0
34
+
35
+ ## 1.112.0
36
+
37
+ ## 1.111.0
38
+
39
+ ## 1.110.0
40
+
41
+ ## 1.109.0
42
+
43
+ ## 1.108.0
44
+
45
+ ### Minor Changes
46
+
47
+ - d8883ce6: ZERO-3640: Refactor wallet completion handling to accept additional parameters; update related API calls
48
+ - 31a2d35a: ZERO-3640: Refactor checkout API call to include useFormData option; update FlowPayment component for improved error handling and code readability
49
+
50
+ ## 1.107.0
51
+
52
+ ## 1.106.0
53
+
54
+ ## 1.105.0
55
+
56
+ ## 1.104.0
57
+
58
+ ## 1.103.0
59
+
60
+ ## 1.102.0
61
+
62
+ ## 1.101.0
63
+
64
+ ## 1.100.0
65
+
66
+ ## 1.99.0
67
+
68
+ ### Minor Changes
69
+
70
+ - d58538b: ZERO-3638: Enhance RC pipeline: add fetch, merge, and pre-release setup with conditional commit
71
+
72
+ ## 1.98.0
73
+
74
+ ## 1.97.0
75
+
76
+ ## 1.96.0
77
+
78
+ ## 1.95.0
79
+
80
+ ## 1.94.0
81
+
82
+ ## 1.93.0
83
+
84
+ ## 1.92.0
85
+
86
+ ## 1.91.0
87
+
88
+ ## 1.90.0
6
89
 
7
90
  ### Minor Changes
8
91
 
9
- - ZERO-3091: Upgrade Next.js to v15 and React to v19
92
+ - f2e9d1d: ZERO-3383: Add custom UI rendering option for apple pay
93
+
94
+ ## 1.89.0
95
+
96
+ ## 1.88.0
97
+
98
+ ## 1.87.0
99
+
100
+ ## 1.86.0
101
+
102
+ ## 1.85.0
103
+
104
+ ## 1.84.0
105
+
106
+ ### Minor Changes
107
+
108
+ - 624a4eb: ZERO-3276: Update installation instructions across multiple README files to standardize format and improve clarity
109
+
110
+ ## 1.83.0
111
+
112
+ ## 1.82.0
113
+
114
+ ## 1.81.0
115
+
116
+ ## 1.80.0
117
+
118
+ ## 1.79.0
10
119
 
11
- ## 2.0.0-beta.0
120
+ ## 1.78.0
12
121
 
13
- ### Major Changes
122
+ ## 1.77.0
14
123
 
15
- - be6c09d: ZERO-3114: Create beta version.
124
+ ## 1.76.0
16
125
 
17
126
  ## 1.75.0
18
127
 
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@akinon/pz-apple-pay",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.20",
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.4",
16
+ "react-dom": "^19.2.4",
17
+ "typescript": "^5.2.2"
18
18
  }
19
19
  }
package/readme.md CHANGED
@@ -2,20 +2,10 @@
2
2
 
3
3
  ## Installation
4
4
 
5
- There are two ways to install the Apple Pay plugin:
6
-
7
- ### 1. Install the npm package using Yarn
8
-
9
- For the latest version, you can install the package using Yarn:
5
+ You can use the following command to install the extension with the latest plugins:
10
6
 
11
7
  ```bash
12
- yarn add @akinon/pz-apple-pay
13
- ```
14
-
15
- ### 2. Preferred installation method
16
8
 
17
- You can also use the following command to install the extension with the latest plugins:
18
-
19
- ```bash
20
9
  npx @akinon/projectzero@latest --plugins
10
+
21
11
  ```
@@ -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>