Debian Codegraph @

shopping/merchant/accounts/apiv1beta/account_tax_client.go

raw symbols SCIP
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/apiv1beta/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 newAccountTaxClientHook clientHook
43
44 // AccountTaxCallOptions contains the retry settings for each method of AccountTaxClient.
45 type AccountTaxCallOptions struct {
46 GetAccountTax []gax.CallOption
47 ListAccountTax []gax.CallOption
48 UpdateAccountTax []gax.CallOption
49 }
50
51 func defaultAccountTaxGRPCClientOptions() []option.ClientOption {
52 return []option.ClientOption{
53 internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"),
54 internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"),
55 internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"),
56 internaloption.WithDefaultUniverseDomain("googleapis.com"),
57 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
58 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
59 internaloption.EnableJwtWithScope(),
60 internaloption.EnableNewAuthLibrary(),
61 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
62 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
63 }
64 }
65
66 func defaultAccountTaxCallOptions() *AccountTaxCallOptions {
67 return &AccountTaxCallOptions{
68 GetAccountTax: []gax.CallOption{
69 gax.WithTimeout(60000 * time.Millisecond),
70 gax.WithRetry(func() gax.Retryer {
71 return gax.OnCodes([]codes.Code{
72 codes.Unavailable,
73 }, gax.Backoff{
74 Initial: 1000 * time.Millisecond,
75 Max: 10000 * time.Millisecond,
76 Multiplier: 1.30,
77 })
78 }),
79 },
80 ListAccountTax: []gax.CallOption{
81 gax.WithTimeout(60000 * time.Millisecond),
82 gax.WithRetry(func() gax.Retryer {
83 return gax.OnCodes([]codes.Code{
84 codes.Unavailable,
85 }, gax.Backoff{
86 Initial: 1000 * time.Millisecond,
87 Max: 10000 * time.Millisecond,
88 Multiplier: 1.30,
89 })
90 }),
91 },
92 UpdateAccountTax: []gax.CallOption{
93 gax.WithTimeout(60000 * time.Millisecond),
94 gax.WithRetry(func() gax.Retryer {
95 return gax.OnCodes([]codes.Code{
96 codes.Unavailable,
97 }, gax.Backoff{
98 Initial: 1000 * time.Millisecond,
99 Max: 10000 * time.Millisecond,
100 Multiplier: 1.30,
101 })
102 }),
103 },
104 }
105 }
106
107 func defaultAccountTaxRESTCallOptions() *AccountTaxCallOptions {
108 return &AccountTaxCallOptions{
109 GetAccountTax: []gax.CallOption{
110 gax.WithTimeout(60000 * time.Millisecond),
111 gax.WithRetry(func() gax.Retryer {
112 return gax.OnHTTPCodes(gax.Backoff{
113 Initial: 1000 * time.Millisecond,
114 Max: 10000 * time.Millisecond,
115 Multiplier: 1.30,
116 },
117 http.StatusServiceUnavailable)
118 }),
119 },
120 ListAccountTax: []gax.CallOption{
121 gax.WithTimeout(60000 * time.Millisecond),
122 gax.WithRetry(func() gax.Retryer {
123 return gax.OnHTTPCodes(gax.Backoff{
124 Initial: 1000 * time.Millisecond,
125 Max: 10000 * time.Millisecond,
126 Multiplier: 1.30,
127 },
128 http.StatusServiceUnavailable)
129 }),
130 },
131 UpdateAccountTax: []gax.CallOption{
132 gax.WithTimeout(60000 * time.Millisecond),
133 gax.WithRetry(func() gax.Retryer {
134 return gax.OnHTTPCodes(gax.Backoff{
135 Initial: 1000 * time.Millisecond,
136 Max: 10000 * time.Millisecond,
137 Multiplier: 1.30,
138 },
139 http.StatusServiceUnavailable)
140 }),
141 },
142 }
143 }
144
145 // internalAccountTaxClient is an interface that defines the methods available from Merchant API.
146 type internalAccountTaxClient interface {
147 Close() error
148 setGoogleClientInfo(...string)
149 Connection() *grpc.ClientConn
150 GetAccountTax(context.Context, *accountspb.GetAccountTaxRequest, ...gax.CallOption) (*accountspb.AccountTax, error)
151 ListAccountTax(context.Context, *accountspb.ListAccountTaxRequest, ...gax.CallOption) *AccountTaxIterator
152 UpdateAccountTax(context.Context, *accountspb.UpdateAccountTaxRequest, ...gax.CallOption) (*accountspb.AccountTax, error)
153 }
154
155 // AccountTaxClient is a client for interacting with Merchant API.
156 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
157 //
158 // Manages account level tax setting data.
159 //
160 // This API defines the following resource model:
161 //
162 // AccountTax
163 type AccountTaxClient struct {
164 // The internal transport-dependent client.
165 internalClient internalAccountTaxClient
166
167 // The call options for this service.
168 CallOptions *AccountTaxCallOptions
169 }
170
171 // Wrapper methods routed to the internal client.
172
173 // Close closes the connection to the API service. The user should invoke this when
174 // the client is no longer required.
175 func (c *AccountTaxClient) Close() error {
176 return c.internalClient.Close()
177 }
178
179 // setGoogleClientInfo sets the name and version of the application in
180 // the `x-goog-api-client` header passed on each request. Intended for
181 // use by Google-written clients.
182 func (c *AccountTaxClient) setGoogleClientInfo(keyval ...string) {
183 c.internalClient.setGoogleClientInfo(keyval...)
184 }
185
186 // Connection returns a connection to the API service.
187 //
188 // Deprecated: Connections are now pooled so this method does not always
189 // return the same resource.
190 func (c *AccountTaxClient) Connection() *grpc.ClientConn {
191 return c.internalClient.Connection()
192 }
193
194 // GetAccountTax returns the tax rules that match the conditions of GetAccountTaxRequest
195 func (c *AccountTaxClient) GetAccountTax(ctx context.Context, req *accountspb.GetAccountTaxRequest, opts ...gax.CallOption) (*accountspb.AccountTax, error) {
196 return c.internalClient.GetAccountTax(ctx, req, opts...)
197 }
198
199 // ListAccountTax lists the tax settings of the sub-accounts only in your
200 // Merchant Center account.
201 // This method can only be called on a multi-client account, otherwise it’ll
202 // return an error.
203 func (c *AccountTaxClient) ListAccountTax(ctx context.Context, req *accountspb.ListAccountTaxRequest, opts ...gax.CallOption) *AccountTaxIterator {
204 return c.internalClient.ListAccountTax(ctx, req, opts...)
205 }
206
207 // UpdateAccountTax updates the tax settings of the account.
208 func (c *AccountTaxClient) UpdateAccountTax(ctx context.Context, req *accountspb.UpdateAccountTaxRequest, opts ...gax.CallOption) (*accountspb.AccountTax, error) {
209 return c.internalClient.UpdateAccountTax(ctx, req, opts...)
210 }
211
212 // accountTaxGRPCClient is a client for interacting with Merchant API over gRPC transport.
213 //
214 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
215 type accountTaxGRPCClient struct {
216 // Connection pool of gRPC connections to the service.
217 connPool gtransport.ConnPool
218
219 // Points back to the CallOptions field of the containing AccountTaxClient
220 CallOptions **AccountTaxCallOptions
221
222 // The gRPC API client.
223 accountTaxClient accountspb.AccountTaxServiceClient
224
225 // The x-goog-* metadata to be sent with each request.
226 xGoogHeaders []string
227
228 logger *slog.Logger
229 }
230
231 // NewAccountTaxClient creates a new account tax service client based on gRPC.
232 // The returned client must be Closed when it is done being used to clean up its underlying connections.
233 //
234 // Manages account level tax setting data.
235 //
236 // This API defines the following resource model:
237 //
238 // AccountTax
239 func NewAccountTaxClient(ctx context.Context, opts ...option.ClientOption) (*AccountTaxClient, error) {
240 clientOpts := defaultAccountTaxGRPCClientOptions()
241 if newAccountTaxClientHook != nil {
242 hookOpts, err := newAccountTaxClientHook(ctx, clientHookParams{})
243 if err != nil {
244 return nil, err
245 }
246 clientOpts = append(clientOpts, hookOpts...)
247 }
248
249 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
250 if err != nil {
251 return nil, err
252 }
253 client := AccountTaxClient{CallOptions: defaultAccountTaxCallOptions()}
254
255 c := &accountTaxGRPCClient{
256 connPool: connPool,
257 accountTaxClient: accountspb.NewAccountTaxServiceClient(connPool),
258 CallOptions: &client.CallOptions,
259 logger: internaloption.GetLogger(opts),
260 }
261 c.setGoogleClientInfo()
262
263 client.internalClient = c
264
265 return &client, nil
266 }
267
268 // Connection returns a connection to the API service.
269 //
270 // Deprecated: Connections are now pooled so this method does not always
271 // return the same resource.
272 func (c *accountTaxGRPCClient) Connection() *grpc.ClientConn {
273 return c.connPool.Conn()
274 }
275
276 // setGoogleClientInfo sets the name and version of the application in
277 // the `x-goog-api-client` header passed on each request. Intended for
278 // use by Google-written clients.
279 func (c *accountTaxGRPCClient) setGoogleClientInfo(keyval ...string) {
280 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
281 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
282 c.xGoogHeaders = []string{
283 "x-goog-api-client", gax.XGoogHeader(kv...),
284 }
285 }
286
287 // Close closes the connection to the API service. The user should invoke this when
288 // the client is no longer required.
289 func (c *accountTaxGRPCClient) Close() error {
290 return c.connPool.Close()
291 }
292
293 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
294 type accountTaxRESTClient struct {
295 // The http endpoint to connect to.
296 endpoint string
297
298 // The http client.
299 httpClient *http.Client
300
301 // The x-goog-* headers to be sent with each request.
302 xGoogHeaders []string
303
304 // Points back to the CallOptions field of the containing AccountTaxClient
305 CallOptions **AccountTaxCallOptions
306
307 logger *slog.Logger
308 }
309
310 // NewAccountTaxRESTClient creates a new account tax service rest client.
311 //
312 // Manages account level tax setting data.
313 //
314 // This API defines the following resource model:
315 //
316 // AccountTax
317 func NewAccountTaxRESTClient(ctx context.Context, opts ...option.ClientOption) (*AccountTaxClient, error) {
318 clientOpts := append(defaultAccountTaxRESTClientOptions(), opts...)
319 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
320 if err != nil {
321 return nil, err
322 }
323
324 callOpts := defaultAccountTaxRESTCallOptions()
325 c := &accountTaxRESTClient{
326 endpoint: endpoint,
327 httpClient: httpClient,
328 CallOptions: &callOpts,
329 logger: internaloption.GetLogger(opts),
330 }
331 c.setGoogleClientInfo()
332
333 return &AccountTaxClient{internalClient: c, CallOptions: callOpts}, nil
334 }
335
336 func defaultAccountTaxRESTClientOptions() []option.ClientOption {
337 return []option.ClientOption{
338 internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"),
339 internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"),
340 internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"),
341 internaloption.WithDefaultUniverseDomain("googleapis.com"),
342 internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"),
343 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
344 internaloption.EnableNewAuthLibrary(),
345 }
346 }
347
348 // setGoogleClientInfo sets the name and version of the application in
349 // the `x-goog-api-client` header passed on each request. Intended for
350 // use by Google-written clients.
351 func (c *accountTaxRESTClient) setGoogleClientInfo(keyval ...string) {
352 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
353 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
354 c.xGoogHeaders = []string{
355 "x-goog-api-client", gax.XGoogHeader(kv...),
356 }
357 }
358
359 // Close closes the connection to the API service. The user should invoke this when
360 // the client is no longer required.
361 func (c *accountTaxRESTClient) Close() error {
362 // Replace httpClient with nil to force cleanup.
363 c.httpClient = nil
364 return nil
365 }
366
367 // Connection returns a connection to the API service.
368 //
369 // Deprecated: This method always returns nil.
370 func (c *accountTaxRESTClient) Connection() *grpc.ClientConn {
371 return nil
372 }
373 func (c *accountTaxGRPCClient) GetAccountTax(ctx context.Context, req *accountspb.GetAccountTaxRequest, opts ...gax.CallOption) (*accountspb.AccountTax, error) {
374 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
375
376 hds = append(c.xGoogHeaders, hds...)
377 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
378 opts = append((*c.CallOptions).GetAccountTax[0:len((*c.CallOptions).GetAccountTax):len((*c.CallOptions).GetAccountTax)], opts...)
379 var resp *accountspb.AccountTax
380 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
381 var err error
382 resp, err = executeRPC(ctx, c.accountTaxClient.GetAccountTax, req, settings.GRPC, c.logger, "GetAccountTax")
383 return err
384 }, opts...)
385 if err != nil {
386 return nil, err
387 }
388 return resp, nil
389 }
390
391 func (c *accountTaxGRPCClient) ListAccountTax(ctx context.Context, req *accountspb.ListAccountTaxRequest, opts ...gax.CallOption) *AccountTaxIterator {
392 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
393
394 hds = append(c.xGoogHeaders, hds...)
395 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
396 opts = append((*c.CallOptions).ListAccountTax[0:len((*c.CallOptions).ListAccountTax):len((*c.CallOptions).ListAccountTax)], opts...)
397 it := &AccountTaxIterator{}
398 req = proto.Clone(req).(*accountspb.ListAccountTaxRequest)
399 it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.AccountTax, string, error) {
400 resp := &accountspb.ListAccountTaxResponse{}
401 if pageToken != "" {
402 req.PageToken = pageToken
403 }
404 if pageSize > math.MaxInt32 {
405 req.PageSize = math.MaxInt32
406 } else if pageSize != 0 {
407 req.PageSize = int32(pageSize)
408 }
409 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
410 var err error
411 resp, err = executeRPC(ctx, c.accountTaxClient.ListAccountTax, req, settings.GRPC, c.logger, "ListAccountTax")
412 return err
413 }, opts...)
414 if err != nil {
415 return nil, "", err
416 }
417
418 it.Response = resp
419 return resp.GetAccountTaxes(), resp.GetNextPageToken(), nil
420 }
421 fetch := func(pageSize int, pageToken string) (string, error) {
422 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
423 if err != nil {
424 return "", err
425 }
426 it.items = append(it.items, items...)
427 return nextPageToken, nil
428 }
429
430 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
431 it.pageInfo.MaxSize = int(req.GetPageSize())
432 it.pageInfo.Token = req.GetPageToken()
433
434 return it
435 }
436
437 func (c *accountTaxGRPCClient) UpdateAccountTax(ctx context.Context, req *accountspb.UpdateAccountTaxRequest, opts ...gax.CallOption) (*accountspb.AccountTax, error) {
438 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "account_tax.name", url.QueryEscape(req.GetAccountTax().GetName()))}
439
440 hds = append(c.xGoogHeaders, hds...)
441 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
442 opts = append((*c.CallOptions).UpdateAccountTax[0:len((*c.CallOptions).UpdateAccountTax):len((*c.CallOptions).UpdateAccountTax)], opts...)
443 var resp *accountspb.AccountTax
444 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
445 var err error
446 resp, err = executeRPC(ctx, c.accountTaxClient.UpdateAccountTax, req, settings.GRPC, c.logger, "UpdateAccountTax")
447 return err
448 }, opts...)
449 if err != nil {
450 return nil, err
451 }
452 return resp, nil
453 }
454
455 // GetAccountTax returns the tax rules that match the conditions of GetAccountTaxRequest
456 func (c *accountTaxRESTClient) GetAccountTax(ctx context.Context, req *accountspb.GetAccountTaxRequest, opts ...gax.CallOption) (*accountspb.AccountTax, error) {
457 baseUrl, err := url.Parse(c.endpoint)
458 if err != nil {
459 return nil, err
460 }
461 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v", req.GetName())
462
463 params := url.Values{}
464 params.Add("$alt", "json;enum-encoding=int")
465
466 baseUrl.RawQuery = params.Encode()
467
468 // Build HTTP headers from client and context metadata.
469 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
470
471 hds = append(c.xGoogHeaders, hds...)
472 hds = append(hds, "Content-Type", "application/json")
473 headers := gax.BuildHeaders(ctx, hds...)
474 opts = append((*c.CallOptions).GetAccountTax[0:len((*c.CallOptions).GetAccountTax):len((*c.CallOptions).GetAccountTax)], opts...)
475 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
476 resp := &accountspb.AccountTax{}
477 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
478 if settings.Path != "" {
479 baseUrl.Path = settings.Path
480 }
481 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
482 if err != nil {
483 return err
484 }
485 httpReq = httpReq.WithContext(ctx)
486 httpReq.Header = headers
487
488 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetAccountTax")
489 if err != nil {
490 return err
491 }
492
493 if err := unm.Unmarshal(buf, resp); err != nil {
494 return err
495 }
496
497 return nil
498 }, opts...)
499 if e != nil {
500 return nil, e
501 }
502 return resp, nil
503 }
504
505 // ListAccountTax lists the tax settings of the sub-accounts only in your
506 // Merchant Center account.
507 // This method can only be called on a multi-client account, otherwise it’ll
508 // return an error.
509 func (c *accountTaxRESTClient) ListAccountTax(ctx context.Context, req *accountspb.ListAccountTaxRequest, opts ...gax.CallOption) *AccountTaxIterator {
510 it := &AccountTaxIterator{}
511 req = proto.Clone(req).(*accountspb.ListAccountTaxRequest)
512 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
513 it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.AccountTax, string, error) {
514 resp := &accountspb.ListAccountTaxResponse{}
515 if pageToken != "" {
516 req.PageToken = pageToken
517 }
518 if pageSize > math.MaxInt32 {
519 req.PageSize = math.MaxInt32
520 } else if pageSize != 0 {
521 req.PageSize = int32(pageSize)
522 }
523 baseUrl, err := url.Parse(c.endpoint)
524 if err != nil {
525 return nil, "", err
526 }
527 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v/accounttax", req.GetParent())
528
529 params := url.Values{}
530 params.Add("$alt", "json;enum-encoding=int")
531 if req.GetPageSize() != 0 {
532 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
533 }
534 if req.GetPageToken() != "" {
535 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
536 }
537
538 baseUrl.RawQuery = params.Encode()
539
540 // Build HTTP headers from client and context metadata.
541 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
542 headers := gax.BuildHeaders(ctx, hds...)
543 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
544 if settings.Path != "" {
545 baseUrl.Path = settings.Path
546 }
547 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
548 if err != nil {
549 return err
550 }
551 httpReq.Header = headers
552
553 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAccountTax")
554 if err != nil {
555 return err
556 }
557 if err := unm.Unmarshal(buf, resp); err != nil {
558 return err
559 }
560
561 return nil
562 }, opts...)
563 if e != nil {
564 return nil, "", e
565 }
566 it.Response = resp
567 return resp.GetAccountTaxes(), resp.GetNextPageToken(), nil
568 }
569
570 fetch := func(pageSize int, pageToken string) (string, error) {
571 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
572 if err != nil {
573 return "", err
574 }
575 it.items = append(it.items, items...)
576 return nextPageToken, nil
577 }
578
579 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
580 it.pageInfo.MaxSize = int(req.GetPageSize())
581 it.pageInfo.Token = req.GetPageToken()
582
583 return it
584 }
585
586 // UpdateAccountTax updates the tax settings of the account.
587 func (c *accountTaxRESTClient) UpdateAccountTax(ctx context.Context, req *accountspb.UpdateAccountTaxRequest, opts ...gax.CallOption) (*accountspb.AccountTax, error) {
588 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
589 body := req.GetAccountTax()
590 jsonReq, err := m.Marshal(body)
591 if err != nil {
592 return nil, err
593 }
594
595 baseUrl, err := url.Parse(c.endpoint)
596 if err != nil {
597 return nil, err
598 }
599 baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v", req.GetAccountTax().GetName())
600
601 params := url.Values{}
602 params.Add("$alt", "json;enum-encoding=int")
603 if req.GetUpdateMask() != nil {
604 field, err := protojson.Marshal(req.GetUpdateMask())
605 if err != nil {
606 return nil, err
607 }
608 params.Add("updateMask", string(field[1:len(field)-1]))
609 }
610
611 baseUrl.RawQuery = params.Encode()
612
613 // Build HTTP headers from client and context metadata.
614 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "account_tax.name", url.QueryEscape(req.GetAccountTax().GetName()))}
615
616 hds = append(c.xGoogHeaders, hds...)
617 hds = append(hds, "Content-Type", "application/json")
618 headers := gax.BuildHeaders(ctx, hds...)
619 opts = append((*c.CallOptions).UpdateAccountTax[0:len((*c.CallOptions).UpdateAccountTax):len((*c.CallOptions).UpdateAccountTax)], opts...)
620 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
621 resp := &accountspb.AccountTax{}
622 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
623 if settings.Path != "" {
624 baseUrl.Path = settings.Path
625 }
626 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
627 if err != nil {
628 return err
629 }
630 httpReq = httpReq.WithContext(ctx)
631 httpReq.Header = headers
632
633 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateAccountTax")
634 if err != nil {
635 return err
636 }
637
638 if err := unm.Unmarshal(buf, resp); err != nil {
639 return err
640 }
641
642 return nil
643 }, opts...)
644 if e != nil {
645 return nil, e
646 }
647 return resp, nil
648 }