ลบการตั้งค่าการชำระเงิน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ตัวอย่างโค้ด Merchant API เพื่อลบการตั้งค่าการชำระเงิน
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.
package shopping.merchant.samples.accounts.checkoutsettings.v1;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.CheckoutSettingsName;
import com.google.shopping.merchant.accounts.v1.CheckoutSettingsServiceClient;
import com.google.shopping.merchant.accounts.v1.CheckoutSettingsServiceSettings;
import com.google.shopping.merchant.accounts.v1.DeleteCheckoutSettingsRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to delete checkoutSettings fora given Merchant Center account. */
public class DeleteCheckoutSettingsSample {
public static void deleteCheckoutSettings(Config config) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
CheckoutSettingsServiceSettings checkoutSettingsServiceSettings =
CheckoutSettingsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Gets the account ID from the config file.
String accountId = config.getAccountId().toString();
// The only valid programId for checkout settings is "checkout"
String programId = "checkout";
// Creates account name to identify the account.
String name =
CheckoutSettingsName.newBuilder().setAccount(accountId).setProgram(programId).build().toString();
// Calls the API and catches and prints any network failures/errors.
try (CheckoutSettingsServiceClient checkoutSettingsServiceClient =
CheckoutSettingsServiceClient.create(checkoutSettingsServiceSettings)) {
DeleteCheckoutSettingsRequest request =
DeleteCheckoutSettingsRequest.newBuilder().setName(name).build();
System.out.println("Sending Delete Checkout Settings request");
checkoutSettingsServiceClient.deleteCheckoutSettings(
request); // No response returned on success.
System.out.println("Delete successful.");
} catch (Exception e) {
System.out.println("An error has occurred: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
deleteCheckoutSettings(config);
}
}
PHP
<?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\Shopping\Merchant\Accounts\V1\Client\CheckoutSettingsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\DeleteCheckoutSettingsRequest;
/**
* This class demonstrates how to delete checkoutSettings for a given Merchant
* Center account.
*/
class DeleteCheckoutSettingsSample
{
/**
* Deletes 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 deleteCheckoutSettings(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
);
// Creates the request object.
$request = (new DeleteCheckoutSettingsRequest())
->setName($name);
// Calls the API and catches and prints any network failures/errors.
try {
printf("Sending Delete Checkout Settings request%s", PHP_EOL);
// No response returned on success.
$checkoutSettingsServiceClient->deleteCheckoutSettings($request);
printf("Delete successful.%s", 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::deleteCheckoutSettings($config);
}
}
// Runs the sample.
$sample = new DeleteCheckoutSettingsSample();
$sample->callSample();
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-21 UTC
[null,null,["อัปเดตล่าสุด 2025-08-21 UTC"],[],[],null,["# Delete checkout settings\n\nMerchant API code sample to delete 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\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.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.DeleteCheckoutSettingsRequest;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /** This class demonstrates how to delete checkoutSettings fora given Merchant Center account. */\n public class DeleteCheckoutSettingsSample {\n\n public static void deleteCheckoutSettings(Config config) throws Exception {\n\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\n // Gets the account ID from the config file.\n String accountId = config.getAccountId().toString();\n // The only valid programId for checkout settings is \"checkout\"\n String programId = \"checkout\";\n // Creates account name to identify the account.\n String name =\n CheckoutSettingsName.newBuilder().setAccount(accountId).setProgram(programId).build().toString();\n\n // Calls the API and catches and prints any network failures/errors.\n try (CheckoutSettingsServiceClient checkoutSettingsServiceClient =\n CheckoutSettingsServiceClient.create(checkoutSettingsServiceSettings)) {\n DeleteCheckoutSettingsRequest request =\n DeleteCheckoutSettingsRequest.newBuilder().setName(name).build();\n\n System.out.println(\"Sending Delete Checkout Settings request\");\n checkoutSettingsServiceClient.deleteCheckoutSettings(\n request); // No response returned on success.\n System.out.println(\"Delete successful.\");\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 deleteCheckoutSettings(config);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/accounts/checkoutsettings/v1/DeleteCheckoutSettingsSample.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\\Shopping\\Merchant\\Accounts\\V1\\Client\\CheckoutSettingsServiceClient;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\DeleteCheckoutSettingsRequest;\n\n /**\n * This class demonstrates how to delete checkoutSettings for a given Merchant\n * Center account.\n */\n class DeleteCheckoutSettingsSample\n {\n /**\n * Deletes 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 deleteCheckoutSettings(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 // Creates the request object.\n $request = (new DeleteCheckoutSettingsRequest())\n -\u003esetName($name);\n\n // Calls the API and catches and prints any network failures/errors.\n try {\n printf(\"Sending Delete Checkout Settings request%s\", PHP_EOL);\n // No response returned on success.\n $checkoutSettingsServiceClient-\u003edeleteCheckoutSettings($request);\n printf(\"Delete successful.%s\", 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::deleteCheckoutSettings($config);\n }\n }\n\n // Runs the sample.\n $sample = new DeleteCheckoutSettingsSample();\n $sample-\u003ecallSample(); \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/php/examples/accounts/checkoutsettings/v1/DeleteCheckoutSettingsSample.php"]]