Debian Codegraph @

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