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