forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createOrderItemRequest.go
53 lines (47 loc) · 1.23 KB
/
createOrderItemRequest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package models
import (
"encoding/json"
)
// Request for creating an order item
type CreateOrderItemRequest struct {
Amount int `json:"amount"`
Description string `json:"description"`
Quantity int `json:"quantity"`
Category string `json:"category"`
Code *string `json:"code,omitempty"`
}
func (c *CreateOrderItemRequest) MarshalJSON() (
[]byte,
error) {
return json.Marshal(c.toMap())
}
func (c *CreateOrderItemRequest) toMap() map[string]any {
structMap := make(map[string]any)
structMap["amount"] = c.Amount
structMap["description"] = c.Description
structMap["quantity"] = c.Quantity
structMap["category"] = c.Category
if c.Code != nil {
structMap["code"] = c.Code
}
return structMap
}
func (c *CreateOrderItemRequest) UnmarshalJSON(input []byte) error {
temp := &struct {
Amount int `json:"amount"`
Description string `json:"description"`
Quantity int `json:"quantity"`
Category string `json:"category"`
Code *string `json:"code,omitempty"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
c.Amount = temp.Amount
c.Description = temp.Description
c.Quantity = temp.Quantity
c.Category = temp.Category
c.Code = temp.Code
return nil
}