Skip to content

Commit 08fa304

Browse files
authored
Update zoho_subscriptions to use Zoho Billing API endpoints (#15036)
* update endpoints * pnpm-lock.yaml * updates * pnpm-lock.yaml * pnpm-lock.yaml * pnpm-lock.yaml * pnpm-lock.yaml
1 parent 2ad6ddc commit 08fa304

File tree

7 files changed

+112
-31
lines changed

7 files changed

+112
-31
lines changed

components/zoho_subscriptions/actions/create-customer/create-customer.mjs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import zohoSubscriptions from "../../zoho_subscriptions.app.mjs";
33
export default {
44
key: "zoho_subscriptions-create-customer",
55
name: "Create Customer",
6-
version: "0.0.1",
7-
description: "Create a new customer. [See the documentation](https://www.zoho.com/subscriptions/api/v1/customers/#create-a-customer)",
6+
version: "0.0.2",
7+
description: "Create a new customer. [See the documentation](https://www.zoho.com/billing/api/v1/customers/#create-a-customer)",
88
type: "action",
99
props: {
1010
zohoSubscriptions,
@@ -80,97 +80,97 @@ export default {
8080
},
8181
billingAddressAttention: {
8282
type: "string",
83-
label: "Attention",
83+
label: "Billing Address - Attention",
8484
description: "Attention of the customer's billing address.",
8585
optional: true,
8686
},
8787
billingAddressStreet: {
8888
type: "string",
89-
label: "Street",
89+
label: "Billing Address - Street",
9090
description: "Street of the customer's billing address.",
9191
optional: true,
9292
},
9393
billingAddressCity: {
9494
type: "string",
95-
label: "City",
95+
label: "Billing Address - City",
9696
description: "City of the customer's billing address.",
9797
optional: true,
9898
},
9999
billingAddressState: {
100100
type: "string",
101-
label: "State",
101+
label: "Billing Address - State",
102102
description: "State of the customer's billing address.",
103103
optional: true,
104104
},
105105
billingAddressZip: {
106106
type: "string",
107-
label: "Zip",
107+
label: "Billing Address - Zip",
108108
description: "Zip of the customer's billing address.",
109109
optional: true,
110110
},
111111
billingAddressCountry: {
112112
type: "string",
113-
label: "Country",
113+
label: "Billing Address - Country",
114114
description: "Country of the customer's billing address.",
115115
optional: true,
116116
},
117117
billingAddressStateCode: {
118118
type: "string",
119-
label: "State Code",
119+
label: "Billing Address - State Code",
120120
description: "State Code of the customer's billing address.",
121121
optional: true,
122122
},
123123
billingAddressFax: {
124124
type: "string",
125-
label: "Fax",
125+
label: "Billing Address - Fax",
126126
description: "Fax of the customer's billing address.",
127127
optional: true,
128128
},
129129
shippingAddressAttention: {
130130
type: "string",
131-
label: "Attention",
131+
label: "Shipping Address - Attention",
132132
description: "Attention of the customer's shipping address.",
133133
optional: true,
134134
},
135135
shippingAddressStreet: {
136136
type: "string",
137-
label: "Street",
137+
label: "Shipping Address - Street",
138138
description: "Street of the customer's shipping address.",
139139
optional: true,
140140
},
141141
shippingAddressCity: {
142142
type: "string",
143-
label: "City",
143+
label: "Shipping Address - City",
144144
description: "City of the customer's shipping address.",
145145
optional: true,
146146
},
147147
shippingAddressState: {
148148
type: "string",
149-
label: "State",
149+
label: "Shipping Address - State",
150150
description: "State of the customer's shipping address.",
151151
optional: true,
152152
},
153153
shippingAddressZip: {
154154
type: "string",
155-
label: "Zip",
155+
label: "Shipping Address - Zip",
156156
description: "Zip of the customer's shipping address.",
157157
optional: true,
158158
},
159159
shippingAddressCountry: {
160160
type: "string",
161-
label: "Country",
161+
label: "Shipping Address - Country",
162162
description: "Country of the customer's shipping address.",
163163
optional: true,
164164
},
165165
shippingAddressStateCode: {
166166
type: "string",
167-
label: "State Code",
167+
label: "Shipping Address - State Code",
168168
description: "State Code of the customer's shipping address.",
169169
optional: true,
170170
},
171171
shippingAddressFax: {
172172
type: "string",
173-
label: "Fax",
173+
label: "Shipping Address - Fax",
174174
description: "Fax of the customer's shipping address.",
175175
optional: true,
176176
},

components/zoho_subscriptions/actions/create-subscription/create-subscription.mjs

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import zohoSubscriptions from "../../zoho_subscriptions.app.mjs";
44
export default {
55
key: "zoho_subscriptions-create-subscription",
66
name: "Create Subscription",
7-
version: "0.0.1",
8-
description: "Create a new subscription. [See the documentation](https://www.zoho.com/subscriptions/api/v1/subscription/#create-a-subscription)",
7+
version: "0.0.2",
8+
description: "Create a new subscription. [See the documentation](https://www.zoho.com/billing/api/v1/subscription/#create-a-subscription)",
99
type: "action",
1010
props: {
1111
zohoSubscriptions,
@@ -29,6 +29,7 @@ export default {
2929
organizationId,
3030
}),
3131
],
32+
reloadProps: true,
3233
},
3334
paymentTerms: {
3435
propDefinition: [
@@ -322,6 +323,35 @@ export default {
322323
optional: true,
323324
},
324325
},
326+
async additionalProps(existingProps) {
327+
const props = {};
328+
if (!this.customerId) {
329+
return props;
330+
}
331+
try {
332+
const { customer } = await this.zohoSubscriptions.getCustomer({
333+
customerId: this.customerId,
334+
});
335+
const { contact_person: contactperson } = await this.zohoSubscriptions.getContactPerson({
336+
customerId: this.customerId,
337+
contactpersonId: customer.primary_contactperson_id,
338+
});
339+
if (!customer.email && !contactperson.email) {
340+
existingProps.contactpersons.hidden = true;
341+
props.contactEmail = {
342+
type: "string",
343+
label: "Contact Email",
344+
};
345+
}
346+
} catch {
347+
props.contactEmail = {
348+
type: "string",
349+
label: "Contact Email",
350+
optional: true,
351+
};
352+
}
353+
return props;
354+
},
325355
async run({ $ }) {
326356
const {
327357
zohoSubscriptions,
@@ -367,14 +397,15 @@ export default {
367397
cfdiUsage,
368398
allowPartialPayments,
369399
accountId,
400+
contactEmail,
370401
} = this;
371402

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

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

380411
let exchangeRateFloat = null;
@@ -404,6 +435,27 @@ export default {
404435
}
405436
}
406437

438+
const { customer } = await zohoSubscriptions.getCustomer({
439+
customerId,
440+
});
441+
if (contactEmail) {
442+
await zohoSubscriptions.updateCustomer({
443+
customerId,
444+
data: {
445+
display_name: customer.display_name,
446+
email: contactEmail,
447+
},
448+
});
449+
} else {
450+
const { contact_person: contactperson } = await zohoSubscriptions.getContactPerson({
451+
customerId,
452+
contactpersonId: customer.primary_contactperson_id,
453+
});
454+
if (!customer.email && !contactperson.email) {
455+
throw new ConfigurationError("Customer must have an email address");
456+
}
457+
}
458+
407459
const response = await zohoSubscriptions.createSubscription({
408460
$,
409461
organizationId,

components/zoho_subscriptions/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/zoho_subscriptions",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Pipedream Zoho Subscriptions Components",
55
"main": "zoho_subscriptions.app.mjs",
66
"keywords": [
@@ -13,6 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16+
"@pipedream/platform": "^3.0.3",
1617
"moment": "^2.29.4"
1718
}
1819
}

components/zoho_subscriptions/sources/payment-failure/payment-failure.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import zohoSubscriptions from "../../zoho_subscriptions.app.mjs";
55
export default {
66
key: "zoho_subscriptions-payment-failure",
77
name: "New Payment Failure",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
description: "Emit new event when a payment fails to process.",
1010
type: "source",
1111
dedupe: "unique",

components/zoho_subscriptions/sources/subscription-created/subscription-created.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import zohoSubscriptions from "../../zoho_subscriptions.app.mjs";
55
export default {
66
key: "zoho_subscriptions-subscription-created",
77
name: "New Subscription Created",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
description: "Emit new event when a new subscription is created.",
1010
type: "source",
1111
dedupe: "unique",

components/zoho_subscriptions/zoho_subscriptions.app.mjs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
cardId: {
99
type: "string",
1010
label: "Card Id",
11-
description: "Enter the card Id of the card which has to be updated..",
11+
description: "Enter the card Id of the card which is to be updated.",
1212
async options({
1313
page, customerId, organizationId,
1414
}) {
@@ -134,7 +134,7 @@ export default {
134134
},
135135
methods: {
136136
_apiUrl() {
137-
return `${this.$auth.api_domain}/subscriptions/v1`;
137+
return `${this.$auth.api_domain}/billing/v1`;
138138
},
139139
_getHeaders(organizationId = null) {
140140
const headers = {
@@ -157,13 +157,38 @@ export default {
157157

158158
return axios($, clearObj(config));
159159
},
160+
getCustomer({
161+
customerId, ...args
162+
}) {
163+
return this._makeRequest({
164+
path: `customers/${customerId}`,
165+
...args,
166+
});
167+
},
168+
getContactPerson({
169+
customerId, contactpersonId, ...args
170+
}) {
171+
return this._makeRequest({
172+
path: `customers/${customerId}/contactpersons/${contactpersonId}`,
173+
...args,
174+
});
175+
},
160176
createCustomer(args = {}) {
161177
return this._makeRequest({
162178
method: "POST",
163179
path: "customers",
164180
...args,
165181
});
166182
},
183+
updateCustomer({
184+
customerId, ...args
185+
}) {
186+
return this._makeRequest({
187+
method: "PUT",
188+
path: `customers/${customerId}`,
189+
...args,
190+
});
191+
},
167192
createSubscription(args = {}) {
168193
return this._makeRequest({
169194
method: "POST",

pnpm-lock.yaml

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)