Skip to content

Commit ac7fe45

Browse files
authored
New Components - pennylane (#14973)
* pennylane init * [Components] pennylane #14952 Sources - New Billing Subscription - New Customer Invoice - New Customer Actions - Create Customer - Create Billing Subscription - Create Customer Invoice * pnpm update * [Components] pennylane #14952 Sources - New Billing Subscription - New Customer Invoice - New Customer Actions - Create Customer - Create Billing Subscription - Create Customer Invoice * pnpm update
1 parent a437fcb commit ac7fe45

File tree

15 files changed

+1221
-17
lines changed

15 files changed

+1221
-17
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import {
2+
DAY_OF_WEEK_OPTIONS,
3+
MODE_OPTIONS,
4+
PAYMENT_CONDITIONS_OPTIONS,
5+
PAYMENT_METHOD_OPTIONS,
6+
RECURRING_RULE_TYPE,
7+
} from "../../common/constants.mjs";
8+
import { parseObject } from "../../common/utils.mjs";
9+
import pennylane from "../../pennylane.app.mjs";
10+
11+
export default {
12+
key: "pennylane-create-billing-subscription",
13+
name: "Create Billing Subscription",
14+
description: "Creates a billing subscription for a customer. [See the documentation](https://pennylane.readme.io/reference/billing_subscriptions-post-1).",
15+
version: "0.0.1",
16+
type: "action",
17+
props: {
18+
pennylane,
19+
currency: {
20+
type: "string",
21+
label: "Currency",
22+
description: "Invoice Currency (ISO 4217). Default is EUR.",
23+
optional: true,
24+
},
25+
mode: {
26+
type: "string",
27+
label: "Mode",
28+
description: "Mode in which the new invoices will be created.",
29+
options: MODE_OPTIONS,
30+
},
31+
start: {
32+
type: "string",
33+
label: "Start",
34+
description: "Start date (ISO 8601)",
35+
},
36+
paymentConditions: {
37+
type: "string",
38+
label: "Payment Conditions",
39+
description: "Customer payment conditions",
40+
options: PAYMENT_CONDITIONS_OPTIONS,
41+
},
42+
paymentMethod: {
43+
type: "string",
44+
label: "Payment Method",
45+
description: "PaymentMethod",
46+
options: PAYMENT_METHOD_OPTIONS,
47+
},
48+
recurringRuleType: {
49+
type: "string",
50+
label: "Recurring Rule Type",
51+
description: "Type of the billing subscription's recurrence",
52+
options: RECURRING_RULE_TYPE,
53+
reloadProps: true,
54+
},
55+
dayOfMonth: {
56+
type: "integer",
57+
label: "Day Of Month",
58+
description: "The day of occurrences of the recurring rule",
59+
hidden: true,
60+
},
61+
dayOfWeek: {
62+
type: "string",
63+
label: "Day Of Week",
64+
description: "The day of occurrences of the recurring rule",
65+
options: DAY_OF_WEEK_OPTIONS,
66+
hidden: true,
67+
},
68+
interval: {
69+
type: "string",
70+
label: "Interval",
71+
description: "The interval of occurrences of the recurring rule",
72+
optional: true,
73+
},
74+
count: {
75+
type: "integer",
76+
label: "Count",
77+
description: "Number of occurrences of the recurring rule",
78+
optional: true,
79+
},
80+
specialMention: {
81+
type: "string",
82+
label: "Special Mention",
83+
description: "Additional details",
84+
optional: true,
85+
},
86+
discount: {
87+
type: "integer",
88+
label: "Discount",
89+
description: "Invoice discount (in percent)",
90+
optional: true,
91+
},
92+
customerId: {
93+
propDefinition: [
94+
pennylane,
95+
"customerId",
96+
],
97+
},
98+
lineItemsSectionsAttributes: {
99+
propDefinition: [
100+
pennylane,
101+
"lineItemsSectionsAttributes",
102+
],
103+
optional: true,
104+
},
105+
invoiceLines: {
106+
propDefinition: [
107+
pennylane,
108+
"lineItems",
109+
],
110+
label: "Invoice Lines",
111+
},
112+
},
113+
async additionalProps(props) {
114+
switch (this.recurringRuleType) {
115+
case "monthly":
116+
props.dayOfMonth.hidden = false;
117+
props.dayOfWeek.hidden = true;
118+
break;
119+
case "weekly":
120+
props.dayOfMonth.hidden = true;
121+
props.dayOfWeek.hidden = false;
122+
break;
123+
case "yearly":
124+
props.dayOfMonth.hidden = true;
125+
props.dayOfWeek.hidden = true;
126+
break;
127+
}
128+
return {};
129+
},
130+
async run({ $ }) {
131+
const response = await this.pennylane.createBillingSubscription({
132+
$,
133+
data: {
134+
create_customer: false,
135+
create_products: false,
136+
billing_subscription: {
137+
currency: this.currency,
138+
mode: this.mode,
139+
start: this.start,
140+
payment_conditions: this.paymentConditions,
141+
payment_method: this.paymentMethod,
142+
recurring_rule: {
143+
type: this.recurringRuleType,
144+
day_of_month: this.dayOfMonth,
145+
day_of_week: this.dayOfWeek,
146+
interval: this.interval,
147+
count: this.count,
148+
},
149+
special_mention: this.specialMention,
150+
discount: this.discount,
151+
customer: {
152+
source_id: this.customerId,
153+
},
154+
line_items_sections_attributes: parseObject(this.lineItemsSectionsAttributes),
155+
invoice_lines: parseObject(this.invoiceLines),
156+
},
157+
},
158+
});
159+
$.export("$summary", `Created billing subscription with ID ${response.billing_subscription.id}`);
160+
return response;
161+
},
162+
};
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import {
3+
BANKING_PROVIDER_OPTIONS,
4+
LANGUAGE_OPTIONS,
5+
PROVIDER_FIELD_NAMES_OPTIONS,
6+
} from "../../common/constants.mjs";
7+
import { parseObject } from "../../common/utils.mjs";
8+
import pennylane from "../../pennylane.app.mjs";
9+
10+
export default {
11+
key: "pennylane-create-customer-invoice",
12+
name: "Create Customer Invoice",
13+
description: "Generates a new invoice for a customer using Pennylane. [See the documentation](https://pennylane.readme.io/reference/customer_invoices-post-1)",
14+
version: "0.0.1",
15+
type: "action",
16+
props: {
17+
pennylane,
18+
date: {
19+
type: "string",
20+
label: "Date",
21+
description: "Invoice date (ISO 8601)",
22+
},
23+
deadline: {
24+
type: "string",
25+
label: "Deadline",
26+
description: "Invoice payment deadline (ISO 8601)",
27+
},
28+
externalId: {
29+
type: "string",
30+
label: "External Id",
31+
description: "An id you can use to refer to the invoice from outside of Pennylane",
32+
optional: true,
33+
},
34+
pdfInvoiceFreeText: {
35+
type: "string",
36+
label: "PDF Invoice Free Text",
37+
description: "For example, the contact details of the person to contact",
38+
optional: true,
39+
},
40+
pdfInvoiceSubject: {
41+
type: "string",
42+
label: "PDF Invoice Subject",
43+
description: "Invoice title",
44+
optional: true,
45+
},
46+
draft: {
47+
type: "boolean",
48+
label: "Draft",
49+
description: "Do you wish to create a draft invoice (otherwise it is a finalized invoice)? Reminder, once created, a finalized invoice cannot be edited!",
50+
},
51+
currency: {
52+
type: "string",
53+
label: "Currency",
54+
description: "Invoice Currency (ISO 4217). Default is EUR.",
55+
optional: true,
56+
},
57+
specialMention: {
58+
type: "string",
59+
label: "Special Mention",
60+
description: "Additional details",
61+
optional: true,
62+
},
63+
discount: {
64+
type: "integer",
65+
label: "Discount",
66+
description: "Invoice discount (in percent)",
67+
optional: true,
68+
},
69+
language: {
70+
type: "string",
71+
label: "Language",
72+
description: "invoice pdf language",
73+
options: LANGUAGE_OPTIONS,
74+
optional: true,
75+
},
76+
bankingProvider: {
77+
type: "string",
78+
label: "Banking Provider",
79+
description: "The banking provider for the transaction",
80+
options: BANKING_PROVIDER_OPTIONS,
81+
reloadProps: true,
82+
},
83+
providerFieldName: {
84+
type: "string",
85+
label: "Provider Field Name",
86+
description: "Name of the field that you want to match",
87+
options: PROVIDER_FIELD_NAMES_OPTIONS,
88+
hidden: true,
89+
},
90+
providerFieldValue: {
91+
type: "string",
92+
label: "Provider Field Value",
93+
description: "Value that you want to match",
94+
},
95+
customerId: {
96+
propDefinition: [
97+
pennylane,
98+
"customerId",
99+
],
100+
},
101+
lineItemsSectionsAttributes: {
102+
propDefinition: [
103+
pennylane,
104+
"lineItemsSectionsAttributes",
105+
],
106+
optional: true,
107+
},
108+
lineItems: {
109+
propDefinition: [
110+
pennylane,
111+
"lineItems",
112+
],
113+
},
114+
categories: {
115+
type: "string[]",
116+
label: "Categories",
117+
description: "A list of objects of categories",
118+
optional: true,
119+
},
120+
startDate: {
121+
type: "string",
122+
label: "Start Date",
123+
description: "Start date of the imputation period (ISO 8601)",
124+
},
125+
endDate: {
126+
type: "string",
127+
label: "End Date",
128+
description: "End date of the imputation period (ISO 8601)",
129+
},
130+
},
131+
async additionalProps(props) {
132+
if (this.bankingProvider === "stripe") {
133+
props.providerFieldName.hidden = false;
134+
}
135+
return {};
136+
},
137+
async run({ $ }) {
138+
try {
139+
const invoice = await this.pennylane.createInvoice({
140+
$,
141+
data: {
142+
create_customer: false,
143+
create_products: false,
144+
invoice: {
145+
date: this.date,
146+
deadline: this.deadline,
147+
external_id: this.externalId,
148+
pdf_invoice_free_text: this.pdfInvoiceFreeText,
149+
pdf_invoice_subject: this.pdfInvoiceSubject,
150+
draft: this.draft,
151+
currency: this.currency,
152+
special_mention: this.specialMention,
153+
discount: this.discount,
154+
language: this.language,
155+
transactions_reference: {
156+
banking_provider: this.bankingProvider,
157+
provider_field_name: (this.bankingProvider === "gocardless")
158+
? "payment_id"
159+
: this.providerFieldName,
160+
provider_field_value: this.providerFieldValue,
161+
},
162+
customer: {
163+
source_id: this.customerId,
164+
},
165+
line_items_sections_attributes: parseObject(this.lineItemsSectionsAttributes),
166+
line_items: parseObject(this.lineItems),
167+
categories: parseObject(this.categories),
168+
imputation_dates: {
169+
start_date: this.startDate,
170+
end_date: this.endDate,
171+
},
172+
},
173+
},
174+
});
175+
176+
$.export("$summary", `Created invoice with ID ${invoice.invoice.id}`);
177+
return invoice;
178+
} catch ({ response }) {
179+
throw new ConfigurationError(response?.data?.message || response?.data?.error);
180+
}
181+
},
182+
};

0 commit comments

Comments
 (0)