|
1 | 1 | // 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"; |
3 | 5 |
|
4 | 6 | export default { |
5 | 7 | key: "zoho_books-create-customer-payment", |
6 | 8 | 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", |
9 | 11 | type: "action", |
10 | 12 | 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", |
34 | 18 | ], |
35 | 19 | }, |
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, |
39 | 25 | }, |
40 | 26 | amount: { |
41 | 27 | type: "string", |
| 28 | + label: "Amount", |
42 | 29 | description: "Amount paid in the respective payment.", |
43 | 30 | }, |
44 | 31 | date: { |
45 | 32 | type: "string", |
| 33 | + label: "Date", |
46 | 34 | description: "Date on which payment is made. Format [yyyy-mm-dd]", |
47 | 35 | }, |
48 | | - reference_number: { |
| 36 | + referenceNumber: { |
49 | 37 | type: "string", |
| 38 | + label: "Reference Number", |
50 | 39 | description: "Reference number generated for the payment. A string of your choice can also be used as the reference number. Max-length [100]", |
51 | 40 | optional: true, |
52 | 41 | }, |
53 | 42 | description: { |
54 | 43 | type: "string", |
| 44 | + label: "Description", |
55 | 45 | description: "Description about the payment.", |
56 | 46 | optional: true, |
57 | 47 | }, |
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: { |
59 | 54 | type: "string", |
| 55 | + label: "Exchange Rate", |
60 | 56 | 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.", |
61 | 57 | optional: true, |
62 | 58 | }, |
63 | | - bank_charges: { |
| 59 | + bankCharges: { |
64 | 60 | type: "string", |
| 61 | + label: "Bank Charges", |
65 | 62 | description: "Denotes any additional bank charges.", |
66 | 63 | optional: true, |
67 | 64 | }, |
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}**", |
71 | 71 | optional: true, |
72 | 72 | }, |
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 | + ], |
77 | 81 | }, |
78 | | - amount_applied: { |
| 82 | + amountApplied: { |
79 | 83 | type: "string", |
| 84 | + label: "Amount Applied", |
80 | 85 | description: "Amount paid for the invoice.", |
81 | 86 | optional: true, |
82 | 87 | }, |
83 | | - tax_amount_withheld: { |
| 88 | + taxAmountWithheld: { |
84 | 89 | type: "string", |
| 90 | + label: "Tax Amount Withheld", |
85 | 91 | description: "Amount withheld for tax.", |
86 | 92 | optional: true, |
87 | 93 | }, |
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 | + ], |
91 | 99 | optional: true, |
92 | 100 | }, |
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 | + ], |
96 | 109 | optional: true, |
97 | 110 | }, |
98 | 111 | }, |
99 | 112 | 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 | + $, |
112 | 115 | data: { |
113 | | - customer_id: this.customer_id, |
114 | | - payment_mode: this.payment_mode, |
| 116 | + customer_id: this.customerId, |
| 117 | + payment_mode: this.paymentMode, |
115 | 118 | amount: this.amount, |
116 | 119 | date: this.date, |
117 | | - reference_number: this.reference_number, |
| 120 | + reference_number: this.referenceNumber, |
118 | 121 | 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), |
128 | 131 | }, |
129 | 132 | }); |
| 133 | + |
| 134 | + $.export("$summary", `Customer payment successfully created with Id: ${response.payment.payment_id}`); |
| 135 | + return response; |
130 | 136 | }, |
131 | 137 | }; |
0 commit comments