Skip to content

Commit e42f6b7

Browse files
committed
fakturoid init
1 parent 8f91060 commit e42f6b7

File tree

8 files changed

+614
-4
lines changed

8 files changed

+614
-4
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import fakturoid from "../../fakturoid.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "fakturoid-cancel-uncancel-invoice",
6+
name: "Cancel or Uncancel Invoice",
7+
description: "Cancels an existing invoice or revokes previous cancellation. [See the documentation](https://www.fakturoid.cz/api/v3)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
fakturoid,
12+
invoiceId: {
13+
propDefinition: [
14+
fakturoid,
15+
"invoiceId",
16+
],
17+
},
18+
action: {
19+
type: "string",
20+
label: "Action",
21+
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+
],
32+
},
33+
},
34+
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,
43+
});
44+
45+
$.export("$summary", `${action === "cancel"
46+
? "Cancelled"
47+
: "Uncancelled"} invoice with ID ${invoiceId}`);
48+
return response;
49+
},
50+
};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import fakturoid from "../../fakturoid.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "fakturoid-create-invoice",
6+
name: "Create Invoice",
7+
description: "Creates a new invoice. [See the documentation](https://www.fakturoid.cz/api/v3/invoices)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
fakturoid,
12+
contactId: {
13+
propDefinition: [
14+
fakturoid,
15+
"contactId",
16+
],
17+
},
18+
lines: {
19+
propDefinition: [
20+
fakturoid,
21+
"lines",
22+
],
23+
},
24+
number: {
25+
propDefinition: [
26+
fakturoid,
27+
"number",
28+
],
29+
optional: true,
30+
},
31+
due: {
32+
propDefinition: [
33+
fakturoid,
34+
"due",
35+
],
36+
optional: true,
37+
},
38+
note: {
39+
propDefinition: [
40+
fakturoid,
41+
"note",
42+
],
43+
optional: true,
44+
},
45+
},
46+
async run({ $ }) {
47+
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,
53+
});
54+
55+
$.export("$summary", `Successfully created invoice with ID ${response.id}`);
56+
return response;
57+
},
58+
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import fakturoid from "../../fakturoid.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "fakturoid-pay-remove-payment-invoice",
6+
name: "Pay or Remove Payment for Invoice",
7+
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}}",
9+
type: "action",
10+
props: {
11+
fakturoid,
12+
invoiceId: {
13+
propDefinition: [
14+
fakturoid,
15+
"invoiceId",
16+
],
17+
},
18+
paymentValue: {
19+
propDefinition: [
20+
fakturoid,
21+
"paymentValue",
22+
],
23+
optional: true,
24+
},
25+
actionType: {
26+
type: "string",
27+
label: "Action Type",
28+
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,
45+
},
46+
},
47+
async run({ $ }) {
48+
const {
49+
actionType, invoiceId, paymentValue, paymentId,
50+
} = this;
51+
52+
if (actionType === "execute") {
53+
const response = await this.fakturoid.payInvoice({
54+
invoiceId,
55+
paymentValue,
56+
});
57+
$.export("$summary", `Successfully executed payment for invoice ID ${invoiceId}`);
58+
return response;
59+
} else if (actionType === "remove") {
60+
if (!paymentId) {
61+
throw new Error("Payment ID must be provided to remove a payment");
62+
}
63+
const response = await this.fakturoid.removePayment({
64+
invoiceId,
65+
paymentId,
66+
});
67+
$.export("$summary", `Successfully removed payment ID ${paymentId} from invoice ID ${invoiceId}`);
68+
return response;
69+
} else {
70+
throw new Error("Invalid action type");
71+
}
72+
},
73+
};
Lines changed: 171 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,179 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "fakturoid",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
invoiceId: {
8+
type: "string",
9+
label: "Invoice ID",
10+
description: "Unique identifier for the invoice",
11+
},
12+
newStatus: {
13+
type: "string",
14+
label: "New Status",
15+
description: "The new status of the invoice (overdue or paid)",
16+
options: [
17+
{
18+
label: "Overdue",
19+
value: "overdue",
20+
},
21+
{
22+
label: "Paid",
23+
value: "paid",
24+
},
25+
],
26+
},
27+
customerId: {
28+
type: "string",
29+
label: "Customer ID",
30+
description: "Identifier for the customer (optional)",
31+
optional: true,
32+
},
33+
contactId: {
34+
type: "string",
35+
label: "Contact ID",
36+
description: "Identifier for the contact related to the invoice",
37+
},
38+
lines: {
39+
type: "string[]",
40+
label: "Lines",
41+
description: "Lines that describe the items in the invoice, as a JSON array",
42+
},
43+
number: {
44+
type: "string",
45+
label: "Number",
46+
description: "The invoice number (optional)",
47+
optional: true,
48+
},
49+
due: {
50+
type: "string",
51+
label: "Due",
52+
description: "The due date of the invoice (optional)",
53+
optional: true,
54+
},
55+
note: {
56+
type: "string",
57+
label: "Note",
58+
description: "Additional notes for the invoice (optional)",
59+
optional: true,
60+
},
61+
paymentValue: {
62+
type: "string",
63+
label: "Payment Value",
64+
description: "Amount of payment to be executed (optional)",
65+
optional: true,
66+
},
67+
},
568
methods: {
6-
// this.$auth contains connected account data
769
authKeys() {
870
console.log(Object.keys(this.$auth));
971
},
72+
_baseUrl() {
73+
return "https://app.fakturoid.cz/api/v3";
74+
},
75+
async _makeRequest(opts = {}) {
76+
const {
77+
$ = this,
78+
method = "GET",
79+
path = "/",
80+
headers,
81+
...otherOpts
82+
} = opts;
83+
84+
return axios($, {
85+
...otherOpts,
86+
method,
87+
url: this._baseUrl() + path,
88+
headers: {
89+
...headers,
90+
"User-Agent": "YourApp ([email protected])",
91+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
92+
},
93+
});
94+
},
95+
async createInvoice({
96+
contactId, lines, number, due, note, ...opts
97+
}) {
98+
return this._makeRequest({
99+
method: "POST",
100+
path: `/accounts/${this.$auth.account_slug}/invoices.json`,
101+
data: {
102+
subject_id: contactId,
103+
lines: lines.map(JSON.parse),
104+
custom_id: number,
105+
due,
106+
note,
107+
},
108+
...opts,
109+
});
110+
},
111+
async cancelInvoice({
112+
invoiceId, ...opts
113+
}) {
114+
return this._makeRequest({
115+
method: "POST",
116+
path: `/accounts/${this.$auth.account_slug}/invoices/${invoiceId}/fire.json`,
117+
params: {
118+
event: "cancel",
119+
},
120+
...opts,
121+
});
122+
},
123+
async undoCancelInvoice({
124+
invoiceId, ...opts
125+
}) {
126+
return this._makeRequest({
127+
method: "POST",
128+
path: `/accounts/${this.$auth.account_slug}/invoices/${invoiceId}/fire.json`,
129+
params: {
130+
event: "undo_cancel",
131+
},
132+
...opts,
133+
});
134+
},
135+
async payInvoice({
136+
invoiceId, paymentValue, ...opts
137+
}) {
138+
const data = paymentValue
139+
? {
140+
amount: paymentValue,
141+
}
142+
: {};
143+
return this._makeRequest({
144+
method: "POST",
145+
path: `/accounts/${this.$auth.account_slug}/invoices/${invoiceId}/payments.json`,
146+
data,
147+
...opts,
148+
});
149+
},
150+
async removePayment({
151+
invoiceId, paymentId, ...opts
152+
}) {
153+
return this._makeRequest({
154+
method: "DELETE",
155+
path: `/accounts/${this.$auth.account_slug}/invoices/${invoiceId}/payments/${paymentId}.json`,
156+
...opts,
157+
});
158+
},
159+
async watchInvoiceStatusChange({
160+
invoiceId, newStatus,
161+
}) {
162+
return {
163+
event_name: `invoice_${newStatus}`,
164+
invoice_id: invoiceId,
165+
};
166+
},
167+
async watchContactsAdded() {
168+
return {
169+
event_name: "subject_created",
170+
};
171+
},
172+
async watchNewInvoiceCreated({ customerId }) {
173+
return {
174+
event_name: "invoice_created",
175+
customer_id: customerId,
176+
};
177+
},
10178
},
11-
};
179+
};

components/fakturoid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)