github.com/Files-com/files-sdk-go/v2@v2.1.2/payment.go (about)

     1  package files_sdk
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	lib "github.com/Files-com/files-sdk-go/v2/lib"
     8  )
     9  
    10  type Payment 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  	UpdatedAt         *time.Time `json:"updated_at,omitempty" path:"updated_at,omitempty" url:"updated_at,omitempty"`
    25  }
    26  
    27  func (p Payment) Identifier() interface{} {
    28  	return p.Id
    29  }
    30  
    31  type PaymentCollection []Payment
    32  
    33  type PaymentListParams struct {
    34  	ListParams
    35  }
    36  
    37  type PaymentFindParams struct {
    38  	Id int64 `url:"-,omitempty" required:"false" json:"-,omitempty" path:"id"`
    39  }
    40  
    41  func (p *Payment) UnmarshalJSON(data []byte) error {
    42  	type payment Payment
    43  	var v payment
    44  	if err := json.Unmarshal(data, &v); err != nil {
    45  		return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{})
    46  	}
    47  
    48  	*p = Payment(v)
    49  	return nil
    50  }
    51  
    52  func (p *PaymentCollection) UnmarshalJSON(data []byte) error {
    53  	type payments PaymentCollection
    54  	var v payments
    55  	if err := json.Unmarshal(data, &v); err != nil {
    56  		return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{})
    57  	}
    58  
    59  	*p = PaymentCollection(v)
    60  	return nil
    61  }
    62  
    63  func (p *PaymentCollection) ToSlice() *[]interface{} {
    64  	ret := make([]interface{}, len(*p))
    65  	for i, v := range *p {
    66  		ret[i] = v
    67  	}
    68  
    69  	return &ret
    70  }