Để sử dụng Merchant Center và các tính năng của Merchant Center, bạn phải chấp nhận Điều khoản dịch vụ (ToS) của Merchant Center cho vị trí doanh nghiệp của mình. Các thoả thuận này nêu rõ các điều khoản pháp lý để sử dụng dịch vụ của Merchant Center.
Hướng dẫn này giải thích cách bạn có thể sử dụng Merchant API để quản lý các thoả thuận này, cho dù là cho tài khoản của riêng bạn hay cho những tài khoản mà bạn quản lý với tư cách là nhà cung cấp bên thứ ba (3P).
Bạn có thể đạt được những điều sau:
- Kiểm tra trạng thái thoả thuận hiện tại về Điều khoản dịch vụ của một tài khoản.
- Hướng dẫn người bán chấp nhận Điều khoản dịch vụ cần thiết.
- Quản lý Điều khoản dịch vụ với tư cách là nhà cung cấp bên thứ ba cho tài khoản khách hàng hoặc tài khoản độc lập.
Điều kiện tiên quyết
Để sử dụng Merchant API, bạn cần có tài khoản Merchant Center. Sau khi tạo tài khoản bằng giao diện người dùng (UI) của Merchant Center, bạn có thể thay đổi tài khoản (chẳng hạn như cập nhật thông tin doanh nghiệp, quản lý người dùng, v.v.) bằng giao diện người dùng hoặc API.
Nếu cần quản lý nhiều tài khoản, bạn có thể tạo tài khoản khách hàng bằng Merchant API. Xem phần Tạo và quản lý tài khoản phụ.
Kiểm tra trạng thái thoả thuận về Điều khoản dịch vụ của tài khoản
Trước khi người bán có thể khai thác tối đa Merchant Center hoặc nếu bạn cần xác minh trạng thái thoả thuận hiện tại của họ, bạn có thể truy xuất trạng thái thoả thuận Điều khoản dịch vụ của họ.
Sử dụng phương thức termsOfServiceAgreementStates.retrieveForApplication
để nhận trạng thái thoả thuận về Điều khoản dịch vụ cho ứng dụng Merchant Center cốt lõi.
Phương thức này trả về Điều khoản dịch vụ hiện tại của bạn (nếu có) và nếu Điều khoản dịch vụ đã được cập nhật kể từ lần chấp nhận gần đây nhất của bạn, thì phương thức này sẽ trả về phiên bản mới nhất mà bạn cần chấp nhận.
Sau đây là một yêu cầu mẫu:
GET https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}/termsOfServiceAgreementStates:retrieveForApplication
Lệnh gọi thành công sẽ trả về một tài nguyên TermsOfServiceAgreementState
. Tài nguyên này chứa:
name
: Giá trị nhận dạng cho trạng thái thoả thuận này.regionCode
: Quốc gia mà trạng thái thoả thuận này áp dụng, thường là quốc gia nơi doanh nghiệp của tài khoản hoạt động.termsOfServiceKind
: Giá trị này sẽ làMERCHANT_CENTER
.accepted
: Thông tin chi tiết về phiên bản Điều khoản dịch vụ mà tài khoản đã chấp nhận, bao gồm cả tên tài nguyêntermsOfService
(chẳng hạn nhưtermsOfService/132
) và người đãacceptedBy
. Thông báo này cũng có thể bao gồm ngàyvalidUntil
nếu có phiên bản Điều khoản dịch vụ mới hơnrequired
.required
: Thông tin chi tiết về một phiên bản Điều khoản dịch vụ mà tài khoản phải chấp nhận. Điều này bao gồm tên tài nguyêntermsOfService
vàtosFileUri
trỏ đến tài liệu Điều khoản dịch vụ mà con người có thể đọc được.
Ví dụ về câu trả lời:
{
"name": "accounts/{ACCOUNT_ID}/termsOfServiceAgreementStates/MERCHANT_CENTER-{REGION_CODE}",
"regionCode": "{REGION_CODE}",
"termsOfServiceKind": "MERCHANT_CENTER",
"accepted": {
"termsOfService": "termsOfService/132",
"acceptedBy": "accounts/{ACCOUNT_ID}"
},
"required": {
"termsOfService": "termsOfService/132",
"tosFileUri": "https://www.google.com/intl/{REGION_CODE}/policies/merchants/terms/"
}
}
Nếu có Điều khoản dịch vụ mới required
, bạn nên hướng dẫn người bán chấp nhận điều khoản đó.
Sau đây là mẫu bạn có thể dùng để truy xuất trạng thái thoả thuận về Điều khoản dịch vụ cho một tài khoản và quốc gia cụ thể:
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.GetTermsOfServiceAgreementStateRequest;
import com.google.shopping.merchant.accounts.v1beta.TermsOfServiceAgreementState;
import com.google.shopping.merchant.accounts.v1beta.TermsOfServiceAgreementStateName;
import com.google.shopping.merchant.accounts.v1beta.TermsOfServiceAgreementStateServiceClient;
import com.google.shopping.merchant.accounts.v1beta.TermsOfServiceAgreementStateServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/**
* This class demonstrates how to get a TermsOfServiceAgreementState for a specific
* TermsOfServiceKind and country.
*/
public class GetTermsOfServiceAgreementStateSample {
public static void getTermsOfServiceAgreementState(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.
TermsOfServiceAgreementStateServiceSettings termsOfServiceAgreementStateServiceSettings =
TermsOfServiceAgreementStateServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates TermsOfServiceAgreementState name to identify TermsOfServiceAgreementState.
String name =
TermsOfServiceAgreementStateName.newBuilder()
.setAccount(config.getAccountId().toString())
// The Identifier is: "{TermsOfServiceKind}-{country}"
.setIdentifier("MERCHANT_CENTER-US")
.build()
.toString();
System.out.println(name);
// Calls the API and catches and prints any network failures/errors.
try (TermsOfServiceAgreementStateServiceClient termsOfServiceAgreementStateServiceClient =
TermsOfServiceAgreementStateServiceClient.create(
termsOfServiceAgreementStateServiceSettings)) {
// The name has the format:
// accounts/{account}/termsOfServiceAgreementStates/{TermsOfServiceKind}-{country}
GetTermsOfServiceAgreementStateRequest request =
GetTermsOfServiceAgreementStateRequest.newBuilder().setName(name).build();
System.out.println("Sending Get TermsOfServiceAgreementState request:");
TermsOfServiceAgreementState response =
termsOfServiceAgreementStateServiceClient.getTermsOfServiceAgreementState(request);
System.out.println("Retrieved TermsOfServiceAgreementState below");
// If the terms of service needs to be accepted, the "required" field will include the
// specific version of the terms of service which needs to be accepted, alongside a link to
// the terms of service itself.
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
getTermsOfServiceAgreementState(config);
}
}
PHP
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1beta\Client\TermsOfServiceAgreementStateServiceClient;
use Google\Shopping\Merchant\Accounts\V1beta\GetTermsOfServiceAgreementStateRequest;
/**
* Demonstrates how to get a TermsOfServiceAgreementState.
*/
class GetTermsOfServiceAgreementState
{
/**
* Gets a TermsOfServiceAgreementState.
*
* @param array $config The configuration data.
* @return void
*/
public static function getTermsOfServiceAgreementState($config): void
{
// Get OAuth credentials.
$credentials = Authentication::useServiceAccountOrTokenFile();
// Create client options.
$options = ['credentials' => $credentials];
// Create a TermsOfServiceAgreementStateServiceClient.
$termsOfServiceAgreementStateServiceClient = new TermsOfServiceAgreementStateServiceClient($options);
// Service agreeement identifier
$identifier = "MERCHANT_CENTER-US";
// Create TermsOfServiceAgreementState name.
$name = "accounts/" . $config['accountId'] . "/termsOfServiceAgreementStates/" . $identifier;
print $name . PHP_EOL;
try {
// Prepare the request.
$request = new GetTermsOfServiceAgreementStateRequest([
'name' => $name,
]);
print "Sending Get TermsOfServiceAgreementState request:" . PHP_EOL;
$response = $termsOfServiceAgreementStateServiceClient->getTermsOfServiceAgreementState($request);
print "Retrieved TermsOfServiceAgreementState below\n";
print $response->serializeToJsonString() . PHP_EOL;
} catch (ApiException $e) {
print $e->getMessage();
}
}
/**
* Helper to execute the sample.
*
* @return void
*/
public function callSample(): void
{
$config = Config::generateConfig();
self::getTermsOfServiceAgreementState($config);
}
}
// Run the script
$sample = new GetTermsOfServiceAgreementState();
$sample->callSample();
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1beta import GetTermsOfServiceAgreementStateRequest
from google.shopping.merchant_accounts_v1beta import TermsOfServiceAgreementStateServiceClient
# Replace with your actual value.
_ACCOUNT_ID = configuration.Configuration().read_merchant_info()
_IDENTIFIER = "MERCHANT_CENTER-US" # Replace with your identifier
def get_terms_of_service_agreement_state():
"""Gets a TermsOfServiceAgreementState for a specific TermsOfServiceKind and country."""
credentials = generate_user_credentials.main()
client = TermsOfServiceAgreementStateServiceClient(credentials=credentials)
name = (
"accounts/"
+ _ACCOUNT_ID
+ "/termsOfServiceAgreementStates/"
+ _IDENTIFIER
)
print(name)
request = GetTermsOfServiceAgreementStateRequest(name=name)
try:
print("Sending Get TermsOfServiceAgreementState request:")
response = client.get_terms_of_service_agreement_state(request=request)
print("Retrieved TermsOfServiceAgreementState below")
print(response)
except RuntimeError as e:
print(e)
if __name__ == "__main__":
get_terms_of_service_agreement_state()
Chấp nhận Điều khoản dịch vụ
Người bán phải chấp nhận Điều khoản dịch vụ mới nhất để duy trì quyền sử dụng các tính năng của Merchant Center.
Chấp nhận Điều khoản dịch vụ cho tài khoản của riêng bạn
Nếu bạn đang quản lý tài khoản Merchant Center của riêng mình, hãy làm như sau:
- Gọi
termsOfServiceAgreementStates.retrieveForApplication
để xác định xem có Điều khoản dịch vụ nào làrequired
hay không. - Nếu cần có Điều khoản dịch vụ, hãy lưu ý tên
termsOfService
trong trườngrequired
(chẳng hạn nhưtermsOfService/132
). Gọi
termsOfService.accept
để chấp nhận Điều khoản dịch vụ. Bạn sẽ cần tên ToS,ACCOUNT_ID
vàregionCode
do retrieveForApplication trả về.Sau đây là một yêu cầu mẫu:
POST https://merchantapi.googleapis.com/accounts/v1beta/{name={termsOfService/VERSION}}:accept { "account": "accounts/{ACCOUNT_ID}", "regionCode": "{REGION_CODE}" }
Một lệnh gọi thành công sẽ trả về một phần nội dung phản hồi trống và cập nhật trạng thái thoả thuận Điều khoản dịch vụ của tài khoản.
Hướng dẫn người bán chấp nhận Điều khoản dịch vụ (đối với nhà cung cấp bên thứ ba)
Nếu là nhà cung cấp bên thứ ba (3P) quản lý các tài khoản Merchant Center độc lập cho các doanh nghiệp khác, bạn không được thay mặt họ chấp nhận Điều khoản dịch vụ. Thay vào đó, bạn nên:
Truy xuất Điều khoản dịch vụ mới nhất: Gọi
termsOfService.retrieveLatest
cho loạiregionCode
vàMERCHANT_CENTER
của người bán để nhận thông tin chi tiết về phiên bản Điều khoản dịch vụ mới nhất mà họ có thể cần chấp nhận.Yêu cầu mẫu:
GET https://merchantapi.googleapis.com/accounts/v1beta/termsOfService:retrieveLatest?regionCode={REGION_CODE}&kind=MERCHANT_CENTER
Phản hồi mẫu:
{ "name": "{termsOfService/VERSION}", "regionCode": "{REGION_CODE}", "kind": "MERCHANT_CENTER", "fileUri": "https://www.google.com/intl/{REGION_CODE}/policies/merchants/terms/" }
Hiển thị Điều khoản dịch vụ: Sử dụng
fileUri
trong phản hồi để hiển thị toàn bộ văn bản của Điều khoản dịch vụ cho người bán trong giao diện người dùng của ứng dụng.Nhận được sự chấp nhận của người bán: Người bán phải đồng ý rõ ràng với các điều khoản trong giao diện người dùng của bạn.
Ghi lại việc chấp nhận bằng API: Sau khi người bán chấp nhận, hãy gọi
termsOfService.accept
bằngname
của Điều khoản dịch vụ nhận được ở bước 1,ACCOUNT_ID
của người bán vàregionCode
của họ.Yêu cầu mẫu:
POST https://merchantapi.googleapis.com/accounts/v1beta/{name={termsOfService/VERSION}}:accept { "account": "accounts/{MERCHANT_ACCOUNT_ID}", "regionCode": "{REGION_CODE}" }
Sau đây là mẫu bạn có thể dùng để chấp nhận thoả thuận Điều khoản dịch vụ cho một tài khoản nhất định (sau khi người bán đã đồng ý):
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.AcceptTermsOfServiceRequest;
import com.google.shopping.merchant.accounts.v1beta.TermsOfServiceServiceClient;
import com.google.shopping.merchant.accounts.v1beta.TermsOfServiceServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to accept the TermsOfService agreement in a given account. */
public class AcceptTermsOfServiceSample {
public static void acceptTermsOfService(String accountId, String tosVersion, String regionCode)
throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
TermsOfServiceServiceSettings tosServiceSettings =
TermsOfServiceServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Calls the API and catches and prints any network failures/errors.
try (TermsOfServiceServiceClient tosServiceClient =
TermsOfServiceServiceClient.create(tosServiceSettings)) {
// The parent has the format: accounts/{account}
AcceptTermsOfServiceRequest request =
AcceptTermsOfServiceRequest.newBuilder()
.setName(String.format("termsOfService/%s", tosVersion))
.setAccount(String.format("accounts/%s", accountId))
.setRegionCode(regionCode)
.build();
System.out.println("Sending request to accept terms of service...");
tosServiceClient.acceptTermsOfService(request);
System.out.println("Successfully accepted terms of service.");
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// See GetTermsOfServiceAgreementStateSample to understand how to check which version of the
// terms of service needs to be accepted, if any.
// Likewise, if you know that the terms of service needs to be accepted, you can also simply
// call RetrieveLatestTermsOfService to get the latest version of the terms of service.
// Region code is either a country when the ToS applies specifically to that country or 001 when
// it applies globally.
acceptTermsOfService(config.getAccountId().toString(), "VERSION_HERE", "REGION_CODE_HERE");
}
}
PHP
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1beta\AcceptTermsOfServiceRequest;
use Google\Shopping\Merchant\Accounts\V1beta\Client\TermsOfServiceServiceClient;
/**
* Demonstrates how to accept the TermsOfService agreement in a given account.
*/
class AcceptTermsOfService
{
/**
* Accepts the Terms of Service agreement.
*
* @param string $accountId The account ID.
* @param string $tosVersion The Terms of Service version.
* @param string $regionCode The region code.
* @return void
*/
public static function acceptTermsOfService($accountId, $tosVersion, $regionCode): void
{
// Get OAuth credentials.
$credentials = Authentication::useServiceAccountOrTokenFile();
// Create client options.
$options = ['credentials' => $credentials];
// Create a TermsOfServiceServiceClient.
$tosServiceClient = new TermsOfServiceServiceClient($options);
try {
// Prepare the request.
$request = new AcceptTermsOfServiceRequest([
'name' => sprintf("termsOfService/%s", $tosVersion),
'account' => sprintf("accounts/%s", $accountId),
'region_code' => $regionCode,
]);
print "Sending request to accept terms of service...\n";
$tosServiceClient->acceptTermsOfService($request);
print "Successfully accepted terms of service.\n";
} catch (ApiException $e) {
print $e->getMessage();
}
}
/**
* Helper to execute the sample.
*
* @return void
*/
public function callSample(): void
{
$config = Config::generateConfig();
// Replace with actual values.
$tosVersion = "132";
$regionCode = "US";
self::acceptTermsOfService($config['accountId'], $tosVersion, $regionCode);
}
}
// Run the script
$sample = new AcceptTermsOfService();
$sample->callSample();
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1beta import AcceptTermsOfServiceRequest
from google.shopping.merchant_accounts_v1beta import TermsOfServiceServiceClient
# Replace with your actual values.
_ACCOUNT_ID = configuration.Configuration().read_merchant_info()
_TOS_VERSION = ( # Replace with the Terms of Service version to accept
"VERSION_HERE"
)
_REGION_CODE = "US" # Replace with the region code
def accept_terms_of_service():
"""Accepts the Terms of Service agreement for a given account."""
credentials = generate_user_credentials.main()
client = TermsOfServiceServiceClient(credentials=credentials)
# Construct the request
request = AcceptTermsOfServiceRequest(
name=f"termsOfService/{_TOS_VERSION}",
account=f"accounts/{_ACCOUNT_ID}",
region_code=_REGION_CODE,
)
try:
print("Sending request to accept terms of service...")
client.accept_terms_of_service(request=request)
print("Successfully accepted terms of service.")
except RuntimeError as e:
print(e)
if __name__ == "__main__":
accept_terms_of_service()
Các điểm cần đặc biệt lưu ý dành cho nhà cung cấp bên thứ ba
Là nhà cung cấp bên thứ ba, bạn có thể quản lý Điều khoản dịch vụ cho tài khoản khách hàng hoặc tài khoản độc lập.
Quản lý Điều khoản dịch vụ cho tài khoản khách hàng
Nếu bạn điều hành một tài khoản nâng cao và tạo tài khoản khách hàng cho nhiều doanh nghiệp:
- Chấp nhận tài khoản nâng cao: Nếu một tài khoản nâng cao cung cấp dịch vụ tổng hợp tài khoản cho các tài khoản khách hàng, thì Điều khoản dịch vụ mà tài khoản nâng cao chấp nhận cũng sẽ áp dụng cho tất cả các tài khoản khách hàng của tài khoản đó có dịch vụ đó.
- Hiển thị và đồng ý: Ngay cả khi việc chấp nhận của tài khoản nâng cao bao gồm cả tài khoản khách hàng, bạn nên (và có thể là yêu cầu pháp lý) hiển thị Điều khoản dịch vụ có liên quan của Google Merchant Center cho chủ sở hữu doanh nghiệp thực tế của từng tài khoản khách hàng. Bạn phải có được sự đồng ý rõ ràng của họ rằng họ hiểu và đồng ý với các điều khoản này, ngay cả khi lệnh gọi API để chấp nhận được thực hiện ở cấp tài khoản nâng cao.
- Kiểm tra trạng thái tài khoản khách hàng: Sử dụng
termsOfServiceAgreementStates.retrieveForApplication
trên một tài khoản khách hàng cụ thể để xác minh trạng thái Điều khoản dịch vụ của tài khoản đó và xem tài khoản đó có thuộc phạm vi thoả thuận của tài khoản nâng cao hay không hoặc có cần thực hiện hành động trực tiếp nào hay không.
Quản lý Điều khoản dịch vụ cho tài khoản độc lập
Như được nêu chi tiết trong bài viết Hướng dẫn người bán chấp nhận Điều khoản dịch vụ, khi bạn hỗ trợ một doanh nghiệp tạo hoặc quản lý tài khoản Merchant Center độc lập, doanh nghiệp đó (chủ sở hữu tài khoản) phải tự mình chấp nhận Điều khoản dịch vụ. Bạn có thể tạo điều kiện cho việc này bằng cách truy xuất và hiển thị Điều khoản dịch vụ, sau đó gọi phương thức termsOfService.accept
thay cho họ sau khi họ đã đưa ra sự đồng ý rõ ràng thông qua giao diện của bạn.