github.com/companieshouse/lfp-pay-api@v0.0.0-20230203133422-0ca455cd79f9/e5/types.go (about) 1 package e5 2 3 // GetTransactionsInput is the struct used to query transactions by company number 4 type GetTransactionsInput struct { 5 CompanyCode string `validate:"required"` 6 CompanyNumber string `validate:"required"` 7 PageNumber int 8 } 9 10 // GetTransactionsResponse returns the output of a get request for company transactions 11 type GetTransactionsResponse struct { 12 Page Page `json:"page"` 13 Transactions []Transaction `json:"data"` 14 } 15 16 // Transaction is a representation of a transaction item in E5 17 type Transaction struct { 18 CompanyCode string `json:"companyCode"` 19 LedgerCode string `json:"ledgerCode"` 20 CustomerCode string `json:"customerCode"` 21 TransactionReference string `json:"transactionReference"` 22 TransactionDate string `json:"transactionDate"` 23 MadeUpDate string `json:"madeUpDate"` 24 Amount float64 `json:"amount"` 25 OutstandingAmount float64 `json:"outstandingAmount"` 26 IsPaid bool `json:"isPaid"` 27 TransactionType string `json:"transactionType"` 28 TransactionSubType string `json:"transactionSubType"` 29 TypeDescription string `json:"typeDescription"` 30 DueDate string `json:"dueDate"` 31 AccountStatus string `json:"accountStatus"` 32 } 33 34 // Page is a representation of a Page data block in part of e5 GET request 35 type Page struct { 36 Size int `json:"size"` 37 TotalElements int `json:"totalElements"` 38 TotalPages int `json:"totalPages"` 39 Number int `json:"number"` 40 } 41 42 // CreatePaymentInput is the struct needed to send a create payment request to the Client API 43 type CreatePaymentInput struct { 44 CompanyCode string `json:"companyCode" validate:"required"` 45 CompanyNumber string `json:"customerCode" validate:"required"` 46 PaymentID string `json:"paymentId" validate:"required"` 47 TotalValue float64 `json:"paymentValue" validate:"required"` 48 Transactions []*CreatePaymentTransaction `json:"transactions" validate:"required"` 49 } 50 51 // CreatePaymentTransaction is the struct to define the transactions you want to pay for 52 type CreatePaymentTransaction struct { 53 Reference string `json:"transactionReference" validate:"required"` 54 Value float64 `json:"allocationValue" validate:"required"` 55 } 56 57 // AuthorisePaymentInput is the struct to authorise payment 58 type AuthorisePaymentInput struct { 59 CompanyCode string `json:"companyCode" validate:"required"` 60 PaymentID string `json:"paymentId" validate:"required"` 61 CardReference string `json:"paymentCardReference"` 62 AuthorisationNumber string `json:"authorisationNumber"` 63 CardType string `json:"cardType"` 64 Email string `json:"emailAddress" validate:"required,email"` 65 } 66 67 // PaymentActionInput input is the struct used for the confirm, reject and timeout actions 68 type PaymentActionInput struct { 69 CompanyCode string `json:"companyCode" validate:"required"` 70 PaymentID string `json:"paymentId" validate:"required"` 71 } 72 73 // PaymentActionResponse is the return value of a successful request to create a payment 74 type PaymentActionResponse struct { 75 Success bool 76 ErrorMessage string 77 } 78 79 // e5ApiErrorResponse is the generic struct used to unmarshal the body of responses that have errored 80 type apiErrorResponse struct { 81 Code int `json:"httpStatusCode"` 82 Status string `json:"status"` 83 Timestamp string `json:"timestamp"` 84 MessageCode string `json:"messageCode,omitempty"` 85 Message string `json:"message"` 86 DebugMessage string `json:"debugMessage"` 87 SubErrors []struct { 88 Object string `json:"object"` 89 Field string `json:"field"` 90 RejectedValue string `json:"rejectedValue"` 91 Message string `json:"message"` 92 } `json:"subErrors,omitempty"` 93 } 94 95 // SubErrorMap converts the sub error struct into a map 96 func (e *apiErrorResponse) SubErrorMap() []map[string]string { 97 subErrors := make([]map[string]string, 0, len(e.SubErrors)) 98 99 for _, sub := range e.SubErrors { 100 subErrors = append(subErrors, map[string]string{ 101 "field": sub.Field, 102 "rejected_value": sub.RejectedValue, 103 "message": sub.Message, 104 }) 105 } 106 107 return subErrors 108 }