github.com/schmorrison/Zoho@v1.1.4/invoice/create_recurring_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/#Recurring_Invoices_Create_a_Recurring_Invoice
    10  //func (c *API) CreateRecurringInvoice(request interface{}, OrganizationID string, params map[string]zoho.Parameter) (data ListContactsResponse, err error) {
    11  func (c *API) CreateRecurringInvoice(
    12  	request interface{},
    13  ) (data CreateRecurringInvoiceResponse, err error) {
    14  
    15  	endpoint := zoho.Endpoint{
    16  		Name: RecurringInvoicesModule,
    17  		URL: fmt.Sprintf(
    18  			"https://invoice.zoho.%s/api/v3/%s",
    19  			c.ZohoTLD,
    20  			RecurringInvoicesModule,
    21  		),
    22  		Method:       zoho.HTTPPost,
    23  		ResponseData: &CreateRecurringInvoiceResponse{},
    24  		URLParameters: map[string]zoho.Parameter{
    25  			"filter_by": "",
    26  		},
    27  		RequestBody: request,
    28  		BodyFormat:  zoho.JSON_STRING,
    29  		Headers: map[string]string{
    30  			InvoiceAPIEndpointHeader: c.OrganizationID,
    31  		},
    32  	}
    33  
    34  	/*for k, v := range params {
    35  		endpoint.URLParameters[k] = v
    36  	}*/
    37  
    38  	err = c.Zoho.HTTPRequest(&endpoint)
    39  	if err != nil {
    40  		return CreateRecurringInvoiceResponse{}, fmt.Errorf(
    41  			"Failed to create recurring invoice: %s",
    42  			err,
    43  		)
    44  	}
    45  
    46  	if v, ok := endpoint.ResponseData.(*CreateRecurringInvoiceResponse); ok {
    47  		// Check if the request succeeded
    48  		if v.Code != 0 {
    49  			return *v, fmt.Errorf("Failed to create recurring invoice: %s", v.Message)
    50  		}
    51  		return *v, nil
    52  	}
    53  	return CreateRecurringInvoiceResponse{}, fmt.Errorf(
    54  		"Data retrieved was not 'CreateRecurringInvoiceResponse'",
    55  	)
    56  }
    57  
    58  type CreateRecurringInvoiceRequest struct {
    59  	RecurrenceName      string               `json:"recurrence_name"`
    60  	ReferenceNumber     string               `json:"reference_number,omitempty"`
    61  	CustomerId          string               `json:"customer_id"`
    62  	TemplateId          string               `json:"template_id"`
    63  	SalespersonId       string               `json:"salesperson_id,omitempty"`
    64  	IsInclusiveTax      bool                 `json:"is_inclusive_tax,omitempty"`
    65  	ContactPersons      []string             `json:"contact_persons,omitempty"`
    66  	StartDate           string               `json:"start_date"`
    67  	EndDate             string               `json:"end_date,omitempty"`
    68  	PlaceOfSupply       string               `json:"place_of_supply,omitempty"`
    69  	GstTreatment        string               `json:"gst_treatment,omitempty"`
    70  	GstNo               string               `json:"gst_no,omitempty"`
    71  	RecurrenceFrequency string               `json:"recurrence_frequency"`
    72  	RepeatEvery         int64                `json:"repeat_every,omitempty"`
    73  	PaymentTerms        int64                `json:"payment_terms,omitempty"`
    74  	PaymentTermsLabel   string               `json:"payment_terms_label,omitempty"`
    75  	CustomFields        []CustomFieldRequest `json:"custom_fields,omitempty"`
    76  	LineItems           []InvoiceLineItem    `json:"line_items,omitempty"`
    77  	TaxId               string               `json:"tax_id,omitempty"`
    78  	Email               string               `json:"email,omitempty"`
    79  	PaymentOptions      PaymentOptions       `json:"payment_options,omitempty"`
    80  	TaxAuthorityId      string               `json:"tax_authority_id,omitempty"`
    81  	TaxExemptionId      string               `json:"tax_exemption_id,omitempty"`
    82  }
    83  
    84  /*
    85  type RecurringInvoiceLineItem struct {
    86  	ItemId         string  `json:"item_id"`
    87  	Name           string  `json:"name,omitempty"`
    88  	Description    string  `json:"description,omitempty"`
    89  	Rate           float64 `json:"rate,omitempty"`
    90  	Quantity       int64   `json:"quantity"`
    91  	Discount       float64 `json:"discount,omitempty"`
    92  	TaxId          string  `json:"tax_id,omitempty"`
    93  	TaxExemptionId string  `json:"tax_exemption_id,omitempty"`
    94  	ItemTotal      float64 `json:"item_total,omitempty"`
    95  	ProductType    string  `json:"product_type,omitempty"`
    96  	HsnOrSac       int64   `json:"hsn_or_sac,omitempty"`
    97  	ProjectId      string  `json:"project_id,omitempty"`
    98  }
    99  */
   100  
   101  type CreateRecurringInvoiceResponse struct {
   102  	Code             int64  `json:"code"`
   103  	Message          string `json:"message"`
   104  	RecurringInvoice struct {
   105  		RecurringInvoiceId string `json:"recurring_invoice_id"`
   106  		RecurrenceName     string `json:"recurrence_name"`
   107  		ReferenceNumber    string `json:"reference_number"`
   108  		IsPreGst           bool   `json:"is_pre_gst"`
   109  		GstNo              string `json:"gst_no"`
   110  		GstTreatment       string `json:"gst_treatment"`
   111  		PlaceOfSupply      string `json:"place_of_supply"`
   112  		CustomerName       string `json:"customer_name"`
   113  		CustomerId         string `json:"customer_id"`
   114  		CurrencyId         string `json:"currency_id"`
   115  		CurrencyCode       string `json:"currency_code"`
   116  		StartDate          string `json:"start_date"`
   117  		EndDate            string `json:"end_date"`
   118  		LastSentDate       string `json:"last_sent_date"`
   119  		NextInvoiceDate    string `json:"next_invoice_date"`
   120  		LineItems          []struct {
   121  			LineItemId  string  `json:"line_item_id"`
   122  			Quantity    int64   `json:"quantity"`
   123  			Name        string  `json:"name"`
   124  			ItemTotal   float64 `json:"item_total"`
   125  			Sku         string  `json:"sku"`
   126  			ProductType string  `json:"product_type"`
   127  			ProjectId   string  `json:"project_id"`
   128  			ProjectName string  `json:"project_name"`
   129  		} `json:"line_items"`
   130  		BillingAddress  ContactAddress `json:"billing_address"`
   131  		ShippingAddress ContactAddress `json:"shipping_address"`
   132  		CustomFields    []struct {
   133  			CustomfieldId string `json:"customfield_id"`
   134  			DataType      string `json:"data_type"`
   135  			Index         int64  `json:"index"`
   136  			IsActive      bool   `json:"is_active"`
   137  			Label         string `json:"label"`
   138  			ShowInAllPdf  bool   `json:"show_in_all_pdf"`
   139  			ShowOnPdf     bool   `json:"show_on_pdf"`
   140  			Value         string `json:"value"`
   141  		} `json:"custom_fields"`
   142  		PaymentOptions PaymentOptions `json:"payment_options"`
   143  	} `json:"recurring_invoice"`
   144  }
   145  
   146  type PaymentOptions struct {
   147  	PaymentGateways []PaymentGateway `json:"payment_gateways,omitempty"`
   148  }
   149  
   150  type PaymentGateway struct {
   151  	AdditionalField1     string `json:"additional_field1,omitempty"`
   152  	Configured           bool   `json:"configured,omitempty"`
   153  	GatewayName          string `json:"gateway_name,omitempty"`
   154  	GatewayNameFormatted string `json:"gateway_name_formatted,omitempty"`
   155  }