@developerx12/invoices-medusa 0.1.3 → 0.1.5
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/.medusa/server/src/admin/index.js +248 -43
- package/.medusa/server/src/admin/index.mjs +251 -46
- package/.medusa/server/src/api/admin/orders/[id]/credit-invoice/route.js +69 -0
- package/.medusa/server/src/api/admin/orders/[id]/invoice/[invoice_id]/upload/route.js +55 -0
- package/.medusa/server/src/api/admin/orders/[id]/invoice/route.js +43 -0
- package/.medusa/server/src/api/admin/orders/[id]/invoice/upload-new/route.js +119 -0
- package/.medusa/server/src/api/middlewares.js +22 -1
- package/.medusa/server/src/core/classes/pdf-generator/templates/credit-invoice-content.js +2 -2
- package/.medusa/server/src/core/classes/pdf-generator/templates/invoice-content.js +3 -3
- package/.medusa/server/src/subscribers/payment-refunded-invoice.js +14 -26
- package/.medusa/server/src/utils/order-invoices.js +65 -0
- package/.medusa/server/src/utils/store-invoice-file.js +37 -0
- package/.medusa/server/src/workflows/index.js +4 -2
- package/.medusa/server/src/workflows/steps/generate-invoice-pdf-step.js +2 -2
- package/.medusa/server/src/workflows/steps/replace-invoice-pdf-step.js +7 -12
- package/.medusa/server/src/workflows/steps/upload-invoice-pdf-step.js +4 -13
- package/.medusa/server/src/workflows/upload-invoice-pdf.js +14 -0
- package/README.md +47 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -185,6 +185,32 @@ POST /admin/orders/:id/invoice/:invoice_id
|
|
|
185
185
|
|
|
186
186
|
Requires admin authentication. Regenerates the invoice PDF.
|
|
187
187
|
|
|
188
|
+
```
|
|
189
|
+
POST /admin/orders/:id/invoice
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Requires admin authentication. Manually creates a new (debit) invoice for the order, including the PDF. Useful when the automatic invoice creation is disabled or did not run. The invoice is created by the same `createInvoiceWorkflow` that the subscribers use. An order can only have one debit invoice, so the request is rejected when the order already has one.
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
POST /admin/orders/:id/credit-invoice
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Requires admin authentication. Manually creates a (credit) invoice for the order. A credit invoice is always based on a refund:
|
|
199
|
+
|
|
200
|
+
- `refund_id` (optional): the refund to credit. When omitted, the most recent refund of the order is used.
|
|
201
|
+
- When the order has no debit invoice yet, one is created first so the credit invoice has a parent invoice to reference.
|
|
202
|
+
- Fails when a credit invoice already exists for the selected refund.
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{ "refund_id": "ref_123" }
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
POST /admin/orders/:id/invoice/:invoice_id/upload
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Requires admin authentication. Uploads a PDF for an existing invoice. The uploaded file **replaces** the generated PDF of the invoice — nothing else about the invoice changes. The request must be `multipart/form-data` with a `file` field (PDF only, max 20MB). The file is stored as a private file in the file module, exactly like the generated PDFs.
|
|
213
|
+
|
|
188
214
|
### Store
|
|
189
215
|
|
|
190
216
|
```
|
|
@@ -207,7 +233,10 @@ The plugin includes an admin widget that displays on the order details page (`or
|
|
|
207
233
|
- Lists all invoices (debit and credit) for the order
|
|
208
234
|
- Shows invoice type with colored badges (gray for debit, green for credit)
|
|
209
235
|
- Download button fetches PDF via API and triggers browser download
|
|
210
|
-
- Refresh button regenerates the invoice PDF
|
|
236
|
+
- Refresh button regenerates the invoice PDF from the order
|
|
237
|
+
- Upload button replaces the PDF of an invoice with an uploaded PDF file
|
|
238
|
+
- **Generate invoice** button creates the invoice for the order manually. An order can only have one debit invoice, so the button is disabled when the order already has one.
|
|
239
|
+
- **Credit invoice** button creates a credit invoice for one of the refunds of the order
|
|
211
240
|
|
|
212
241
|
## Workflows
|
|
213
242
|
|
|
@@ -219,6 +248,7 @@ import {
|
|
|
219
248
|
createCreditInvoiceWorkflow,
|
|
220
249
|
generateInvoicePdfWorkflow,
|
|
221
250
|
refreshInvoicePdfWorkflow,
|
|
251
|
+
uploadInvoicePdfWorkflow,
|
|
222
252
|
} from "@developerx12/invoices-medusa/workflows"
|
|
223
253
|
```
|
|
224
254
|
|
|
@@ -277,6 +307,22 @@ const { result } = await refreshInvoicePdfWorkflow(container).run({
|
|
|
277
307
|
// result.file_id — the new file ID
|
|
278
308
|
```
|
|
279
309
|
|
|
310
|
+
### `uploadInvoicePdfWorkflow`
|
|
311
|
+
|
|
312
|
+
Replaces the PDF of an existing invoice with an externally provided file (e.g. a manually uploaded invoice document).
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
const { result } = await uploadInvoicePdfWorkflow(container).run({
|
|
316
|
+
input: {
|
|
317
|
+
invoice_id: "inv_01J...",
|
|
318
|
+
file_name: "invoice-42.pdf",
|
|
319
|
+
data: "<base64 encoded pdf>", // base64-encoded file content
|
|
320
|
+
},
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
// result.file_id — the new file ID
|
|
324
|
+
```
|
|
325
|
+
|
|
280
326
|
## Backfill script
|
|
281
327
|
|
|
282
328
|
To generate and upload PDFs for invoices created before file storage was introduced:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@developerx12/invoices-medusa",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Add invoices to Medusa v2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"@tanstack/react-query": "5.64.2",
|
|
76
76
|
"date-fns": "^4.1.0",
|
|
77
77
|
"lodash.merge": "^4.6.2",
|
|
78
|
+
"multer": "^2.1.1",
|
|
78
79
|
"dejavu-fonts-ttf": "^2.37.3",
|
|
79
80
|
"pdfmake": "^0.3.7",
|
|
80
81
|
"react-i18next": "^15.7.4"
|