Skip to content

Commit b754a4b

Browse files
committed
[Components] fakturoid #13809
Sources - Invoice Status Change (Instant) - New Contact - New Invoice Actions - Create Invoice - Cancel Uncancel Invoice - Pay Remove Payment Invoice
1 parent e42f6b7 commit b754a4b

File tree

12 files changed

+607
-261
lines changed

12 files changed

+607
-261
lines changed
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,49 @@
1+
import constants from "../../common/constants.mjs";
12
import fakturoid from "../../fakturoid.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "fakturoid-cancel-uncancel-invoice",
66
name: "Cancel or Uncancel Invoice",
77
description: "Cancels an existing invoice or revokes previous cancellation. [See the documentation](https://www.fakturoid.cz/api/v3)",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
fakturoid,
12+
accountSlug: {
13+
propDefinition: [
14+
fakturoid,
15+
"accountSlug",
16+
],
17+
},
1218
invoiceId: {
1319
propDefinition: [
1420
fakturoid,
1521
"invoiceId",
22+
({ accountSlug }) => ({
23+
accountSlug,
24+
}),
1625
],
1726
},
1827
action: {
1928
type: "string",
2029
label: "Action",
2130
description: "The action to perform on the invoice (cancel or uncancel)",
22-
options: [
23-
{
24-
label: "Cancel",
25-
value: "cancel",
26-
},
27-
{
28-
label: "Uncancel",
29-
value: "undo_cancel",
30-
},
31-
],
31+
options: constants.ACTION_OPTIONS,
3232
},
3333
},
3434
async run({ $ }) {
35-
const {
36-
invoiceId, action,
37-
} = this;
38-
const method = action === "cancel"
39-
? "cancelInvoice"
40-
: "undoCancelInvoice";
41-
const response = await this.fakturoid[method]({
42-
invoiceId,
35+
const response = await this.fakturoid.fireInvoice({
36+
$,
37+
accountSlug: this.accountSlug,
38+
invoiceId: this.invoiceId,
39+
params: {
40+
event: this.action,
41+
},
4342
});
4443

45-
$.export("$summary", `${action === "cancel"
44+
$.export("$summary", `${this.action === "cancel"
4645
? "Cancelled"
47-
: "Uncancelled"} invoice with ID ${invoiceId}`);
46+
: "Uncancelled"} invoice with ID ${this.invoiceId}`);
4847
return response;
4948
},
5049
};

components/fakturoid/actions/create-invoice/create-invoice.mjs

Lines changed: 106 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,136 @@
1+
import constants, { parseObject } from "../../common/constants.mjs";
12
import fakturoid from "../../fakturoid.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "fakturoid-create-invoice",
66
name: "Create Invoice",
77
description: "Creates a new invoice. [See the documentation](https://www.fakturoid.cz/api/v3/invoices)",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
fakturoid,
12-
contactId: {
12+
accountSlug: {
1313
propDefinition: [
1414
fakturoid,
15-
"contactId",
15+
"accountSlug",
1616
],
1717
},
18-
lines: {
19-
propDefinition: [
20-
fakturoid,
21-
"lines",
22-
],
18+
customId: {
19+
type: "string",
20+
label: "Custom Id",
21+
description: "Identifier in your application",
22+
optional: true,
2323
},
24-
number: {
25-
propDefinition: [
26-
fakturoid,
27-
"number",
28-
],
24+
documentType: {
25+
type: "string",
26+
label: "Document Type",
27+
description: "Type of document",
28+
options: constants.DOCUMENT_TYPE_OPTIONS,
29+
reloadProps: true,
2930
optional: true,
3031
},
31-
due: {
32+
subjectId: {
3233
propDefinition: [
3334
fakturoid,
34-
"due",
35+
"subjectId",
36+
({ accountSlug }) => ({
37+
accountSlug,
38+
}),
3539
],
40+
},
41+
orderNumber: {
42+
type: "string",
43+
label: "Order Number",
44+
description: "Order number in your application",
3645
optional: true,
3746
},
3847
note: {
39-
propDefinition: [
40-
fakturoid,
41-
"note",
42-
],
48+
type: "string",
49+
label: "Note",
50+
description: "Additional notes for the invoice",
51+
optional: true,
52+
},
53+
due: {
54+
type: "string",
55+
label: "Due",
56+
description: "Invoice due date in number of days from today",
4357
optional: true,
4458
},
59+
issuedOn: {
60+
type: "string",
61+
label: "Issued On",
62+
description: "Date of issue. **Format: YYYY-MM-DD**",
63+
optional: true,
64+
},
65+
taxableFulfillmentDue: {
66+
type: "string",
67+
label: "Taxable Fulfillment Due",
68+
description: "Chargeable event date.",
69+
optional: true,
70+
},
71+
tags: {
72+
type: "string[]",
73+
label: "Tags",
74+
description: "List of tags",
75+
optional: true,
76+
},
77+
roundTotal: {
78+
type: "boolean",
79+
label: "Tound Total",
80+
description: "Round total amount (VAT included)",
81+
optional: true,
82+
},
83+
subtotal: {
84+
type: "string",
85+
label: "Subtotal",
86+
description: "Total without VAT",
87+
optional: true,
88+
},
89+
total: {
90+
type: "string",
91+
label: "Total",
92+
description: "Total with VAT",
93+
optional: true,
94+
},
95+
lines: {
96+
type: "string[]",
97+
label: "Lines",
98+
description: "List of object lines to invoice. [See the documentation](https://www.fakturoid.cz/api/v3/invoices#attributes). **Example: {\"name\": \"Hard work\",\"quantity\": \"1.0\",\"unit_name\": \"h\",\"unit_price\": \"40000\",\"vat_rate\": \"21\"}**",
99+
},
100+
},
101+
async additionalProps() {
102+
const props = {};
103+
if (this.documentType === "proforma") {
104+
props.proformaFollowupDocument = {
105+
type: "string",
106+
label: "Proforma Followup Document",
107+
description: "What to issue after a proforma is paid.",
108+
options: constants.PROFORMA_OPTIONS,
109+
optional: true,
110+
};
111+
}
112+
return props;
45113
},
46114
async run({ $ }) {
47115
const response = await this.fakturoid.createInvoice({
48-
contactId: this.contactId,
49-
lines: this.lines.map(JSON.parse),
50-
number: this.number,
51-
due: this.due,
52-
note: this.note,
116+
$,
117+
accountSlug: this.accountSlug,
118+
data: {
119+
custom_id: this.customId,
120+
document_type: this.documentType,
121+
proforma_followup_document: this.proformaFollowupDocument,
122+
subject_id: this.subjectId,
123+
order_number: this.orderNumber,
124+
note: this.note,
125+
due: this.due,
126+
issued_on: this.issuedOn,
127+
taxable_fulfillment_due: this.taxableFulfillmentDue,
128+
tags: parseObject(this.tags),
129+
round_total: this.roundTotal,
130+
subtotal: this.subtotal && parseFloat(this.subtotal),
131+
total: this.total && parseFloat(this.total),
132+
lines: parseObject(this.lines),
133+
},
53134
});
54135

55136
$.export("$summary", `Successfully created invoice with ID ${response.id}`);
Lines changed: 76 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,109 @@
1+
import constants from "../../common/constants.mjs";
12
import fakturoid from "../../fakturoid.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "fakturoid-pay-remove-payment-invoice",
66
name: "Pay or Remove Payment for Invoice",
77
description: "Executes payment for an invoice or removes an already applied payment. [See the documentation](https://www.fakturoid.cz/api/v3/invoice-payments)",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
fakturoid,
12-
invoiceId: {
12+
accountSlug: {
1313
propDefinition: [
1414
fakturoid,
15-
"invoiceId",
15+
"accountSlug",
1616
],
1717
},
18-
paymentValue: {
18+
invoiceId: {
1919
propDefinition: [
2020
fakturoid,
21-
"paymentValue",
21+
"invoiceId",
22+
({ accountSlug }) => ({
23+
accountSlug,
24+
}),
2225
],
23-
optional: true,
2426
},
2527
actionType: {
2628
type: "string",
2729
label: "Action Type",
2830
description: "Specify if you want to execute or remove a payment",
29-
options: [
30-
{
31-
label: "Execute Payment",
32-
value: "execute",
33-
},
34-
{
35-
label: "Remove Payment",
36-
value: "remove",
37-
},
38-
],
39-
},
40-
paymentId: {
41-
type: "string",
42-
label: "Payment ID",
43-
description: "ID of the payment to be removed. Required if action type is remove.",
44-
optional: true,
31+
options: constants.ACTION_TYPE_OPTIONS,
32+
reloadProps: true,
4533
},
4634
},
47-
async run({ $ }) {
48-
const {
49-
actionType, invoiceId, paymentValue, paymentId,
50-
} = this;
35+
async additionalProps() {
36+
const props = {};
37+
if (this.actionType === "execute") {
38+
props.paidOn = {
39+
type: "string",
40+
label: "Paid On",
41+
description: "Payment date. **Format: YYYY-MM-DD** Default: Today",
42+
optional: true,
43+
};
44+
props.currency = {
45+
type: "string",
46+
label: "Currency",
47+
description: "Currency [ISO Code](https://en.wikipedia.org/wiki/ISO_4217#List_of_ISO_4217_currency_codes) (same as invoice currency)",
48+
optional: true,
49+
};
50+
props.amount = {
51+
type: "string",
52+
label: "Amount",
53+
description: "Paid amount in document currency. Default: Remaining amount to pay",
54+
optional: true,
55+
};
56+
props.markDocumentAsPaid = {
57+
type: "boolean",
58+
label: "Mark Document As Paid",
59+
description: "Mark document as paid? Default: true if the total paid amount becomes greater or equal to remaining amount to pay",
60+
optional: true,
61+
};
62+
} else if (this.actionType === "remove") {
63+
props.paymentId = {
64+
type: "string",
65+
label: "Payment ID",
66+
description: "ID of the payment to be removed.",
67+
options: async () => {
68+
const { payments } = await this.fakturoid.getInvoice({
69+
accountSlug: this.accountSlug,
70+
invoiceId: this.invoiceId,
71+
});
5172

52-
if (actionType === "execute") {
73+
return payments.map(({
74+
id: value, paid_on: pOn, currency, amount,
75+
}) => ({
76+
label: `${currency} ${amount} (${pOn})`,
77+
value,
78+
}));
79+
},
80+
};
81+
}
82+
return props;
83+
},
84+
async run({ $ }) {
85+
if (this.actionType === "execute") {
5386
const response = await this.fakturoid.payInvoice({
54-
invoiceId,
55-
paymentValue,
87+
accountSlug: this.accountSlug,
88+
invoiceId: this.invoiceId,
89+
data: {
90+
paid_on: this.paidOn,
91+
currency: this.currency,
92+
amount: this.amount && parseFloat(this.amount),
93+
mark_document_as_paid: this.markDocumentAsPaid,
94+
},
5695
});
57-
$.export("$summary", `Successfully executed payment for invoice ID ${invoiceId}`);
96+
$.export("$summary", `Successfully executed payment for invoice ID ${this.invoiceId}`);
5897
return response;
59-
} else if (actionType === "remove") {
60-
if (!paymentId) {
61-
throw new Error("Payment ID must be provided to remove a payment");
62-
}
98+
} else if (this.actionType === "remove") {
6399
const response = await this.fakturoid.removePayment({
64-
invoiceId,
65-
paymentId,
100+
$,
101+
accountSlug: this.accountSlug,
102+
invoiceId: this.invoiceId,
103+
paymentId: this.paymentId,
66104
});
67-
$.export("$summary", `Successfully removed payment ID ${paymentId} from invoice ID ${invoiceId}`);
105+
$.export("$summary", `Successfully removed payment ID ${this.paymentId} from invoice ID ${this.invoiceId}`);
68106
return response;
69-
} else {
70-
throw new Error("Invalid action type");
71107
}
72108
},
73109
};

0 commit comments

Comments
 (0)