strapi-plugin-payone-provider 5.7.26 → 5.8.26
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/README.md +1191 -1191
- package/admin/src/components/Initializer/index.jsx +16 -16
- package/admin/src/components/PluginIcon/index.jsx +17 -17
- package/admin/src/index.js +57 -57
- package/admin/src/pages/App/components/AppHeader.jsx +45 -45
- package/admin/src/pages/App/components/AppTabs.jsx +105 -105
- package/admin/src/pages/App/components/ApplePayBtn.jsx +355 -355
- package/admin/src/pages/App/components/ApplePayConfig.jsx +357 -357
- package/admin/src/pages/App/components/DocsPanel.jsx +53 -53
- package/admin/src/pages/App/components/RenderInput.jsx +78 -78
- package/admin/src/pages/App/components/StatusBadge.jsx +87 -87
- package/admin/src/pages/App/components/icons/BankIcon.jsx +10 -10
- package/admin/src/pages/App/components/icons/ChevronDownIcon.jsx +9 -9
- package/admin/src/pages/App/components/icons/ChevronUpIcon.jsx +9 -9
- package/admin/src/pages/App/components/icons/CreditCardIcon.jsx +9 -9
- package/admin/src/pages/App/components/icons/ErrorIcon.jsx +10 -10
- package/admin/src/pages/App/components/icons/InfoIcon.jsx +9 -9
- package/admin/src/pages/App/components/icons/MarkCircle.jsx +19 -19
- package/admin/src/pages/App/components/icons/PaymentIcon.jsx +10 -10
- package/admin/src/pages/App/components/icons/PendingIcon.jsx +9 -9
- package/admin/src/pages/App/components/icons/PersonIcon.jsx +9 -9
- package/admin/src/pages/App/components/icons/SuccessIcon.jsx +9 -9
- package/admin/src/pages/App/components/icons/WalletIcon.jsx +9 -9
- package/admin/src/pages/App/components/icons/index.jsx +12 -12
- package/admin/src/pages/App/components/payment-actions/AuthorizationForm.jsx +334 -334
- package/admin/src/pages/App/components/payment-actions/CaptureForm.jsx +120 -120
- package/admin/src/pages/App/components/payment-actions/PaymentActionsPanel.jsx +183 -183
- package/admin/src/pages/App/components/payment-actions/PaymentMethodSelector.jsx +315 -315
- package/admin/src/pages/App/components/payment-actions/PaymentResult.jsx +129 -129
- package/admin/src/pages/App/components/payment-actions/PreauthorizationForm.jsx +273 -273
- package/admin/src/pages/App/components/payment-actions/RefundForm.jsx +114 -114
- package/admin/src/pages/App/components/transaction-history/ImportExportBar.jsx +153 -153
- package/admin/src/pages/App/components/transaction-history/details/TransactionHistoryItem.jsx +526 -526
- package/admin/src/pages/App/index.jsx +96 -96
- package/admin/src/pages/App/styles.css +176 -176
- package/admin/src/pages/constants/paymentConstants.js +71 -71
- package/admin/src/pages/hooks/use-system-theme.js +27 -27
- package/admin/src/pages/hooks/usePaymentActions.js +498 -498
- package/admin/src/pages/hooks/usePluginTranslations.js +12 -12
- package/admin/src/pages/hooks/useSettings.js +183 -183
- package/admin/src/pages/hooks/useTransactionHistory.js +148 -148
- package/admin/src/pages/utils/api.js +97 -97
- package/admin/src/pages/utils/applePayConstants.js +196 -196
- package/admin/src/pages/utils/formatTransactionData.js +15 -15
- package/admin/src/pages/utils/getInputComponent.jsx +200 -200
- package/admin/src/pages/utils/paymentUtils.js +661 -661
- package/admin/src/pages/utils/tooltipHelpers.js +18 -18
- package/admin/src/pages/utils/transactionTableUtils.js +71 -71
- package/admin/src/pluginId.js +9 -9
- package/admin/src/translations/de.json +235 -235
- package/admin/src/translations/en.json +235 -235
- package/admin/src/translations/fr.json +235 -235
- package/admin/src/translations/ru.json +235 -235
- package/admin/src/utils/prefixPluginTranslations.js +13 -13
- package/package.json +45 -45
- package/server/bootstrap.js +107 -107
- package/server/config/index.js +83 -83
- package/server/content-types/index.js +4 -4
- package/server/content-types/transactions/index.js +4 -4
- package/server/content-types/transactions/schema.json +86 -86
- package/server/controllers/index.js +7 -7
- package/server/controllers/payone.js +503 -506
- package/server/destroy.js +5 -5
- package/server/index.js +23 -23
- package/server/policies/index.js +7 -7
- package/server/policies/is-auth.js +29 -29
- package/server/policies/isSuperAdmin.js +20 -20
- package/server/register.js +5 -5
- package/server/routes/index.js +218 -218
- package/server/services/applePayService.js +295 -295
- package/server/services/index.js +9 -9
- package/server/services/paymentService.js +264 -223
- package/server/services/payone.js +78 -78
- package/server/services/settingsService.js +59 -59
- package/server/services/testConnectionService.js +115 -115
- package/server/services/transactionService.js +262 -262
- package/server/utils/csvTransactions.js +82 -82
- package/server/utils/normalize.js +39 -39
- package/server/utils/paymentMethodParams.js +288 -288
- package/server/utils/requestBuilder.js +115 -100
- package/server/utils/responseParser.js +141 -141
- package/strapi-admin.js +4 -4
- package/strapi-server.js +3 -3
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { Box, Flex, Typography, Button } from "@strapi/design-system";
|
|
3
|
-
import { Play } from "@strapi/icons";
|
|
4
|
-
import RenderInput from "../RenderInput";
|
|
5
|
-
import { getCurrencyOptions } from "../../../utils/countryLanguageUtils";
|
|
6
|
-
import { usePluginTranslations } from "../../../hooks/usePluginTranslations";
|
|
7
|
-
|
|
8
|
-
const RefundForm = ({ paymentActions }) => {
|
|
9
|
-
const { t } = usePluginTranslations();
|
|
10
|
-
const currencyOptions = getCurrencyOptions();
|
|
11
|
-
return (
|
|
12
|
-
<Flex direction="column" alignItems="stretch" gap={4}>
|
|
13
|
-
<Flex direction="row" gap={2}>
|
|
14
|
-
<Typography variant="omega" fontWeight="semiBold" textColor="neutral800" className="payment-form-title">
|
|
15
|
-
{t("refund.title", "Refund")}
|
|
16
|
-
</Typography>
|
|
17
|
-
<Typography variant="pi" textColor="neutral600" className="payment-form-description">
|
|
18
|
-
{t("refund.description", "Refund a captured payment.")}
|
|
19
|
-
</Typography>
|
|
20
|
-
</Flex>
|
|
21
|
-
|
|
22
|
-
<Box
|
|
23
|
-
style={{
|
|
24
|
-
display: "grid",
|
|
25
|
-
gridTemplateColumns: "repeat(auto-fit, minmax(250px, 1fr))",
|
|
26
|
-
gap: "16px",
|
|
27
|
-
}}
|
|
28
|
-
>
|
|
29
|
-
<RenderInput
|
|
30
|
-
name="refundTxid"
|
|
31
|
-
label={t("common.transactionId", "Transaction ID *")}
|
|
32
|
-
value={paymentActions.paymentState.refundTxid || ""}
|
|
33
|
-
onChange={(e) =>
|
|
34
|
-
paymentActions.handleFieldChange("refundTxid", e.target.value)
|
|
35
|
-
}
|
|
36
|
-
inputType="textInput"
|
|
37
|
-
placeholder={t("refund.placeholderTxid", "Enter TxId from capture")}
|
|
38
|
-
required
|
|
39
|
-
tooltipContent={t("refund.tooltipTxid", "Transaction ID from a previous capture")}
|
|
40
|
-
/>
|
|
41
|
-
|
|
42
|
-
<RenderInput
|
|
43
|
-
name="refundSequenceNumber"
|
|
44
|
-
label={t("refund.sequenceNumber", "Sequence Number")}
|
|
45
|
-
value={paymentActions.paymentState.refundSequenceNumber || "2"}
|
|
46
|
-
onChange={(e) =>
|
|
47
|
-
paymentActions.handleFieldChange(
|
|
48
|
-
"refundSequenceNumber",
|
|
49
|
-
e.target.value
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
inputType="textInput"
|
|
53
|
-
placeholder="2"
|
|
54
|
-
tooltipContent={t("refund.tooltipSequence", "Sequence number for this refund (1-127), default is 2 for first refund")}
|
|
55
|
-
/>
|
|
56
|
-
|
|
57
|
-
<RenderInput
|
|
58
|
-
name="refundAmount"
|
|
59
|
-
label={t("common.amount", "Amount *")}
|
|
60
|
-
value={paymentActions.paymentState.paymentAmount || ""}
|
|
61
|
-
onChange={(e) =>
|
|
62
|
-
paymentActions.handleFieldChange("paymentAmount", e.target.value)
|
|
63
|
-
}
|
|
64
|
-
inputType="textInput"
|
|
65
|
-
placeholder="1000"
|
|
66
|
-
required
|
|
67
|
-
tooltipContent={t("refund.tooltipAmount", "Amount in cents to refund (will be negative automatically)")}
|
|
68
|
-
/>
|
|
69
|
-
|
|
70
|
-
<RenderInput
|
|
71
|
-
name="refundCurrency"
|
|
72
|
-
label={t("common.currency", "Currency")}
|
|
73
|
-
value={paymentActions.paymentState.refundCurrency || "EUR"}
|
|
74
|
-
onChange={(e) =>
|
|
75
|
-
paymentActions.handleFieldChange("refundCurrency", e.target.value)
|
|
76
|
-
}
|
|
77
|
-
inputType="select"
|
|
78
|
-
options={currencyOptions}
|
|
79
|
-
placeholder="EUR"
|
|
80
|
-
tooltipContent="Currency code (e.g., EUR, USD)"
|
|
81
|
-
/>
|
|
82
|
-
|
|
83
|
-
<RenderInput
|
|
84
|
-
name="refundReference"
|
|
85
|
-
label="Reference"
|
|
86
|
-
value={paymentActions.paymentState.refundReference || ""}
|
|
87
|
-
onChange={(e) =>
|
|
88
|
-
paymentActions.handleFieldChange("refundReference", e.target.value)
|
|
89
|
-
}
|
|
90
|
-
inputType="textInput"
|
|
91
|
-
placeholder="Optional reference"
|
|
92
|
-
tooltipContent="Optional reference for this refund"
|
|
93
|
-
/>
|
|
94
|
-
</Box>
|
|
95
|
-
|
|
96
|
-
<Button
|
|
97
|
-
variant="default"
|
|
98
|
-
onClick={() => paymentActions.handleRefund()}
|
|
99
|
-
loading={paymentActions.isProcessingPayment}
|
|
100
|
-
startIcon={<Play />}
|
|
101
|
-
style={{ maxWidth: "200px" }}
|
|
102
|
-
className="payment-button payment-button-primary"
|
|
103
|
-
disabled={
|
|
104
|
-
!paymentActions.paymentState.refundTxid.trim() ||
|
|
105
|
-
!paymentActions.paymentState.paymentAmount.trim()
|
|
106
|
-
}
|
|
107
|
-
>
|
|
108
|
-
{t("refund.submit", "Refund")}
|
|
109
|
-
</Button>
|
|
110
|
-
</Flex>
|
|
111
|
-
);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export default RefundForm;
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Box, Flex, Typography, Button } from "@strapi/design-system";
|
|
3
|
+
import { Play } from "@strapi/icons";
|
|
4
|
+
import RenderInput from "../RenderInput";
|
|
5
|
+
import { getCurrencyOptions } from "../../../utils/countryLanguageUtils";
|
|
6
|
+
import { usePluginTranslations } from "../../../hooks/usePluginTranslations";
|
|
7
|
+
|
|
8
|
+
const RefundForm = ({ paymentActions }) => {
|
|
9
|
+
const { t } = usePluginTranslations();
|
|
10
|
+
const currencyOptions = getCurrencyOptions();
|
|
11
|
+
return (
|
|
12
|
+
<Flex direction="column" alignItems="stretch" gap={4}>
|
|
13
|
+
<Flex direction="row" gap={2}>
|
|
14
|
+
<Typography variant="omega" fontWeight="semiBold" textColor="neutral800" className="payment-form-title">
|
|
15
|
+
{t("refund.title", "Refund")}
|
|
16
|
+
</Typography>
|
|
17
|
+
<Typography variant="pi" textColor="neutral600" className="payment-form-description">
|
|
18
|
+
{t("refund.description", "Refund a captured payment.")}
|
|
19
|
+
</Typography>
|
|
20
|
+
</Flex>
|
|
21
|
+
|
|
22
|
+
<Box
|
|
23
|
+
style={{
|
|
24
|
+
display: "grid",
|
|
25
|
+
gridTemplateColumns: "repeat(auto-fit, minmax(250px, 1fr))",
|
|
26
|
+
gap: "16px",
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
<RenderInput
|
|
30
|
+
name="refundTxid"
|
|
31
|
+
label={t("common.transactionId", "Transaction ID *")}
|
|
32
|
+
value={paymentActions.paymentState.refundTxid || ""}
|
|
33
|
+
onChange={(e) =>
|
|
34
|
+
paymentActions.handleFieldChange("refundTxid", e.target.value)
|
|
35
|
+
}
|
|
36
|
+
inputType="textInput"
|
|
37
|
+
placeholder={t("refund.placeholderTxid", "Enter TxId from capture")}
|
|
38
|
+
required
|
|
39
|
+
tooltipContent={t("refund.tooltipTxid", "Transaction ID from a previous capture")}
|
|
40
|
+
/>
|
|
41
|
+
|
|
42
|
+
<RenderInput
|
|
43
|
+
name="refundSequenceNumber"
|
|
44
|
+
label={t("refund.sequenceNumber", "Sequence Number")}
|
|
45
|
+
value={paymentActions.paymentState.refundSequenceNumber || "2"}
|
|
46
|
+
onChange={(e) =>
|
|
47
|
+
paymentActions.handleFieldChange(
|
|
48
|
+
"refundSequenceNumber",
|
|
49
|
+
e.target.value
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
inputType="textInput"
|
|
53
|
+
placeholder="2"
|
|
54
|
+
tooltipContent={t("refund.tooltipSequence", "Sequence number for this refund (1-127), default is 2 for first refund")}
|
|
55
|
+
/>
|
|
56
|
+
|
|
57
|
+
<RenderInput
|
|
58
|
+
name="refundAmount"
|
|
59
|
+
label={t("common.amount", "Amount *")}
|
|
60
|
+
value={paymentActions.paymentState.paymentAmount || ""}
|
|
61
|
+
onChange={(e) =>
|
|
62
|
+
paymentActions.handleFieldChange("paymentAmount", e.target.value)
|
|
63
|
+
}
|
|
64
|
+
inputType="textInput"
|
|
65
|
+
placeholder="1000"
|
|
66
|
+
required
|
|
67
|
+
tooltipContent={t("refund.tooltipAmount", "Amount in cents to refund (will be negative automatically)")}
|
|
68
|
+
/>
|
|
69
|
+
|
|
70
|
+
<RenderInput
|
|
71
|
+
name="refundCurrency"
|
|
72
|
+
label={t("common.currency", "Currency")}
|
|
73
|
+
value={paymentActions.paymentState.refundCurrency || "EUR"}
|
|
74
|
+
onChange={(e) =>
|
|
75
|
+
paymentActions.handleFieldChange("refundCurrency", e.target.value)
|
|
76
|
+
}
|
|
77
|
+
inputType="select"
|
|
78
|
+
options={currencyOptions}
|
|
79
|
+
placeholder="EUR"
|
|
80
|
+
tooltipContent="Currency code (e.g., EUR, USD)"
|
|
81
|
+
/>
|
|
82
|
+
|
|
83
|
+
<RenderInput
|
|
84
|
+
name="refundReference"
|
|
85
|
+
label="Reference"
|
|
86
|
+
value={paymentActions.paymentState.refundReference || ""}
|
|
87
|
+
onChange={(e) =>
|
|
88
|
+
paymentActions.handleFieldChange("refundReference", e.target.value)
|
|
89
|
+
}
|
|
90
|
+
inputType="textInput"
|
|
91
|
+
placeholder="Optional reference"
|
|
92
|
+
tooltipContent="Optional reference for this refund"
|
|
93
|
+
/>
|
|
94
|
+
</Box>
|
|
95
|
+
|
|
96
|
+
<Button
|
|
97
|
+
variant="default"
|
|
98
|
+
onClick={() => paymentActions.handleRefund()}
|
|
99
|
+
loading={paymentActions.isProcessingPayment}
|
|
100
|
+
startIcon={<Play />}
|
|
101
|
+
style={{ maxWidth: "200px" }}
|
|
102
|
+
className="payment-button payment-button-primary"
|
|
103
|
+
disabled={
|
|
104
|
+
!paymentActions.paymentState.refundTxid.trim() ||
|
|
105
|
+
!paymentActions.paymentState.paymentAmount.trim()
|
|
106
|
+
}
|
|
107
|
+
>
|
|
108
|
+
{t("refund.submit", "Refund")}
|
|
109
|
+
</Button>
|
|
110
|
+
</Flex>
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export default RefundForm;
|
|
@@ -1,153 +1,153 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { Box, Button, Flex } from "@strapi/design-system";
|
|
3
|
-
import { ArrowsCounterClockwise, Download, Upload } from "@strapi/icons";
|
|
4
|
-
import { useNotification } from "@strapi/strapi/admin";
|
|
5
|
-
import { usePluginTranslations } from "../../../hooks/usePluginTranslations";
|
|
6
|
-
import usePayoneRequests from "../../../utils/api";
|
|
7
|
-
|
|
8
|
-
const ImportExportBar = ({ filters, sortBy = "createdAt", sortOrder = "desc", onImportDone, handleReset }) => {
|
|
9
|
-
const { t } = usePluginTranslations();
|
|
10
|
-
const { toggleNotification } = useNotification();
|
|
11
|
-
const { exportTransactions, importTransactions } = usePayoneRequests();
|
|
12
|
-
const [exporting, setExporting] = React.useState(false);
|
|
13
|
-
const [importing, setImporting] = React.useState(false);
|
|
14
|
-
const fileInputRef = React.useRef(null);
|
|
15
|
-
|
|
16
|
-
const handleExport = async (format) => {
|
|
17
|
-
setExporting(true);
|
|
18
|
-
try {
|
|
19
|
-
const res = await exportTransactions({
|
|
20
|
-
format,
|
|
21
|
-
filters,
|
|
22
|
-
sort_by: sortBy,
|
|
23
|
-
sort_order: sortOrder,
|
|
24
|
-
});
|
|
25
|
-
const blob = res?.data ?? res;
|
|
26
|
-
if (!(blob instanceof Blob)) {
|
|
27
|
-
throw new Error("Invalid export response");
|
|
28
|
-
}
|
|
29
|
-
const url = URL.createObjectURL(blob);
|
|
30
|
-
const a = document.createElement("a");
|
|
31
|
-
a.href = url;
|
|
32
|
-
a.download = `transactions.${format}`;
|
|
33
|
-
a.click();
|
|
34
|
-
URL.revokeObjectURL(url);
|
|
35
|
-
toggleNotification({ type: "success", message: t("export.success", "Export completed") });
|
|
36
|
-
} catch (err) {
|
|
37
|
-
console.error("Export failed:", err);
|
|
38
|
-
toggleNotification({ type: "danger", message: t("export.error", "Export failed") });
|
|
39
|
-
} finally {
|
|
40
|
-
setExporting(false);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const handleImportClick = () => {
|
|
45
|
-
fileInputRef.current?.click();
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const handleImportFile = async (e) => {
|
|
49
|
-
const file = e.target.files?.[0];
|
|
50
|
-
if (!file) return;
|
|
51
|
-
setImporting(true);
|
|
52
|
-
try {
|
|
53
|
-
const text = await new Promise((resolve, reject) => {
|
|
54
|
-
const r = new FileReader();
|
|
55
|
-
r.onload = () => resolve(r.result ?? "");
|
|
56
|
-
r.onerror = reject;
|
|
57
|
-
r.readAsText(file, "utf-8");
|
|
58
|
-
});
|
|
59
|
-
const ext = (file.name || "").toLowerCase();
|
|
60
|
-
let payload;
|
|
61
|
-
if (ext.endsWith(".csv")) {
|
|
62
|
-
payload = { format: "csv", data: text };
|
|
63
|
-
} else {
|
|
64
|
-
const parsed = JSON.parse(text);
|
|
65
|
-
payload = Array.isArray(parsed) ? parsed : (parsed?.data ?? []);
|
|
66
|
-
if (!Array.isArray(payload)) payload = [];
|
|
67
|
-
payload = { data: payload };
|
|
68
|
-
}
|
|
69
|
-
const res = await importTransactions(payload);
|
|
70
|
-
const data = res?.data ?? res;
|
|
71
|
-
const imported = data?.imported ?? 0;
|
|
72
|
-
const failed = data?.failed ?? 0;
|
|
73
|
-
if (typeof onImportDone === "function") onImportDone();
|
|
74
|
-
if (failed > 0) {
|
|
75
|
-
toggleNotification({
|
|
76
|
-
type: "warning",
|
|
77
|
-
message: t("import.partial", "Import completed: {{imported}} imported, {{failed}} failed.", { imported, failed }),
|
|
78
|
-
});
|
|
79
|
-
} else {
|
|
80
|
-
toggleNotification({
|
|
81
|
-
type: "success",
|
|
82
|
-
message: t("import.success", "Imported transactions.", { count: imported }),
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
} catch (err) {
|
|
86
|
-
console.error("Import failed:", err);
|
|
87
|
-
toggleNotification({ type: "danger", message: t("import.error", "Import failed") });
|
|
88
|
-
} finally {
|
|
89
|
-
setImporting(false);
|
|
90
|
-
e.target.value = "";
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
<Flex gap={2} width={"100%"}>
|
|
96
|
-
<Box>
|
|
97
|
-
<Button
|
|
98
|
-
variant="secondary"
|
|
99
|
-
size="S"
|
|
100
|
-
startIcon={<Download />}
|
|
101
|
-
loading={exporting}
|
|
102
|
-
onClick={() => handleExport("json")}
|
|
103
|
-
minWidth={"140px"}
|
|
104
|
-
>
|
|
105
|
-
{t("export.json", "Export JSON")}
|
|
106
|
-
</Button>
|
|
107
|
-
</Box>
|
|
108
|
-
{/* <Box>
|
|
109
|
-
<Button
|
|
110
|
-
variant="secondary"
|
|
111
|
-
size="S"
|
|
112
|
-
startIcon={<Download />}
|
|
113
|
-
loading={exporting}
|
|
114
|
-
onClick={() => handleExport("csv")}
|
|
115
|
-
minWidth={"140px"}
|
|
116
|
-
>
|
|
117
|
-
{t("export.csv", "Export CSV")}
|
|
118
|
-
</Button>
|
|
119
|
-
</Box> */}
|
|
120
|
-
<Box>
|
|
121
|
-
<input
|
|
122
|
-
ref={fileInputRef}
|
|
123
|
-
type="file"
|
|
124
|
-
accept=".json,.csv,application/json,text/csv"
|
|
125
|
-
style={{ display: "none" }}
|
|
126
|
-
onChange={handleImportFile}
|
|
127
|
-
/>
|
|
128
|
-
<Button
|
|
129
|
-
variant="secondary"
|
|
130
|
-
size="S"
|
|
131
|
-
startIcon={<Upload/>}
|
|
132
|
-
loading={importing}
|
|
133
|
-
minWidth={"140px"}
|
|
134
|
-
onClick={handleImportClick}
|
|
135
|
-
>
|
|
136
|
-
{t("import.button", "Import")}
|
|
137
|
-
</Button>
|
|
138
|
-
</Box>
|
|
139
|
-
|
|
140
|
-
<Button
|
|
141
|
-
variant="secondary"
|
|
142
|
-
onClick={handleReset}
|
|
143
|
-
startIcon={<ArrowsCounterClockwise />}
|
|
144
|
-
size="S"
|
|
145
|
-
maxWidth="100px"
|
|
146
|
-
>
|
|
147
|
-
{t("filters.reset", "Reset")}
|
|
148
|
-
</Button>
|
|
149
|
-
</Flex>
|
|
150
|
-
);
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
export default ImportExportBar;
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Box, Button, Flex } from "@strapi/design-system";
|
|
3
|
+
import { ArrowsCounterClockwise, Download, Upload } from "@strapi/icons";
|
|
4
|
+
import { useNotification } from "@strapi/strapi/admin";
|
|
5
|
+
import { usePluginTranslations } from "../../../hooks/usePluginTranslations";
|
|
6
|
+
import usePayoneRequests from "../../../utils/api";
|
|
7
|
+
|
|
8
|
+
const ImportExportBar = ({ filters, sortBy = "createdAt", sortOrder = "desc", onImportDone, handleReset }) => {
|
|
9
|
+
const { t } = usePluginTranslations();
|
|
10
|
+
const { toggleNotification } = useNotification();
|
|
11
|
+
const { exportTransactions, importTransactions } = usePayoneRequests();
|
|
12
|
+
const [exporting, setExporting] = React.useState(false);
|
|
13
|
+
const [importing, setImporting] = React.useState(false);
|
|
14
|
+
const fileInputRef = React.useRef(null);
|
|
15
|
+
|
|
16
|
+
const handleExport = async (format) => {
|
|
17
|
+
setExporting(true);
|
|
18
|
+
try {
|
|
19
|
+
const res = await exportTransactions({
|
|
20
|
+
format,
|
|
21
|
+
filters,
|
|
22
|
+
sort_by: sortBy,
|
|
23
|
+
sort_order: sortOrder,
|
|
24
|
+
});
|
|
25
|
+
const blob = res?.data ?? res;
|
|
26
|
+
if (!(blob instanceof Blob)) {
|
|
27
|
+
throw new Error("Invalid export response");
|
|
28
|
+
}
|
|
29
|
+
const url = URL.createObjectURL(blob);
|
|
30
|
+
const a = document.createElement("a");
|
|
31
|
+
a.href = url;
|
|
32
|
+
a.download = `transactions.${format}`;
|
|
33
|
+
a.click();
|
|
34
|
+
URL.revokeObjectURL(url);
|
|
35
|
+
toggleNotification({ type: "success", message: t("export.success", "Export completed") });
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.error("Export failed:", err);
|
|
38
|
+
toggleNotification({ type: "danger", message: t("export.error", "Export failed") });
|
|
39
|
+
} finally {
|
|
40
|
+
setExporting(false);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const handleImportClick = () => {
|
|
45
|
+
fileInputRef.current?.click();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const handleImportFile = async (e) => {
|
|
49
|
+
const file = e.target.files?.[0];
|
|
50
|
+
if (!file) return;
|
|
51
|
+
setImporting(true);
|
|
52
|
+
try {
|
|
53
|
+
const text = await new Promise((resolve, reject) => {
|
|
54
|
+
const r = new FileReader();
|
|
55
|
+
r.onload = () => resolve(r.result ?? "");
|
|
56
|
+
r.onerror = reject;
|
|
57
|
+
r.readAsText(file, "utf-8");
|
|
58
|
+
});
|
|
59
|
+
const ext = (file.name || "").toLowerCase();
|
|
60
|
+
let payload;
|
|
61
|
+
if (ext.endsWith(".csv")) {
|
|
62
|
+
payload = { format: "csv", data: text };
|
|
63
|
+
} else {
|
|
64
|
+
const parsed = JSON.parse(text);
|
|
65
|
+
payload = Array.isArray(parsed) ? parsed : (parsed?.data ?? []);
|
|
66
|
+
if (!Array.isArray(payload)) payload = [];
|
|
67
|
+
payload = { data: payload };
|
|
68
|
+
}
|
|
69
|
+
const res = await importTransactions(payload);
|
|
70
|
+
const data = res?.data ?? res;
|
|
71
|
+
const imported = data?.imported ?? 0;
|
|
72
|
+
const failed = data?.failed ?? 0;
|
|
73
|
+
if (typeof onImportDone === "function") onImportDone();
|
|
74
|
+
if (failed > 0) {
|
|
75
|
+
toggleNotification({
|
|
76
|
+
type: "warning",
|
|
77
|
+
message: t("import.partial", "Import completed: {{imported}} imported, {{failed}} failed.", { imported, failed }),
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
toggleNotification({
|
|
81
|
+
type: "success",
|
|
82
|
+
message: t("import.success", "Imported transactions.", { count: imported }),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error("Import failed:", err);
|
|
87
|
+
toggleNotification({ type: "danger", message: t("import.error", "Import failed") });
|
|
88
|
+
} finally {
|
|
89
|
+
setImporting(false);
|
|
90
|
+
e.target.value = "";
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<Flex gap={2} width={"100%"}>
|
|
96
|
+
<Box>
|
|
97
|
+
<Button
|
|
98
|
+
variant="secondary"
|
|
99
|
+
size="S"
|
|
100
|
+
startIcon={<Download />}
|
|
101
|
+
loading={exporting}
|
|
102
|
+
onClick={() => handleExport("json")}
|
|
103
|
+
minWidth={"140px"}
|
|
104
|
+
>
|
|
105
|
+
{t("export.json", "Export JSON")}
|
|
106
|
+
</Button>
|
|
107
|
+
</Box>
|
|
108
|
+
{/* <Box>
|
|
109
|
+
<Button
|
|
110
|
+
variant="secondary"
|
|
111
|
+
size="S"
|
|
112
|
+
startIcon={<Download />}
|
|
113
|
+
loading={exporting}
|
|
114
|
+
onClick={() => handleExport("csv")}
|
|
115
|
+
minWidth={"140px"}
|
|
116
|
+
>
|
|
117
|
+
{t("export.csv", "Export CSV")}
|
|
118
|
+
</Button>
|
|
119
|
+
</Box> */}
|
|
120
|
+
<Box>
|
|
121
|
+
<input
|
|
122
|
+
ref={fileInputRef}
|
|
123
|
+
type="file"
|
|
124
|
+
accept=".json,.csv,application/json,text/csv"
|
|
125
|
+
style={{ display: "none" }}
|
|
126
|
+
onChange={handleImportFile}
|
|
127
|
+
/>
|
|
128
|
+
<Button
|
|
129
|
+
variant="secondary"
|
|
130
|
+
size="S"
|
|
131
|
+
startIcon={<Upload/>}
|
|
132
|
+
loading={importing}
|
|
133
|
+
minWidth={"140px"}
|
|
134
|
+
onClick={handleImportClick}
|
|
135
|
+
>
|
|
136
|
+
{t("import.button", "Import")}
|
|
137
|
+
</Button>
|
|
138
|
+
</Box>
|
|
139
|
+
|
|
140
|
+
<Button
|
|
141
|
+
variant="secondary"
|
|
142
|
+
onClick={handleReset}
|
|
143
|
+
startIcon={<ArrowsCounterClockwise />}
|
|
144
|
+
size="S"
|
|
145
|
+
maxWidth="100px"
|
|
146
|
+
>
|
|
147
|
+
{t("filters.reset", "Reset")}
|
|
148
|
+
</Button>
|
|
149
|
+
</Flex>
|
|
150
|
+
);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export default ImportExportBar;
|