-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathOrder.java
More file actions
452 lines (358 loc) · 12 KB
/
Order.java
File metadata and controls
452 lines (358 loc) · 12 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
/*
* Voucherify API
* Voucherify promotion engine REST API. Please see https://docs.voucherify.io/docs for more details.
*
* The version of the OpenAPI document: v2018-08-01
* Contact: support@voucherify.io
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package io.voucherify.client.model;
import java.util.Objects;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import io.voucherify.client.model.OrderItem;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.openapitools.jackson.nullable.JsonNullable;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import io.voucherify.client.JSON;
/**
* Order information.
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class Order {
public static final String SERIALIZED_NAME_ID = "id";
@SerializedName(SERIALIZED_NAME_ID)
private String id;
public static final String SERIALIZED_NAME_SOURCE_ID = "source_id";
@SerializedName(SERIALIZED_NAME_SOURCE_ID)
private String sourceId;
/**
* The order status.
*/
@JsonAdapter(StatusEnum.Adapter.class)
public enum StatusEnum {
CREATED("CREATED"),
PAID("PAID"),
CANCELED("CANCELED"),
FULFILLED("FULFILLED");
private String value;
StatusEnum(String value) {
this.value = value;
}
public String getValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
public static StatusEnum fromValue(String value) {
for (StatusEnum b : StatusEnum.values()) {
if (b.value.equals(value)) {
return b;
}
}
return null;
}
public static class Adapter extends TypeAdapter<StatusEnum> {
@Override
public void write(final JsonWriter jsonWriter, final StatusEnum enumeration) throws IOException {
jsonWriter.value(enumeration.getValue());
}
@Override
public StatusEnum read(final JsonReader jsonReader) throws IOException {
String value = jsonReader.nextString();
return StatusEnum.fromValue(value);
}
}
}
public static final String SERIALIZED_NAME_STATUS = "status";
@SerializedName(SERIALIZED_NAME_STATUS)
private StatusEnum status;
public static final String SERIALIZED_NAME_AMOUNT = "amount";
@SerializedName(SERIALIZED_NAME_AMOUNT)
private Integer amount;
public static final String SERIALIZED_NAME_INITIAL_AMOUNT = "initial_amount";
@SerializedName(SERIALIZED_NAME_INITIAL_AMOUNT)
private Integer initialAmount;
public static final String SERIALIZED_NAME_DISCOUNT_AMOUNT = "discount_amount";
@SerializedName(SERIALIZED_NAME_DISCOUNT_AMOUNT)
private Integer discountAmount;
public static final String SERIALIZED_NAME_ITEMS = "items";
@SerializedName(SERIALIZED_NAME_ITEMS)
private List<OrderItem> items;
public static final String SERIALIZED_NAME_METADATA = "metadata";
@SerializedName(SERIALIZED_NAME_METADATA)
private Map<String, Object> metadata;
public Order() {
}
public Order id(String id) {
this.id = id;
return this;
}
/**
* Unique ID assigned by Voucherify of an existing order that will be linked to the redemption of this request.
* @return id
**/
@javax.annotation.Nullable
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Order sourceId(String sourceId) {
this.sourceId = sourceId;
return this;
}
/**
* Unique source ID of an existing order that will be linked to the redemption of this request.
* @return sourceId
**/
@javax.annotation.Nullable
public String getSourceId() {
return sourceId;
}
public void setSourceId(String sourceId) {
this.sourceId = sourceId;
}
public Order status(StatusEnum status) {
this.status = status;
return this;
}
/**
* The order status.
* @return status
**/
@javax.annotation.Nullable
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
public Order amount(Integer amount) {
this.amount = amount;
return this;
}
/**
* A positive integer in the smallest currency unit (e.g. 100 cents for $1.00) representing the total amount of the order. This is the sum of the order items' amounts.
* @return amount
**/
@javax.annotation.Nullable
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amount) {
this.amount = amount;
}
public Order initialAmount(Integer initialAmount) {
this.initialAmount = initialAmount;
return this;
}
/**
* A positive integer in the smallest currency unit (e.g. 100 cents for $1.00) representing the total amount of the order. This is the sum of the order items' amounts.
* @return initialAmount
**/
@javax.annotation.Nullable
public Integer getInitialAmount() {
return initialAmount;
}
public void setInitialAmount(Integer initialAmount) {
this.initialAmount = initialAmount;
}
public Order discountAmount(Integer discountAmount) {
this.discountAmount = discountAmount;
return this;
}
/**
* Sum of all order-level discounts applied to the order. It is expressed as an integer in the smallest currency unit (e.g. 100 cents for $1.00).
* @return discountAmount
**/
@javax.annotation.Nullable
public Integer getDiscountAmount() {
return discountAmount;
}
public void setDiscountAmount(Integer discountAmount) {
this.discountAmount = discountAmount;
}
public Order items(List<OrderItem> items) {
this.items = items;
return this;
}
public Order addItemsItem(OrderItem itemsItem) {
if (this.items == null) {
this.items = new ArrayList<>();
}
this.items.add(itemsItem);
return this;
}
/**
* Array of items applied to the order. It can include up to 500 items.
* @return items
**/
@javax.annotation.Nullable
public List<OrderItem> getItems() {
return items;
}
public void setItems(List<OrderItem> items) {
this.items = items;
}
public Order metadata(Map<String, Object> metadata) {
this.metadata = metadata;
return this;
}
/**
* A set of custom key/value pairs that you can attach to an order. It can be useful for storing additional information about the order in a structured format. It can be used to define business validation rules or discount formulas.
* @return metadata
**/
@javax.annotation.Nullable
public Map<String, Object> getMetadata() {
return metadata;
}
public void setMetadata(Map<String, Object> metadata) {
this.metadata = metadata;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Order order = (Order) o;
return Objects.equals(this.id, order.id) &&
Objects.equals(this.sourceId, order.sourceId) &&
Objects.equals(this.status, order.status) &&
Objects.equals(this.amount, order.amount) &&
Objects.equals(this.initialAmount, order.initialAmount) &&
Objects.equals(this.discountAmount, order.discountAmount) &&
Objects.equals(this.items, order.items) &&
Objects.equals(this.metadata, order.metadata);
}
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
}
@Override
public int hashCode() {
return Objects.hash(id, sourceId, status, amount, initialAmount, discountAmount, items, metadata);
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Order {\n");
sb.append(" id: ").append(toIndentedString(id)).append("\n");
sb.append(" sourceId: ").append(toIndentedString(sourceId)).append("\n");
sb.append(" status: ").append(toIndentedString(status)).append("\n");
sb.append(" amount: ").append(toIndentedString(amount)).append("\n");
sb.append(" initialAmount: ").append(toIndentedString(initialAmount)).append("\n");
sb.append(" discountAmount: ").append(toIndentedString(discountAmount)).append("\n");
sb.append(" items: ").append(toIndentedString(items)).append("\n");
sb.append(" metadata: ").append(toIndentedString(metadata)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
public static HashSet<String> openapiFields;
public static HashSet<String> openapiRequiredFields;
static {
// a set of all properties/fields (JSON key names)
openapiFields = new HashSet<String>();
openapiFields.add("id");
openapiFields.add("source_id");
openapiFields.add("status");
openapiFields.add("amount");
openapiFields.add("initial_amount");
openapiFields.add("discount_amount");
openapiFields.add("items");
openapiFields.add("metadata");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!Order.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'Order' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<Order> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(Order.class));
return (TypeAdapter<T>) new TypeAdapter<Order>() {
@Override
public void write(JsonWriter out, Order value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public Order read(JsonReader in) throws IOException {
JsonElement jsonElement = elementAdapter.read(in);
return thisAdapter.fromJsonTree(jsonElement);
}
}.nullSafe();
}
}
/**
* Create an instance of Order given an JSON string
*
* @param jsonString JSON string
* @return An instance of Order
* @throws IOException if the JSON string is invalid with respect to Order
*/
public static Order fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Order.class);
}
/**
* Convert an instance of Order to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}