Skip to content

Commit d110209

Browse files
14645 components zoho books (#14764)
* [Components] zoho-books #14645 - Component refactoring Sources - New Customer - New Expense - New Sales Invoice Actions - Create Customer - Create Estimate * pnpm update * some adjusts * some adjusts * Improve description --------- Co-authored-by: Leo Vu <vunguyenhung@outlook.com>
1 parent a8245f7 commit d110209

File tree

27 files changed

+3049
-1154
lines changed

27 files changed

+3049
-1154
lines changed
Lines changed: 77 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,137 @@
11
// legacy_hash_id: a_XziR2J
2-
import { axios } from "@pipedream/platform";
2+
import { PAYMENT_MODE_OPTIONS } from "../../common/constants.mjs";
3+
import { parseObject } from "../../common/utils.mjs";
4+
import zohoBooks from "../../zoho_books.app.mjs";
35

46
export default {
57
key: "zoho_books-create-customer-payment",
68
name: "Create Customer Payment",
7-
description: "Creates a new payment.",
8-
version: "0.2.1",
9+
description: "Creates a new payment. [See the documentation](https://www.zoho.com/books/api/v3/customer-payments/#create-a-payment)",
10+
version: "0.3.0",
911
type: "action",
1012
props: {
11-
zoho_books: {
12-
type: "app",
13-
app: "zoho_books",
14-
},
15-
organization_id: {
16-
type: "string",
17-
description: "In Zoho Books, your business is termed as an organization. If you have multiple businesses, you simply set each of those up as an individual organization. Each organization is an independent Zoho Books Organization with it's own organization ID, base currency, time zone, language, contacts, reports, etc.\n\nThe parameter `organization_id` should be sent in with every API request to identify the organization.\n\nThe `organization_id` can be obtained from the GET `/organizations` API's JSON response. Alternatively, it can be obtained from the **Manage Organizations** page in the admin console.",
18-
},
19-
customer_id: {
20-
type: "string",
21-
description: "Customer ID of the customer involved in the payment.",
22-
},
23-
payment_mode: {
24-
type: "string",
25-
description: "Mode through which payment is made. This can be `check`, `cash`, `creditcard`, `banktransfer`, `bankremittance`, `autotransaction` or `others`. Max-length [100]",
26-
options: [
27-
"check",
28-
"cash",
29-
"creditcard",
30-
"banktransfer",
31-
"bankremittance",
32-
"autotransaction",
33-
"others",
13+
zohoBooks,
14+
customerId: {
15+
propDefinition: [
16+
zohoBooks,
17+
"customerId",
3418
],
3519
},
36-
invoices: {
37-
type: "any",
38-
description: "List of invoices associated with the payment. Each invoice object contains `invoice_id`, `invoice_number`, `date`, `invoice_amount`, `amount_applied` and `balance_amount`.",
20+
paymentMode: {
21+
type: "string",
22+
label: "Payment Mode",
23+
description: "Mode through which payment is made.",
24+
options: PAYMENT_MODE_OPTIONS,
3925
},
4026
amount: {
4127
type: "string",
28+
label: "Amount",
4229
description: "Amount paid in the respective payment.",
4330
},
4431
date: {
4532
type: "string",
33+
label: "Date",
4634
description: "Date on which payment is made. Format [yyyy-mm-dd]",
4735
},
48-
reference_number: {
36+
referenceNumber: {
4937
type: "string",
38+
label: "Reference Number",
5039
description: "Reference number generated for the payment. A string of your choice can also be used as the reference number. Max-length [100]",
5140
optional: true,
5241
},
5342
description: {
5443
type: "string",
44+
label: "Description",
5545
description: "Description about the payment.",
5646
optional: true,
5747
},
58-
exchange_rate: {
48+
invoices: {
49+
type: "string[]",
50+
label: "Invoices",
51+
description: "List of invoice objects associated with the payment. Each invoice object contains `invoice_id`, `invoice_number`, `date`, `invoice_amount`, `amount_applied` and `balance_amount`. **Example: {\"invoice_id\": \"90300000079426\", \"amount_applied\": 450}**",
52+
},
53+
exchangeRate: {
5954
type: "string",
55+
label: "Exchange Rate",
6056
description: "Exchange rate for the currency used in the invoices and customer's currency. The payment amount would be the multiplicative product of the original amount and the exchange rate. Default is 1.",
6157
optional: true,
6258
},
63-
bank_charges: {
59+
bankCharges: {
6460
type: "string",
61+
label: "Bank Charges",
6562
description: "Denotes any additional bank charges.",
6663
optional: true,
6764
},
68-
custom_fields: {
69-
type: "any",
70-
description: "Additional fields for the payments.",
65+
customFields: {
66+
propDefinition: [
67+
zohoBooks,
68+
"customFields",
69+
],
70+
description: "A list of Additional field objects for the payments. **Example: {\"label\": \"label\", \"value\": 129890}**",
7171
optional: true,
7272
},
73-
invoice_id: {
74-
type: "string",
75-
description: "ID of the invoice to get payments of.",
76-
optional: true,
73+
invoiceId: {
74+
propDefinition: [
75+
zohoBooks,
76+
"invoiceId",
77+
({ customerId }) => ({
78+
customerId,
79+
}),
80+
],
7781
},
78-
amount_applied: {
82+
amountApplied: {
7983
type: "string",
84+
label: "Amount Applied",
8085
description: "Amount paid for the invoice.",
8186
optional: true,
8287
},
83-
tax_amount_withheld: {
88+
taxAmountWithheld: {
8489
type: "string",
90+
label: "Tax Amount Withheld",
8591
description: "Amount withheld for tax.",
8692
optional: true,
8793
},
88-
account_id: {
89-
type: "string",
90-
description: "ID of the cash/bank account the payment has to be deposited.",
94+
accountId: {
95+
propDefinition: [
96+
zohoBooks,
97+
"accountId",
98+
],
9199
optional: true,
92100
},
93-
contact_persons: {
94-
type: "string",
95-
description: "IDs of the contact personsthe thank you mail has to be triggered.",
101+
contactPersons: {
102+
propDefinition: [
103+
zohoBooks,
104+
"contactPersons",
105+
({ customerId }) => ({
106+
customerId,
107+
}),
108+
],
96109
optional: true,
97110
},
98111
},
99112
async run({ $ }) {
100-
//See the API docs: https://www.zoho.com/books/api/v3/#Customer-Payments_Create_a_payment
101-
102-
if (!this.organization_id || !this.customer_id || !this.payment_mode || !this.invoices || !this.amount || !this.date) {
103-
throw new Error("Must provide organization_id, customer_id, payment_mode, invoices, amount, and date parameters.");
104-
}
105-
106-
return await axios($, {
107-
method: "post",
108-
url: `https://books.${this.zoho_books.$auth.base_api_uri}/api/v3/customerpayments?organization_id=${this.organization_id}`,
109-
headers: {
110-
Authorization: `Zoho-oauthtoken ${this.zoho_books.$auth.oauth_access_token}`,
111-
},
113+
const response = await this.zohoBooks.createCustomerPayment({
114+
$,
112115
data: {
113-
customer_id: this.customer_id,
114-
payment_mode: this.payment_mode,
116+
customer_id: this.customerId,
117+
payment_mode: this.paymentMode,
115118
amount: this.amount,
116119
date: this.date,
117-
reference_number: this.reference_number,
120+
reference_number: this.referenceNumber,
118121
description: this.description,
119-
invoices: this.invoices,
120-
exchange_rate: this.exchange_rate,
121-
bank_charges: this.bank_charges,
122-
custom_fields: this.custom_fields,
123-
invoice_id: this.invoice_id,
124-
amount_applied: this.amount_applied,
125-
tax_amount_withheld: this.tax_amount_withheld,
126-
account_id: this.account_id,
127-
contact_persons: this.contact_persons,
122+
invoices: parseObject(this.invoices),
123+
exchange_rate: this.exchangeRate && parseFloat(this.exchangeRate),
124+
bank_charges: this.bankCharges && parseFloat(this.bankCharges),
125+
custom_fields: parseObject(this.customFields),
126+
invoice_id: this.invoiceId,
127+
amount_applied: this.amountApplied && parseFloat(this.amountApplied),
128+
tax_amount_withheld: this.taxAmountWithheld && parseFloat(this.taxAmountWithheld),
129+
account_id: this.accountId,
130+
contact_persons: parseObject(this.contactPersons),
128131
},
129132
});
133+
134+
$.export("$summary", `Customer payment successfully created with Id: ${response.payment.payment_id}`);
135+
return response;
130136
},
131137
};
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// legacy_hash_id: a_Xzi1qo
2+
import {
3+
CUSTOMER_SUB_TYPE_OPTIONS,
4+
LANGUAGE_CODE_OPTIONS,
5+
} from "../../common/constants.mjs";
6+
import {
7+
clearObj,
8+
parseObject,
9+
} from "../../common/utils.mjs";
10+
import zohoBooks from "../../zoho_books.app.mjs";
11+
12+
export default {
13+
key: "zoho_books-create-customer",
14+
name: "Create Customer",
15+
description: "Creates a new customer. [See the documentation](https://www.zoho.com/books/api/v3/items/#create-an-item)",
16+
version: "0.0.1",
17+
type: "action",
18+
props: {
19+
zohoBooks,
20+
contactName: {
21+
type: "string",
22+
label: "Contact Name",
23+
description: "Display Name of the contact. Max-length [200].",
24+
},
25+
companyName: {
26+
type: "string",
27+
label: "Company Name",
28+
description: "Company Name of the contact. Max-length [200].",
29+
optional: true,
30+
},
31+
website: {
32+
type: "string",
33+
label: "Website",
34+
description: "Website of the contact.",
35+
optional: true,
36+
},
37+
languageCode: {
38+
type: "string",
39+
label: "Language Code",
40+
description: "The language of a contact.",
41+
options: LANGUAGE_CODE_OPTIONS,
42+
optional: true,
43+
},
44+
customerSubType: {
45+
type: "string",
46+
label: "Customer Sub Type",
47+
description: "Type of the customer.",
48+
options: CUSTOMER_SUB_TYPE_OPTIONS,
49+
optional: true,
50+
},
51+
creditLimit: {
52+
type: "string",
53+
label: "Credit Limit",
54+
description: "Credit limit for a customer.",
55+
optional: true,
56+
},
57+
tags: {
58+
type: "string[]",
59+
label: "Tags",
60+
description: "An array of tag objects. **Example: {\"tag_id\":\"124567890\",\"tag_option_id\":\"1234567890\"}**",
61+
optional: true,
62+
},
63+
isPortalEnabled: {
64+
type: "boolean",
65+
label: "Is Portal Enabled",
66+
description: "To enable client portal for the contact.",
67+
optional: true,
68+
},
69+
currencyId: {
70+
propDefinition: [
71+
zohoBooks,
72+
"currencyId",
73+
],
74+
optional: true,
75+
},
76+
paymentTerms: {
77+
propDefinition: [
78+
zohoBooks,
79+
"paymentTerms",
80+
],
81+
description: "Net payment term for the customer.",
82+
optional: true,
83+
},
84+
paymentTermsLabel: {
85+
propDefinition: [
86+
zohoBooks,
87+
"paymentTermsLabel",
88+
],
89+
description: "Label for the paymet due details.",
90+
optional: true,
91+
},
92+
notes: {
93+
propDefinition: [
94+
zohoBooks,
95+
"notes",
96+
],
97+
description: "Commennts about the payment made by the contact.",
98+
optional: true,
99+
},
100+
exchangeRate: {
101+
propDefinition: [
102+
zohoBooks,
103+
"exchangeRate",
104+
],
105+
description: "Exchange rate for the opening balance.",
106+
optional: true,
107+
},
108+
vatTreatment: {
109+
propDefinition: [
110+
zohoBooks,
111+
"vatTreatment",
112+
],
113+
optional: true,
114+
},
115+
gstNo: {
116+
propDefinition: [
117+
zohoBooks,
118+
"gstNo",
119+
],
120+
optional: true,
121+
},
122+
avataxUseCode: {
123+
propDefinition: [
124+
zohoBooks,
125+
"avataxUseCode",
126+
],
127+
optional: true,
128+
},
129+
taxId: {
130+
propDefinition: [
131+
zohoBooks,
132+
"taxId",
133+
],
134+
description: "ID of the tax to be associated to the estimate.",
135+
optional: true,
136+
},
137+
},
138+
async run({ $ }) {
139+
const response = await this.zohoBooks.createContact({
140+
$,
141+
data: clearObj({
142+
contact_name: this.contactName,
143+
company_name: this.companyName,
144+
website: this.website,
145+
language_code: this.languageCode,
146+
contact_type: "customer",
147+
customer_sub_type: this.customerSubType,
148+
credit_limit: this.creditLimit,
149+
tags: parseObject(this.tags),
150+
is_portal_enabled: this.isPortalEnabled,
151+
currency_id: this.currencyId,
152+
payment_terms: this.paymentTerms,
153+
payment_terms_label: this.paymentTermsLabel,
154+
notes: this.notes,
155+
exchange_rate: this.exchangeRate && parseFloat(this.exchangeRate),
156+
vat_treatment: this.vatTreatment,
157+
gst_no: this.gstNo,
158+
avatax_use_code: this.avataxUseCode,
159+
tax_id: this.taxId,
160+
}),
161+
});
162+
163+
$.export("$summary", `Contact successfully created with Id: ${response.contact.contact_id}`);
164+
return response;
165+
},
166+
};

0 commit comments

Comments
 (0)