Tworzenie subkont i zarządzanie nimi

W Merchant API konta zaawansowane mogą mieć relację subkonta z innym kontem. Subkonta ułatwiają zarządzanie wieloma sprzedawcami i domenami na dużą skalę, np. sprzedawcom działającym w wielu krajach. Aby dowiedzieć się, jakie rodzaje firm kwalifikują się do korzystania z konta zaawansowanego, przeczytaj artykuł Firmy, które kwalifikują się do korzystania z zaawansowanych ustawień konta.

Za pomocą interfejsu Merchant Accounts API możesz tworzyć nowe subkonta na swoim koncie zaawansowanym. Aby wykonać to połączenie, musisz mieć konto zaawansowane. Nie możesz używać interfejsu Merchant Center API do przenoszenia dotychczasowych samodzielnych kont sprzedawców na swoje konto.

Aby przekonwertować konto Merchant Center na konto zaawansowane, musisz być administratorem konta. Musisz też sprawdzić, czy na Twoim koncie nie ma żadnych oczekujących problemów. Informacje o tym, jak uzyskać konto zaawansowane, znajdziesz w artykule Prośba o skonfigurowanie konta zaawansowanego.

Dostawcy zewnętrzni mogą używać interfejsu Merchant Accounts API do tworzenia interfejsu, który umożliwia sprzedawcom tworzenie i zarządzanie szczegółami konta.

Tworzenie subkonta

Aby utworzyć nowe subkonto w ramach konta zaawansowanego, zadzwoń do accounts.createAndConfigure:

  1. W polu account podaj dane podrzędnego konta.
  2. W polu users wpisz nowych autoryzowanych użytkowników. Dostęp użytkownika jest również dziedziczony z konta nadrzędnego.
  3. W polu service wpisz accountAggregation.

    Oto przykład tworzenia subkonta na koncie account/123, które jest agregatorem dla subkonta:

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

Ten przykład pokazuje, jak utworzyć nowe podkonto za pomocą pakietu CreateAndConfigureAccountRequest.

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);
  }
}

Pobieranie subkont

Aby wyświetlić listę wszystkich subkont danego multikonta klientów, użyj metody accounts.listSubaccounts.

Oto przykładowa prośba:

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

Oto przykład odpowiedzi po pomyślnym wywołaniu:

{
  "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"
    }
  ]
}

Usuwanie subkonta

Aby usunąć subkonto, użyj metody accounts.delete. Wykonywanie tej metody wymaga dostępu administratora.

Oto przykładowa prośba:

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

W przypadku powodzenia treść odpowiedzi to pusty obiekt JSON.

Zaakceptuj Warunki korzystania z usługi

Subkonta dziedziczą Warunki korzystania z usługi Merchant Center, które zostały zaakceptowane przez konto nadrzędne.

Aktualizowanie informacji o firmie

Za pomocą interfejsu Merchant Accounts API możesz edytować informacje o firmie.