-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - pennylane #14973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - pennylane #14973
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
162 changes: 162 additions & 0 deletions
162
components/pennylane/actions/create-billing-subscription/create-billing-subscription.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
182 changes: 182 additions & 0 deletions
182
components/pennylane/actions/create-customer-invoice/create-customer-invoice.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.