github.com/schmorrison/Zoho@v1.1.4/subscriptions/customers.go (about)

     1  package subscriptions
     2  
     3  import (
     4  	"fmt"
     5  
     6  	zoho "github.com/schmorrison/Zoho"
     7  )
     8  
     9  // GetCustomer will return customer specified by id
    10  // https://www.zoho.com/subscriptions/api/v1/#Invoices_Retrieve_a_subscription
    11  func (s *API) GetCustomer(id string) (data CustomerResponse, err error) {
    12  	endpoint := zoho.Endpoint{
    13  		Name: "customers",
    14  		URL: fmt.Sprintf(
    15  			"https://subscriptions.zoho.%s/api/v1/customers/%s",
    16  			s.ZohoTLD,
    17  			id,
    18  		),
    19  		Method:       zoho.HTTPGet,
    20  		ResponseData: &CustomerResponse{},
    21  		Headers: map[string]string{
    22  			ZohoSubscriptionsEndpointHeader: s.OrganizationID,
    23  		},
    24  	}
    25  
    26  	err = s.Zoho.HTTPRequest(&endpoint)
    27  	if err != nil {
    28  		return CustomerResponse{}, fmt.Errorf("Failed to retrieve customer (%s): %s", id, err)
    29  	}
    30  
    31  	if v, ok := endpoint.ResponseData.(*CustomerResponse); ok {
    32  		return *v, nil
    33  	}
    34  
    35  	return CustomerResponse{}, fmt.Errorf("Data retrieved was not 'CustomerResponse'")
    36  }
    37  
    38  type CustomerResponse struct {
    39  	Code     int64  `json:"code"`
    40  	Message  string `json:"message"`
    41  	Customer struct {
    42  		CustomerID  string `json:"customer_id"`
    43  		DisplayName string `json:"display_name"`
    44  		Salutation  string `json:"salutation"`
    45  		FirstName   string `json:"first_name"`
    46  		LastName    string `json:"last_name"`
    47  		Email       string `json:"email"`
    48  		Tags        []struct {
    49  			TagOptionID    string `json:"tag_option_id"`
    50  			IsTagMandatory bool   `json:"is_tag_mandatory"`
    51  			TagName        string `json:"tag_name"`
    52  			TagID          string `json:"tag_id"`
    53  			TagOptionName  string `json:"tag_option_name"`
    54  		} `json:"tags"`
    55  		CompanyName     string `json:"company_name"`
    56  		Phone           string `json:"phone"`
    57  		Mobile          string `json:"mobile"`
    58  		Website         string `json:"website"`
    59  		Designation     string `json:"designation"`
    60  		Department      string `json:"department"`
    61  		IsPortalEnabled bool   `json:"is_portal_enabled"`
    62  		BillingAddress  struct {
    63  			Attention   string `json:"attention"`
    64  			Street      string `json:"street"`
    65  			City        string `json:"city"`
    66  			State       string `json:"state"`
    67  			Zip         string `json:"zip"`
    68  			Country     string `json:"country"`
    69  			CountryCode string `json:"country_code"`
    70  			StateCode   string `json:"state_code"`
    71  			Fax         string `json:"fax"`
    72  		} `json:"billing_address"`
    73  		ShippingAddress struct {
    74  			Attention   string `json:"attention"`
    75  			Street      string `json:"street"`
    76  			City        string `json:"city"`
    77  			State       string `json:"state"`
    78  			Zip         string `json:"zip"`
    79  			Country     string `json:"country"`
    80  			CountryCode string `json:"country_code"`
    81  			StateCode   string `json:"state_code"`
    82  			Fax         string `json:"fax"`
    83  		} `json:"shipping_address"`
    84  		CurrencyCode           string        `json:"currency_code"`
    85  		CurrencyID             string        `json:"currency_id"`
    86  		AchSupported           bool          `json:"ach_supported"`
    87  		GstNo                  string        `json:"gst_no"`
    88  		GstTreatment           string        `json:"gst_treatment"`
    89  		PlaceOfContact         string        `json:"place_of_contact"`
    90  		PricePrecision         int64         `json:"price_precision"`
    91  		UnusedCredits          float64       `json:"unused_credits"`
    92  		Outstanding            float64       `json:"outstanding"`
    93  		Notes                  string        `json:"notes"`
    94  		Status                 string        `json:"status"`
    95  		CustomFields           []CustomField `json:"custom_fields"`
    96  		ZcrmAccountID          string        `json:"zcrm_account_id"`
    97  		ZcrmContactID          string        `json:"zcrm_contact_id"`
    98  		UpdatedTime            string        `json:"updated_time"`
    99  		CreatedTime            string        `json:"created_time"`
   100  		Source                 string        `json:"source"`
   101  		PaymentTermsLabel      string        `json:"payment_terms_label"`
   102  		IsLinkedWithZohocrm    bool          `json:"is_linked_with_zohocrm"`
   103  		PrimaryContactpersonID string        `json:"primary_contactperson_id"`
   104  		CanAddCard             bool          `json:"can_add_card"`
   105  		CanAddBankAccount      bool          `json:"can_add_bank_account"`
   106  		DefaultTemplates       struct {
   107  			InvoiceTemplateID    string `json:"invoice_template_id"`
   108  			CreditnoteTemplateID string `json:"creditnote_template_id"`
   109  		} `json:"default_templates"`
   110  		Documents []struct {
   111  			CanShowInPortal   bool   `json:"can_show_in_portal"`
   112  			FileName          string `json:"file_name"`
   113  			FileType          string `json:"file_type"`
   114  			FileSize          int64  `json:"file_size"`
   115  			FileSizeFormatted string `json:"file_size_formatted"`
   116  			DocumentID        string `json:"document_id"`
   117  			AttachmentOrder   int64  `json:"attachment_order"`
   118  		} `json:"documents"`
   119  	} `json:"customer"`
   120  }