@akinon/pz-apple-pay 1.119.0-rc.2 → 1.119.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 +1 -13
- package/package.json +1 -1
- package/src/hooks/use-apple-pay.tsx +39 -51
- package/src/views/index.tsx +2 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
# @akinon/pz-apple-pay
|
|
2
2
|
|
|
3
|
-
## 1.119.0
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- 6ad72e8d: ZERO-4032: Add loading state management for payment submissions across multiple components and add safe guarding
|
|
8
|
-
|
|
9
|
-
## 1.119.0-rc.1
|
|
10
|
-
|
|
11
|
-
## 1.119.0-rc.0
|
|
12
|
-
|
|
13
|
-
### Minor Changes
|
|
14
|
-
|
|
15
|
-
- 6ad72e8d: ZERO-4032: Add loading state management for payment submissions across multiple components and add safe guarding
|
|
3
|
+
## 1.119.0
|
|
16
4
|
|
|
17
5
|
## 1.118.0
|
|
18
6
|
|
package/package.json
CHANGED
|
@@ -11,7 +11,6 @@ export default function useApplePay() {
|
|
|
11
11
|
);
|
|
12
12
|
const dispatch = useAppDispatch();
|
|
13
13
|
const [errors, setErrors] = useState(null);
|
|
14
|
-
const [isProcessing, setIsProcessing] = useState(false);
|
|
15
14
|
|
|
16
15
|
const paymentErrors = useMemo(() => {
|
|
17
16
|
if (typeof errors === 'string') {
|
|
@@ -80,70 +79,60 @@ export default function useApplePay() {
|
|
|
80
79
|
}, [walletPaymentData]);
|
|
81
80
|
|
|
82
81
|
const initPaymentRequest = async () => {
|
|
83
|
-
if (isProcessing) return;
|
|
84
|
-
|
|
85
|
-
setIsProcessing(true);
|
|
86
82
|
setErrors(null);
|
|
87
83
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
const request = paymentRequest;
|
|
85
|
+
const paymentRequestResponse = await request.show();
|
|
86
|
+
|
|
87
|
+
if (paymentRequestResponse.details?.token?.paymentData) {
|
|
88
|
+
const paymentData = paymentRequestResponse.details.token.paymentData;
|
|
89
|
+
|
|
90
|
+
const walletPaymentPageResponse = await dispatch(
|
|
91
|
+
checkoutApi.endpoints.setWalletPaymentPage.initiate({
|
|
92
|
+
payment_token: JSON.stringify(paymentData)
|
|
93
|
+
})
|
|
94
|
+
).unwrap();
|
|
91
95
|
|
|
92
|
-
if (
|
|
93
|
-
|
|
96
|
+
if (walletPaymentPageResponse.errors) {
|
|
97
|
+
setErrors(walletPaymentPageResponse.errors);
|
|
98
|
+
}
|
|
94
99
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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({
|
|
107
|
+
success: true
|
|
98
108
|
})
|
|
99
109
|
).unwrap();
|
|
100
110
|
|
|
101
|
-
if (
|
|
102
|
-
setErrors(
|
|
111
|
+
if (paymentCompleteResponse.errors) {
|
|
112
|
+
setErrors(paymentCompleteResponse.errors);
|
|
103
113
|
}
|
|
104
114
|
|
|
105
115
|
if (
|
|
106
|
-
|
|
107
|
-
(c) => c.page_name === '
|
|
116
|
+
paymentCompleteResponse.context_list.find(
|
|
117
|
+
(c) => c.page_name === 'ThankYouPage'
|
|
108
118
|
)
|
|
109
119
|
) {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
paymentCompleteResponse.context_list.find(
|
|
122
|
-
(c) => c.page_name === 'ThankYouPage'
|
|
123
|
-
)
|
|
124
|
-
) {
|
|
125
|
-
const redirectUrl = paymentCompleteResponse.context_list.find(
|
|
126
|
-
(c) => c.page_name === 'ThankYouPage'
|
|
127
|
-
)?.page_context.context_data.redirect_url;
|
|
128
|
-
|
|
129
|
-
const redirectUrlWithLocale = `${
|
|
130
|
-
window.location.origin
|
|
131
|
-
}${getUrlPathWithLocale(redirectUrl, getCookie('pz-locale'))}`;
|
|
132
|
-
|
|
133
|
-
await paymentRequestResponse.complete('success');
|
|
134
|
-
window.location.href = redirectUrlWithLocale;
|
|
135
|
-
} else {
|
|
136
|
-
await paymentRequestResponse.complete('fail');
|
|
137
|
-
}
|
|
120
|
+
const redirectUrl = paymentCompleteResponse.context_list.find(
|
|
121
|
+
(c) => c.page_name === 'ThankYouPage'
|
|
122
|
+
)?.page_context.context_data.redirect_url;
|
|
123
|
+
|
|
124
|
+
const redirectUrlWithLocale = `${
|
|
125
|
+
window.location.origin
|
|
126
|
+
}${getUrlPathWithLocale(redirectUrl, getCookie('pz-locale'))}`;
|
|
127
|
+
|
|
128
|
+
await paymentRequestResponse.complete('success');
|
|
129
|
+
window.location.href = redirectUrlWithLocale;
|
|
138
130
|
} else {
|
|
139
131
|
await paymentRequestResponse.complete('fail');
|
|
140
132
|
}
|
|
133
|
+
} else {
|
|
134
|
+
await paymentRequestResponse.complete('fail');
|
|
141
135
|
}
|
|
142
|
-
} catch (error) {
|
|
143
|
-
console.error('Apple Pay error:', error);
|
|
144
|
-
setErrors(error?.message || 'Payment failed');
|
|
145
|
-
} finally {
|
|
146
|
-
setIsProcessing(false);
|
|
147
136
|
}
|
|
148
137
|
};
|
|
149
138
|
|
|
@@ -152,7 +141,6 @@ export default function useApplePay() {
|
|
|
152
141
|
paymentErrors,
|
|
153
142
|
setPaymentErrors: setErrors,
|
|
154
143
|
onMerchantValidation,
|
|
155
|
-
initPaymentRequest
|
|
156
|
-
isProcessing
|
|
144
|
+
initPaymentRequest
|
|
157
145
|
};
|
|
158
146
|
}
|
package/src/views/index.tsx
CHANGED
|
@@ -15,7 +15,7 @@ export default function ApplePay({ customUIRender }: ApplePayProps) {
|
|
|
15
15
|
const { walletPaymentData } = useAppSelector(
|
|
16
16
|
(state: RootState) => state.checkout
|
|
17
17
|
);
|
|
18
|
-
const { paymentErrors, initPaymentRequest
|
|
18
|
+
const { paymentErrors, initPaymentRequest } = useApplePay();
|
|
19
19
|
|
|
20
20
|
if (!walletPaymentData) {
|
|
21
21
|
return null;
|
|
@@ -30,9 +30,7 @@ export default function ApplePay({ customUIRender }: ApplePayProps) {
|
|
|
30
30
|
|
|
31
31
|
return (
|
|
32
32
|
<div>
|
|
33
|
-
<button onClick={initPaymentRequest}
|
|
34
|
-
{isProcessing ? 'Processing...' : 'Pay with Apple Pay'}
|
|
35
|
-
</button>
|
|
33
|
+
<button onClick={initPaymentRequest}>Pay with Apple Pay</button>
|
|
36
34
|
|
|
37
35
|
{paymentErrors?.length > 0 && (
|
|
38
36
|
<div className="text-error-100 text-xs mt-5">{paymentErrors}</div>
|