Debian Codegraph @

shopping/merchant/accounts/apiv1/accounts_client.go

raw
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package accounts
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 accountspb "cloud.google.com/go/shopping/merchant/accounts/apiv1/accountspb"
30 gax "github.com/googleapis/gax-go/v2"
31 "google.golang.org/api/iterator"
32 "google.golang.org/api/option"
33 "google.golang.org/api/option/internaloption"
34 gtransport "google.golang.org/api/transport/grpc"
35 httptransport "google.golang.org/api/transport/http"
36 "google.golang.org/grpc"
37 "google.golang.org/grpc/codes"
38 "google.golang.org/protobuf/encoding/protojson"
39 "google.golang.org/protobuf/proto"
40 )
41
42 var newClientHook clientHook
43
44 // CallOptions contains the retry settings for each method of Client.
45 type CallOptions struct {
46 GetAccount []gax.CallOption
47 CreateAndConfigureAccount []gax.CallOption
48 DeleteAccount []gax.CallOption
49 UpdateAccount []gax.CallOption
50 ListAccounts []gax.CallOption
51 ListSubAccounts []gax.CallOption
52 }
53
54 func defaultGRPCClientOptions() []option.ClientOption {
55 return []option.ClientOption{
56 internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"),
57 internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"),
58 internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"),
59 internaloption.WithDefaultUniverseDomain("googleapis.com"),
60 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
61 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
62 internaloption.EnableJwtWithScope(),
63 internaloption.EnableNewAuthLibrary(),
64 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
65 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
66 }
67 }
68
69 func defaultCallOptions() *CallOptions {
70 return &CallOptions{
71 GetAccount: []gax.CallOption{
72 gax.WithTimeout(60000 * time.Millisecond),
73 gax.WithRetry(func() gax.Retryer {
74 return gax.OnCodes([]codes.Code{
75 codes.Unavailable,
76 }, gax.Backoff{
77 Initial: 1000 * time.Millisecond,
78 Max: 10000 * time.Millisecond,
79 Multiplier: 1.30,
80 })
81 }),
82 },
83 CreateAndConfigureAccount: []gax.CallOption{
84 gax.WithTimeout(60000 * time.Millisecond),
85 gax.WithRetry(func() gax.Retryer {
86 return gax.OnCodes([]codes.Code{
87 codes.Unavailable,
88 }, gax.Backoff{
89 Initial: 1000 * time.Millisecond,
90 Max: 10000 * time.Millisecond,
91 Multiplier: 1.30,
92 })
93 }),
94 },
95 DeleteAccount: []gax.CallOption{
96 gax.WithTimeout(60000 * time.Millisecond),
97 gax.WithRetry(func() gax.Retryer {
98 return gax.OnCodes([]codes.Code{
99 codes.Unavailable,
100 }, gax.Backoff{
101 Initial: 1000 * time.Millisecond,
102 Max: 10000 * time.Millisecond,
103 Multiplier: 1.30,
104 })
105 }),
106 },
107 UpdateAccount: []gax.CallOption{
108 gax.WithTimeout(60000 * time.Millisecond),
109 gax.WithRetry(func() gax.Retryer {
110 return gax.OnCodes([]codes.Code{
111 codes.Unavailable,
112 }, gax.Backoff{
113 Initial: 1000 * time.Millisecond,
114 Max: 10000 * time.Millisecond,
115 Multiplier: 1.30,
116 })
117 }),
118 },
119 ListAccounts: []gax.CallOption{
120 gax.WithTimeout(60000 * time.Millisecond),
121 gax.WithRetry(func() gax.Retryer {
122 return gax.OnCodes([]codes.Code{
123 codes.Unavailable,
124 }, gax.Backoff{
125 Initial: 1000 * time.Millisecond,
126 Max: 10000 * time.Millisecond,
127 Multiplier: 1.30,
128 })
129 }),
130 },
131 ListSubAccounts: []gax.CallOption{
132 gax.WithTimeout(60000 * time.Millisecond),
133 gax.WithRetry(func() gax.Retryer {
134 return gax.OnCodes([]codes.Code{
135 codes.Unavailable,
136 }, gax.Backoff{
137 Initial: 1000 * time.Millisecond,
138 Max: 10000 * time.Millisecond,
139 Multiplier: 1.30,
140 })
141 }),
142 },
143 }
144 }
145
146 func defaultRESTCallOptions() *CallOptions {
147 return &CallOptions{
148 GetAccount: []gax.CallOption{
149 gax.WithTimeout(60000 * time.Millisecond),
150 gax.WithRetry(func() gax.Retryer {
151 return gax.OnHTTPCodes(gax.Backoff{
152 Initial: 1000 * time.Millisecond,
153 Max: 10000 * time.Millisecond,
154 Multiplier: 1.30,
155 },
156 http.StatusServiceUnavailable)
157 }),
158 },
159 CreateAndConfigureAccount: []gax.CallOption{
160 gax.WithTimeout(60000 * time.Millisecond),
161 gax.WithRetry(func() gax.Retryer {
162 return gax.OnHTTPCodes(gax.Backoff{
163 Initial: 1000 * time.Millisecond,
164 Max: 10000 * time.Millisecond,
165 Multiplier: 1.30,
166 },
167 http.StatusServiceUnavailable)
168 }),
169 },
170 DeleteAccount: []gax.CallOption{
171 gax.WithTimeout(60000 * time.Millisecond),
172 gax.WithRetry(func() gax.Retryer {
173 return gax.OnHTTPCodes(gax.Backoff{
174 Initial: 1000 * time.Millisecond,
175 Max: 10000 * time.Millisecond,
176 Multiplier: 1.30,
177 },
178 http.StatusServiceUnavailable)
179 }),
180 },
181 UpdateAccount: []gax.CallOption{
182 gax.WithTimeout(60000 * time.Millisecond),
183 gax.WithRetry(func() gax.Retryer {
184 return gax.OnHTTPCodes(gax.Backoff{
185 Initial: 1000 * time.Millisecond,
186 Max: 10000 * time.Millisecond,
187 Multiplier: 1.30,
188 },
189 http.StatusServiceUnavailable)
190 }),
191 },
192 ListAccounts: []gax.CallOption{
193 gax.WithTimeout(60000 * time.Millisecond),
194 gax.WithRetry(func() gax.Retryer {
195 return gax.OnHTTPCodes(gax.Backoff{
196 Initial: 1000 * time.Millisecond,
197 Max: 10000 * time.Millisecond,
198 Multiplier: 1.30,
199 },
200 http.StatusServiceUnavailable)
201 }),
202 },
203 ListSubAccounts: []gax.CallOption{
204 gax.WithTimeout(60000 * time.Millisecond),
205 gax.WithRetry(func() gax.Retryer {
206 return gax.OnHTTPCodes(gax.Backoff{
207 Initial: 1000 * time.Millisecond,
208 Max: 10000 * time.Millisecond,
209 Multiplier: 1.30,
210 },
211 http.StatusServiceUnavailable)
212 }),
213 },
214 }
215 }
216
217 // internalClient is an interface that defines the methods available from Merchant API.
218 type internalClient interface {
219 Close() error
220 setGoogleClientInfo(...string)
221 Connection() *grpc.ClientConn
222 GetAccount(context.Context, *accountspb.GetAccountRequest, ...gax.CallOption) (*accountspb.Account, error)
223 CreateAndConfigureAccount(context.Context, *accountspb.CreateAndConfigureAccountRequest, ...gax.CallOption) (*accountspb.Account, error)
224 DeleteAccount(context.Context, *accountspb.DeleteAccountRequest, ...gax.CallOption) error
225 UpdateAccount(context.Context, *accountspb.UpdateAccountRequest, ...gax.CallOption) (*accountspb.Account, error)
226 ListAccounts(context.Context, *accountspb.ListAccountsRequest, ...gax.CallOption) *AccountIterator
227 ListSubAccounts(context.Context, *accountspb.ListSubAccountsRequest, ...gax.CallOption) *AccountIterator
228 }
229
230 // Client is a client for interacting with Merchant API.
231 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
232 //
233 // Service to support Accounts API.
234 type Client struct {
235 // The internal transport-dependent client.
236 internalClient internalClient
237
238 // The call options for this service.
239 CallOptions *CallOptions
240 }
241
242 // Wrapper methods routed to the internal client.
243
244 // Close closes the connection to the API service. The user should invoke this when
245 // the client is no longer required.
246 func (c *Client) Close() error {
247 return c.internalClient.Close()
248 }
249
250 // setGoogleClientInfo sets the name and version of the application in
251 // the `x-goog-api-client` header passed on each request. Intended for
252 // use by Google-written clients.
253 func (c *Client) setGoogleClientInfo(keyval ...string) {
254 c.internalClient.setGoogleClientInfo(keyval...)
255 }
256
257 // Connection returns a connection to the API service.
258 //
259 // Deprecated: Connections are now pooled so this method does not always
260 // return the same resource.
261 func (c *Client) Connection() *grpc.ClientConn {
262 return c.internalClient.Connection()
263 }
264
265 // GetAccount retrieves an account from your Merchant Center account.
266 // After inserting, updating, or deleting an account, it may take several
267 // minutes before changes take effect.
268 func (c *Client) GetAccount(ctx context.Context, req *accountspb.GetAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) {
269 return c.internalClient.GetAccount(ctx, req, opts...)
270 }
271
272 // CreateAndConfigureAccount creates a Merchant Center account with additional configuration. Adds the
273 // user that makes the request as an admin for the new account.
274 func (c *Client) CreateAndConfigureAccount(ctx context.Context, req *accountspb.CreateAndConfigureAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) {
275 return c.internalClient.CreateAndConfigureAccount(ctx, req, opts...)
276 }
277
278 // DeleteAccount deletes the specified account regardless of its type: standalone, advanced
279 // account or sub-account. Deleting an advanced account leads to the deletion
280 // of all of its sub-accounts. Executing this method requires admin access.
281 // The deletion succeeds only if the account does not provide services
282 // to any other account and has no processed offers. You can use the force
283 // parameter to override this.
284 func (c *Client) DeleteAccount(ctx context.Context, req *accountspb.DeleteAccountRequest, opts ...gax.CallOption) error {
285 return c.internalClient.DeleteAccount(ctx, req, opts...)
286 }
287
288 // UpdateAccount updates an account regardless of its type: standalone, advanced account or
289 // sub-account. Executing this method requires admin access.
290 func (c *Client) UpdateAccount(ctx context.Context, req *accountspb.UpdateAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) {
291 return c.internalClient.UpdateAccount(ctx, req, opts...)
292 }
293
294 // ListAccounts note: For the accounts.list method, quota and limits usage are charged
295 // for each user, and not for the Merchant Center ID or the advanced account
296 // ID. To list several sub-accounts, you should use the
297 // accounts.listSubaccounts method, which is more suitable for advanced
298 // accounts use case.
299 func (c *Client) ListAccounts(ctx context.Context, req *accountspb.ListAccountsRequest, opts ...gax.CallOption) *AccountIterator {
300 return c.internalClient.ListAccounts(ctx, req, opts...)
301 }
302
303 // ListSubAccounts list all sub-accounts for a given advanced account. This is a
304 // convenience wrapper for the more powerful accounts.list method. This
305 // method will produce the same results as calling ListsAccounts with the
306 // following filter:
307 // relationship(providerId={parent} AND service(type="ACCOUNT_AGGREGATION"))
308 func (c *Client) ListSubAccounts(ctx context.Context, req *accountspb.ListSubAccountsRequest, opts ...gax.CallOption) *AccountIterator {
309 return c.internalClient.ListSubAccounts(ctx, req, opts...)
310 }
311
312 // gRPCClient is a client for interacting with Merchant API over gRPC transport.
313 //
314 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
315 type gRPCClient struct {
316 // Connection pool of gRPC connections to the service.
317 connPool gtransport.ConnPool
318
319 // Points back to the CallOptions field of the containing Client
320 CallOptions **CallOptions
321
322 // The gRPC API client.
323 client accountspb.AccountsServiceClient
324
325 // The x-goog-* metadata to be sent with each request.
326 xGoogHeaders []string
327
328 logger *slog.Logger
329 }
330
331 // NewClient creates a new accounts service client based on gRPC.
332 // The returned client must be Closed when it is done being used to clean up its underlying connections.
333 //
334 // Service to support Accounts API.
335 func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
336 clientOpts := defaultGRPCClientOptions()
337 if newClientHook != nil {
338 hookOpts, err := newClientHook(ctx, clientHookParams{})
339 if err != nil {
340 return nil, err
341 }
342 clientOpts = append(clientOpts, hookOpts...)
343 }
344
345 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
346 if err != nil {
347 return nil, err
348 }
349 client := Client{CallOptions: defaultCallOptions()}
350
351 c := &gRPCClient{
352 connPool: connPool,
353 client: accountspb.NewAccountsServiceClient(connPool),
354 CallOptions: &client.CallOptions,
355 logger: internaloption.GetLogger(opts),
356 }
357 c.setGoogleClientInfo()
358
359 client.internalClient = c
360
361 return &client, nil
362 }
363
364 // Connection returns a connection to the API service.
365 //
366 // Deprecated: Connections are now pooled so this method does not always
367 // return the same resource.
368 func (c *gRPCClient) Connection() *grpc.ClientConn {
369 return c.connPool.Conn()
370 }
371
372 // setGoogleClientInfo sets the name and version of the application in
373 // the `x-goog-api-client` header passed on each request. Intended for
374 // use by Google-written clients.
375 func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
376 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
377 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
378 c.xGoogHeaders = []string{
379 "x-goog-api-client", gax.XGoogHeader(kv...),
380 }
381 }
382
383 // Close closes the connection to the API service. The user should invoke this when
384 // the client is no longer required.
385 func (c *gRPCClient) Close() error {
386 return c.connPool.Close()
387 }
388
389 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
390 type restClient struct {
391 // The http endpoint to connect to.
392 endpoint string
393
394 // The http client.
395 httpClient *http.Client
396
397 // The x-goog-* headers to be sent with each request.
398 xGoogHeaders []string
399
400 // Points back to the CallOptions field of the containing Client
401 CallOptions **CallOptions
402
403 logger *slog.Logger
404 }
405
406 // NewRESTClient creates a new accounts service rest client.
407 //
408 // Service to support Accounts API.
409 func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
410 clientOpts := append(defaultRESTClientOptions(), opts...)
411 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
412 if err != nil {
413 return nil, err
414 }
415
416 callOpts := defaultRESTCallOptions()
417 c := &restClient{
418 endpoint: endpoint,
419 httpClient: httpClient,
420 CallOptions: &callOpts,
421 logger: internaloption.GetLogger(opts),
422 }
423 c.setGoogleClientInfo()
424
425 return &Client{internalClient: c, CallOptions: callOpts}, nil
426 }
427
428 func defaultRESTClientOptions() []option.ClientOption {
429 return []option.ClientOption{
430 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
431 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
432 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
433 internaloption.WithDefaultUniverseDomain("googleapis.com"),
434 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
435 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
436 internaloption.EnableNewAuthLibrary(),
437 }
438 }
439
440 // setGoogleClientInfo sets the name and version of the application in
441 // the `x-goog-api-client` header passed on each request. Intended for
442 // use by Google-written clients.
443 func (c *restClient) setGoogleClientInfo(keyval ...string) {
444 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
445 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
446 c.xGoogHeaders = []string{
447 "x-goog-api-client", gax.XGoogHeader(kv...),
448 }
449 }
450
451 // Close closes the connection to the API service. The user should invoke this when
452 // the client is no longer required.
453 func (c *restClient) Close() error {
454 // Replace httpClient with nil to force cleanup.
455 c.httpClient = nil
456 return nil
457 }
458
459 // Connection returns a connection to the API service.
460 //
461 // Deprecated: This method always returns nil.
462 func (c *restClient) Connection() *grpc.ClientConn {
463 return nil
464 }
465 func (c *gRPCClient) GetAccount(ctx context.Context, req *accountspb.GetAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) {
466 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
467
468 hds = append(c.xGoogHeaders, hds...)
469 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
470 opts = append((*c.CallOptions).GetAccount[0:len((*c.CallOptions).GetAccount):len((*c.CallOptions).GetAccount)], opts...)
471 var resp *accountspb.Account
472 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
473 var err error
474 resp, err = executeRPC(ctx, c.client.GetAccount, req, settings.GRPC, c.logger, "GetAccount")
475 return err
476 }, opts...)
477 if err != nil {
478 return nil, err
479 }
480 return resp, nil
481 }
482
483 func (c *gRPCClient) CreateAndConfigureAccount(ctx context.Context, req *accountspb.CreateAndConfigureAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) {
484 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
485 opts = append((*c.CallOptions).CreateAndConfigureAccount[0:len((*c.CallOptions).CreateAndConfigureAccount):len((*c.CallOptions).CreateAndConfigureAccount)], opts...)
486 var resp *accountspb.Account
487 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
488 var err error
489 resp, err = executeRPC(ctx, c.client.CreateAndConfigureAccount, req, settings.GRPC, c.logger, "CreateAndConfigureAccount")
490 return err
491 }, opts...)
492 if err != nil {
493 return nil, err
494 }
495 return resp, nil
496 }
497
498 func (c *gRPCClient) DeleteAccount(ctx context.Context, req *accountspb.DeleteAccountRequest, opts ...gax.CallOption) error {
499 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
500
501 hds = append(c.xGoogHeaders, hds...)
502 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
503 opts = append((*c.CallOptions).DeleteAccount[0:len((*c.CallOptions).DeleteAccount):len((*c.CallOptions).DeleteAccount)], opts...)
504 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
505 var err error
506 _, err = executeRPC(ctx, c.client.DeleteAccount, req, settings.GRPC, c.logger, "DeleteAccount")
507 return err
508 }, opts...)
509 return err
510 }
511
512 func (c *gRPCClient) UpdateAccount(ctx context.Context, req *accountspb.UpdateAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) {
513 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "account.name", url.QueryEscape(req.GetAccount().GetName()))}
514
515 hds = append(c.xGoogHeaders, hds...)
516 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
517 opts = append((*c.CallOptions).UpdateAccount[0:len((*c.CallOptions).UpdateAccount):len((*c.CallOptions).UpdateAccount)], opts...)
518 var resp *accountspb.Account
519 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
520 var err error
521 resp, err = executeRPC(ctx, c.client.UpdateAccount, req, settings.GRPC, c.logger, "UpdateAccount")
522 return err
523 }, opts...)
524 if err != nil {
525 return nil, err
526 }
527 return resp, nil
528 }
529
530 func (c *gRPCClient) ListAccounts(ctx context.Context, req *accountspb.ListAccountsRequest, opts ...gax.CallOption) *AccountIterator {
531 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
532 opts = append((*c.CallOptions).ListAccounts[0:len((*c.CallOptions).ListAccounts):len((*c.CallOptions).ListAccounts)], opts...)
533 it := &AccountIterator{}
534 req = proto.Clone(req).(*accountspb.ListAccountsRequest)
535 it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.Account, string, error) {
536 resp := &accountspb.ListAccountsResponse{}
537 if pageToken != "" {
538 req.PageToken = pageToken
539 }
540 if pageSize > math.MaxInt32 {
541 req.PageSize = math.MaxInt32
542 } else if pageSize != 0 {
543 req.PageSize = int32(pageSize)
544 }
545 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
546 var err error
547 resp, err = executeRPC(ctx, c.client.ListAccounts, req, settings.GRPC, c.logger, "ListAccounts")
548 return err
549 }, opts...)
550 if err != nil {
551 return nil, "", err
552 }
553
554 it.Response = resp
555 return resp.GetAccounts(), resp.GetNextPageToken(), nil
556 }
557 fetch := func(pageSize int, pageToken string) (string, error) {
558 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
559 if err != nil {
560 return "", err
561 }
562 it.items = append(it.items, items...)
563 return nextPageToken, nil
564 }
565
566 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
567 it.pageInfo.MaxSize = int(req.GetPageSize())
568 it.pageInfo.Token = req.GetPageToken()
569
570 return it
571 }
572
573 func (c *gRPCClient) ListSubAccounts(ctx context.Context, req *accountspb.ListSubAccountsRequest, opts ...gax.CallOption) *AccountIterator {
574 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "provider", url.QueryEscape(req.GetProvider()))}
575
576 hds = append(c.xGoogHeaders, hds...)
577 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
578 opts = append((*c.CallOptions).ListSubAccounts[0:len((*c.CallOptions).ListSubAccounts):len((*c.CallOptions).ListSubAccounts)], opts...)
579 it := &AccountIterator{}
580 req = proto.Clone(req).(*accountspb.ListSubAccountsRequest)
581 it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.Account, string, error) {
582 resp := &accountspb.ListSubAccountsResponse{}
583 if pageToken != "" {
584 req.PageToken = pageToken
585 }
586 if pageSize > math.MaxInt32 {
587 req.PageSize = math.MaxInt32
588 } else if pageSize != 0 {
589 req.PageSize = int32(pageSize)
590 }
591 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
592 var err error
593 resp, err = executeRPC(ctx, c.client.ListSubAccounts, req, settings.GRPC, c.logger, "ListSubAccounts")
594 return err
595 }, opts...)
596 if err != nil {
597 return nil, "", err
598 }
599
600 it.Response = resp
601 return resp.GetAccounts(), resp.GetNextPageToken(), nil
602 }
603 fetch := func(pageSize int, pageToken string) (string, error) {
604 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
605 if err != nil {
606 return "", err
607 }
608 it.items = append(it.items, items...)
609 return nextPageToken, nil
610 }
611
612 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
613 it.pageInfo.MaxSize = int(req.GetPageSize())
614 it.pageInfo.Token = req.GetPageToken()
615
616 return it
617 }
618
619 // GetAccount retrieves an account from your Merchant Center account.
620 // After inserting, updating, or deleting an account, it may take several
621 // minutes before changes take effect.
622 func (c *restClient) GetAccount(ctx context.Context, req *accountspb.GetAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) {
623 baseUrl, err := url.Parse(c.endpoint)
624 if err != nil {
625 return nil, err
626 }
627 baseUrl.Path += fmt.Sprintf("/accounts/v1/%v", req.GetName())
628
629 params := url.Values{}
630 params.Add("$alt", "json;enum-encoding=int")
631
632 baseUrl.RawQuery = params.Encode()
633
634 // Build HTTP headers from client and context metadata.
635 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
636
637 hds = append(c.xGoogHeaders, hds...)
638 hds = append(hds, "Content-Type", "application/json")
639 headers := gax.BuildHeaders(ctx, hds...)
640 opts = append((*c.CallOptions).GetAccount[0:len((*c.CallOptions).GetAccount):len((*c.CallOptions).GetAccount)], opts...)
641 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
642 resp := &accountspb.Account{}
643 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
644 if settings.Path != "" {
645 baseUrl.Path = settings.Path
646 }
647 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
648 if err != nil {
649 return err
650 }
651 httpReq = httpReq.WithContext(ctx)
652 httpReq.Header = headers
653
654 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetAccount")
655 if err != nil {
656 return err
657 }
658
659 if err := unm.Unmarshal(buf, resp); err != nil {
660 return err
661 }
662
663 return nil
664 }, opts...)
665 if e != nil {
666 return nil, e
667 }
668 return resp, nil
669 }
670
671 // CreateAndConfigureAccount creates a Merchant Center account with additional configuration. Adds the
672 // user that makes the request as an admin for the new account.
673 func (c *restClient) CreateAndConfigureAccount(ctx context.Context, req *accountspb.CreateAndConfigureAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) {
674 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
675 jsonReq, err := m.Marshal(req)
676 if err != nil {
677 return nil, err
678 }
679
680 baseUrl, err := url.Parse(c.endpoint)
681 if err != nil {
682 return nil, err
683 }
684 baseUrl.Path += fmt.Sprintf("/accounts/v1/accounts:createAndConfigure")
685
686 params := url.Values{}
687 params.Add("$alt", "json;enum-encoding=int")
688
689 baseUrl.RawQuery = params.Encode()
690
691 // Build HTTP headers from client and context metadata.
692 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
693 headers := gax.BuildHeaders(ctx, hds...)
694 opts = append((*c.CallOptions).CreateAndConfigureAccount[0:len((*c.CallOptions).CreateAndConfigureAccount):len((*c.CallOptions).CreateAndConfigureAccount)], opts...)
695 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
696 resp := &accountspb.Account{}
697 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
698 if settings.Path != "" {
699 baseUrl.Path = settings.Path
700 }
701 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
702 if err != nil {
703 return err
704 }
705 httpReq = httpReq.WithContext(ctx)
706 httpReq.Header = headers
707
708 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateAndConfigureAccount")
709 if err != nil {
710 return err
711 }
712
713 if err := unm.Unmarshal(buf, resp); err != nil {
714 return err
715 }
716
717 return nil
718 }, opts...)
719 if e != nil {
720 return nil, e
721 }
722 return resp, nil
723 }
724
725 // DeleteAccount deletes the specified account regardless of its type: standalone, advanced
726 // account or sub-account. Deleting an advanced account leads to the deletion
727 // of all of its sub-accounts. Executing this method requires admin access.
728 // The deletion succeeds only if the account does not provide services
729 // to any other account and has no processed offers. You can use the force
730 // parameter to override this.
731 func (c *restClient) DeleteAccount(ctx context.Context, req *accountspb.DeleteAccountRequest, opts ...gax.CallOption) error {
732 baseUrl, err := url.Parse(c.endpoint)
733 if err != nil {
734 return err
735 }
736 baseUrl.Path += fmt.Sprintf("/accounts/v1/%v", req.GetName())
737
738 params := url.Values{}
739 params.Add("$alt", "json;enum-encoding=int")
740 if req.GetForce() {
741 params.Add("force", fmt.Sprintf("%v", req.GetForce()))
742 }
743
744 baseUrl.RawQuery = params.Encode()
745
746 // Build HTTP headers from client and context metadata.
747 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
748
749 hds = append(c.xGoogHeaders, hds...)
750 hds = append(hds, "Content-Type", "application/json")
751 headers := gax.BuildHeaders(ctx, hds...)
752 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
753 if settings.Path != "" {
754 baseUrl.Path = settings.Path
755 }
756 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
757 if err != nil {
758 return err
759 }
760 httpReq = httpReq.WithContext(ctx)
761 httpReq.Header = headers
762
763 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteAccount")
764 return err
765 }, opts...)
766 }
767
768 // UpdateAccount updates an account regardless of its type: standalone, advanced account or
769 // sub-account. Executing this method requires admin access.
770 func (c *restClient) UpdateAccount(ctx context.Context, req *accountspb.UpdateAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) {
771 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
772 body := req.GetAccount()
773 jsonReq, err := m.Marshal(body)
774 if err != nil {
775 return nil, err
776 }
777
778 baseUrl, err := url.Parse(c.endpoint)
779 if err != nil {
780 return nil, err
781 }
782 baseUrl.Path += fmt.Sprintf("/accounts/v1/%v", req.GetAccount().GetName())
783
784 params := url.Values{}
785 params.Add("$alt", "json;enum-encoding=int")
786 if req.GetUpdateMask() != nil {
787 field, err := protojson.Marshal(req.GetUpdateMask())
788 if err != nil {
789 return nil, err
790 }
791 params.Add("updateMask", string(field[1:len(field)-1]))
792 }
793
794 baseUrl.RawQuery = params.Encode()
795
796 // Build HTTP headers from client and context metadata.
797 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "account.name", url.QueryEscape(req.GetAccount().GetName()))}
798
799 hds = append(c.xGoogHeaders, hds...)
800 hds = append(hds, "Content-Type", "application/json")
801 headers := gax.BuildHeaders(ctx, hds...)
802 opts = append((*c.CallOptions).UpdateAccount[0:len((*c.CallOptions).UpdateAccount):len((*c.CallOptions).UpdateAccount)], opts...)
803 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
804 resp := &accountspb.Account{}
805 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
806 if settings.Path != "" {
807 baseUrl.Path = settings.Path
808 }
809 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
810 if err != nil {
811 return err
812 }
813 httpReq = httpReq.WithContext(ctx)
814 httpReq.Header = headers
815
816 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateAccount")
817 if err != nil {
818 return err
819 }
820
821 if err := unm.Unmarshal(buf, resp); err != nil {
822 return err
823 }
824
825 return nil
826 }, opts...)
827 if e != nil {
828 return nil, e
829 }
830 return resp, nil
831 }
832
833 // ListAccounts note: For the accounts.list method, quota and limits usage are charged
834 // for each user, and not for the Merchant Center ID or the advanced account
835 // ID. To list several sub-accounts, you should use the
836 // accounts.listSubaccounts method, which is more suitable for advanced
837 // accounts use case.
838 func (c *restClient) ListAccounts(ctx context.Context, req *accountspb.ListAccountsRequest, opts ...gax.CallOption) *AccountIterator {
839 it := &AccountIterator{}
840 req = proto.Clone(req).(*accountspb.ListAccountsRequest)
841 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
842 it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.Account, string, error) {
843 resp := &accountspb.ListAccountsResponse{}
844 if pageToken != "" {
845 req.PageToken = pageToken
846 }
847 if pageSize > math.MaxInt32 {
848 req.PageSize = math.MaxInt32
849 } else if pageSize != 0 {
850 req.PageSize = int32(pageSize)
851 }
852 baseUrl, err := url.Parse(c.endpoint)
853 if err != nil {
854 return nil, "", err
855 }
856 baseUrl.Path += fmt.Sprintf("/accounts/v1/accounts")
857
858 params := url.Values{}
859 params.Add("$alt", "json;enum-encoding=int")
860 if req.GetFilter() != "" {
861 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
862 }
863 if req.GetPageSize() != 0 {
864 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
865 }
866 if req.GetPageToken() != "" {
867 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
868 }
869
870 baseUrl.RawQuery = params.Encode()
871
872 // Build HTTP headers from client and context metadata.
873 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
874 headers := gax.BuildHeaders(ctx, hds...)
875 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
876 if settings.Path != "" {
877 baseUrl.Path = settings.Path
878 }
879 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
880 if err != nil {
881 return err
882 }
883 httpReq.Header = headers
884
885 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAccounts")
886 if err != nil {
887 return err
888 }
889 if err := unm.Unmarshal(buf, resp); err != nil {
890 return err
891 }
892
893 return nil
894 }, opts...)
895 if e != nil {
896 return nil, "", e
897 }
898 it.Response = resp
899 return resp.GetAccounts(), resp.GetNextPageToken(), nil
900 }
901
902 fetch := func(pageSize int, pageToken string) (string, error) {
903 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
904 if err != nil {
905 return "", err
906 }
907 it.items = append(it.items, items...)
908 return nextPageToken, nil
909 }
910
911 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
912 it.pageInfo.MaxSize = int(req.GetPageSize())
913 it.pageInfo.Token = req.GetPageToken()
914
915 return it
916 }
917
918 // ListSubAccounts list all sub-accounts for a given advanced account. This is a
919 // convenience wrapper for the more powerful accounts.list method. This
920 // method will produce the same results as calling ListsAccounts with the
921 // following filter:
922 // relationship(providerId={parent} AND service(type="ACCOUNT_AGGREGATION"))
923 func (c *restClient) ListSubAccounts(ctx context.Context, req *accountspb.ListSubAccountsRequest, opts ...gax.CallOption) *AccountIterator {
924 it := &AccountIterator{}
925 req = proto.Clone(req).(*accountspb.ListSubAccountsRequest)
926 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
927 it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.Account, string, error) {
928 resp := &accountspb.ListSubAccountsResponse{}
929 if pageToken != "" {
930 req.PageToken = pageToken
931 }
932 if pageSize > math.MaxInt32 {
933 req.PageSize = math.MaxInt32
934 } else if pageSize != 0 {
935 req.PageSize = int32(pageSize)
936 }
937 baseUrl, err := url.Parse(c.endpoint)
938 if err != nil {
939 return nil, "", err
940 }
941 baseUrl.Path += fmt.Sprintf("/accounts/v1/%v:listSubaccounts", req.GetProvider())
942
943 params := url.Values{}
944 params.Add("$alt", "json;enum-encoding=int")
945 if req.GetPageSize() != 0 {
946 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
947 }
948 if req.GetPageToken() != "" {
949 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
950 }
951
952 baseUrl.RawQuery = params.Encode()
953
954 // Build HTTP headers from client and context metadata.
955 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
956 headers := gax.BuildHeaders(ctx, hds...)
957 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
958 if settings.Path != "" {
959 baseUrl.Path = settings.Path
960 }
961 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
962 if err != nil {
963 return err
964 }
965 httpReq.Header = headers
966
967 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListSubAccounts")
968 if err != nil {
969 return err
970 }
971 if err := unm.Unmarshal(buf, resp); err != nil {
972 return err
973 }
974
975 return nil
976 }, opts...)
977 if e != nil {
978 return nil, "", e
979 }
980 it.Response = resp
981 return resp.GetAccounts(), resp.GetNextPageToken(), nil
982 }
983
984 fetch := func(pageSize int, pageToken string) (string, error) {
985 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
986 if err != nil {
987 return "", err
988 }
989 it.items = append(it.items, items...)
990 return nextPageToken, nil
991 }
992
993 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
994 it.pageInfo.MaxSize = int(req.GetPageSize())
995 it.pageInfo.Token = req.GetPageToken()
996
997 return it
998 }