github.com/schmorrison/Zoho@v1.1.4/invoice/create_payment.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/#Customer_Payments_Create_a_payment 10 //func (c *API) CreatePayment(request interface{}, OrganizationID string, params map[string]zoho.Parameter) (data ListContactsResponse, err error) { 11 func (c *API) CreatePayment(request interface{}) (data CreatePaymentResponse, err error) { 12 13 endpoint := zoho.Endpoint{ 14 Name: ContactsModule, 15 URL: fmt.Sprintf("https://invoice.zoho.%s/api/v3/%s", c.ZohoTLD, ContactsModule), 16 Method: zoho.HTTPPost, 17 ResponseData: &CreatePaymentResponse{}, 18 URLParameters: map[string]zoho.Parameter{ 19 "filter_by": "", 20 }, 21 RequestBody: request, 22 BodyFormat: zoho.JSON_STRING, 23 Headers: map[string]string{ 24 InvoiceAPIEndpointHeader: c.OrganizationID, 25 }, 26 } 27 28 /*for k, v := range params { 29 endpoint.URLParameters[k] = v 30 }*/ 31 32 err = c.Zoho.HTTPRequest(&endpoint) 33 if err != nil { 34 return CreatePaymentResponse{}, fmt.Errorf("Failed to create payment: %s", err) 35 } 36 37 if v, ok := endpoint.ResponseData.(*CreatePaymentResponse); ok { 38 // Check if the request succeeded 39 if v.Code != 0 { 40 return *v, fmt.Errorf("Failed to create payment: %s", v.Message) 41 } 42 return *v, nil 43 } 44 return CreatePaymentResponse{}, fmt.Errorf("Data retrieved was not 'CreatePaymentResponse'") 45 } 46 47 type CreatePaymentRequest struct { 48 CustomerId string `json:"customer_id"` 49 PaymentMode string `json:"payment_mode"` 50 Amount float64 `json:"amount"` 51 Date string `json:"date"` 52 ReferenceNumber string `json:"reference_number"` 53 Description string `json:"description"` 54 Invoices []CreatePaymentInvoice `json:"invoices"` 55 ExchangeRate float64 `json:"exchange_rate"` 56 BankCharges float64 `json:"bank_charges"` 57 CustomFields []struct { 58 Label string `json:"label"` 59 Value string `json:"value"` 60 } 61 } 62 63 type CreatePaymentInvoice struct { 64 CustomerId string `json:"invoice_id"` 65 AmountApplied float64 `json:"amount_applied"` 66 } 67 68 type CreatePaymentResponse struct { 69 Code int64 `json:"code"` 70 Message string `json:"message"` 71 Payment struct { 72 PaymentId string `json:"payment_id"` 73 PaymentMode string `json:"payment_mode"` 74 Amount float64 `json:"amount"` 75 AmountRefunded float64 `json:"amount_refunded"` 76 BankCharges float64 `json:"bank_charges"` 77 Date float64 `json:"date"` 78 Status string `json:"status"` 79 ReferenceNumber string `json:"reference_number"` 80 CustomerId string `json:"customer_id"` 81 CustomerName string `json:"customer_name"` 82 Email string `json:"email"` 83 Invoices []struct { 84 InvoiceId string `json:"invoice_id"` 85 InvoicePaymentId string `json:"invoice_payment_id"` 86 InvoiceNumber string `json:"invoice_number"` 87 Date string `json:"date"` 88 InvoiceAmount float64 `json:"invoice_amount"` 89 AmountApplied float64 `json:"amount_applied"` 90 BalanceAmount float64 `json:"balance_amount"` 91 } 92 CurrencyCode string `json:"currency_code"` 93 CurrencySymbol string `json:"currency_symbol"` 94 CustomFields []struct { 95 CustomfieldId int64 `json:"customfield_id"` 96 DataType string `json:"data_type"` 97 Index int64 `json:"index"` 98 Label string `json:"label"` 99 ShowOnPdf bool `json:"show_on_pdf"` 100 ShowInAllPdf bool `json:"show_in_all_pdf"` 101 Value string `json:"value"` 102 } 103 } 104 }