-
-
Notifications
You must be signed in to change notification settings - Fork 121
/
tl_payments_send_payment_form_gen.go
417 lines (383 loc) · 10.8 KB
/
tl_payments_send_payment_form_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
// 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{}
)
// PaymentsSendPaymentFormRequest represents TL type `payments.sendPaymentForm#2d03522f`.
// Send compiled payment form
//
// See https://core.telegram.org/method/payments.sendPaymentForm for reference.
type PaymentsSendPaymentFormRequest struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// Form ID
FormID int64
// Invoice field of PaymentsSendPaymentFormRequest.
Invoice InputInvoiceClass
// ID of saved and validated order info¹
//
// Links:
// 1) https://core.telegram.org/constructor/payments.validatedRequestedInfo
//
// Use SetRequestedInfoID and GetRequestedInfoID helpers.
RequestedInfoID string
// Chosen shipping option ID
//
// Use SetShippingOptionID and GetShippingOptionID helpers.
ShippingOptionID string
// Payment credentials
Credentials InputPaymentCredentialsClass
// Tip, 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 SetTipAmount and GetTipAmount helpers.
TipAmount int64
}
// PaymentsSendPaymentFormRequestTypeID is TL type id of PaymentsSendPaymentFormRequest.
const PaymentsSendPaymentFormRequestTypeID = 0x2d03522f
// Ensuring interfaces in compile-time for PaymentsSendPaymentFormRequest.
var (
_ bin.Encoder = &PaymentsSendPaymentFormRequest{}
_ bin.Decoder = &PaymentsSendPaymentFormRequest{}
_ bin.BareEncoder = &PaymentsSendPaymentFormRequest{}
_ bin.BareDecoder = &PaymentsSendPaymentFormRequest{}
)
func (s *PaymentsSendPaymentFormRequest) Zero() bool {
if s == nil {
return true
}
if !(s.Flags.Zero()) {
return false
}
if !(s.FormID == 0) {
return false
}
if !(s.Invoice == nil) {
return false
}
if !(s.RequestedInfoID == "") {
return false
}
if !(s.ShippingOptionID == "") {
return false
}
if !(s.Credentials == nil) {
return false
}
if !(s.TipAmount == 0) {
return false
}
return true
}
// String implements fmt.Stringer.
func (s *PaymentsSendPaymentFormRequest) String() string {
if s == nil {
return "PaymentsSendPaymentFormRequest(nil)"
}
type Alias PaymentsSendPaymentFormRequest
return fmt.Sprintf("PaymentsSendPaymentFormRequest%+v", Alias(*s))
}
// FillFrom fills PaymentsSendPaymentFormRequest from given interface.
func (s *PaymentsSendPaymentFormRequest) FillFrom(from interface {
GetFormID() (value int64)
GetInvoice() (value InputInvoiceClass)
GetRequestedInfoID() (value string, ok bool)
GetShippingOptionID() (value string, ok bool)
GetCredentials() (value InputPaymentCredentialsClass)
GetTipAmount() (value int64, ok bool)
}) {
s.FormID = from.GetFormID()
s.Invoice = from.GetInvoice()
if val, ok := from.GetRequestedInfoID(); ok {
s.RequestedInfoID = val
}
if val, ok := from.GetShippingOptionID(); ok {
s.ShippingOptionID = val
}
s.Credentials = from.GetCredentials()
if val, ok := from.GetTipAmount(); ok {
s.TipAmount = val
}
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*PaymentsSendPaymentFormRequest) TypeID() uint32 {
return PaymentsSendPaymentFormRequestTypeID
}
// TypeName returns name of type in TL schema.
func (*PaymentsSendPaymentFormRequest) TypeName() string {
return "payments.sendPaymentForm"
}
// TypeInfo returns info about TL type.
func (s *PaymentsSendPaymentFormRequest) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "payments.sendPaymentForm",
ID: PaymentsSendPaymentFormRequestTypeID,
}
if s == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "FormID",
SchemaName: "form_id",
},
{
Name: "Invoice",
SchemaName: "invoice",
},
{
Name: "RequestedInfoID",
SchemaName: "requested_info_id",
Null: !s.Flags.Has(0),
},
{
Name: "ShippingOptionID",
SchemaName: "shipping_option_id",
Null: !s.Flags.Has(1),
},
{
Name: "Credentials",
SchemaName: "credentials",
},
{
Name: "TipAmount",
SchemaName: "tip_amount",
Null: !s.Flags.Has(2),
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (s *PaymentsSendPaymentFormRequest) SetFlags() {
if !(s.RequestedInfoID == "") {
s.Flags.Set(0)
}
if !(s.ShippingOptionID == "") {
s.Flags.Set(1)
}
if !(s.TipAmount == 0) {
s.Flags.Set(2)
}
}
// Encode implements bin.Encoder.
func (s *PaymentsSendPaymentFormRequest) Encode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode payments.sendPaymentForm#2d03522f as nil")
}
b.PutID(PaymentsSendPaymentFormRequestTypeID)
return s.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (s *PaymentsSendPaymentFormRequest) EncodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode payments.sendPaymentForm#2d03522f as nil")
}
s.SetFlags()
if err := s.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.sendPaymentForm#2d03522f: field flags: %w", err)
}
b.PutLong(s.FormID)
if s.Invoice == nil {
return fmt.Errorf("unable to encode payments.sendPaymentForm#2d03522f: field invoice is nil")
}
if err := s.Invoice.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.sendPaymentForm#2d03522f: field invoice: %w", err)
}
if s.Flags.Has(0) {
b.PutString(s.RequestedInfoID)
}
if s.Flags.Has(1) {
b.PutString(s.ShippingOptionID)
}
if s.Credentials == nil {
return fmt.Errorf("unable to encode payments.sendPaymentForm#2d03522f: field credentials is nil")
}
if err := s.Credentials.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.sendPaymentForm#2d03522f: field credentials: %w", err)
}
if s.Flags.Has(2) {
b.PutLong(s.TipAmount)
}
return nil
}
// Decode implements bin.Decoder.
func (s *PaymentsSendPaymentFormRequest) Decode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode payments.sendPaymentForm#2d03522f to nil")
}
if err := b.ConsumeID(PaymentsSendPaymentFormRequestTypeID); err != nil {
return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: %w", err)
}
return s.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (s *PaymentsSendPaymentFormRequest) DecodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode payments.sendPaymentForm#2d03522f to nil")
}
{
if err := s.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field flags: %w", err)
}
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field form_id: %w", err)
}
s.FormID = value
}
{
value, err := DecodeInputInvoice(b)
if err != nil {
return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field invoice: %w", err)
}
s.Invoice = value
}
if s.Flags.Has(0) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field requested_info_id: %w", err)
}
s.RequestedInfoID = value
}
if s.Flags.Has(1) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field shipping_option_id: %w", err)
}
s.ShippingOptionID = value
}
{
value, err := DecodeInputPaymentCredentials(b)
if err != nil {
return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field credentials: %w", err)
}
s.Credentials = value
}
if s.Flags.Has(2) {
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field tip_amount: %w", err)
}
s.TipAmount = value
}
return nil
}
// GetFormID returns value of FormID field.
func (s *PaymentsSendPaymentFormRequest) GetFormID() (value int64) {
if s == nil {
return
}
return s.FormID
}
// GetInvoice returns value of Invoice field.
func (s *PaymentsSendPaymentFormRequest) GetInvoice() (value InputInvoiceClass) {
if s == nil {
return
}
return s.Invoice
}
// SetRequestedInfoID sets value of RequestedInfoID conditional field.
func (s *PaymentsSendPaymentFormRequest) SetRequestedInfoID(value string) {
s.Flags.Set(0)
s.RequestedInfoID = value
}
// GetRequestedInfoID returns value of RequestedInfoID conditional field and
// boolean which is true if field was set.
func (s *PaymentsSendPaymentFormRequest) GetRequestedInfoID() (value string, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(0) {
return value, false
}
return s.RequestedInfoID, true
}
// SetShippingOptionID sets value of ShippingOptionID conditional field.
func (s *PaymentsSendPaymentFormRequest) SetShippingOptionID(value string) {
s.Flags.Set(1)
s.ShippingOptionID = value
}
// GetShippingOptionID returns value of ShippingOptionID conditional field and
// boolean which is true if field was set.
func (s *PaymentsSendPaymentFormRequest) GetShippingOptionID() (value string, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(1) {
return value, false
}
return s.ShippingOptionID, true
}
// GetCredentials returns value of Credentials field.
func (s *PaymentsSendPaymentFormRequest) GetCredentials() (value InputPaymentCredentialsClass) {
if s == nil {
return
}
return s.Credentials
}
// SetTipAmount sets value of TipAmount conditional field.
func (s *PaymentsSendPaymentFormRequest) SetTipAmount(value int64) {
s.Flags.Set(2)
s.TipAmount = value
}
// GetTipAmount returns value of TipAmount conditional field and
// boolean which is true if field was set.
func (s *PaymentsSendPaymentFormRequest) GetTipAmount() (value int64, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(2) {
return value, false
}
return s.TipAmount, true
}
// PaymentsSendPaymentForm invokes method payments.sendPaymentForm#2d03522f returning error if any.
// Send compiled payment form
//
// Possible errors:
//
// 400 MESSAGE_ID_INVALID: The provided message id is invalid.
//
// See https://core.telegram.org/method/payments.sendPaymentForm for reference.
func (c *Client) PaymentsSendPaymentForm(ctx context.Context, request *PaymentsSendPaymentFormRequest) (PaymentsPaymentResultClass, error) {
var result PaymentsPaymentResultBox
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
return nil, err
}
return result.PaymentResult, nil
}