-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
tl_invoice_gen.go
586 lines (541 loc) · 14.2 KB
/
tl_invoice_gen.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
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// Invoice represents TL type `invoice#cd886e0`.
// Invoice
//
// See https://core.telegram.org/constructor/invoice for reference.
type Invoice struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// Test invoice
Test bool
// Set this flag if you require the user's full name to complete the order
NameRequested bool
// Set this flag if you require the user's phone number to complete the order
PhoneRequested bool
// Set this flag if you require the user's email address to complete the order
EmailRequested bool
// Set this flag if you require the user's shipping address to complete the order
ShippingAddressRequested bool
// Set this flag if the final price depends on the shipping method
Flexible bool
// Set this flag if user's phone number should be sent to provider
PhoneToProvider bool
// Set this flag if user's email address should be sent to provider
EmailToProvider bool
// Three-letter ISO 4217 currency¹ code
//
// Links:
// 1) https://core.telegram.org/bots/payments#supported-currencies
Currency string
// Price breakdown, a list of components (e.g. product price, tax, discount, delivery
// cost, delivery tax, bonus, etc.)
Prices []LabeledPrice
// The maximum accepted amount for tips in the smallest units of the currency (integer,
// not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp
// parameter in currencies.json¹, it shows the number of digits past the decimal point
// for each currency (2 for the majority of currencies).
//
// Links:
// 1) https://core.telegram.org/bots/payments/currencies.json
//
// Use SetMaxTipAmount and GetMaxTipAmount helpers.
MaxTipAmount int64
// A vector of suggested amounts of tips in the smallest units of the currency (integer,
// not float/double). At most 4 suggested tip amounts can be specified. The suggested tip
// amounts must be positive, passed in a strictly increased order and must not exceed
// max_tip_amount.
//
// Use SetSuggestedTipAmounts and GetSuggestedTipAmounts helpers.
SuggestedTipAmounts []int64
}
// InvoiceTypeID is TL type id of Invoice.
const InvoiceTypeID = 0xcd886e0
// Ensuring interfaces in compile-time for Invoice.
var (
_ bin.Encoder = &Invoice{}
_ bin.Decoder = &Invoice{}
_ bin.BareEncoder = &Invoice{}
_ bin.BareDecoder = &Invoice{}
)
func (i *Invoice) Zero() bool {
if i == nil {
return true
}
if !(i.Flags.Zero()) {
return false
}
if !(i.Test == false) {
return false
}
if !(i.NameRequested == false) {
return false
}
if !(i.PhoneRequested == false) {
return false
}
if !(i.EmailRequested == false) {
return false
}
if !(i.ShippingAddressRequested == false) {
return false
}
if !(i.Flexible == false) {
return false
}
if !(i.PhoneToProvider == false) {
return false
}
if !(i.EmailToProvider == false) {
return false
}
if !(i.Currency == "") {
return false
}
if !(i.Prices == nil) {
return false
}
if !(i.MaxTipAmount == 0) {
return false
}
if !(i.SuggestedTipAmounts == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (i *Invoice) String() string {
if i == nil {
return "Invoice(nil)"
}
type Alias Invoice
return fmt.Sprintf("Invoice%+v", Alias(*i))
}
// FillFrom fills Invoice from given interface.
func (i *Invoice) FillFrom(from interface {
GetTest() (value bool)
GetNameRequested() (value bool)
GetPhoneRequested() (value bool)
GetEmailRequested() (value bool)
GetShippingAddressRequested() (value bool)
GetFlexible() (value bool)
GetPhoneToProvider() (value bool)
GetEmailToProvider() (value bool)
GetCurrency() (value string)
GetPrices() (value []LabeledPrice)
GetMaxTipAmount() (value int64, ok bool)
GetSuggestedTipAmounts() (value []int64, ok bool)
}) {
i.Test = from.GetTest()
i.NameRequested = from.GetNameRequested()
i.PhoneRequested = from.GetPhoneRequested()
i.EmailRequested = from.GetEmailRequested()
i.ShippingAddressRequested = from.GetShippingAddressRequested()
i.Flexible = from.GetFlexible()
i.PhoneToProvider = from.GetPhoneToProvider()
i.EmailToProvider = from.GetEmailToProvider()
i.Currency = from.GetCurrency()
i.Prices = from.GetPrices()
if val, ok := from.GetMaxTipAmount(); ok {
i.MaxTipAmount = val
}
if val, ok := from.GetSuggestedTipAmounts(); ok {
i.SuggestedTipAmounts = val
}
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*Invoice) TypeID() uint32 {
return InvoiceTypeID
}
// TypeName returns name of type in TL schema.
func (*Invoice) TypeName() string {
return "invoice"
}
// TypeInfo returns info about TL type.
func (i *Invoice) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "invoice",
ID: InvoiceTypeID,
}
if i == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Test",
SchemaName: "test",
Null: !i.Flags.Has(0),
},
{
Name: "NameRequested",
SchemaName: "name_requested",
Null: !i.Flags.Has(1),
},
{
Name: "PhoneRequested",
SchemaName: "phone_requested",
Null: !i.Flags.Has(2),
},
{
Name: "EmailRequested",
SchemaName: "email_requested",
Null: !i.Flags.Has(3),
},
{
Name: "ShippingAddressRequested",
SchemaName: "shipping_address_requested",
Null: !i.Flags.Has(4),
},
{
Name: "Flexible",
SchemaName: "flexible",
Null: !i.Flags.Has(5),
},
{
Name: "PhoneToProvider",
SchemaName: "phone_to_provider",
Null: !i.Flags.Has(6),
},
{
Name: "EmailToProvider",
SchemaName: "email_to_provider",
Null: !i.Flags.Has(7),
},
{
Name: "Currency",
SchemaName: "currency",
},
{
Name: "Prices",
SchemaName: "prices",
},
{
Name: "MaxTipAmount",
SchemaName: "max_tip_amount",
Null: !i.Flags.Has(8),
},
{
Name: "SuggestedTipAmounts",
SchemaName: "suggested_tip_amounts",
Null: !i.Flags.Has(8),
},
}
return typ
}
// Encode implements bin.Encoder.
func (i *Invoice) Encode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode invoice#cd886e0 as nil")
}
b.PutID(InvoiceTypeID)
return i.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (i *Invoice) EncodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode invoice#cd886e0 as nil")
}
if !(i.Test == false) {
i.Flags.Set(0)
}
if !(i.NameRequested == false) {
i.Flags.Set(1)
}
if !(i.PhoneRequested == false) {
i.Flags.Set(2)
}
if !(i.EmailRequested == false) {
i.Flags.Set(3)
}
if !(i.ShippingAddressRequested == false) {
i.Flags.Set(4)
}
if !(i.Flexible == false) {
i.Flags.Set(5)
}
if !(i.PhoneToProvider == false) {
i.Flags.Set(6)
}
if !(i.EmailToProvider == false) {
i.Flags.Set(7)
}
if !(i.MaxTipAmount == 0) {
i.Flags.Set(8)
}
if !(i.SuggestedTipAmounts == nil) {
i.Flags.Set(8)
}
if err := i.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode invoice#cd886e0: field flags: %w", err)
}
b.PutString(i.Currency)
b.PutVectorHeader(len(i.Prices))
for idx, v := range i.Prices {
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode invoice#cd886e0: field prices element with index %d: %w", idx, err)
}
}
if i.Flags.Has(8) {
b.PutLong(i.MaxTipAmount)
}
if i.Flags.Has(8) {
b.PutVectorHeader(len(i.SuggestedTipAmounts))
for _, v := range i.SuggestedTipAmounts {
b.PutLong(v)
}
}
return nil
}
// Decode implements bin.Decoder.
func (i *Invoice) Decode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode invoice#cd886e0 to nil")
}
if err := b.ConsumeID(InvoiceTypeID); err != nil {
return fmt.Errorf("unable to decode invoice#cd886e0: %w", err)
}
return i.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (i *Invoice) DecodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode invoice#cd886e0 to nil")
}
{
if err := i.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode invoice#cd886e0: field flags: %w", err)
}
}
i.Test = i.Flags.Has(0)
i.NameRequested = i.Flags.Has(1)
i.PhoneRequested = i.Flags.Has(2)
i.EmailRequested = i.Flags.Has(3)
i.ShippingAddressRequested = i.Flags.Has(4)
i.Flexible = i.Flags.Has(5)
i.PhoneToProvider = i.Flags.Has(6)
i.EmailToProvider = i.Flags.Has(7)
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode invoice#cd886e0: field currency: %w", err)
}
i.Currency = value
}
{
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode invoice#cd886e0: field prices: %w", err)
}
if headerLen > 0 {
i.Prices = make([]LabeledPrice, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
var value LabeledPrice
if err := value.Decode(b); err != nil {
return fmt.Errorf("unable to decode invoice#cd886e0: field prices: %w", err)
}
i.Prices = append(i.Prices, value)
}
}
if i.Flags.Has(8) {
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode invoice#cd886e0: field max_tip_amount: %w", err)
}
i.MaxTipAmount = value
}
if i.Flags.Has(8) {
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode invoice#cd886e0: field suggested_tip_amounts: %w", err)
}
if headerLen > 0 {
i.SuggestedTipAmounts = make([]int64, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode invoice#cd886e0: field suggested_tip_amounts: %w", err)
}
i.SuggestedTipAmounts = append(i.SuggestedTipAmounts, value)
}
}
return nil
}
// SetTest sets value of Test conditional field.
func (i *Invoice) SetTest(value bool) {
if value {
i.Flags.Set(0)
i.Test = true
} else {
i.Flags.Unset(0)
i.Test = false
}
}
// GetTest returns value of Test conditional field.
func (i *Invoice) GetTest() (value bool) {
return i.Flags.Has(0)
}
// SetNameRequested sets value of NameRequested conditional field.
func (i *Invoice) SetNameRequested(value bool) {
if value {
i.Flags.Set(1)
i.NameRequested = true
} else {
i.Flags.Unset(1)
i.NameRequested = false
}
}
// GetNameRequested returns value of NameRequested conditional field.
func (i *Invoice) GetNameRequested() (value bool) {
return i.Flags.Has(1)
}
// SetPhoneRequested sets value of PhoneRequested conditional field.
func (i *Invoice) SetPhoneRequested(value bool) {
if value {
i.Flags.Set(2)
i.PhoneRequested = true
} else {
i.Flags.Unset(2)
i.PhoneRequested = false
}
}
// GetPhoneRequested returns value of PhoneRequested conditional field.
func (i *Invoice) GetPhoneRequested() (value bool) {
return i.Flags.Has(2)
}
// SetEmailRequested sets value of EmailRequested conditional field.
func (i *Invoice) SetEmailRequested(value bool) {
if value {
i.Flags.Set(3)
i.EmailRequested = true
} else {
i.Flags.Unset(3)
i.EmailRequested = false
}
}
// GetEmailRequested returns value of EmailRequested conditional field.
func (i *Invoice) GetEmailRequested() (value bool) {
return i.Flags.Has(3)
}
// SetShippingAddressRequested sets value of ShippingAddressRequested conditional field.
func (i *Invoice) SetShippingAddressRequested(value bool) {
if value {
i.Flags.Set(4)
i.ShippingAddressRequested = true
} else {
i.Flags.Unset(4)
i.ShippingAddressRequested = false
}
}
// GetShippingAddressRequested returns value of ShippingAddressRequested conditional field.
func (i *Invoice) GetShippingAddressRequested() (value bool) {
return i.Flags.Has(4)
}
// SetFlexible sets value of Flexible conditional field.
func (i *Invoice) SetFlexible(value bool) {
if value {
i.Flags.Set(5)
i.Flexible = true
} else {
i.Flags.Unset(5)
i.Flexible = false
}
}
// GetFlexible returns value of Flexible conditional field.
func (i *Invoice) GetFlexible() (value bool) {
return i.Flags.Has(5)
}
// SetPhoneToProvider sets value of PhoneToProvider conditional field.
func (i *Invoice) SetPhoneToProvider(value bool) {
if value {
i.Flags.Set(6)
i.PhoneToProvider = true
} else {
i.Flags.Unset(6)
i.PhoneToProvider = false
}
}
// GetPhoneToProvider returns value of PhoneToProvider conditional field.
func (i *Invoice) GetPhoneToProvider() (value bool) {
return i.Flags.Has(6)
}
// SetEmailToProvider sets value of EmailToProvider conditional field.
func (i *Invoice) SetEmailToProvider(value bool) {
if value {
i.Flags.Set(7)
i.EmailToProvider = true
} else {
i.Flags.Unset(7)
i.EmailToProvider = false
}
}
// GetEmailToProvider returns value of EmailToProvider conditional field.
func (i *Invoice) GetEmailToProvider() (value bool) {
return i.Flags.Has(7)
}
// GetCurrency returns value of Currency field.
func (i *Invoice) GetCurrency() (value string) {
return i.Currency
}
// GetPrices returns value of Prices field.
func (i *Invoice) GetPrices() (value []LabeledPrice) {
return i.Prices
}
// SetMaxTipAmount sets value of MaxTipAmount conditional field.
func (i *Invoice) SetMaxTipAmount(value int64) {
i.Flags.Set(8)
i.MaxTipAmount = value
}
// GetMaxTipAmount returns value of MaxTipAmount conditional field and
// boolean which is true if field was set.
func (i *Invoice) GetMaxTipAmount() (value int64, ok bool) {
if !i.Flags.Has(8) {
return value, false
}
return i.MaxTipAmount, true
}
// SetSuggestedTipAmounts sets value of SuggestedTipAmounts conditional field.
func (i *Invoice) SetSuggestedTipAmounts(value []int64) {
i.Flags.Set(8)
i.SuggestedTipAmounts = value
}
// GetSuggestedTipAmounts returns value of SuggestedTipAmounts conditional field and
// boolean which is true if field was set.
func (i *Invoice) GetSuggestedTipAmounts() (value []int64, ok bool) {
if !i.Flags.Has(8) {
return value, false
}
return i.SuggestedTipAmounts, true
}