github.com/schmorrison/Zoho@v1.1.4/invoice/get_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_Get_an_invoice
    10  //func (c *API) GetInvoice(request interface{}, OrganizationID string, params map[string]zoho.Parameter) (data GetInvoiceResponse, err error) {
    11  func (c *API) GetInvoice(invoiceId string) (data GetInvoiceResponse, err error) {
    12  
    13  	endpoint := zoho.Endpoint{
    14  		Name: InvoicesModule,
    15  		URL: fmt.Sprintf(
    16  			"https://invoice.zoho.%s/api/v3/%s/%s",
    17  			c.ZohoTLD,
    18  			InvoicesModule,
    19  			invoiceId,
    20  		),
    21  		Method:       zoho.HTTPGet,
    22  		ResponseData: &GetInvoiceResponse{},
    23  		URLParameters: map[string]zoho.Parameter{
    24  			"filter_by": "",
    25  		},
    26  		BodyFormat: zoho.JSON_STRING,
    27  		Headers: map[string]string{
    28  			InvoiceAPIEndpointHeader: c.OrganizationID,
    29  		},
    30  	}
    31  
    32  	/*for k, v := range params {
    33  	  	endpoint.URLParameters[k] = v
    34  	  }
    35  	*/
    36  
    37  	err = c.Zoho.HTTPRequest(&endpoint)
    38  	if err != nil {
    39  		return GetInvoiceResponse{}, fmt.Errorf("Failed to retrieve invoice: %s", err)
    40  	}
    41  
    42  	if v, ok := endpoint.ResponseData.(*GetInvoiceResponse); ok {
    43  		// Check if the request succeeded
    44  		if v.Code != 0 {
    45  			return *v, fmt.Errorf("Failed to retrieve invoice: %s", v.Message)
    46  		}
    47  		return *v, nil
    48  	}
    49  	return GetInvoiceResponse{}, fmt.Errorf("Data retrieved was not 'GetInvoiceResponse'")
    50  }
    51  
    52  type GetInvoiceResponse struct {
    53  	Code    int64  `json:"code"`
    54  	Message string `json:"message"`
    55  	Invoice struct {
    56  		InvoiceId           string   `json:"invoice_id"`
    57  		AchPaymentInitiated bool     `json:"ach_payment_initiated"`
    58  		InvoiceNumber       string   `json:"invoice_number"`
    59  		IsPreGst            bool     `json:"is_pre_gst"`
    60  		PlaceOfSupply       string   `json:"place_of_supply"`
    61  		GstNo               string   `json:"gst_no"`
    62  		GstTreatment        string   `json:"gst_treatment"`
    63  		Date                string   `json:"date"`
    64  		Status              string   `json:"status"`
    65  		PaymentTerms        int64    `json:"payment_terms"`
    66  		PaymentTermsLabel   string   `json:"payment_terms_label"`
    67  		DueDate             string   `json:"due_date"`
    68  		PaymentExpectedDate string   `json:"payment_expected_date"`
    69  		LastPaymentDate     string   `json:"last_payment_date"`
    70  		ReferenceNumber     string   `json:"reference_number"`
    71  		CustomerId          string   `json:"customer_id"`
    72  		CustomerName        string   `json:"customer_name"`
    73  		ContactPersons      []string `json:"contact_persons"`
    74  		CurrencyId          string   `json:"currency_id"`
    75  		CurrencyCode        string   `json:"currency_code"`
    76  		ExchangeRate        float64  `json:"exchange_rate"`
    77  		Discount            float64  `json:"discount"`
    78  		IsDiscountBeforeTax bool     `json:"is_discount_before_tax"`
    79  		DiscountType        string   `json:"discount_type"`
    80  		IsInclusiveTax      bool     `json:"is_inclusive_tax"`
    81  		RecurringInvoiceId  string   `json:"recurring_invoice_id"`
    82  		IsViewedByClient    bool     `json:"is_viewed_by_client"`
    83  		HasAttachment       bool     `json:"has_attachment"`
    84  		ClientViewedTime    string   `json:"client_viewed_time"`
    85  		LineItems           []struct {
    86  			LineItemId     string   `json:"line_item_id"`
    87  			ItemId         string   `json:"item_id"`
    88  			ProjectId      string   `json:"project_id"`
    89  			ProjectName    string   `json:"project_name"`
    90  			ItemType       string   `json:"item_type"`
    91  			ProductType    string   `json:"product_type"`
    92  			TimeEntryIds   []string `json:"time_entry_ids"`
    93  			ExpenseId      string   `json:"expense_id"`
    94  			Name           string   `json:"name"`
    95  			ItemOrder      float64  `json:"item_order"`
    96  			BcyRate        float64  `json:"bcy_rate"`
    97  			Rate           float64  `json:"rate"`
    98  			Quantity       int64    `json:"quantity"`
    99  			Unit           string   `json:"unit"`
   100  			DiscountAmount float64  `json:"discount_amount"`
   101  			Discount       float64  `json:"discount"`
   102  			TaxId          string   `json:"tax_id"`
   103  			TaxName        string   `json:"tax_name"`
   104  			TaxType        string   `json:"tax_type"`
   105  			TaxPercentage  float64  `json:"tax_percentage"`
   106  			ItemTotal      float64  `json:"item_total"`
   107  		} `json:"line_items"`
   108  		ShippingCharge        float64 `json:"shipping_charge"`
   109  		Adjustment            float64 `json:"adjustment"`
   110  		AdjustmentDescription string  `json:"adjustment_description"`
   111  		SubTotal              float64 `json:"sub_total"`
   112  		TaxTotal              float64 `json:"tax_total"`
   113  		Total                 float64 `json:"total"`
   114  		Taxes                 []struct {
   115  			TaxName   string  `json:"tax_name"`
   116  			TaxAmount float64 `json:"tax_amount"`
   117  		} `json:"taxes"`
   118  		PaymentReminderEnabled bool           `json:"payment_reminder_enabled"`
   119  		PaymentMade            float64        `json:"payment_made"`
   120  		CreditsApplied         float64        `json:"credits_applied"`
   121  		TaxAmountWithheld      float64        `json:"tax_amount_withheld"`
   122  		Balance                float64        `json:"balance"`
   123  		WriteOffAmount         float64        `json:"write_off_amount"`
   124  		AllowPartialPayments   bool           `json:"allow_partial_payments"`
   125  		PricePrecision         int64          `json:"price_precision"`
   126  		PaymentOptions         PaymentOptions `json:"payment_options"`
   127  		IsEmailed              bool           `json:"is_emailed"`
   128  		RemindersSent          int64          `json:"reminders_sent"`
   129  		LastReminderSentDate   string         `json:"last_reminder_sent_date"`
   130  		BillingAddress         struct {
   131  			Address string `json:"address"`
   132  			Street2 string `json:"street2"`
   133  			City    string `json:"city"`
   134  			State   string `json:"state"`
   135  			Zip     string `json:"zip"`
   136  			Country string `json:"country"`
   137  			Fax     string `json:"fax"`
   138  		} `json:"billing_address"`
   139  		ShippingAddress struct {
   140  			Address string `json:"address"`
   141  			City    string `json:"city"`
   142  			State   string `json:"state"`
   143  			Zip     string `json:"zip"`
   144  			Country string `json:"country"`
   145  			Fax     string `json:"fax"`
   146  		} `json:"shipping_address"`
   147  		Notes string `json:"notes"`
   148  		Terms string `json:"terms"`
   149  		/*CustomFields []struct {
   150  		    CustomfieldId int64  `json:"customfield_id"`
   151  		    DataType      string `json:"data_type"`
   152  		    Index         int64  `json:"index"`
   153  		    Label         string `json:"label"`
   154  		    ShowOnPdf     bool   `json:"show_on_pdf"`
   155  		    ShowInAllPdf  bool   `json:"show_in_all_pdf"`
   156  		    Value         int64  `json:"value"`
   157  		} `json:"custom_fields"`*/
   158  		TemplateId       string `json:"template_id"`
   159  		TemplateName     string `json:"template_name"`
   160  		CreatedTime      string `json:"created_time"`
   161  		LastModifiedTime string `json:"last_modified_time"`
   162  		AttachmentName   string `json:"attachment_name"`
   163  		CanSendInMail    bool   `json:"can_send_in_mail"`
   164  		SalespersonId    string `json:"salesperson_id"`
   165  		SalespersonName  string `json:"salesperson_name"`
   166  		InvoiceUrl       string `json:"invoice_url"`
   167  	} `json:"invoice"`
   168  }