Stay organized with collections
Save and categorize content based on your preferences.
Merchant API code sample to update checkout settings.
Java
// Copyright 2025 Google LLC// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// https://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.packageshopping.merchant.samples.accounts.checkoutsettings.v1;importcom.google.api.gax.core.FixedCredentialsProvider;importcom.google.auth.oauth2.GoogleCredentials;importcom.google.protobuf.FieldMask;importcom.google.shopping.merchant.accounts.v1.CheckoutSettings;importcom.google.shopping.merchant.accounts.v1.CheckoutSettingsName;importcom.google.shopping.merchant.accounts.v1.CheckoutSettingsServiceClient;importcom.google.shopping.merchant.accounts.v1.CheckoutSettingsServiceSettings;importcom.google.shopping.merchant.accounts.v1.UpdateCheckoutSettingsRequest;importcom.google.shopping.merchant.accounts.v1.UriSettings;importcom.google.shopping.type.Destination.DestinationEnum;importshopping.merchant.samples.utils.Authenticator;importshopping.merchant.samples.utils.Config;/** * This class demonstrates how to update the checkout settings for a given Merchant Center account */publicclassUpdateCheckoutSettingsSample{publicstaticvoidupdateBusinessInfo(Configconfig)throwsException{// Obtains OAuth token based on the user's configuration.GoogleCredentialscredential=newAuthenticator().authenticate();// Creates service settings using the credentials retrieved above.CheckoutSettingsServiceSettingscheckoutSettingsServiceSettings=CheckoutSettingsServiceSettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create(credential)).build();try(CheckoutSettingsServiceClientcheckoutSettingsServiceClient=CheckoutSettingsServiceClient.create(checkoutSettingsServiceSettings)){StringaccountId=config.getAccountId().toString();// The only valid programId for checkout settings is "checkout"StringprogramId="checkout";Stringname=CheckoutSettingsName.newBuilder().setAccount(accountId).setProgram(programId).build().toString();// Replace this with your checkout URL.StringcheckoutUrl="https://myshopify.com/cart/1234:1";CheckoutSettingscheckoutSettings=CheckoutSettings.newBuilder().setName(name).setUriSettings(UriSettings.newBuilder().setCheckoutUriTemplate(checkoutUrl)).addEligibleDestinations(DestinationEnum.SHOPPING_ADS).build();FieldMaskfieldMask=FieldMask.newBuilder().addPaths("uri_settings").addPaths("eligible_destinations").build();UpdateCheckoutSettingsRequestrequest=UpdateCheckoutSettingsRequest.newBuilder().setCheckoutSettings(checkoutSettings).setUpdateMask(fieldMask).build();System.out.println("Sending update checkoutSettings request:");CheckoutSettingsresponse=checkoutSettingsServiceClient.updateCheckoutSettings(request);System.out.println("Updated Checkout Settings below:");System.out.println(response);}catch(Exceptione){System.out.println("An error has occurred: ");System.out.println(e);}}publicstaticvoidmain(String[]args)throwsException{Configconfig=Config.load();updateBusinessInfo(config);}}
<?php/** * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */require_once __DIR__ . '/../../../../vendor/autoload.php';require_once __DIR__ . '/../../../Authentication/Authentication.php';require_once __DIR__ . '/../../../Authentication/Config.php';use Google\ApiCore\ApiException;use Google\Protobuf\FieldMask;use Google\Shopping\Merchant\Accounts\V1\CheckoutSettings;use Google\Shopping\Merchant\Accounts\V1\Client\CheckoutSettingsServiceClient;use Google\Shopping\Merchant\Accounts\V1\UpdateCheckoutSettingsRequest;use Google\Shopping\Merchant\Accounts\V1\UriSettings;use Google\Shopping\Type\Destination\DestinationEnum;/** * This class demonstrates how to update the checkout settings for a given * Merchant Center account. */class UpdateCheckoutSettingsSample{ /** * Updates the checkout settings for a given Merchant Center account. * * @param array $config The configuration file for the Merchant Center account. * * @return void */ public static function updateCheckoutSettings(array $config): void { // Obtains OAuth credentials from the configuration file. $credentials = Authentication::useServiceAccountOrTokenFile(); // Creates a client. $checkoutSettingsServiceClient = new CheckoutSettingsServiceClient([ 'credentials' => $credentials ]); // The only valid programId for checkout settings is "checkout". $programId = 'checkout'; // Constructs the resource name format: // `accounts/{account}/programs/{program}/checkoutSettings`. $name = sprintf( 'accounts/%s/programs/%s/checkoutSettings', $config['accountId'], $programId ); // Replace this with your checkout URL. $checkoutUrl = 'https://myshopify.com/cart/1234:1'; // Creates the URI settings with the checkout URL. $uriSettings = new UriSettings([ 'checkout_uri_template' => $checkoutUrl ]); // Creates the checkout settings with the name, URI settings, and // eligible destinations. The name is required for an update. $checkoutSettings = new CheckoutSettings([ 'name' => $name, 'uri_settings' => $uriSettings, 'eligible_destinations' => [DestinationEnum::SHOPPING_ADS] ]); // Creates a field mask to specify which fields to update. $fieldMask = new FieldMask([ 'paths' => ['uri_settings', 'eligible_destinations'] ]); // Creates the request object. $request = (new UpdateCheckoutSettingsRequest()) ->setCheckoutSettings($checkoutSettings) ->setUpdateMask($fieldMask); // Calls the API and catches and prints any network failures/errors. try { printf("Sending update checkoutSettings request:%s", PHP_EOL); $response = $checkoutSettingsServiceClient->updateCheckoutSettings($request); printf("Updated Checkout Settings below:%s", PHP_EOL); print $response->serializeToJsonString(true) . PHP_EOL; } catch (ApiException $e) { printf("An error has occurred: %s", PHP_EOL); print $e->getMessage(); } } /** * Executes the sample. * * @return void */ public function callSample(): void { $config = Config::generateConfig(); self::updateCheckoutSettings($config); }}// Runs the sample.$sample = new UpdateCheckoutSettingsSample();$sample->callSample();
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-21 UTC."],[],[],null,["# Update checkout settings\n\nMerchant API code sample to update checkout settings. \n\n### Java\n\n // Copyright 2025 Google LLC\n\n // Licensed under the Apache License, Version 2.0 (the \"License\");\n // you may not use this file except in compliance with the License.\n // You may obtain a copy of the License at\n //\n // https://www.apache.org/licenses/LICENSE-2.0\n //\n // Unless required by applicable law or agreed to in writing, software\n // distributed under the License is distributed on an \"AS IS\" BASIS,\n // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n // See the License for the specific language governing permissions and\n // limitations under the License.\n package shopping.merchant.samples.accounts.checkoutsettings.v1;\n\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.protobuf.FieldMask;\n import com.google.shopping.merchant.accounts.v1.CheckoutSettings;\n import com.google.shopping.merchant.accounts.v1.CheckoutSettingsName;\n import com.google.shopping.merchant.accounts.v1.CheckoutSettingsServiceClient;\n import com.google.shopping.merchant.accounts.v1.CheckoutSettingsServiceSettings;\n import com.google.shopping.merchant.accounts.v1.UpdateCheckoutSettingsRequest;\n import com.google.shopping.merchant.accounts.v1.UriSettings;\n import com.google.shopping.type.Destination.DestinationEnum;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /**\n * This class demonstrates how to update the checkout settings for a given Merchant Center account\n */\n public class UpdateCheckoutSettingsSample {\n public static void updateBusinessInfo(Config config) throws Exception {\n // Obtains OAuth token based on the user's configuration.\n GoogleCredentials credential = new Authenticator().authenticate();\n\n // Creates service settings using the credentials retrieved above.\n CheckoutSettingsServiceSettings checkoutSettingsServiceSettings =\n CheckoutSettingsServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n try (CheckoutSettingsServiceClient checkoutSettingsServiceClient =\n CheckoutSettingsServiceClient.create(checkoutSettingsServiceSettings)) {\n String accountId = config.getAccountId().toString();\n // The only valid programId for checkout settings is \"checkout\"\n String programId = \"checkout\";\n String name =\n CheckoutSettingsName.newBuilder()\n .setAccount(accountId)\n .setProgram(programId)\n .build()\n .toString();\n // Replace this with your checkout URL.\n String checkoutUrl = \"https://myshopify.com/cart/1234:1\";\n CheckoutSettings checkoutSettings =\n CheckoutSettings.newBuilder()\n .setName(name)\n .setUriSettings(UriSettings.newBuilder().setCheckoutUriTemplate(checkoutUrl))\n .addEligibleDestinations(DestinationEnum.SHOPPING_ADS)\n .build();\n FieldMask fieldMask =\n FieldMask.newBuilder().addPaths(\"uri_settings\").addPaths(\"eligible_destinations\").build();\n UpdateCheckoutSettingsRequest request =\n UpdateCheckoutSettingsRequest.newBuilder()\n .setCheckoutSettings(checkoutSettings)\n .setUpdateMask(fieldMask)\n .build();\n\n System.out.println(\"Sending update checkoutSettings request:\");\n CheckoutSettings response = checkoutSettingsServiceClient.updateCheckoutSettings(request);\n\n System.out.println(\"Updated Checkout Settings below:\");\n System.out.println(response);\n } catch (Exception e) {\n System.out.println(\"An error has occurred: \");\n System.out.println(e);\n }\n }\n\n public static void main(String[] args) throws Exception {\n Config config = Config.load();\n\n updateBusinessInfo(config);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/accounts/checkoutsettings/v1/UpdateCheckoutSettingsSample.java\n\n### PHP\n\n\n \u003c?php\n /**\n * Copyright 2025 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n require_once __DIR__ . '/../../../../vendor/autoload.php';\n require_once __DIR__ . '/../../../Authentication/Authentication.php';\n require_once __DIR__ . '/../../../Authentication/Config.php';\n\n use Google\\ApiCore\\ApiException;\n use Google\\Protobuf\\FieldMask;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\CheckoutSettings;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\Client\\CheckoutSettingsServiceClient;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\UpdateCheckoutSettingsRequest;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\UriSettings;\n use Google\\Shopping\\Type\\Destination\\DestinationEnum;\n\n /**\n * This class demonstrates how to update the checkout settings for a given\n * Merchant Center account.\n */\n class UpdateCheckoutSettingsSample\n {\n /**\n * Updates the checkout settings for a given Merchant Center account.\n *\n * @param array $config The configuration file for the Merchant Center account.\n *\n * @return void\n */\n public static function updateCheckoutSettings(array $config): void\n {\n // Obtains OAuth credentials from the configuration file.\n $credentials = Authentication::useServiceAccountOrTokenFile();\n\n // Creates a client.\n $checkoutSettingsServiceClient = new CheckoutSettingsServiceClient([\n 'credentials' =\u003e $credentials\n ]);\n\n // The only valid programId for checkout settings is \"checkout\".\n $programId = 'checkout';\n\n // Constructs the resource name format:\n // `accounts/{account}/programs/{program}/checkoutSettings`.\n $name = sprintf(\n 'accounts/%s/programs/%s/checkoutSettings',\n $config['accountId'],\n $programId\n );\n\n // Replace this with your checkout URL.\n $checkoutUrl = 'https://myshopify.com/cart/1234:1';\n\n // Creates the URI settings with the checkout URL.\n $uriSettings = new UriSettings([\n 'checkout_uri_template' =\u003e $checkoutUrl\n ]);\n\n // Creates the checkout settings with the name, URI settings, and\n // eligible destinations. The name is required for an update.\n $checkoutSettings = new CheckoutSettings([\n 'name' =\u003e $name,\n 'uri_settings' =\u003e $uriSettings,\n 'eligible_destinations' =\u003e [DestinationEnum::SHOPPING_ADS]\n ]);\n\n // Creates a field mask to specify which fields to update.\n $fieldMask = new FieldMask([\n 'paths' =\u003e ['uri_settings', 'eligible_destinations']\n ]);\n\n // Creates the request object.\n $request = (new UpdateCheckoutSettingsRequest())\n -\u003esetCheckoutSettings($checkoutSettings)\n -\u003esetUpdateMask($fieldMask);\n\n // Calls the API and catches and prints any network failures/errors.\n try {\n printf(\"Sending update checkoutSettings request:%s\", PHP_EOL);\n $response = $checkoutSettingsServiceClient-\u003eupdateCheckoutSettings($request);\n printf(\"Updated Checkout Settings below:%s\", PHP_EOL);\n print $response-\u003eserializeToJsonString(true) . PHP_EOL;\n } catch (ApiException $e) {\n printf(\"An error has occurred: %s\", PHP_EOL);\n print $e-\u003egetMessage();\n }\n }\n\n /**\n * Executes the sample.\n *\n * @return void\n */\n public function callSample(): void\n {\n $config = Config::generateConfig();\n self::updateCheckoutSettings($config);\n }\n }\n\n // Runs the sample.\n $sample = new UpdateCheckoutSettingsSample();\n $sample-\u003ecallSample(); \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/php/examples/accounts/checkoutsettings/v1/UpdateCheckoutSettingsSample.php"]]