github.com/schmorrison/Zoho@v1.1.4/invoice/update_invoice.go (about) 1 package invoice 2 3 import ( 4 "fmt" 5 6 zoho "github.com/schmorrison/Zoho" 7 ) 8 9 //https://www.zoho.com/invoice/api/v3/#Invoices_Update_an_invoice 10 //func (c *API) UpdateRecurringInvoice(request interface{}, OrganizationID string, params map[string]zoho.Parameter) (data UpdateInvoiceResponse, err error) { 11 func (c *API) UpdateInvoice( 12 request interface{}, 13 invoiceId string, 14 ) (data UpdateInvoiceResponse, err error) { 15 endpoint := zoho.Endpoint{ 16 Name: ContactsModule, 17 URL: fmt.Sprintf( 18 "https://invoice.zoho.%s/api/v3/%s/%s", 19 c.ZohoTLD, 20 InvoicesModule, 21 invoiceId, 22 ), 23 Method: zoho.HTTPPut, 24 ResponseData: &UpdateInvoiceResponse{}, 25 URLParameters: map[string]zoho.Parameter{ 26 "filter_by": "", 27 }, 28 RequestBody: &request, 29 BodyFormat: zoho.JSON_STRING, 30 Headers: map[string]string{ 31 InvoiceAPIEndpointHeader: c.OrganizationID, 32 }, 33 } 34 35 /*for k, v := range params { 36 endpoint.URLParameters[k] = v 37 }*/ 38 39 err = c.Zoho.HTTPRequest(&endpoint) 40 if err != nil { 41 return UpdateInvoiceResponse{}, fmt.Errorf("Failed to update invoice: %s", err) 42 } 43 44 if v, ok := endpoint.ResponseData.(*UpdateInvoiceResponse); ok { 45 // Check if the request succeeded 46 if v.Code != 0 { 47 return *v, fmt.Errorf("Failed to update invoice: %s", v.Message) 48 } 49 return *v, nil 50 } 51 return UpdateInvoiceResponse{}, fmt.Errorf("Data retrieved was not 'UpdateInvoiceResponse'") 52 } 53 54 type UpdateInvoiceRequest struct { 55 CustomerId string `json:"customer_id"` 56 //ContactName string `json:"contact_name,omitempty"` 57 ContactPersons []string `json:"contact_persons,omitempty"` 58 InvoiceNumber string `json:"invoice_number,omitempty"` 59 ReferenceNumber string `json:"reference_number,omitempty"` 60 PlaceOfSupply string `json:"place_of_supply,omitempty"` 61 GstTreatment string `json:"gst_treatment,omitempty"` 62 GstNo string `json:"gst_no,omitempty"` 63 TemplateId string `json:"template_id,omitempty"` 64 Date string `json:"date,omitempty"` 65 PaymentTerms int64 `json:"payment_terms,omitempty"` 66 PaymentTermsLabel string `json:"payment_terms_label,omitempty"` 67 DueDate string `json:"due_date,omitempty"` 68 Discount float64 `json:"discount,omitempty"` 69 IsDiscountBeforeTax bool `json:"is_discount_before_tax,omitempty"` 70 DiscountType string `json:"discount_type,omitempty"` 71 IsInclusiveTax bool `json:"is_inclusive_tax,omitempty"` 72 ExchangeRate float64 `json:"exchange_rate,omitempty"` 73 RecurringInvoiceId string `json:"recurring_invoice_id,omitempty"` 74 InvoicedEstimateId string `json:"invoiced_estimate_id,omitempty"` 75 SalespersonId string `json:"salesperson_id,omitempty"` 76 CustomFields []CustomFieldRequest `json:"custom_fields,omitempty"` 77 ProjectId string `json:"project_id,omitempty"` 78 LineItems []InvoiceLineItem `json:"line_items"` 79 PaymentOptions PaymentOptions `json:"payment_options"` 80 AllowPartialPayments bool `json:"allow_partial_payments"` 81 CustomBody string `json:"custom_body,omitempty"` 82 CustomSubject string `json:"custom_subject,omitempty"` 83 Notes string `json:"notes,omitempty"` 84 Terms string `json:"terms,omitempty"` 85 ShippingCharge float64 `json:"shipping_charge,omitempty"` 86 Adjustment float64 `json:"adjustment,omitempty"` 87 AdjustmentDescription string `json:"adjustment_description"` 88 Reason string `json:"reason,omitempty"` 89 TaxAuthorityId string `json:"tax_authority_id,omitempty"` 90 TaxExemptionId string `json:"tax_exemption_id,omitempty"` 91 } 92 93 type UpdateInvoiceResponse struct { 94 Code int64 `json:"code"` 95 Message string `json:"message"` 96 Invoice struct { 97 InvoiceId string `json:"invoice_id"` 98 AchPaymentInitiated bool `json:"ach_payment_initiated"` 99 InvoiceNumber string `json:"invoice_number"` 100 IsPreGst bool `json:"is_pre_gst"` 101 PlaceOfSupply string `json:"place_of_supply"` 102 GstNo string `json:"gst_no"` 103 GstTreatment string `json:"gst_treatment"` 104 Date string `json:"date"` 105 Status string `json:"status"` 106 PaymentTerms int64 `json:"payment_terms"` 107 PaymentTermsLabel string `json:"payment_terms_label"` 108 DueDate string `json:"due_date"` 109 PaymentExpectedDate string `json:"payment_expected_date"` 110 LastPaymentDate string `json:"last_payment_date"` 111 ReferenceNumber string `json:"reference_number"` 112 CustomerId string `json:"customer_id"` 113 CustomerName string `json:"customer_name"` 114 ContactPersons []string `json:"contact_persons"` 115 CurrencyId string `json:"currency_id"` 116 CurrencyCode string `json:"currency_code"` 117 ExchangeRate float64 `json:"exchange_rate"` 118 Discount float64 `json:"discount"` 119 IsDiscountBeforeTax bool `json:"is_discount_before_tax"` 120 DiscountType string `json:"discount_type"` 121 IsInclusiveTax bool `json:"is_inclusive_tax"` 122 RecurringInvoiceId string `json:"recurring_invoice_id"` 123 IsViewedByClient bool `json:"is_viewed_by_client"` 124 HasAttachment bool `json:"has_attachment"` 125 ClientViewedTime string `json:"client_viewed_time"` 126 LineItems []InvoiceLineItem `json:"line_items"` 127 ShippingCharge float64 `json:"shipping_charge"` 128 Adjustment float64 `json:"adjustment"` 129 AdjustmentDescription string `json:"adjustment_description"` 130 SubTotal float64 `json:"sub_total"` 131 TaxTotal float64 `json:"tax_total"` 132 Total float64 `json:"total"` 133 Taxes []struct { 134 TaxName string `json:"tax_name"` 135 TaxAmount float64 `json:"tax_amount"` 136 } `json:"taxes"` 137 PaymentReminderEnabled bool `json:"payment_reminder_enabled"` 138 PaymentMade float64 `json:"payment_made"` 139 CreditsApplied float64 `json:"credits_applied"` 140 TaxAmountWithheld float64 `json:"tax_amount_withheld"` 141 Balance float64 `json:"balance"` 142 WriteOffAmount float64 `json:"write_off_amount"` 143 AllowPartialPayments bool `json:"allow_partial_payments"` 144 PricePrecision int64 `json:"price_precision"` 145 PaymentOptions PaymentOptions `json:"payment_options"` 146 IsEmailed bool `json:"is_emailed"` 147 RemindersSent int64 `json:"reminders_sent"` 148 LastReminderSentDate string `json:"last_reminder_sent_date"` 149 BillingAddress ContactAddress `json:"billing_address"` 150 ShippingAddress ContactAddress `json:"shipping_address"` 151 Notes string `json:"notes"` 152 Terms string `json:"terms"` 153 CustomFields []struct { 154 CustomfieldId string `json:"customfield_id"` 155 DataType string `json:"data_type"` 156 Index int64 `json:"index"` 157 Label string `json:"label"` 158 ShowOnPdf bool `json:"show_on_pdf"` 159 ShowInAllPdf bool `json:"show_in_all_pdf"` 160 Value string `json:"value"` 161 } `json:"custom_fields"` 162 TemplateId string `json:"template_id"` 163 TemplateName string `json:"template_name"` 164 CreatedTime string `json:"created_time"` 165 LastModifiedTime string `json:"last_modified_time"` 166 AttachmentName string `json:"attachment_name"` 167 CanSendInMail bool `json:"can_send_in_mail"` 168 SalespersonId string `json:"salesperson_id"` 169 SalespersonName string `json:"salesperson_name"` 170 InvoiceUrl string `json:"invoice_url"` 171 } `json:"invoice"` 172 }