github.com/Files-com/files-sdk-go/v3@v3.1.81/invoice.go (about)

     1  package files_sdk
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	lib "github.com/Files-com/files-sdk-go/v3/lib"
     8  )
     9  
    10  type Invoice struct {
    11  	Id                int64      `json:"id,omitempty" path:"id,omitempty" url:"id,omitempty"`
    12  	Amount            string     `json:"amount,omitempty" path:"amount,omitempty" url:"amount,omitempty"`
    13  	Balance           string     `json:"balance,omitempty" path:"balance,omitempty" url:"balance,omitempty"`
    14  	CreatedAt         *time.Time `json:"created_at,omitempty" path:"created_at,omitempty" url:"created_at,omitempty"`
    15  	Currency          string     `json:"currency,omitempty" path:"currency,omitempty" url:"currency,omitempty"`
    16  	DownloadUri       string     `json:"download_uri,omitempty" path:"download_uri,omitempty" url:"download_uri,omitempty"`
    17  	InvoiceLineItems  []string   `json:"invoice_line_items,omitempty" path:"invoice_line_items,omitempty" url:"invoice_line_items,omitempty"`
    18  	Method            string     `json:"method,omitempty" path:"method,omitempty" url:"method,omitempty"`
    19  	PaymentLineItems  []string   `json:"payment_line_items,omitempty" path:"payment_line_items,omitempty" url:"payment_line_items,omitempty"`
    20  	PaymentReversedAt *time.Time `json:"payment_reversed_at,omitempty" path:"payment_reversed_at,omitempty" url:"payment_reversed_at,omitempty"`
    21  	PaymentType       string     `json:"payment_type,omitempty" path:"payment_type,omitempty" url:"payment_type,omitempty"`
    22  	SiteName          string     `json:"site_name,omitempty" path:"site_name,omitempty" url:"site_name,omitempty"`
    23  	Type              string     `json:"type,omitempty" path:"type,omitempty" url:"type,omitempty"`
    24  }
    25  
    26  func (i Invoice) Identifier() interface{} {
    27  	return i.Id
    28  }
    29  
    30  type InvoiceCollection []Invoice
    31  
    32  type InvoiceListParams struct {
    33  	ListParams
    34  }
    35  
    36  type InvoiceFindParams struct {
    37  	Id int64 `url:"-,omitempty" required:"false" json:"-,omitempty" path:"id"`
    38  }
    39  
    40  func (i *Invoice) UnmarshalJSON(data []byte) error {
    41  	type invoice Invoice
    42  	var v invoice
    43  	if err := json.Unmarshal(data, &v); err != nil {
    44  		return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{})
    45  	}
    46  
    47  	*i = Invoice(v)
    48  	return nil
    49  }
    50  
    51  func (i *InvoiceCollection) UnmarshalJSON(data []byte) error {
    52  	type invoices InvoiceCollection
    53  	var v invoices
    54  	if err := json.Unmarshal(data, &v); err != nil {
    55  		return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{})
    56  	}
    57  
    58  	*i = InvoiceCollection(v)
    59  	return nil
    60  }
    61  
    62  func (i *InvoiceCollection) ToSlice() *[]interface{} {
    63  	ret := make([]interface{}, len(*i))
    64  	for i, v := range *i {
    65  		ret[i] = v
    66  	}
    67  
    68  	return &ret
    69  }