strapi-plugin-payone-provider 1.5.8 → 1.6.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.
Files changed (53) hide show
  1. package/admin/src/index.js +3 -3
  2. package/admin/src/pages/App/components/ApplePayBtn.jsx +304 -0
  3. package/admin/src/pages/App/components/{ApplePayButton.js → ApplePayButton.jsx} +141 -137
  4. package/admin/src/pages/App/components/{ApplePayConfig.js → ApplePayConfig.jsx} +64 -130
  5. package/admin/src/pages/App/components/{PaymentActionsPanel.js → PaymentActionsPanel.jsx} +62 -14
  6. package/admin/src/pages/App/components/icons/index.jsx +11 -0
  7. package/admin/src/pages/App/components/paymentActions/{AuthorizationForm.js → AuthorizationForm.jsx} +45 -35
  8. package/admin/src/pages/App/components/paymentActions/{PaymentMethodSelector.js → PaymentMethodSelector.jsx} +111 -31
  9. package/admin/src/pages/App/components/paymentActions/{PreauthorizationForm.js → PreauthorizationForm.jsx} +3 -70
  10. package/admin/src/pages/constants/paymentConstants.js +1 -2
  11. package/admin/src/pages/hooks/usePaymentActions.js +1 -76
  12. package/package.json +49 -49
  13. package/server/bootstrap.js +59 -1
  14. package/server/controllers/payone.js +6 -48
  15. package/server/routes/index.js +1 -1
  16. package/server/services/applePayService.js +51 -407
  17. package/server/services/paymentService.js +0 -68
  18. package/server/services/payone.js +0 -3
  19. package/server/services/settingsService.js +0 -21
  20. package/server/services/testConnectionService.js +0 -14
  21. package/server/services/transactionService.js +2 -16
  22. package/server/utils/paymentMethodParams.js +60 -21
  23. package/server/utils/requestBuilder.js +0 -22
  24. package/admin/src/pages/App/components/icons/index.js +0 -11
  25. /package/admin/src/components/Initializer/{index.js → index.jsx} +0 -0
  26. /package/admin/src/components/PluginIcon/{index.js → index.jsx} +0 -0
  27. /package/admin/src/pages/App/components/{AppHeader.js → AppHeader.jsx} +0 -0
  28. /package/admin/src/pages/App/components/{AppTabs.js → AppTabs.jsx} +0 -0
  29. /package/admin/src/pages/App/components/{ApplePayConfigPanel.js → ApplePayConfigPanel.jsx} +0 -0
  30. /package/admin/src/pages/App/components/{ConfigurationPanel.js → ConfigurationPanel.jsx} +0 -0
  31. /package/admin/src/pages/App/components/{DocsPanel.js → DocsPanel.jsx} +0 -0
  32. /package/admin/src/pages/App/components/{GooglePayConfig.js → GooglePayConfig.jsx} +0 -0
  33. /package/admin/src/pages/App/components/{GooglePayConfigPanel.js → GooglePayConfigPanel.jsx} +0 -0
  34. /package/admin/src/pages/App/components/{GooglePaybutton.js → GooglePaybutton.jsx} +0 -0
  35. /package/admin/src/pages/App/components/{HistoryPanel.js → HistoryPanel.jsx} +0 -0
  36. /package/admin/src/pages/App/components/{StatusBadge.js → StatusBadge.jsx} +0 -0
  37. /package/admin/src/pages/App/components/{TransactionHistoryItem.js → TransactionHistoryItem.jsx} +0 -0
  38. /package/admin/src/pages/App/components/icons/{BankIcon.js → BankIcon.jsx} +0 -0
  39. /package/admin/src/pages/App/components/icons/{ChevronDownIcon.js → ChevronDownIcon.jsx} +0 -0
  40. /package/admin/src/pages/App/components/icons/{ChevronUpIcon.js → ChevronUpIcon.jsx} +0 -0
  41. /package/admin/src/pages/App/components/icons/{CreditCardIcon.js → CreditCardIcon.jsx} +0 -0
  42. /package/admin/src/pages/App/components/icons/{ErrorIcon.js → ErrorIcon.jsx} +0 -0
  43. /package/admin/src/pages/App/components/icons/{InfoIcon.js → InfoIcon.jsx} +0 -0
  44. /package/admin/src/pages/App/components/icons/{PaymentIcon.js → PaymentIcon.jsx} +0 -0
  45. /package/admin/src/pages/App/components/icons/{PendingIcon.js → PendingIcon.jsx} +0 -0
  46. /package/admin/src/pages/App/components/icons/{PersonIcon.js → PersonIcon.jsx} +0 -0
  47. /package/admin/src/pages/App/components/icons/{SuccessIcon.js → SuccessIcon.jsx} +0 -0
  48. /package/admin/src/pages/App/components/icons/{WalletIcon.js → WalletIcon.jsx} +0 -0
  49. /package/admin/src/pages/App/components/paymentActions/{CaptureForm.js → CaptureForm.jsx} +0 -0
  50. /package/admin/src/pages/App/components/paymentActions/{CardDetailsInput.js → CardDetailsInput.jsx} +0 -0
  51. /package/admin/src/pages/App/components/paymentActions/{PaymentResult.js → PaymentResult.jsx} +0 -0
  52. /package/admin/src/pages/App/components/paymentActions/{RefundForm.js → RefundForm.jsx} +0 -0
  53. /package/admin/src/pages/App/{index.js → index.jsx} +0 -0
@@ -1,7 +1,7 @@
1
1
  import pluginPkg from "../../package.json";
2
2
  import pluginId from "./pluginId";
3
- import Initializer from "./components/Initializer";
4
- import PluginIcon from "./components/PluginIcon";
3
+ import Initializer from "./components/Initializer/index.jsx";
4
+ import PluginIcon from "./components/PluginIcon/index.jsx";
5
5
  import { injectGooglePayScript } from "./pages/utils/injectGooglePayScript";
6
6
 
7
7
  const name = pluginPkg.strapi.name;
@@ -16,7 +16,7 @@ export default {
16
16
  defaultMessage: "Payone Provider"
17
17
  },
18
18
  Component: async () => {
19
- const component = await import("./pages/App");
19
+ const component = await import("./pages/App/index.jsx");
20
20
  return component;
21
21
  },
22
22
  permissions: []
@@ -0,0 +1,304 @@
1
+ import React from "react";
2
+ import ApplePayButton from "apple-pay-button";
3
+ import { Box, Typography, Alert } from "@strapi/design-system";
4
+ import { request } from "@strapi/helper-plugin";
5
+ import pluginId from "../../../pluginId";
6
+
7
+ const ApplePayBtn = ({
8
+ amount,
9
+ onTokenReceived,
10
+ onError,
11
+ settings,
12
+ buttonStyle = "black",
13
+ type = "pay",
14
+ }) => {
15
+ const handleEventsForApplePay = (session, amountValue, currencyCode) => {
16
+ session.onvalidatemerchant = async (event) => {
17
+ try {
18
+ const merchantSession = await request(
19
+ `/${pluginId}/validate-apple-pay-merchant`,
20
+ {
21
+ method: "POST",
22
+ body: {
23
+ domain: window.location.hostname,
24
+ displayName: settings?.merchantName || "Store",
25
+ currency: currencyCode,
26
+ },
27
+ }
28
+ );
29
+
30
+ if (merchantSession.error) {
31
+ throw new Error(
32
+ merchantSession.error.message || "Merchant validation failed"
33
+ );
34
+ }
35
+
36
+ const sessionData = merchantSession.data || merchantSession;
37
+
38
+ if (!sessionData || !sessionData.merchantIdentifier) {
39
+ console.error(
40
+ "[Apple Pay Button] Invalid merchant session: missing merchantIdentifier"
41
+ );
42
+ throw new Error(
43
+ "Invalid merchant session: missing merchantIdentifier"
44
+ );
45
+ }
46
+
47
+ session.completeMerchantValidation(sessionData);
48
+ console.log(
49
+ "[Apple Pay Button] Merchant validation completed successfully"
50
+ );
51
+ } catch (error) {
52
+ console.error("[Apple Pay Button] Merchant validation error:", error);
53
+ if (onError) {
54
+ onError(error);
55
+ }
56
+ session.completeMerchantValidation({});
57
+ }
58
+ };
59
+
60
+ session.onpaymentmethodselected = (event) => {
61
+ const update = {
62
+ newTotal: {
63
+ label: settings?.merchantName || "Total",
64
+ type: "final",
65
+ amount: amountValue,
66
+ },
67
+ };
68
+ session.completePaymentMethodSelection(update);
69
+ };
70
+
71
+ session.onshippingmethodselected = (event) => {
72
+ const update = {
73
+ newTotal: {
74
+ label: settings?.merchantName || "Total",
75
+ type: "final",
76
+ amount: amountValue,
77
+ },
78
+ };
79
+ session.completeShippingMethodSelection(update);
80
+ };
81
+
82
+ session.onshippingcontactselected = (event) => {
83
+ const update = {
84
+ newTotal: {
85
+ label: settings?.merchantName || "Total",
86
+ type: "final",
87
+ amount: amountValue,
88
+ },
89
+ };
90
+ session.completeShippingContactSelection(update);
91
+ };
92
+
93
+ session.onpaymentauthorized = async (event) => {
94
+ try {
95
+ const paymentData = event.payment;
96
+
97
+ if (!paymentData || !paymentData.token) {
98
+ const result = {
99
+ status: window.ApplePaySession.STATUS_FAILURE,
100
+ };
101
+ session.completePayment(result);
102
+ if (onError) {
103
+ onError(new Error("Payment token is missing"));
104
+ }
105
+ return;
106
+ }
107
+
108
+ const tokenObject = paymentData.token;
109
+
110
+ if (!tokenObject.paymentData) {
111
+ console.error(
112
+ "[Apple Pay] Invalid token structure: missing paymentData"
113
+ );
114
+ const result = {
115
+ status: window.ApplePaySession.STATUS_FAILURE,
116
+ };
117
+ session.completePayment(result);
118
+ if (onError) {
119
+ onError(new Error("Invalid Apple Pay token structure"));
120
+ }
121
+ return;
122
+ }
123
+
124
+ // Encode token as Base64 for transmission
125
+ let tokenString;
126
+ try {
127
+ tokenString = btoa(
128
+ unescape(encodeURIComponent(JSON.stringify(tokenObject)))
129
+ );
130
+ } catch (e) {
131
+ console.error("[Apple Pay] Token encoding error:", e);
132
+ tokenString = btoa(
133
+ unescape(encodeURIComponent(JSON.stringify(tokenObject)))
134
+ );
135
+ }
136
+
137
+ if (onTokenReceived) {
138
+ const result = await onTokenReceived(tokenString, {
139
+ paymentToken: tokenObject,
140
+ billingContact: paymentData.billingContact,
141
+ shippingContact: paymentData.shippingContact,
142
+ amount: amountValue, //
143
+ currency: currencyCode,
144
+ });
145
+
146
+ if (result && typeof result.then === "function") {
147
+ await result;
148
+ }
149
+
150
+ const paymentResult = {
151
+ status: window.ApplePaySession.STATUS_SUCCESS,
152
+ };
153
+ session.completePayment(paymentResult);
154
+ } else {
155
+ const paymentResult = {
156
+ status: window.ApplePaySession.STATUS_SUCCESS,
157
+ };
158
+ session.completePayment(paymentResult);
159
+ }
160
+ } catch (error) {
161
+ console.error("[Apple Pay] Payment authorization error:", error);
162
+ const result = {
163
+ status: window.ApplePaySession.STATUS_FAILURE,
164
+ };
165
+ session.completePayment(result);
166
+ if (onError) {
167
+ onError(error);
168
+ }
169
+ }
170
+ };
171
+
172
+ session.oncancel = (event) => {
173
+ console.log("[Apple Pay Button] Session cancelled by user");
174
+ };
175
+ };
176
+
177
+ const handleApplePayClick = () => {
178
+ if (!settings?.mid) {
179
+ const error = new Error(
180
+ "Merchant ID is not configured. Please set Merchant ID in plugin settings."
181
+ );
182
+ if (onError) {
183
+ onError(error);
184
+ }
185
+ return;
186
+ }
187
+
188
+ if (typeof window === "undefined" || !window.ApplePaySession) {
189
+ if (onError) {
190
+ onError(new Error("Apple Pay is not supported in this environment."));
191
+ }
192
+ return;
193
+ }
194
+
195
+ const amountValue = amount ? (parseFloat(amount) / 100).toFixed(2) : "0.00";
196
+ const applePayConfig = settings?.applePayConfig || {};
197
+ const supportedNetworks = applePayConfig.supportedNetworks || [
198
+ "visa",
199
+ "masterCard",
200
+ "amex",
201
+ ];
202
+ const merchantCapabilities = applePayConfig.merchantCapabilities || [
203
+ "supports3DS",
204
+ ];
205
+ const currencyCode = applePayConfig.currencyCode || "EUR";
206
+ const countryCode = applePayConfig.countryCode || "DE";
207
+
208
+ const applePayRequest = {
209
+ countryCode: countryCode,
210
+ currencyCode: currencyCode,
211
+ merchantCapabilities: merchantCapabilities,
212
+ supportedNetworks: supportedNetworks,
213
+ total: {
214
+ label: settings?.merchantName || "Total",
215
+ type: "final",
216
+ amount: amountValue,
217
+ },
218
+ };
219
+
220
+ const session = new window.ApplePaySession(3, applePayRequest);
221
+
222
+ handleEventsForApplePay(session, amountValue, currencyCode);
223
+
224
+ session.begin();
225
+ };
226
+
227
+ const mode = (settings?.mode || 'test').toLowerCase();
228
+ const isLiveMode = mode === 'live';
229
+
230
+ if (!settings?.mid) {
231
+ return (
232
+ <Box>
233
+ <Alert closeLabel="Close" title="Merchant ID Missing" variant="warning">
234
+ <Typography variant="pi" marginTop={2}>
235
+ Merchant ID is not configured. Please set Merchant ID in plugin
236
+ settings. You can find your merchantIdentifier in PMI at:
237
+ CONFIGURATION → PAYMENT PORTALS → [Your Portal] → Payment type
238
+ configuration tab.
239
+ </Typography>
240
+ </Alert>
241
+ </Box>
242
+ );
243
+ }
244
+
245
+ if (!isLiveMode) {
246
+ return (
247
+ <Box>
248
+ <Alert closeLabel="Close" title="⚠️ Apple Pay Only Works in Live Mode" variant="danger">
249
+ <Typography variant="pi" marginTop={2}>
250
+ <strong>Apple Pay is only supported in live mode.</strong> According to Payone documentation, test mode support will be available at a later time.
251
+ </Typography>
252
+ <Typography variant="pi" marginTop={2}>
253
+ Please switch to <strong>live mode</strong> in plugin settings to use Apple Pay.
254
+ </Typography>
255
+ <Typography variant="pi" marginTop={2} fontWeight="bold" textColor="danger600">
256
+ ⚠️ Apple Pay will NOT work in test mode!
257
+ </Typography>
258
+ </Alert>
259
+ </Box>
260
+ );
261
+ }
262
+
263
+ const buttonStyleMap = {
264
+ black: "black",
265
+ white: "white",
266
+ "white-outline": "white-outline",
267
+ };
268
+
269
+ const buttonTypeMap = {
270
+ pay: "plain",
271
+ buy: "buy",
272
+ donate: "donate",
273
+ "check-out": "check-out",
274
+ book: "book",
275
+ subscribe: "subscribe",
276
+ };
277
+
278
+ const nativeButtonStyle = buttonStyleMap[buttonStyle] || "black";
279
+ const nativeButtonType = buttonTypeMap[type] || "plain";
280
+
281
+ return (
282
+ <Box style={{ minHeight: "40px", width: "100%" }}>
283
+ <ApplePayButton
284
+ onClick={handleApplePayClick}
285
+ buttonStyle={nativeButtonStyle}
286
+ type={nativeButtonType}
287
+ style={{
288
+ width: "100%",
289
+ borderRadius: "8px",
290
+ }}
291
+ />
292
+ <Typography
293
+ variant="pi"
294
+ textColor="neutral600"
295
+ style={{ fontSize: "12px", marginTop: "8px", marginRight: "6px" }}
296
+ >
297
+ Apple Pay does NOT work on localhost. Use a production domain with
298
+ HTTPS.
299
+ </Typography>
300
+ </Box>
301
+ );
302
+ };
303
+
304
+ export default ApplePayBtn;