Skip to content

Commit 92a59ef

Browse files
committed
updates
1 parent 20bddc8 commit 92a59ef

File tree

3 files changed

+96
-19
lines changed

3 files changed

+96
-19
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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/zoho_subscriptions.app.mjs

Lines changed: 26 additions & 1 deletion
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
}) {
@@ -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",

0 commit comments

Comments
 (0)