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)",
type: "action",
props: {
zohoSubscriptions,
organizationId: {
propDefinition: [
zohoSubscriptions,
"organizationId",
],
},
displayName: {
type: "string",
label: "Display Name",
description: "Name of the customer which will be displayed in the interface and invoices.",
},
salutation: {
type: "string",
label: "Salutation",
description: "Salutation of the customer.",
optional: true,
},
firstName: {
type: "string",
label: "First Name",
description: "First name of the customer.",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "Last name of the customer.",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "Email address of the customer.",
},
companyName: {
type: "string",
label: "Company Name",
description: "Registered name of the company the customer represents.",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "Customer's landline or fixed-line number.",
optional: true,
},
mobile: {
type: "string",
label: "Mobile",
description: "Customer's mobile phone number.",
optional: true,
},
department: {
type: "string",
label: "Department",
description: "Customer's department.",
optional: true,
},
designation: {
type: "string",
label: "Designation",
description: "Customer's designation.",
optional: true,
},
website: {
type: "string",
label: "Website",
description: "Customer's website if any.",
optional: true,
},
billingAddressAttention: {
type: "string",
label: "Attention",
description: "Attention of the customer's billing address.",
optional: true,
},
billingAddressStreet: {
type: "string",
label: "Street",
description: "Street of the customer's billing address.",
optional: true,
},
billingAddressCity: {
type: "string",
label: "City",
description: "City of the customer's billing address.",
optional: true,
},
billingAddressState: {
type: "string",
label: "State",
description: "State of the customer's billing address.",
optional: true,
},
billingAddressZip: {
type: "string",
label: "Zip",
description: "Zip of the customer's billing address.",
optional: true,
},
billingAddressCountry: {
type: "string",
label: "Country",
description: "Country of the customer's billing address.",
optional: true,
},
billingAddressStateCode: {
type: "string",
label: "State Code",
description: "State Code of the customer's billing address.",
optional: true,
},
billingAddressFax: {
type: "string",
label: "Fax",
description: "Fax of the customer's billing address.",
optional: true,
},
shippingAddressAttention: {
type: "string",
label: "Attention",
description: "Attention of the customer's shipping address.",
optional: true,
},
shippingAddressStreet: {
type: "string",
label: "Street",
description: "Street of the customer's shipping address.",
optional: true,
},
shippingAddressCity: {
type: "string",
label: "City",
description: "City of the customer's shipping address.",
optional: true,
},
shippingAddressState: {
type: "string",
label: "State",
description: "State of the customer's shipping address.",
optional: true,
},
shippingAddressZip: {
type: "string",
label: "Zip",
description: "Zip of the customer's shipping address.",
optional: true,
},
shippingAddressCountry: {
type: "string",
label: "Country",
description: "Country of the customer's shipping address.",
optional: true,
},
shippingAddressStateCode: {
type: "string",
label: "State Code",
description: "State Code of the customer's shipping address.",
optional: true,
},
shippingAddressFax: {
type: "string",
label: "Fax",
description: "Fax of the customer's shipping address.",
optional: true,
},
paymentTerms: {
propDefinition: [
zohoSubscriptions,
"paymentTerms",
],
description: "Net payment term for the customer.",
optional: true,
},
paymentTermsLabel: {
propDefinition: [
zohoSubscriptions,
"paymentTermsLabel",
],
description: "Text field of payment terms.",
optional: true,
},
currencyCode: {
type: "string",
label: "Currency Code",
description: "Currency code of the currency in which the customer wants to pay. If **Currency Code** is not specified here, the currency chosen in your Zoho Subscriptions organization will be used for billing.",
optional: true,
},
achSupported: {
type: "boolean",
label: "ACH Supported",
description: "Set to true if ACH payment is supported for the customer. Default is `false`",
optional: true,
},
twitter: {
type: "string",
label: "Twitter",
description: "Twitter profile of the customer.",
optional: true,
},
facebook: {
type: "string",
label: "Facebook",
description: "Facebook profile of the customer.",
optional: true,
},
skype: {
type: "string",
label: "Skype",
description: "Skype ID of the customer.",
optional: true,
},
notes: {
type: "string",
label: "Notes",
description: "A short note about the customer.",
optional: true,
},
isPortalEnabled: {
type: "boolean",
label: "Is Portal Enabled",
description: "Is Client portal enabled for the customer.",
optional: true,
},
gstNo: {
type: "string",
label: "GTS Number",
description: "GSTIN Number for the customer. `India GTS only`.",
optional: true,
},
gstTreatment: {
type: "string",
label: "GST Treatment",
description: "GST Treatment for the customer. `India GTS only`.",
options: [
"business_gst",
"business_none",
"consumer",
"overseas",
"business_gst",
"business_none",
"consumer",
"overseas",
],
optional: true,
},
placeOfContact: {
type: "string",
label: "Place Of Contact",
description: "Customer's place of contact. `India GTS only`.",
optional: true,
},
vatTreatment: {
type: "string",
label: "VAT Treatment",
description: "VAT treatment of the contact. `VAT only`.",
options: [
"uk",
"eu_vat_registered",
"overseas",
],
optional: true,
},
taxRegNo: {
type: "string",
label: "Tax Registration Number",
description: "12 digit Tax Registration number of a contact with Tax treatment as **home_country_mexico**, **border_region_mexico**, **non_mexico**. Consumers generic RFC: `XAXX010101000`, Overseas generic RFC: `XEXX010101000`. `Mexico only`.",
optional: true,
},
tdsTaxId: {
type: "string",
label: "TDS Tax Id",
description: "ID of the TDS tax. `Mexico only`.",
optional: true,
},
taxTreatment: {
type: "string",
label: "Tax Treatment",
description: "VAT treatment of the contact. `Mexico only`.",
options: [
"home_country_mexico",
"border_region_mexico",
"non_mexico",
],
optional: true,
},
taxRegime: {
type: "string",
label: "Tax Regime",
description: "Tax Regime of the contact. `Mexico only`.",
options: [
"general_legal_person",
"legal_entities_non_profit",
"resident_abroad",
"production_cooperative_societies",
"agricultural_livestock",
"optional_group_of_companies",
"coordinated",
"simplified_trust",
"wages_salaries_income",
"lease",
"property_disposal_acquisition",
"other_income",
"resident_abroad",
"divident_income",
"individual_business_professional",
"interest_income",
"income_obtaining_price",
"no_tax_obligation",
"tax_incorporation",
"income_through_technology_platform",
"simplified_trust",
],
optional: true,
},
isTdsRegistered: {
type: "boolean",
label: "Is TDS Registered",
description: "Boolean to check if tax is registered. `Mexico only`.",
optional: true,
},
vatRegNo: {
type: "string",
label: "VAT Registration Number",
description: "VAT Registration number of a contact with length should be between 2 and 12 characters. `VAT only`.",
optional: true,
},
isTaxable: {
type: "boolean",
label: "Is Taxable",
description: "Set to true if customer's transactions must be tax inclusive. `Sales Tax` , `GST only`",
optional: true,
},
taxId: {
type: "string",
label: "Tax Id",
description: "Unique ID of the tax or tax group that can be collected from the contact. Tax can be given only if **Is Taxable** is `true`.",
optional: true,
},
taxAuthorityId: {
type: "string",
label: "Tax Authority Id",
description: "Unique ID of the tax authority. Tax authority depends on the location of the customer. For example, if the customer is located in NY, then the tax authority is NY tax authority.",
optional: true,
},
taxAuthorityName: {
type: "string",
label: "Tax Authority Name",
description: "Unique name of the tax authority. Either **Tax Authority Id** or **Tax Authority Name** can be given.",
optional: true,
},
taxExemptionId: {
type: "string",
label: "Tax Exemption Id",
description: "Unique ID of the tax exemption. `Sales Tax` , `GST only`",
optional: true,
},
taxExemptionCode: {
type: "string",
label: "Tax Exemption Code",
description: "Unique code of the tax exemption. `Sales Tax` , `GST only`",
optional: true,
},
invoiceTemplateId: {
type: "string",
label: "Invoice Template Id",
description: "Unique Id used to denote the invoice template.",
optional: true,
},
creditnoteTemplateId: {
type: "string",
label: "Credit Note Template Id",
description: "Unique Id used to denote the credit note template.",
optional: true,
},
customFields: {
propDefinition: [
zohoSubscriptions,
"customFields",
],
description: "Additional fields for customers.",
optional: true,
},
},
async run({ $ }) {
const {
zohoSubscriptions,
organizationId,
displayName,
firstName,
lastName,
companyName,
billingAddressAttention,
billingAddressStreet,
billingAddressCity,
billingAddressState,
billingAddressZip,
billingAddressCountry,
billingAddressStateCode,
billingAddressFax,
shippingAddressAttention,
shippingAddressStreet,
shippingAddressCity,
shippingAddressState,
shippingAddressZip,
shippingAddressCountry,
shippingAddressStateCode,
shippingAddressFax,
paymentTerms,
paymentTermsLabel,
currencyCode,
achSupported,
isPortalEnabled,
gstNo,
gstTreatment,
placeOfContact,
vatTreatment,
taxRegNo,
tdsTaxId,
taxTreatment,
taxRegime,
isTdsRegistered,
vatRegNo,
isTaxable,
taxId,
taxAuthorityId,
taxAuthorityName,
taxExemptionId,
taxExemptionCode,
invoiceTemplateId,
creditnoteTemplateId,
customFields,
...data
} = this;
const response = await zohoSubscriptions.createCustomer({
$,
organizationId,
data: {
...data,
display_name: displayName,
first_name: firstName,
last_name: lastName,
company_name: companyName,
billing_address: {
attention: billingAddressAttention,
street: billingAddressStreet,
city: billingAddressCity,
state: billingAddressState,
zip: billingAddressZip,
country: billingAddressCountry,
stateCode: billingAddressStateCode,
fax: billingAddressFax,
},
shipping_address: {
attention: shippingAddressAttention,
street: shippingAddressStreet,
city: shippingAddressCity,
state: shippingAddressState,
zip: shippingAddressZip,
country: shippingAddressCountry,
stateCode: shippingAddressStateCode,
fax: shippingAddressFax,
},
payment_terms: paymentTerms,
payment_terms_label: paymentTermsLabel,
currency_code: currencyCode,
ach_supported: achSupported,
is_portal_enabled: isPortalEnabled,
gst_no: gstNo,
gst_treatment: gstTreatment,
place_of_contact: placeOfContact,
vat_treatment: vatTreatment,
tax_reg_no: taxRegNo,
tds_tax_id: tdsTaxId,
tax_treatment: taxTreatment,
tax_regime: taxRegime,
is_tds_registered: isTdsRegistered,
vat_reg_no: vatRegNo,
is_taxable: isTaxable,
tax_id: taxId,
tax_authority_id: taxAuthorityId,
tax_authority_name: taxAuthorityName,
tax_exemption_id: taxExemptionId,
tax_exemption_code: taxExemptionCode,
default_templates: {
invoice_template_id: invoiceTemplateId,
creditnote_template_id: creditnoteTemplateId,
},
custom_fields: customFields && Object.entries(customFields).map(([
key,
value,
]) => ({
label: key,
value: value,
})),
},
});
$.export("$summary", `A new customer with Id: ${response.customer?.customer_id} was successfully created!`);
return response;
},
};