forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createOrderRequest.go
119 lines (112 loc) · 4.24 KB
/
createOrderRequest.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package models
import (
"encoding/json"
"github.com/apimatic/go-core-runtime/types"
)
// Request for creating an order
type CreateOrderRequest struct {
Items []CreateOrderItemRequest `json:"items"`
Customer CreateCustomerRequest `json:"customer"`
Payments []CreatePaymentRequest `json:"payments"`
Code string `json:"code"`
CustomerId types.Optional[string] `json:"customer_id"`
Shipping *CreateShippingRequest `json:"shipping,omitempty"`
Metadata types.Optional[map[string]string] `json:"metadata"`
AntifraudEnabled *bool `json:"antifraud_enabled,omitempty"`
Ip *string `json:"ip,omitempty"`
SessionId *string `json:"session_id,omitempty"`
Location *CreateLocationRequest `json:"location,omitempty"`
Device *CreateDeviceRequest `json:"device,omitempty"`
Closed bool `json:"closed"`
Currency *string `json:"currency,omitempty"`
Antifraud *CreateAntifraudRequest `json:"antifraud,omitempty"`
Submerchant *CreateSubMerchantRequest `json:"submerchant,omitempty"`
}
func (c *CreateOrderRequest) MarshalJSON() (
[]byte,
error) {
return json.Marshal(c.toMap())
}
func (c *CreateOrderRequest) toMap() map[string]any {
structMap := make(map[string]any)
structMap["items"] = c.Items
structMap["customer"] = c.Customer
structMap["payments"] = c.Payments
structMap["code"] = c.Code
if c.CustomerId.IsValueSet() {
structMap["customer_id"] = c.CustomerId.Value()
}
if c.Shipping != nil {
structMap["shipping"] = c.Shipping
}
if c.Metadata.IsValueSet() {
structMap["metadata"] = c.Metadata.Value()
}
if c.AntifraudEnabled != nil {
structMap["antifraud_enabled"] = c.AntifraudEnabled
}
if c.Ip != nil {
structMap["ip"] = c.Ip
}
if c.SessionId != nil {
structMap["session_id"] = c.SessionId
}
if c.Location != nil {
structMap["location"] = c.Location
}
if c.Device != nil {
structMap["device"] = c.Device
}
structMap["closed"] = c.Closed
if c.Currency != nil {
structMap["currency"] = c.Currency
}
if c.Antifraud != nil {
structMap["antifraud"] = c.Antifraud
}
if c.Submerchant != nil {
structMap["submerchant"] = c.Submerchant
}
return structMap
}
func (c *CreateOrderRequest) UnmarshalJSON(input []byte) error {
temp := &struct {
Items []CreateOrderItemRequest `json:"items"`
Customer CreateCustomerRequest `json:"customer"`
Payments []CreatePaymentRequest `json:"payments"`
Code string `json:"code"`
CustomerId types.Optional[string] `json:"customer_id"`
Shipping *CreateShippingRequest `json:"shipping,omitempty"`
Metadata types.Optional[map[string]string] `json:"metadata"`
AntifraudEnabled *bool `json:"antifraud_enabled,omitempty"`
Ip *string `json:"ip,omitempty"`
SessionId *string `json:"session_id,omitempty"`
Location *CreateLocationRequest `json:"location,omitempty"`
Device *CreateDeviceRequest `json:"device,omitempty"`
Closed bool `json:"closed"`
Currency *string `json:"currency,omitempty"`
Antifraud *CreateAntifraudRequest `json:"antifraud,omitempty"`
Submerchant *CreateSubMerchantRequest `json:"submerchant,omitempty"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
c.Items = temp.Items
c.Customer = temp.Customer
c.Payments = temp.Payments
c.Code = temp.Code
c.CustomerId = temp.CustomerId
c.Shipping = temp.Shipping
c.Metadata = temp.Metadata
c.AntifraudEnabled = temp.AntifraudEnabled
c.Ip = temp.Ip
c.SessionId = temp.SessionId
c.Location = temp.Location
c.Device = temp.Device
c.Closed = temp.Closed
c.Currency = temp.Currency
c.Antifraud = temp.Antifraud
c.Submerchant = temp.Submerchant
return nil
}