From 12d6e2dd2180fc3c500c665ae52d927fcba1875d Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 11 Oct 2024 11:47:23 -0400 Subject: [PATCH 1/4] init --- .../create-customer/create-customer.mjs | 42 ++++++++ .../create-subscription.mjs | 53 +++++++++ .../update-subscription.mjs | 50 +++++++++ components/chargify/chargify.app.mjs | 102 +++++++++++++++++- .../sources/new-customer/new-customer.mjs | 89 +++++++++++++++ .../new-subscription-state.mjs | 54 ++++++++++ .../new-subscription/new-subscription.mjs | 68 ++++++++++++ 7 files changed, 453 insertions(+), 5 deletions(-) create mode 100644 components/chargify/actions/create-customer/create-customer.mjs create mode 100644 components/chargify/actions/create-subscription/create-subscription.mjs create mode 100644 components/chargify/actions/update-subscription/update-subscription.mjs create mode 100644 components/chargify/sources/new-customer/new-customer.mjs create mode 100644 components/chargify/sources/new-subscription-state/new-subscription-state.mjs create mode 100644 components/chargify/sources/new-subscription/new-subscription.mjs diff --git a/components/chargify/actions/create-customer/create-customer.mjs b/components/chargify/actions/create-customer/create-customer.mjs new file mode 100644 index 0000000000000..b0ffee036692f --- /dev/null +++ b/components/chargify/actions/create-customer/create-customer.mjs @@ -0,0 +1,42 @@ +import chargify from "../../chargify.app.mjs"; + +export default { + key: "chargify-create-customer", + name: "Create Customer", + description: "Creates a new customer in Chargify", + version: "0.0.{{ts}}", + type: "action", + props: { + chargify, + name: { + type: "string", + label: "Name", + description: "The name of the customer", + }, + email: { + type: "string", + label: "Email", + description: "The email of the customer", + optional: true, + }, + organization: { + type: "string", + label: "Organization", + description: "The organization of the customer", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.chargify.createCustomer({ + data: { + customer: { + first_name: this.name, + email: this.email, + organization: this.organization, + }, + }, + }); + $.export("$summary", `Successfully created customer ${this.name}`); + return response; + }, +}; \ No newline at end of file diff --git a/components/chargify/actions/create-subscription/create-subscription.mjs b/components/chargify/actions/create-subscription/create-subscription.mjs new file mode 100644 index 0000000000000..46dfae7ebda4c --- /dev/null +++ b/components/chargify/actions/create-subscription/create-subscription.mjs @@ -0,0 +1,53 @@ +js +import chargify from "../../chargify.app.mjs"; + +export default { + key: "chargify-create-subscription", + name: "Create Subscription", + description: "Establishes a new subscription for a given customer in Chargify", + version: "0.0.{{ts}}", + type: "action", + props: { + chargify, + customerId: { + propDefinition: [ + chargify, + "customerId" + ] + }, + productId: { + propDefinition: [ + chargify, + "productId" + ] + }, + couponCode: { + propDefinition: [ + chargify, + "couponCode" + ], + optional: true + }, + nextBillingAt: { + propDefinition: [ + chargify, + "nextBillingAt" + ], + optional: true + }, + }, + async run({ $ }) { + const response = await this.chargify.createSubscription({ + data: { + subscription: { + customer_id: this.customerId, + product_id: this.productId, + coupon_code: this.couponCode, + next_billing_at: this.nextBillingAt + } + } + }); + $.export("$summary", `Successfully created subscription with ID: ${response.id}`); + return response; + }, +}; \ No newline at end of file diff --git a/components/chargify/actions/update-subscription/update-subscription.mjs b/components/chargify/actions/update-subscription/update-subscription.mjs new file mode 100644 index 0000000000000..ff42812d8f27d --- /dev/null +++ b/components/chargify/actions/update-subscription/update-subscription.mjs @@ -0,0 +1,50 @@ +import chargify from "../../chargify.app.mjs"; + +export default { + key: "chargify-update-subscription", + name: "Update Subscription", + description: "Modifies an existing subscription in Chargify using its unique 'subscription_id'.", + version: "0.0.{{ts}}", + type: "action", + props: { + chargify, + subscriptionId: { + propDefinition: [ + chargify, + "subscriptionId", + ], + }, + productId: { + propDefinition: [ + chargify, + "productId", + ], + }, + nextBillingAt: { + propDefinition: [ + chargify, + "nextBillingAt", + ], + }, + couponCode: { + propDefinition: [ + chargify, + "couponCode", + ], + }, + }, + async run({ $ }) { + const response = await this.chargify.updateSubscription({ + subscriptionId: this.subscriptionId, + data: { + subscription: { + product_id: this.productId, + next_billing_at: this.nextBillingAt, + coupon_code: this.couponCode, + }, + }, + }); + $.export("$summary", `Successfully updated subscription ${this.subscriptionId}`); + return response; + }, +}; \ No newline at end of file diff --git a/components/chargify/chargify.app.mjs b/components/chargify/chargify.app.mjs index fb19cd17138b5..7d8e09ca961f4 100644 --- a/components/chargify/chargify.app.mjs +++ b/components/chargify/chargify.app.mjs @@ -1,11 +1,103 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "chargify", - propDefinitions: {}, + propDefinitions: { + customerId: { + type: "string", + label: "Customer ID", + description: "The ID of the customer", + }, + subscriptionId: { + type: "string", + label: "Subscription ID", + description: "The ID of the subscription", + }, + name: { + type: "string", + label: "Name", + description: "The name of the customer", + optional: true, + }, + email: { + type: "string", + label: "Email", + description: "The email of the customer", + optional: true, + }, + organization: { + type: "string", + label: "Organization", + description: "The organization of the customer", + optional: true, + }, + productId: { + type: "string", + label: "Product ID", + description: "The ID of the product", + }, + couponCode: { + type: "string", + label: "Coupon Code", + description: "The coupon code", + optional: true, + }, + nextBillingAt: { + type: "string", + label: "Next Billing At", + description: "The next billing date", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.chargify.com/api/v2"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + method = "GET", + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.api_token}`, + }, + }); + }, + async createCustomer(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/customers", + ...opts, + }); + }, + async getSubscriptions(opts = {}) { + return this._makeRequest({ + path: "/subscriptions", + ...opts, + }); + }, + async createSubscription(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/subscriptions", + ...opts, + }); + }, + async updateSubscription({ subscriptionId, ...opts }) { + return this._makeRequest({ + method: "PUT", + path: `/subscriptions/${subscriptionId}`, + ...opts, + }); }, }, -}; +}; \ No newline at end of file diff --git a/components/chargify/sources/new-customer/new-customer.mjs b/components/chargify/sources/new-customer/new-customer.mjs new file mode 100644 index 0000000000000..9e39f9a2a6ee5 --- /dev/null +++ b/components/chargify/sources/new-customer/new-customer.mjs @@ -0,0 +1,89 @@ +import chargify from "../../chargify.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "chargify-new-customer", + name: "New Customer", + description: "Emits an event when a new customer is added in Chargify", + version: "0.0.{{ts}}", + type: "source", + dedupe: "unique", + props: { + chargify, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: 60 * 15, // 15 minutes + }, + }, + }, + methods: { + _getCustomerId(customer) { + return customer.id; + }, + _getTimestamp(customer) { + return +new Date(customer.created_at); + }, + }, + hooks: { + async deploy() { + const customers = await this.chargify._makeRequest({ + path: "/customers", + params: { order: "desc", per_page: 1 }, + }); + if (customers.length > 0) { + const lastProcessedCustomerId = this._getCustomerId(customers[0]); + this.db.set("lastProcessedCustomerId", lastProcessedCustomerId); + const lastTimestamp = this._getTimestamp(customers[0]); + this.db.set("lastTimestamp", lastTimestamp); + } + }, + }, + async run() { + const lastCustomerId = this.db.get("lastProcessedCustomerId") || 0; + const lastTimestamp = this.db.get("lastTimestamp") || 0; + const params = { + page: 1, + per_page: 100, + }; + + while (true) { + const { data: customers } = await this.chargify._makeRequest({ + path: "/customers", + params, + }); + + if (customers.length === 0) { + console.log("No new customers found, exiting"); + break; + } + + for (const customer of customers) { + const customerId = this._getCustomerId(customer); + const timestamp = this._getTimestamp(customer); + + if (customerId > lastCustomerId && timestamp > lastTimestamp) { + this.$emit(customer, { + id: customerId, + summary: `New Customer: ${customer.first_name} ${customer.last_name}`, + ts: timestamp, + }); + } else { + console.log("No new customers found, exiting"); + break; + } + } + + params.page++; + } + + const { data: latestCustomer } = await this.chargify._makeRequest({ + path: "/customers", + params: { order: "desc", per_page: 1 }, + }); + + this.db.set("lastCustomerId", this._getCustomerId(latestCustomer[0])); + this.db.set("lastTimestamp", this._getTimestamp(latestCustomer[0])); + }, +}; \ No newline at end of file diff --git a/components/chargify/sources/new-subscription-state/new-subscription-state.mjs b/components/chargify/sources/new-subscription-state/new-subscription-state.mjs new file mode 100644 index 0000000000000..d128e48d6d510 --- /dev/null +++ b/components/chargify/sources/new-subscription-state/new-subscription-state.mjs @@ -0,0 +1,54 @@ +import chargify from "../../chargify.app.mjs"; + +export default { + key: "chargify-new-subscription-state", + name: "New Subscription State", + description: "Emits an event when the state of a subscription changes", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + chargify, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: 60 * 15, // check every 15 minutes + }, + }, + subscriptionId: { + propDefinition: [chargify, "subscriptionId"], + }, + }, + + methods: { + _getSubscription() { + return this.chargify.getSubscriptions({ + subscriptionId: this.subscriptionId, + }); + }, + }, + + hooks: { + async deploy() { + // get the current state of the subscription + const subscription = await this._getSubscription(); + this.db.set("currentState", subscription.state); + }, + }, + + async run() { + const subscription = await this._getSubscription(); + const currentState = this.db.get("currentState"); + + // check if state has changed + if (subscription.state !== currentState) { + this.$emit(subscription, { + id: subscription.id, + summary: `Subscription state changed to ${subscription.state}`, + ts: Date.now(), + }); + this.db.set("currentState", subscription.state); + } + }, +}; \ No newline at end of file diff --git a/components/chargify/sources/new-subscription/new-subscription.mjs b/components/chargify/sources/new-subscription/new-subscription.mjs new file mode 100644 index 0000000000000..d8e2345f94fc3 --- /dev/null +++ b/components/chargify/sources/new-subscription/new-subscription.mjs @@ -0,0 +1,68 @@ +import chargify from "../../chargify.app.mjs"; + +export default { + key: "chargify-new-subscription", + name: "New Subscription", + description: "Emit new event when a new subscription is created.", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + chargify, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: 60 * 15, // 15 minutes + }, + }, + customerId: { + propDefinition: [chargify, "customerId"], + }, + subscriptionId: { + propDefinition: [chargify, "subscriptionId"], + }, + name: { + propDefinition: [chargify, "name"], + }, + email: { + propDefinition: [chargify, "email"], + }, + organization: { + propDefinition: [chargify, "organization"], + }, + productId: { + propDefinition: [chargify, "productId"], + }, + couponCode: { + propDefinition: [chargify, "couponCode"], + }, + nextBillingAt: { + propDefinition: [chargify, "nextBillingAt"], + }, + }, + methods: { + _getSubscriptionId() { + return this.db.get("subscriptionId"); + }, + _setSubscriptionId(id) { + this.db.set("subscriptionId", id); + }, + }, + async run() { + const subscriptions = await this.chargify.getSubscriptions({ + customerId: this.customerId, + }); + + for (const subscription of subscriptions) { + if (subscription.id > this._getSubscriptionId()) { + this.$emit(subscription, { + id: subscription.id, + summary: `New subscription: ${subscription.name}`, + ts: Date.now(), + }); + this._setSubscriptionId(subscription.id); + } + } + }, +}; \ No newline at end of file From 4d596e3ed2f37755f006a24efa42193a7014dc44 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 11 Oct 2024 15:32:13 -0400 Subject: [PATCH 2/4] new components --- .../create-customer/create-customer.mjs | 84 ++++++++-- .../create-subscription.mjs | 35 ++-- .../update-subscription.mjs | 21 ++- components/chargify/chargify.app.mjs | 156 ++++++++++++++---- components/chargify/package.json | 18 ++ components/chargify/sources/common/base.mjs | 71 ++++++++ .../new-customer-instant.mjs | 22 +++ .../new-customer-instant/test-event.mjs | 35 ++++ .../sources/new-customer/new-customer.mjs | 89 ---------- .../new-subscription-instant.mjs | 22 +++ .../new-subscription-instant/test-event.mjs | 132 +++++++++++++++ .../new-subscription-state-instant.mjs | 22 +++ .../test-event.mjs | 130 +++++++++++++++ .../new-subscription-state.mjs | 54 ------ .../new-subscription/new-subscription.mjs | 68 -------- 15 files changed, 680 insertions(+), 279 deletions(-) create mode 100644 components/chargify/package.json create mode 100644 components/chargify/sources/common/base.mjs create mode 100644 components/chargify/sources/new-customer-instant/new-customer-instant.mjs create mode 100644 components/chargify/sources/new-customer-instant/test-event.mjs delete mode 100644 components/chargify/sources/new-customer/new-customer.mjs create mode 100644 components/chargify/sources/new-subscription-instant/new-subscription-instant.mjs create mode 100644 components/chargify/sources/new-subscription-instant/test-event.mjs create mode 100644 components/chargify/sources/new-subscription-state-instant/new-subscription-state-instant.mjs create mode 100644 components/chargify/sources/new-subscription-state-instant/test-event.mjs delete mode 100644 components/chargify/sources/new-subscription-state/new-subscription-state.mjs delete mode 100644 components/chargify/sources/new-subscription/new-subscription.mjs diff --git a/components/chargify/actions/create-customer/create-customer.mjs b/components/chargify/actions/create-customer/create-customer.mjs index b0ffee036692f..016411119d257 100644 --- a/components/chargify/actions/create-customer/create-customer.mjs +++ b/components/chargify/actions/create-customer/create-customer.mjs @@ -3,21 +3,25 @@ import chargify from "../../chargify.app.mjs"; export default { key: "chargify-create-customer", name: "Create Customer", - description: "Creates a new customer in Chargify", - version: "0.0.{{ts}}", + description: "Creates a new customer in Chargify. [See the documentation](https://developers.maxio.com/http/advanced-billing-api/api-endpoints/customers/create-customer)", + version: "0.0.1", type: "action", props: { chargify, - name: { + firstName: { type: "string", - label: "Name", - description: "The name of the customer", + label: "First Name", + description: "The first name of the customer", + }, + lastName: { + type: "string", + label: "Last Name", + description: "The last name of the customer", }, email: { type: "string", label: "Email", description: "The email of the customer", - optional: true, }, organization: { type: "string", @@ -25,18 +29,76 @@ export default { description: "The organization of the customer", optional: true, }, + address: { + type: "string", + label: "Street Address", + description: "Street address of the customer (line 1)", + optional: true, + }, + address2: { + type: "string", + label: "Street Address (line 2)", + description: "Street address of the customer (line 2)", + optional: true, + }, + city: { + type: "string", + label: "City", + description: "City of the customer", + optional: true, + }, + state: { + type: "string", + label: "State", + description: "State/Region of the customer", + optional: true, + }, + zip: { + type: "string", + label: "Zip", + description: "Zip code of the customer", + optional: true, + }, + country: { + type: "string", + label: "Country", + description: "The country code of the customer. Example: `US`", + optional: true, + }, + phone: { + type: "string", + label: "Phone", + description: "Phone number of the customer", + optional: true, + }, + taxExempt: { + type: "boolean", + label: "Tax Exempt", + description: "Set to `true` if the customer is tax exempt.", + optional: true, + }, }, async run({ $ }) { - const response = await this.chargify.createCustomer({ + const { customer } = await this.chargify.createCustomer({ + $, data: { customer: { - first_name: this.name, + first_name: this.firstName, + last_name: this.lastName, email: this.email, organization: this.organization, + address: this.address, + address_2: this.address2, + city: this.city, + state: this.state, + zip: this.zip, + country: this.country, + phone: this.phone, + tax_exempt: this.taxExempt, }, }, }); - $.export("$summary", `Successfully created customer ${this.name}`); - return response; + $.export("$summary", `Successfully created customer with ID ${customer.id}`); + return customer; }, -}; \ No newline at end of file +}; diff --git a/components/chargify/actions/create-subscription/create-subscription.mjs b/components/chargify/actions/create-subscription/create-subscription.mjs index 46dfae7ebda4c..67691287ec192 100644 --- a/components/chargify/actions/create-subscription/create-subscription.mjs +++ b/components/chargify/actions/create-subscription/create-subscription.mjs @@ -1,53 +1,58 @@ -js import chargify from "../../chargify.app.mjs"; export default { key: "chargify-create-subscription", name: "Create Subscription", - description: "Establishes a new subscription for a given customer in Chargify", - version: "0.0.{{ts}}", + description: "Establishes a new subscription for a given customer in Chargify. [See the documentation](https://developers.maxio.com/http/advanced-billing-api/api-endpoints/subscriptions/create-subscription)", + version: "0.0.1", type: "action", props: { chargify, customerId: { propDefinition: [ chargify, - "customerId" - ] + "customerId", + ], }, productId: { propDefinition: [ chargify, - "productId" - ] + "productId", + ], }, couponCode: { propDefinition: [ chargify, - "couponCode" + "couponCode", ], - optional: true }, nextBillingAt: { propDefinition: [ chargify, - "nextBillingAt" + "nextBillingAt", + ], + }, + paymentCollectionMethod: { + propDefinition: [ + chargify, + "paymentCollectionMethod", ], - optional: true }, }, async run({ $ }) { const response = await this.chargify.createSubscription({ + $, data: { subscription: { customer_id: this.customerId, product_id: this.productId, coupon_code: this.couponCode, - next_billing_at: this.nextBillingAt - } - } + next_billing_at: this.nextBillingAt, + payment_collection_method: this.paymentCollectionMethod, + }, + }, }); $.export("$summary", `Successfully created subscription with ID: ${response.id}`); return response; }, -}; \ No newline at end of file +}; diff --git a/components/chargify/actions/update-subscription/update-subscription.mjs b/components/chargify/actions/update-subscription/update-subscription.mjs index ff42812d8f27d..01e1a6421ed2f 100644 --- a/components/chargify/actions/update-subscription/update-subscription.mjs +++ b/components/chargify/actions/update-subscription/update-subscription.mjs @@ -3,8 +3,8 @@ import chargify from "../../chargify.app.mjs"; export default { key: "chargify-update-subscription", name: "Update Subscription", - description: "Modifies an existing subscription in Chargify using its unique 'subscription_id'.", - version: "0.0.{{ts}}", + description: "Modifies an existing subscription in Chargify. [See the documentation](https://developers.maxio.com/http/advanced-billing-api/api-endpoints/subscriptions/update-subscription)", + version: "0.0.1", type: "action", props: { chargify, @@ -19,6 +19,13 @@ export default { chargify, "productId", ], + optional: true, + }, + couponCode: { + propDefinition: [ + chargify, + "couponCode", + ], }, nextBillingAt: { propDefinition: [ @@ -26,25 +33,27 @@ export default { "nextBillingAt", ], }, - couponCode: { + paymentCollectionMethod: { propDefinition: [ chargify, - "couponCode", + "paymentCollectionMethod", ], }, }, async run({ $ }) { const response = await this.chargify.updateSubscription({ + $, subscriptionId: this.subscriptionId, data: { subscription: { product_id: this.productId, - next_billing_at: this.nextBillingAt, coupon_code: this.couponCode, + next_billing_at: this.nextBillingAt, + payment_collection_method: this.paymentCollectionMethod, }, }, }); $.export("$summary", `Successfully updated subscription ${this.subscriptionId}`); return response; }, -}; \ No newline at end of file +}; diff --git a/components/chargify/chargify.app.mjs b/components/chargify/chargify.app.mjs index 7d8e09ca961f4..499ef2d70d568 100644 --- a/components/chargify/chargify.app.mjs +++ b/components/chargify/chargify.app.mjs @@ -8,96 +8,180 @@ export default { type: "string", label: "Customer ID", description: "The ID of the customer", + async options({ page }) { + const customers = await this.listCustomers({ + params: { + page: page + 1, + }, + }); + return customers?.map(({ customer }) => ({ + value: customer.id, + label: `${customer.first_name} ${customer.last_name}`, + })) || []; + }, }, subscriptionId: { type: "string", label: "Subscription ID", description: "The ID of the subscription", - }, - name: { - type: "string", - label: "Name", - description: "The name of the customer", - optional: true, - }, - email: { - type: "string", - label: "Email", - description: "The email of the customer", - optional: true, - }, - organization: { - type: "string", - label: "Organization", - description: "The organization of the customer", - optional: true, + async options({ page }) { + const subscriptions = await this.listSubscriptions({ + params: { + page: page + 1, + }, + }); + return subscriptions?.map(({ subscription }) => ({ + value: subscription.id, + label: `${subscription.customer.first_name} ${subscription.customer.last_name} - ${subscription.product.name}`, + })) || []; + }, }, productId: { type: "string", label: "Product ID", description: "The ID of the product", + async options({ page }) { + const products = await this.listProducts({ + params: { + page: page + 1, + }, + }); + return products?.map(({ product }) => ({ + value: product.id, + label: product.name, + })) || []; + }, }, couponCode: { type: "string", label: "Coupon Code", description: "The coupon code", optional: true, + async options({ page }) { + const coupons = await this.listCoupons({ + params: { + page: page + 1, + }, + }); + return coupons?.map(({ coupon }) => ({ + value: coupon.code, + label: coupon.name, + })) || []; + }, + }, + paymentCollectionMethod: { + type: "string", + label: "Payment Collection Method", + description: "The type of payment collection to be used in the subscription", + optional: true, + options: [ + "automatic", + "remittance", + "prepaid", + ], }, nextBillingAt: { type: "string", label: "Next Billing At", - description: "The next billing date", + description: "The next billing date in ISO-8601 format. Example: `2024-10-31T00:00:00Z`", optional: true, }, }, methods: { _baseUrl() { - return "https://api.chargify.com/api/v2"; + return `https://${this.$auth.subdomain}.chargify.com`; }, - async _makeRequest(opts = {}) { + _makeRequest(opts = {}) { const { $ = this, - method = "GET", path, - headers, ...otherOpts } = opts; return axios($, { ...otherOpts, - method, - url: this._baseUrl() + path, + url: `${this._baseUrl()}${path}`, headers: { - ...headers, - Authorization: `Bearer ${this.$auth.api_token}`, + "Content-type": "application/json", + "Accept": "application/json", + }, + auth: { + username: `${this.$auth.api_key}`, + password: "", }, }); }, - async createCustomer(opts = {}) { + createWebhook(opts = {}) { return this._makeRequest({ method: "POST", - path: "/customers", + path: "/endpoints.json", + ...opts, + }); + }, + deleteWebhook({ + hookId, ...opts + }) { + return this._makeRequest({ + method: "PUT", + path: `/endpoints/${hookId}.json`, ...opts, }); }, - async getSubscriptions(opts = {}) { + enableWebhooks(opts = {}) { return this._makeRequest({ - path: "/subscriptions", + method: "PUT", + path: "/webhooks/settings.json", + data: { + webhooks_enabled: true, + }, + ...opts, + }); + }, + listCustomers(opts = {}) { + return this._makeRequest({ + path: "/customers.json", + ...opts, + }); + }, + listSubscriptions(opts = {}) { + return this._makeRequest({ + path: "/subscriptions.json", + ...opts, + }); + }, + listProducts(opts = {}) { + return this._makeRequest({ + path: "/products.json", + ...opts, + }); + }, + listCoupons(opts = {}) { + return this._makeRequest({ + path: "/coupons.json", + ...opts, + }); + }, + createCustomer(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/customers.json", ...opts, }); }, - async createSubscription(opts = {}) { + createSubscription(opts = {}) { return this._makeRequest({ method: "POST", - path: "/subscriptions", + path: "/subscriptions.json", ...opts, }); }, - async updateSubscription({ subscriptionId, ...opts }) { + updateSubscription({ + subscriptionId, ...opts + }) { return this._makeRequest({ method: "PUT", - path: `/subscriptions/${subscriptionId}`, + path: `/subscriptions/${subscriptionId}.json`, ...opts, }); }, }, -}; \ No newline at end of file +}; diff --git a/components/chargify/package.json b/components/chargify/package.json new file mode 100644 index 0000000000000..89314a086ed2a --- /dev/null +++ b/components/chargify/package.json @@ -0,0 +1,18 @@ +{ + "name": "@pipedream/chargify", + "version": "0.0.1", + "description": "Pipedream Chargify Components", + "main": "chargify.app.mjs", + "keywords": [ + "pipedream", + "chargify" + ], + "homepage": "https://pipedream.com/apps/chargify", + "author": "Pipedream (https://pipedream.com/)", + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" + } +} diff --git a/components/chargify/sources/common/base.mjs b/components/chargify/sources/common/base.mjs new file mode 100644 index 0000000000000..79d16a72599e5 --- /dev/null +++ b/components/chargify/sources/common/base.mjs @@ -0,0 +1,71 @@ +import chargify from "../../chargify.app.mjs"; + +export default { + props: { + chargify, + db: "$.service.db", + http: "$.interface.http", + }, + hooks: { + async deploy() { + // ensure webhooks are enabled in user's account + await this.chargify.enableWebhooks(); + }, + async activate() { + const { endpoint: { id } } = await this.chargify.createWebhook({ + data: { + endpoint: { + url: this.http.endpoint, + webhook_subscriptions: [ + this.getEventType(), + ], + }, + }, + }); + this._setHookId(id); + }, + async deactivate() { + const hookId = this._getHookId(); + if (hookId) { + await this.chargify.deleteWebhook({ + hookId, + data: { + endpoint: { + url: this.http.endpoint, + webhook_subscriptions: [], + }, + }, + }); + } + }, + }, + methods: { + _getHookId() { + return this.db.get("hookId"); + }, + _setHookId(hookId) { + this.db.set("hookId", hookId); + }, + generateMeta(item) { + return { + id: item.id, + summary: this.getSummary(item), + ts: Date.now(), + }; + }, + getEventType() { + throw new Error("getEventType is not implemented"); + }, + getSummary() { + throw new Error("getSummary is not implemented"); + }, + }, + async run(event) { + const { body } = event; + if (!body) { + return; + } + const meta = this.generateMeta(body); + this.$emit(body, meta); + }, +}; diff --git a/components/chargify/sources/new-customer-instant/new-customer-instant.mjs b/components/chargify/sources/new-customer-instant/new-customer-instant.mjs new file mode 100644 index 0000000000000..9dcb36e880802 --- /dev/null +++ b/components/chargify/sources/new-customer-instant/new-customer-instant.mjs @@ -0,0 +1,22 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "chargify-new-customer-instant", + name: "New Customer (Instant)", + description: "Emit new event when a new customer is added in Chargify", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEventType() { + return "customer_create"; + }, + getSummary(item) { + return `New Customer with ID: ${item["payload[customer][id]"]}`; + }, + }, + sampleEmit, +}; diff --git a/components/chargify/sources/new-customer-instant/test-event.mjs b/components/chargify/sources/new-customer-instant/test-event.mjs new file mode 100644 index 0000000000000..69bfbae5755b3 --- /dev/null +++ b/components/chargify/sources/new-customer-instant/test-event.mjs @@ -0,0 +1,35 @@ +export default { + "id": "2566241561", + "event": "customer_create", + "payload[customer][id]": "83698432", + "payload[customer][first_name]": "FirstName", + "payload[customer][last_name]": "LastName", + "payload[customer][organization]": "", + "payload[customer][email]": "test@email.com", + "payload[customer][created_at]": "2024-10-11 15:12:51 -0400", + "payload[customer][updated_at]": "2024-10-11 15:12:51 -0400", + "payload[customer][reference]": "", + "payload[customer][address]": "", + "payload[customer][address_2]": "", + "payload[customer][address_3]": "", + "payload[customer][city]": "", + "payload[customer][state]": "", + "payload[customer][zip]": "", + "payload[customer][country]": "", + "payload[customer][phone]": "", + "payload[customer][portal_invite_last_sent_at]": "", + "payload[customer][portal_invite_last_accepted_at]": "", + "payload[customer][verified]": "false", + "payload[customer][portal_customer_created_at]": "", + "payload[customer][vat_number]": "", + "payload[customer][cc_emails]": "", + "payload[customer][tax_exempt]": "false", + "payload[customer][tax_exempt_reason]": "", + "payload[customer][parent_id]": "", + "payload[customer][locale]": "", + "payload[customer][salesforce_id]": "", + "payload[customer][default_auto_renewal_profile_id]": "", + "payload[site][id]": "87942", + "payload[site][subdomain]": "testing", + "payload[event_id]": "4833962613" +} \ No newline at end of file diff --git a/components/chargify/sources/new-customer/new-customer.mjs b/components/chargify/sources/new-customer/new-customer.mjs deleted file mode 100644 index 9e39f9a2a6ee5..0000000000000 --- a/components/chargify/sources/new-customer/new-customer.mjs +++ /dev/null @@ -1,89 +0,0 @@ -import chargify from "../../chargify.app.mjs"; -import { axios } from "@pipedream/platform"; - -export default { - key: "chargify-new-customer", - name: "New Customer", - description: "Emits an event when a new customer is added in Chargify", - version: "0.0.{{ts}}", - type: "source", - dedupe: "unique", - props: { - chargify, - db: "$.service.db", - timer: { - type: "$.interface.timer", - default: { - intervalSeconds: 60 * 15, // 15 minutes - }, - }, - }, - methods: { - _getCustomerId(customer) { - return customer.id; - }, - _getTimestamp(customer) { - return +new Date(customer.created_at); - }, - }, - hooks: { - async deploy() { - const customers = await this.chargify._makeRequest({ - path: "/customers", - params: { order: "desc", per_page: 1 }, - }); - if (customers.length > 0) { - const lastProcessedCustomerId = this._getCustomerId(customers[0]); - this.db.set("lastProcessedCustomerId", lastProcessedCustomerId); - const lastTimestamp = this._getTimestamp(customers[0]); - this.db.set("lastTimestamp", lastTimestamp); - } - }, - }, - async run() { - const lastCustomerId = this.db.get("lastProcessedCustomerId") || 0; - const lastTimestamp = this.db.get("lastTimestamp") || 0; - const params = { - page: 1, - per_page: 100, - }; - - while (true) { - const { data: customers } = await this.chargify._makeRequest({ - path: "/customers", - params, - }); - - if (customers.length === 0) { - console.log("No new customers found, exiting"); - break; - } - - for (const customer of customers) { - const customerId = this._getCustomerId(customer); - const timestamp = this._getTimestamp(customer); - - if (customerId > lastCustomerId && timestamp > lastTimestamp) { - this.$emit(customer, { - id: customerId, - summary: `New Customer: ${customer.first_name} ${customer.last_name}`, - ts: timestamp, - }); - } else { - console.log("No new customers found, exiting"); - break; - } - } - - params.page++; - } - - const { data: latestCustomer } = await this.chargify._makeRequest({ - path: "/customers", - params: { order: "desc", per_page: 1 }, - }); - - this.db.set("lastCustomerId", this._getCustomerId(latestCustomer[0])); - this.db.set("lastTimestamp", this._getTimestamp(latestCustomer[0])); - }, -}; \ No newline at end of file diff --git a/components/chargify/sources/new-subscription-instant/new-subscription-instant.mjs b/components/chargify/sources/new-subscription-instant/new-subscription-instant.mjs new file mode 100644 index 0000000000000..9551da104e7cd --- /dev/null +++ b/components/chargify/sources/new-subscription-instant/new-subscription-instant.mjs @@ -0,0 +1,22 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "chargify-new-subscription-instant", + name: "New Subscription (Instant)", + description: "Emit new event when a new subscription is created.", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEventType() { + return "signup_success"; + }, + getSummary(item) { + return `New Subscription with ID: ${item["payload[subscription][id]"]}`; + }, + }, + sampleEmit, +}; diff --git a/components/chargify/sources/new-subscription-instant/test-event.mjs b/components/chargify/sources/new-subscription-instant/test-event.mjs new file mode 100644 index 0000000000000..9e265b8021903 --- /dev/null +++ b/components/chargify/sources/new-subscription-instant/test-event.mjs @@ -0,0 +1,132 @@ +export default { + "id": "2566271773", + "event": "signup_success", + "payload[subscription][id]": "79431158", + "payload[subscription][state]": "active", + "payload[subscription][trial_started_at]": "", + "payload[subscription][trial_ended_at]": "", + "payload[subscription][activated_at]": "2024-10-11 15:22:07 -0400", + "payload[subscription][created_at]": "2024-10-11 15:22:06 -0400", + "payload[subscription][updated_at]": "2024-10-11 15:22:08 -0400", + "payload[subscription][expires_at]": "", + "payload[subscription][balance_in_cents]": "0", + "payload[subscription][current_period_ends_at]": "2024-11-11 14:22:06 -0500", + "payload[subscription][next_assessment_at]": "2024-11-11 14:22:06 -0500", + "payload[subscription][canceled_at]": "", + "payload[subscription][cancellation_message]": "", + "payload[subscription][next_product_id]": "", + "payload[subscription][next_product_handle]": "", + "payload[subscription][cancel_at_end_of_period]": "false", + "payload[subscription][payment_collection_method]": "automatic", + "payload[subscription][snap_day]": "", + "payload[subscription][cancellation_method]": "", + "payload[subscription][current_period_started_at]": "2024-10-11 15:22:06 -0400", + "payload[subscription][previous_state]": "active", + "payload[subscription][signup_payment_id]": "1170015322", + "payload[subscription][signup_revenue]": "0.00", + "payload[subscription][delayed_cancel_at]": "", + "payload[subscription][coupon_code]": "", + "payload[subscription][total_revenue_in_cents]": "0", + "payload[subscription][product_price_in_cents]": "0", + "payload[subscription][product_version_number]": "1", + "payload[subscription][payment_type]": "", + "payload[subscription][referral_code]": "", + "payload[subscription][coupon_use_count]": "", + "payload[subscription][coupon_uses_allowed]": "", + "payload[subscription][reason_code]": "", + "payload[subscription][automatically_resume_at]": "", + "payload[subscription][offer_id]": "", + "payload[subscription][payer_id]": "", + "payload[subscription][receives_invoice_emails]": "", + "payload[subscription][product_price_point_id]": "3322919", + "payload[subscription][next_product_price_point_id]": "", + "payload[subscription][credit_balance_in_cents]": "0", + "payload[subscription][prepayment_balance_in_cents]": "0", + "payload[subscription][net_terms]": "", + "payload[subscription][stored_credential_transaction_id]": "", + "payload[subscription][locale]": "", + "payload[subscription][reference]": "", + "payload[subscription][currency]": "USD", + "payload[subscription][on_hold_at]": "", + "payload[subscription][scheduled_cancellation_at]": "", + "payload[subscription][product_price_point_type]": "default", + "payload[subscription][dunning_communication_delay_enabled]": "false", + "payload[subscription][dunning_communication_delay_time_zone]": "", + "payload[subscription][customer][id]": "83698432", + "payload[subscription][customer][first_name]": "FirstName", + "payload[subscription][customer][last_name]": "LastName", + "payload[subscription][customer][organization]": "", + "payload[subscription][customer][email]": "firstname@lastname.com", + "payload[subscription][customer][created_at]": "2024-10-11 15:12:51 -0400", + "payload[subscription][customer][updated_at]": "2024-10-11 15:12:51 -0400", + "payload[subscription][customer][reference]": "", + "payload[subscription][customer][address]": "", + "payload[subscription][customer][address_2]": "", + "payload[subscription][customer][address_3]": "", + "payload[subscription][customer][city]": "", + "payload[subscription][customer][state]": "", + "payload[subscription][customer][state_name]": "", + "payload[subscription][customer][zip]": "", + "payload[subscription][customer][country]": "", + "payload[subscription][customer][country_name]": "", + "payload[subscription][customer][phone]": "", + "payload[subscription][customer][portal_invite_last_sent_at]": "", + "payload[subscription][customer][portal_invite_last_accepted_at]": "", + "payload[subscription][customer][verified]": "false", + "payload[subscription][customer][portal_customer_created_at]": "", + "payload[subscription][customer][vat_number]": "", + "payload[subscription][customer][cc_emails]": "", + "payload[subscription][customer][tax_exempt]": "false", + "payload[subscription][customer][tax_exempt_reason]": "", + "payload[subscription][customer][parent_id]": "", + "payload[subscription][customer][locale]": "", + "payload[subscription][customer][salesforce_id]": "", + "payload[subscription][product][id]": "6748126", + "payload[subscription][product][name]": "Pro Plan", + "payload[subscription][product][handle]": "", + "payload[subscription][product][description]": "", + "payload[subscription][product][accounting_code]": "", + "payload[subscription][product][request_credit_card]": "true", + "payload[subscription][product][expiration_interval]": "", + "payload[subscription][product][expiration_interval_unit]": "never", + "payload[subscription][product][created_at]": "2024-10-11 12:56:32 -0400", + "payload[subscription][product][updated_at]": "2024-10-11 12:56:32 -0400", + "payload[subscription][product][price_in_cents]": "0", + "payload[subscription][product][interval]": "1", + "payload[subscription][product][interval_unit]": "month", + "payload[subscription][product][initial_charge_in_cents]": "", + "payload[subscription][product][trial_price_in_cents]": "", + "payload[subscription][product][trial_interval]": "", + "payload[subscription][product][trial_interval_unit]": "month", + "payload[subscription][product][archived_at]": "", + "payload[subscription][product][require_credit_card]": "false", + "payload[subscription][product][return_params]": "", + "payload[subscription][product][taxable]": "false", + "payload[subscription][product][update_return_url]": "", + "payload[subscription][product][tax_code]": "", + "payload[subscription][product][initial_charge_after_trial]": "false", + "payload[subscription][product][version_number]": "1", + "payload[subscription][product][update_return_params]": "", + "payload[subscription][product][default_product_price_point_id]": "3322919", + "payload[subscription][product][request_billing_address]": "false", + "payload[subscription][product][require_billing_address]": "false", + "payload[subscription][product][require_shipping_address]": "false", + "payload[subscription][product][use_site_exchange_rate]": "true", + "payload[subscription][product][item_category]": "", + "payload[subscription][product][product_price_point_id]": "3322919", + "payload[subscription][product][product_price_point_name]": "Original", + "payload[subscription][product][product_price_point_handle]": "uuid:b0c26c80-6a1f-013d-c9f9-063702f7df93", + "payload[subscription][product][product_family][id]": "2699089", + "payload[subscription][product][product_family][name]": "Billing Plans", + "payload[subscription][product][product_family][description]": "", + "payload[subscription][product][product_family][handle]": "testing-billing-plans", + "payload[subscription][product][product_family][accounting_code]": "", + "payload[subscription][product][product_family][created_at]": "2024-10-11 11:23:44 -0400", + "payload[subscription][product][product_family][updated_at]": "2024-10-11 11:23:44 -0400", + "payload[subscription][group]": "", + "payload[subscription][initial_billing_at]": "", + "payload[subscription][referred_by]": "", + "payload[site][id]": "87942", + "payload[site][subdomain]": "testing", + "payload[event_id]": "4833997313" +} \ No newline at end of file diff --git a/components/chargify/sources/new-subscription-state-instant/new-subscription-state-instant.mjs b/components/chargify/sources/new-subscription-state-instant/new-subscription-state-instant.mjs new file mode 100644 index 0000000000000..98bd4044abce8 --- /dev/null +++ b/components/chargify/sources/new-subscription-state-instant/new-subscription-state-instant.mjs @@ -0,0 +1,22 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "chargify-new-subscription-state-instant", + name: "New Subscription State (Instant)", + description: "Emit new event when the state of a subscription changes", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEventType() { + return "subscription_state_change"; + }, + getSummary(item) { + return `State updated for subscription ${item["payload[subscription][id]"]}`; + }, + }, + sampleEmit, +}; diff --git a/components/chargify/sources/new-subscription-state-instant/test-event.mjs b/components/chargify/sources/new-subscription-state-instant/test-event.mjs new file mode 100644 index 0000000000000..066982231c74a --- /dev/null +++ b/components/chargify/sources/new-subscription-state-instant/test-event.mjs @@ -0,0 +1,130 @@ +export default { + "id": "2566279204", + "event": "subscription_state_change", + "payload[subscription][id]": "79431128", + "payload[subscription][state]": "on_hold", + "payload[subscription][trial_started_at]": "", + "payload[subscription][trial_ended_at]": "", + "payload[subscription][activated_at]": "2024-10-11 15:20:08 -0400", + "payload[subscription][created_at]": "2024-10-11 15:20:06 -0400", + "payload[subscription][updated_at]": "2024-10-11 15:28:31 -0400", + "payload[subscription][expires_at]": "", + "payload[subscription][balance_in_cents]": "0", + "payload[subscription][current_period_ends_at]": "2024-11-11 14:20:06 -0500", + "payload[subscription][next_assessment_at]": "2024-11-11 14:20:06 -0500", + "payload[subscription][canceled_at]": "", + "payload[subscription][cancellation_message]": "", + "payload[subscription][next_product_id]": "", + "payload[subscription][next_product_handle]": "", + "payload[subscription][cancel_at_end_of_period]": "false", + "payload[subscription][payment_collection_method]": "automatic", + "payload[subscription][snap_day]": "", + "payload[subscription][cancellation_method]": "", + "payload[subscription][current_period_started_at]": "2024-10-11 15:20:06 -0400", + "payload[subscription][previous_state]": "active", + "payload[subscription][signup_payment_id]": "1170014104", + "payload[subscription][signup_revenue]": "0.00", + "payload[subscription][delayed_cancel_at]": "", + "payload[subscription][coupon_code]": "", + "payload[subscription][total_revenue_in_cents]": "0", + "payload[subscription][product_price_in_cents]": "0", + "payload[subscription][product_version_number]": "1", + "payload[subscription][payment_type]": "", + "payload[subscription][referral_code]": "", + "payload[subscription][coupon_use_count]": "", + "payload[subscription][coupon_uses_allowed]": "", + "payload[subscription][reason_code]": "", + "payload[subscription][automatically_resume_at]": "", + "payload[subscription][offer_id]": "", + "payload[subscription][payer_id]": "", + "payload[subscription][receives_invoice_emails]": "", + "payload[subscription][product_price_point_id]": "3322919", + "payload[subscription][next_product_price_point_id]": "", + "payload[subscription][credit_balance_in_cents]": "0", + "payload[subscription][prepayment_balance_in_cents]": "0", + "payload[subscription][net_terms]": "", + "payload[subscription][stored_credential_transaction_id]": "", + "payload[subscription][locale]": "", + "payload[subscription][reference]": "", + "payload[subscription][currency]": "USD", + "payload[subscription][on_hold_at]": "2024-10-11 15:28:31 -0400", + "payload[subscription][scheduled_cancellation_at]": "", + "payload[subscription][product_price_point_type]": "default", + "payload[subscription][dunning_communication_delay_enabled]": "false", + "payload[subscription][dunning_communication_delay_time_zone]": "", + "payload[subscription][customer][id]": "83697711", + "payload[subscription][customer][first_name]": "FirstName", + "payload[subscription][customer][last_name]": "LastName", + "payload[subscription][customer][organization]": "", + "payload[subscription][customer][email]": "test@email.com", + "payload[subscription][customer][created_at]": "2024-10-11 15:08:35 -0400", + "payload[subscription][customer][updated_at]": "2024-10-11 15:08:35 -0400", + "payload[subscription][customer][reference]": "", + "payload[subscription][customer][address]": "", + "payload[subscription][customer][address_2]": "", + "payload[subscription][customer][address_3]": "", + "payload[subscription][customer][city]": "", + "payload[subscription][customer][state]": "", + "payload[subscription][customer][state_name]": "", + "payload[subscription][customer][zip]": "", + "payload[subscription][customer][country]": "", + "payload[subscription][customer][country_name]": "", + "payload[subscription][customer][phone]": "", + "payload[subscription][customer][portal_invite_last_sent_at]": "", + "payload[subscription][customer][portal_invite_last_accepted_at]": "", + "payload[subscription][customer][verified]": "false", + "payload[subscription][customer][portal_customer_created_at]": "", + "payload[subscription][customer][vat_number]": "", + "payload[subscription][customer][cc_emails]": "", + "payload[subscription][customer][tax_exempt]": "false", + "payload[subscription][customer][tax_exempt_reason]": "", + "payload[subscription][customer][parent_id]": "", + "payload[subscription][customer][locale]": "", + "payload[subscription][customer][salesforce_id]": "", + "payload[subscription][product][id]": "6748126", + "payload[subscription][product][name]": "Pro Plan", + "payload[subscription][product][handle]": "", + "payload[subscription][product][description]": "", + "payload[subscription][product][accounting_code]": "", + "payload[subscription][product][request_credit_card]": "true", + "payload[subscription][product][expiration_interval]": "", + "payload[subscription][product][expiration_interval_unit]": "never", + "payload[subscription][product][created_at]": "2024-10-11 12:56:32 -0400", + "payload[subscription][product][updated_at]": "2024-10-11 12:56:32 -0400", + "payload[subscription][product][price_in_cents]": "0", + "payload[subscription][product][interval]": "1", + "payload[subscription][product][interval_unit]": "month", + "payload[subscription][product][initial_charge_in_cents]": "", + "payload[subscription][product][trial_price_in_cents]": "", + "payload[subscription][product][trial_interval]": "", + "payload[subscription][product][trial_interval_unit]": "month", + "payload[subscription][product][archived_at]": "", + "payload[subscription][product][require_credit_card]": "false", + "payload[subscription][product][return_params]": "", + "payload[subscription][product][taxable]": "false", + "payload[subscription][product][update_return_url]": "", + "payload[subscription][product][tax_code]": "", + "payload[subscription][product][initial_charge_after_trial]": "false", + "payload[subscription][product][version_number]": "1", + "payload[subscription][product][update_return_params]": "", + "payload[subscription][product][default_product_price_point_id]": "3322919", + "payload[subscription][product][request_billing_address]": "false", + "payload[subscription][product][require_billing_address]": "false", + "payload[subscription][product][require_shipping_address]": "false", + "payload[subscription][product][use_site_exchange_rate]": "true", + "payload[subscription][product][item_category]": "", + "payload[subscription][product][product_price_point_id]": "3322919", + "payload[subscription][product][product_price_point_name]": "Original", + "payload[subscription][product][product_price_point_handle]": "uuid:b0c26c80-6a1f-013d-c9f9-063702f7df93", + "payload[subscription][product][product_family][id]": "2699089", + "payload[subscription][product][product_family][name]": "Billing Plans", + "payload[subscription][product][product_family][description]": "", + "payload[subscription][product][product_family][handle]": "testing-billing-plans", + "payload[subscription][product][product_family][accounting_code]": "", + "payload[subscription][product][product_family][created_at]": "2024-10-11 11:23:44 -0400", + "payload[subscription][product][product_family][updated_at]": "2024-10-11 11:23:44 -0400", + "payload[subscription][group]": "", + "payload[site][id]": "87942", + "payload[site][subdomain]": "testing", + "payload[event_id]": "4834010965" +} \ No newline at end of file diff --git a/components/chargify/sources/new-subscription-state/new-subscription-state.mjs b/components/chargify/sources/new-subscription-state/new-subscription-state.mjs deleted file mode 100644 index d128e48d6d510..0000000000000 --- a/components/chargify/sources/new-subscription-state/new-subscription-state.mjs +++ /dev/null @@ -1,54 +0,0 @@ -import chargify from "../../chargify.app.mjs"; - -export default { - key: "chargify-new-subscription-state", - name: "New Subscription State", - description: "Emits an event when the state of a subscription changes", - version: "0.0.1", - type: "source", - dedupe: "unique", - props: { - chargify, - db: "$.service.db", - timer: { - type: "$.interface.timer", - default: { - intervalSeconds: 60 * 15, // check every 15 minutes - }, - }, - subscriptionId: { - propDefinition: [chargify, "subscriptionId"], - }, - }, - - methods: { - _getSubscription() { - return this.chargify.getSubscriptions({ - subscriptionId: this.subscriptionId, - }); - }, - }, - - hooks: { - async deploy() { - // get the current state of the subscription - const subscription = await this._getSubscription(); - this.db.set("currentState", subscription.state); - }, - }, - - async run() { - const subscription = await this._getSubscription(); - const currentState = this.db.get("currentState"); - - // check if state has changed - if (subscription.state !== currentState) { - this.$emit(subscription, { - id: subscription.id, - summary: `Subscription state changed to ${subscription.state}`, - ts: Date.now(), - }); - this.db.set("currentState", subscription.state); - } - }, -}; \ No newline at end of file diff --git a/components/chargify/sources/new-subscription/new-subscription.mjs b/components/chargify/sources/new-subscription/new-subscription.mjs deleted file mode 100644 index d8e2345f94fc3..0000000000000 --- a/components/chargify/sources/new-subscription/new-subscription.mjs +++ /dev/null @@ -1,68 +0,0 @@ -import chargify from "../../chargify.app.mjs"; - -export default { - key: "chargify-new-subscription", - name: "New Subscription", - description: "Emit new event when a new subscription is created.", - version: "0.0.1", - type: "source", - dedupe: "unique", - props: { - chargify, - db: "$.service.db", - timer: { - type: "$.interface.timer", - default: { - intervalSeconds: 60 * 15, // 15 minutes - }, - }, - customerId: { - propDefinition: [chargify, "customerId"], - }, - subscriptionId: { - propDefinition: [chargify, "subscriptionId"], - }, - name: { - propDefinition: [chargify, "name"], - }, - email: { - propDefinition: [chargify, "email"], - }, - organization: { - propDefinition: [chargify, "organization"], - }, - productId: { - propDefinition: [chargify, "productId"], - }, - couponCode: { - propDefinition: [chargify, "couponCode"], - }, - nextBillingAt: { - propDefinition: [chargify, "nextBillingAt"], - }, - }, - methods: { - _getSubscriptionId() { - return this.db.get("subscriptionId"); - }, - _setSubscriptionId(id) { - this.db.set("subscriptionId", id); - }, - }, - async run() { - const subscriptions = await this.chargify.getSubscriptions({ - customerId: this.customerId, - }); - - for (const subscription of subscriptions) { - if (subscription.id > this._getSubscriptionId()) { - this.$emit(subscription, { - id: subscription.id, - summary: `New subscription: ${subscription.name}`, - ts: Date.now(), - }); - this._setSubscriptionId(subscription.id); - } - } - }, -}; \ No newline at end of file From 46e93d49129cfc7df9fb2e647d5285152e44f944 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 11 Oct 2024 15:33:11 -0400 Subject: [PATCH 3/4] pnpm-lock.yaml --- pnpm-lock.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed825eed80aef..4e759080e4df0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1559,6 +1559,12 @@ importers: dependencies: '@pipedream/platform': 1.6.0 + components/chargify: + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 + components/chartmogul: specifiers: '@pipedream/platform': ^1.2.1 From 1ff60c1a7ba778974513538bdab4fc3f91144845 Mon Sep 17 00:00:00 2001 From: Leo Vu Date: Tue, 15 Oct 2024 11:16:25 +0700 Subject: [PATCH 4/4] Fix action summary --- .../actions/create-subscription/create-subscription.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/chargify/actions/create-subscription/create-subscription.mjs b/components/chargify/actions/create-subscription/create-subscription.mjs index 67691287ec192..d2eadaf55f3ea 100644 --- a/components/chargify/actions/create-subscription/create-subscription.mjs +++ b/components/chargify/actions/create-subscription/create-subscription.mjs @@ -52,7 +52,7 @@ export default { }, }, }); - $.export("$summary", `Successfully created subscription with ID: ${response.id}`); + $.export("$summary", `Successfully created subscription with ID: ${response.subscription.id}`); return response; }, };