Skip to content
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

Update zoho_subscriptions to use Zoho Billing API endpoints #15036

Merged
merged 10 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
Expand Up @@ -3,8 +3,8 @@ import zohoSubscriptions from "../../zoho_subscriptions.app.mjs";
export default {
key: "zoho_subscriptions-create-customer",
name: "Create Customer",
version: "0.0.1",
description: "Create a new customer. [See the documentation](https://www.zoho.com/subscriptions/api/v1/customers/#create-a-customer)",
version: "0.0.2",
description: "Create a new customer. [See the documentation](https://www.zoho.com/billing/api/v1/customers/#create-a-customer)",
type: "action",
props: {
zohoSubscriptions,
Expand Down Expand Up @@ -80,97 +80,97 @@ export default {
},
billingAddressAttention: {
type: "string",
label: "Attention",
label: "Billing Address - Attention",
description: "Attention of the customer's billing address.",
optional: true,
},
billingAddressStreet: {
type: "string",
label: "Street",
label: "Billing Address - Street",
description: "Street of the customer's billing address.",
optional: true,
},
billingAddressCity: {
type: "string",
label: "City",
label: "Billing Address - City",
description: "City of the customer's billing address.",
optional: true,
},
billingAddressState: {
type: "string",
label: "State",
label: "Billing Address - State",
description: "State of the customer's billing address.",
optional: true,
},
billingAddressZip: {
type: "string",
label: "Zip",
label: "Billing Address - Zip",
description: "Zip of the customer's billing address.",
optional: true,
},
billingAddressCountry: {
type: "string",
label: "Country",
label: "Billing Address - Country",
description: "Country of the customer's billing address.",
optional: true,
},
billingAddressStateCode: {
type: "string",
label: "State Code",
label: "Billing Address - State Code",
description: "State Code of the customer's billing address.",
optional: true,
},
billingAddressFax: {
type: "string",
label: "Fax",
label: "Billing Address - Fax",
description: "Fax of the customer's billing address.",
optional: true,
},
shippingAddressAttention: {
type: "string",
label: "Attention",
label: "Shipping Address - Attention",
description: "Attention of the customer's shipping address.",
optional: true,
},
shippingAddressStreet: {
type: "string",
label: "Street",
label: "Shipping Address - Street",
description: "Street of the customer's shipping address.",
optional: true,
},
shippingAddressCity: {
type: "string",
label: "City",
label: "Shipping Address - City",
description: "City of the customer's shipping address.",
optional: true,
},
shippingAddressState: {
type: "string",
label: "State",
label: "Shipping Address - State",
description: "State of the customer's shipping address.",
optional: true,
},
shippingAddressZip: {
type: "string",
label: "Zip",
label: "Shipping Address - Zip",
description: "Zip of the customer's shipping address.",
optional: true,
},
shippingAddressCountry: {
type: "string",
label: "Country",
label: "Shipping Address - Country",
description: "Country of the customer's shipping address.",
optional: true,
},
shippingAddressStateCode: {
type: "string",
label: "State Code",
label: "Shipping Address - State Code",
description: "State Code of the customer's shipping address.",
optional: true,
},
shippingAddressFax: {
type: "string",
label: "Fax",
label: "Shipping Address - Fax",
description: "Fax of the customer's shipping address.",
optional: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import zohoSubscriptions from "../../zoho_subscriptions.app.mjs";
export default {
key: "zoho_subscriptions-create-subscription",
name: "Create Subscription",
version: "0.0.1",
description: "Create a new subscription. [See the documentation](https://www.zoho.com/subscriptions/api/v1/subscription/#create-a-subscription)",
version: "0.0.2",
description: "Create a new subscription. [See the documentation](https://www.zoho.com/billing/api/v1/subscription/#create-a-subscription)",
type: "action",
props: {
zohoSubscriptions,
Expand All @@ -29,6 +29,7 @@ export default {
organizationId,
}),
],
reloadProps: true,
},
paymentTerms: {
propDefinition: [
Expand Down Expand Up @@ -322,6 +323,35 @@ export default {
optional: true,
},
},
async additionalProps(existingProps) {
const props = {};
if (!this.customerId) {
return props;
}
try {
const { customer } = await this.zohoSubscriptions.getCustomer({
customerId: this.customerId,
});
const { contact_person: contactperson } = await this.zohoSubscriptions.getContactPerson({
customerId: this.customerId,
contactpersonId: customer.primary_contactperson_id,
});
if (!customer.email && !contactperson.email) {
existingProps.contactpersons.hidden = true;
props.contactEmail = {
type: "string",
label: "Contact Email",
};
}
} catch {
props.contactEmail = {
type: "string",
label: "Contact Email",
optional: true,
};
}
return props;
},
async run({ $ }) {
const {
zohoSubscriptions,
Expand Down Expand Up @@ -367,14 +397,15 @@ export default {
cfdiUsage,
allowPartialPayments,
accountId,
contactEmail,
} = this;

if (autoCollect && !cardId) {
throw new ConfigurationError("By setting Auto-Collect to `true`, you must to fill in the card Id.");
throw new ConfigurationError("If setting Auto-Collect to `true`, you must fill in the card Id.");
}

if (autoCollect && !accountId) {
throw new ConfigurationError("By setting Auto-Collect to `true`, you must to fill in the Account Id.");
throw new ConfigurationError("If setting Auto-Collect to `true`, you must fill in the Account Id.");
}

let exchangeRateFloat = null;
Expand Down Expand Up @@ -404,6 +435,27 @@ export default {
}
}

const { customer } = await zohoSubscriptions.getCustomer({
customerId,
});
if (contactEmail) {
await zohoSubscriptions.updateCustomer({
customerId,
data: {
display_name: customer.display_name,
email: contactEmail,
},
});
} else {
const { contact_person: contactperson } = await zohoSubscriptions.getContactPerson({
customerId,
contactpersonId: customer.primary_contactperson_id,
});
if (!customer.email && !contactperson.email) {
throw new ConfigurationError("Customer must have an email address");
}
}

const response = await zohoSubscriptions.createSubscription({
$,
organizationId,
Expand Down
3 changes: 2 additions & 1 deletion components/zoho_subscriptions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/zoho_subscriptions",
"version": "0.1.0",
"version": "0.1.1",
"description": "Pipedream Zoho Subscriptions Components",
"main": "zoho_subscriptions.app.mjs",
"keywords": [
Expand All @@ -13,6 +13,7 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3",
"moment": "^2.29.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import zohoSubscriptions from "../../zoho_subscriptions.app.mjs";
export default {
key: "zoho_subscriptions-payment-failure",
name: "New Payment Failure",
version: "0.0.1",
version: "0.0.2",
description: "Emit new event when a payment fails to process.",
type: "source",
dedupe: "unique",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import zohoSubscriptions from "../../zoho_subscriptions.app.mjs";
export default {
key: "zoho_subscriptions-subscription-created",
name: "New Subscription Created",
version: "0.0.1",
version: "0.0.2",
description: "Emit new event when a new subscription is created.",
type: "source",
dedupe: "unique",
Expand Down
29 changes: 27 additions & 2 deletions components/zoho_subscriptions/zoho_subscriptions.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
cardId: {
type: "string",
label: "Card Id",
description: "Enter the card Id of the card which has to be updated..",
description: "Enter the card Id of the card which is to be updated.",
async options({
page, customerId, organizationId,
}) {
Expand Down Expand Up @@ -134,7 +134,7 @@ export default {
},
methods: {
_apiUrl() {
return `${this.$auth.api_domain}/subscriptions/v1`;
return `${this.$auth.api_domain}/billing/v1`;
},
_getHeaders(organizationId = null) {
const headers = {
Expand All @@ -157,13 +157,38 @@ export default {

return axios($, clearObj(config));
},
getCustomer({
customerId, ...args
}) {
return this._makeRequest({
path: `customers/${customerId}`,
...args,
});
},
getContactPerson({
customerId, contactpersonId, ...args
}) {
return this._makeRequest({
path: `customers/${customerId}/contactpersons/${contactpersonId}`,
...args,
});
},
createCustomer(args = {}) {
return this._makeRequest({
method: "POST",
path: "customers",
...args,
});
},
updateCustomer({
customerId, ...args
}) {
return this._makeRequest({
method: "PUT",
path: `customers/${customerId}`,
...args,
});
},
createSubscription(args = {}) {
return this._makeRequest({
method: "POST",
Expand Down
Loading
Loading