Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import {
DAY_OF_WEEK_OPTIONS,
MODE_OPTIONS,
PAYMENT_CONDITIONS_OPTIONS,
PAYMENT_METHOD_OPTIONS,
RECURRING_RULE_TYPE,
} from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";
import pennylane from "../../pennylane.app.mjs";

export default {
key: "pennylane-create-billing-subscription",
name: "Create Billing Subscription",
description: "Creates a billing subscription for a customer. [See the documentation](https://pennylane.readme.io/reference/billing_subscriptions-post-1).",
version: "0.0.1",
type: "action",
props: {
pennylane,
currency: {
type: "string",
label: "Currency",
description: "Invoice Currency (ISO 4217). Default is EUR.",
optional: true,
},
mode: {
type: "string",
label: "Mode",
description: "Mode in which the new invoices will be created.",
options: MODE_OPTIONS,
},
start: {
type: "string",
label: "Start",
description: "Start date (ISO 8601)",
},
paymentConditions: {
type: "string",
label: "Payment Conditions",
description: "Customer payment conditions",
options: PAYMENT_CONDITIONS_OPTIONS,
},
paymentMethod: {
type: "string",
label: "Payment Method",
description: "PaymentMethod",
options: PAYMENT_METHOD_OPTIONS,
},
recurringRuleType: {
type: "string",
label: "Recurring Rule Type",
description: "Type of the billing subscription's recurrence",
options: RECURRING_RULE_TYPE,
reloadProps: true,
},
dayOfMonth: {
type: "integer",
label: "Day Of Month",
description: "The day of occurrences of the recurring rule",
hidden: true,
},
dayOfWeek: {
type: "string",
label: "Day Of Week",
description: "The day of occurrences of the recurring rule",
options: DAY_OF_WEEK_OPTIONS,
hidden: true,
},
interval: {
type: "string",
label: "Interval",
description: "The interval of occurrences of the recurring rule",
optional: true,
},
count: {
type: "integer",
label: "Count",
description: "Number of occurrences of the recurring rule",
optional: true,
},
specialMention: {
type: "string",
label: "Special Mention",
description: "Additional details",
optional: true,
},
discount: {
type: "integer",
label: "Discount",
description: "Invoice discount (in percent)",
optional: true,
},
customerId: {
propDefinition: [
pennylane,
"customerId",
],
},
lineItemsSectionsAttributes: {
propDefinition: [
pennylane,
"lineItemsSectionsAttributes",
],
optional: true,
},
invoiceLines: {
propDefinition: [
pennylane,
"lineItems",
],
label: "Invoice Lines",
},
},
async additionalProps(props) {
switch (this.recurringRuleType) {
case "monthly":
props.dayOfMonth.hidden = false;
props.dayOfWeek.hidden = true;
break;
case "weekly":
props.dayOfMonth.hidden = true;
props.dayOfWeek.hidden = false;
break;
case "yearly":
props.dayOfMonth.hidden = true;
props.dayOfWeek.hidden = true;
break;
}
return {};
},
async run({ $ }) {
const response = await this.pennylane.createBillingSubscription({
$,
data: {
create_customer: false,
create_products: false,
billing_subscription: {
currency: this.currency,
mode: this.mode,
start: this.start,
payment_conditions: this.paymentConditions,
payment_method: this.paymentMethod,
recurring_rule: {
type: this.recurringRuleType,
day_of_month: this.dayOfMonth,
day_of_week: this.dayOfWeek,
interval: this.interval,
count: this.count,
},
special_mention: this.specialMention,
discount: this.discount,
customer: {
source_id: this.customerId,
},
line_items_sections_attributes: parseObject(this.lineItemsSectionsAttributes),
invoice_lines: parseObject(this.invoiceLines),
},
},
});
$.export("$summary", `Created billing subscription with ID ${response.billing_subscription.id}`);
return response;
},
Comment on lines +130 to +161
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Check for null or empty invoiceLines in createBillingSubscription.
Since invoiceLines is mandatory, consider throwing an error or ensuring a fallback if users supply an empty array. This can help prevent partially configured subscriptions from reaching the API.

if (!this.invoiceLines || !this.invoiceLines.length) {
-  // Currently no check
+  throw new ConfigurationError("At least one invoice line must be provided");
}

Committable suggestion skipped: line range outside the PR's diff.

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { ConfigurationError } from "@pipedream/platform";
import {
BANKING_PROVIDER_OPTIONS,
LANGUAGE_OPTIONS,
PROVIDER_FIELD_NAMES_OPTIONS,
} from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";
import pennylane from "../../pennylane.app.mjs";

export default {
key: "pennylane-create-customer-invoice",
name: "Create Customer Invoice",
description: "Generates a new invoice for a customer using Pennylane. [See the documentation](https://pennylane.readme.io/reference/customer_invoices-post-1)",
version: "0.0.1",
type: "action",
props: {
pennylane,
date: {
type: "string",
label: "Date",
description: "Invoice date (ISO 8601)",
},
deadline: {
type: "string",
label: "Deadline",
description: "Invoice payment deadline (ISO 8601)",
},
externalId: {
type: "string",
label: "External Id",
description: "An id you can use to refer to the invoice from outside of Pennylane",
optional: true,
},
pdfInvoiceFreeText: {
type: "string",
label: "PDF Invoice Free Text",
description: "For example, the contact details of the person to contact",
optional: true,
},
pdfInvoiceSubject: {
type: "string",
label: "PDF Invoice Subject",
description: "Invoice title",
optional: true,
},
draft: {
type: "boolean",
label: "Draft",
description: "Do you wish to create a draft invoice (otherwise it is a finalized invoice)? Reminder, once created, a finalized invoice cannot be edited!",
},
currency: {
type: "string",
label: "Currency",
description: "Invoice Currency (ISO 4217). Default is EUR.",
optional: true,
},
specialMention: {
type: "string",
label: "Special Mention",
description: "Additional details",
optional: true,
},
discount: {
type: "integer",
label: "Discount",
description: "Invoice discount (in percent)",
optional: true,
},
language: {
type: "string",
label: "Language",
description: "invoice pdf language",
options: LANGUAGE_OPTIONS,
optional: true,
},
bankingProvider: {
type: "string",
label: "Banking Provider",
description: "The banking provider for the transaction",
options: BANKING_PROVIDER_OPTIONS,
reloadProps: true,
},
providerFieldName: {
type: "string",
label: "Provider Field Name",
description: "Name of the field that you want to match",
options: PROVIDER_FIELD_NAMES_OPTIONS,
hidden: true,
},
providerFieldValue: {
type: "string",
label: "Provider Field Value",
description: "Value that you want to match",
},
customerId: {
propDefinition: [
pennylane,
"customerId",
],
},
lineItemsSectionsAttributes: {
propDefinition: [
pennylane,
"lineItemsSectionsAttributes",
],
optional: true,
},
lineItems: {
propDefinition: [
pennylane,
"lineItems",
],
},
categories: {
type: "string[]",
label: "Categories",
description: "A list of objects of categories",
optional: true,
},
startDate: {
type: "string",
label: "Start Date",
description: "Start date of the imputation period (ISO 8601)",
},
endDate: {
type: "string",
label: "End Date",
description: "End date of the imputation period (ISO 8601)",
},
},
async additionalProps(props) {
if (this.bankingProvider === "stripe") {
props.providerFieldName.hidden = false;
}
return {};
},
async run({ $ }) {
try {
const invoice = await this.pennylane.createInvoice({
$,
data: {
create_customer: false,
create_products: false,
invoice: {
date: this.date,
deadline: this.deadline,
external_id: this.externalId,
pdf_invoice_free_text: this.pdfInvoiceFreeText,
pdf_invoice_subject: this.pdfInvoiceSubject,
draft: this.draft,
currency: this.currency,
special_mention: this.specialMention,
discount: this.discount,
language: this.language,
transactions_reference: {
banking_provider: this.bankingProvider,
provider_field_name: (this.bankingProvider === "gocardless")
? "payment_id"
: this.providerFieldName,
provider_field_value: this.providerFieldValue,
},
customer: {
source_id: this.customerId,
},
line_items_sections_attributes: parseObject(this.lineItemsSectionsAttributes),
line_items: parseObject(this.lineItems),
categories: parseObject(this.categories),
imputation_dates: {
start_date: this.startDate,
end_date: this.endDate,
},
},
},
});

$.export("$summary", `Created invoice with ID ${invoice.invoice.id}`);
return invoice;
} catch ({ response }) {
throw new ConfigurationError(response?.data?.message || response?.data?.error);
}
},
};
Loading
Loading