Tạo và quản lý tài khoản phụ

Trong Merchant API, tài khoản nâng cao có thể có mối quan hệ tài khoản phụ với một tài khoản khác. Tài khoản phụ giúp những doanh nghiệp quản lý nhiều người bán và miền ở quy mô lớn, chẳng hạn như các nhà bán lẻ hoạt động ở nhiều quốc gia. Để biết những loại hình doanh nghiệp đủ điều kiện sử dụng tài khoản nâng cao, hãy xem bài viết Những công ty đủ điều kiện sử dụng chế độ cài đặt tài khoản nâng cao.

Bạn có thể sử dụng Merchant Accounts API để tạo tài khoản phụ mới trong tài khoản nâng cao. Bạn phải có tài khoản nâng cao hiện tại để thực hiện lệnh gọi này. Bạn không thể sử dụng Merchant API để di chuyển các tài khoản người bán độc lập hiện có trong tài khoản của mình.

Để chuyển đổi tài khoản Merchant Center thành tài khoản nâng cao, bạn phải là quản trị viên tài khoản. Bạn cũng phải đảm bảo rằng tài khoản của mình không có vấn đề nào đang chờ xử lý. Để biết thông tin về cách yêu cầu tài khoản nâng cao, hãy xem bài viết Yêu cầu chế độ thiết lập tài khoản nâng cao.

Nhà cung cấp bên thứ ba có thể sử dụng API Tài khoản người bán để phát triển một giao diện cho phép người bán tạo và quản lý thông tin tài khoản của họ.

Tạo tài khoản phụ

Để tạo tài khoản phụ mới trong tài khoản nâng cao, hãy gọi accounts.createAndConfigure:

  1. Cung cấp thông tin chi tiết về tài khoản phụ trong trường account.
  2. Chỉ định mọi người dùng được uỷ quyền mới trong trường users. Quyền truy cập của người dùng cũng được kế thừa từ tài khoản mẹ.
  3. Chỉ định accountAggregation trong trường service.

    Dưới đây là ví dụ về cách tạo tài khoản phụ trong tài khoản account/123. Đây là tài khoản tổng hợp cho tài khoản phụ:

    POST https://merchantapi.googleapis.com/accounts/v1beta/accounts:createAndConfigure
    
    {
      "account": {
        "accountName": "merchantStore",
        "adultContent": false,
        "testAccount": false,
        "timeZone": {
          "id": "America/New_York",
        }
        "languageCode": "en-US",
      },
      "service": [
        {
          "accountAggregation": {},
          "provider": "providers/123"
        }
      ]
    }
    

Mẫu sau đây minh hoạ cách bạn có thể sử dụng gói CreateAndConfigureAccountRequest để tạo một tài khoản phụ mới.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.Account;
import com.google.shopping.merchant.accounts.v1beta.AccountAggregation;
import com.google.shopping.merchant.accounts.v1beta.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1beta.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1beta.CreateAndConfigureAccountRequest;
import com.google.shopping.merchant.accounts.v1beta.CreateAndConfigureAccountRequest.AddAccountService;
import com.google.type.TimeZone;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to create a sub-account under an MCA account. */
public class CreateSubAccountSample {

  private static String getParent(String accountId) {
    return String.format("accounts/%s", accountId);
  }

  public static void createSubAccount(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.
    AccountsServiceSettings accountsServiceSettings =
        AccountsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates parent/provider to identify the MCA account into which to insert the subaccount.
    String parent = getParent(config.getAccountId().toString());

    // Calls the API and catches and prints any network failures/errors.
    try (AccountsServiceClient accountsServiceClient =
        AccountsServiceClient.create(accountsServiceSettings)) {

      CreateAndConfigureAccountRequest request =
          CreateAndConfigureAccountRequest.newBuilder()
              .setAccount(
                  Account.newBuilder()
                      .setAccountName("Demo Business")
                      .setAdultContent(false)
                      .setTimeZone(TimeZone.newBuilder().setId("America/New_York").build())
                      .setLanguageCode("en-US")
                      .build())
              .addService(
                  AddAccountService.newBuilder()
                      .setProvider(parent)
                      .setAccountAggregation(AccountAggregation.getDefaultInstance())
                      .build())
              .build();

      System.out.println("Sending Create SubAccount request");
      Account response = accountsServiceClient.createAndConfigureAccount(request);
      System.out.println("Inserted Account Name below");
      // Format: `accounts/{account}
      System.out.println(response.getName());
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    createSubAccount(config);
  }
}

Truy xuất tài khoản phụ

Để liệt kê tất cả tài khoản phụ cho một tài khoản nhiều khách hàng nhất định, hãy sử dụng phương thức accounts.listSubaccounts.

Sau đây là một yêu cầu mẫu:

GET https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}:listSubaccounts

Dưới đây là phản hồi mẫu từ một lệnh gọi thành công:

{
  "accounts": [
    {
      "name": "accounts/{ACCOUNT_ID}",
      "accountId": "{ACCOUNT_ID}",
      "accountName": "{ACCOUNT_NAME}",
      "timeZone": {
        "id": "America/Los_Angeles"
      },
      "languageCode": "en-US"
    },
    {
      "name": "accounts/{ACCOUNT_ID}",
      "accountId": "{ACCOUNT_ID}",
      "accountName": "{ACCOUNT_NAME}",
      "timeZone": {
        "id": "America/Los_Angeles"
      },
      "languageCode": "en-US"
    }
  ]
}

Xoá tài khoản phụ

Để xoá tài khoản phụ, hãy sử dụng phương thức accounts.delete. Bạn cần có quyền quản trị để thực thi phương thức này.

Sau đây là một yêu cầu mẫu:

DELETE https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}

Nếu thành công, nội dung phản hồi sẽ là một đối tượng JSON trống.

Chấp nhận Điều khoản dịch vụ

Tài khoản phụ kế thừa Điều khoản dịch vụ (TOS) của Merchant Center mà tài khoản chính đã ký.

Cập nhật thông tin doanh nghiệp

Bạn có thể sử dụng Merchant Accounts API để chỉnh sửa thông tin doanh nghiệp.