فلترة الحسابات التي يمكنك الوصول إليها

يمكنك استخدام Merchant Accounts API لعرض قائمة مُفلترة بالحسابات التي يمكنك الوصول إليها، بما في ذلك الحسابات الفرعية. يمكنك الفلترة حسب الأسماء المعروضة والعلاقات بالحسابات الأخرى. على سبيل المثال، يمكنك الفلترة حسب الحسابات التي تحتوي على أسماء معروضة تتضمّن السلسلة "store"، والتي تتضمّن أيضًا حالة ربط PENDING، للاطّلاع على كل متاجرك التي لم تقبل طلب ربط حساب حتى الآن.

للاطّلاع على جميع حساباتك الفرعية، اتصل على الرقم accounts.v1beta.accounts.listSubAccounts.

لعرض قائمة مفلتَرة بجميع الحسابات التي يمكنك الوصول إليها، بما في ذلك الحسابات الفرعية وأي حسابات تم فيها منحك دور User، اتصل بالرقم accounts.v1beta.accounts.list وحدِّد معايير الفلترة في حقل filter.

لمعرفة التفاصيل حول بنية حقل filter، يُرجى الاطّلاع على مرجع بنية الفلتر.

في ما يلي أنواع الفلاتر التي يمكنك استخدامها:

فلاتر الحسابات

يمكنك استخدام الحقول التالية للفلترة على مستوى account:

  • accountName: الفلترة حسب accountName لمصدر account
  • relationship(...): الفلاتر حسب نوع العلاقة التي يربطها الحساب بحساب آخر يمكنك تضمين فلاتر relationship(...) متعددة في طلب واحد.

فلاتر العلاقات

يمكنك استخدام الدالة relationship(...) للفلترة استنادًا إلى المعايير التالية:

  • providerId: معرّف التاجر لمقدّم الخدمة. على سبيل المثال، إذا كان ينبغي أن يعرض المحاولة الفلتر فقط الحسابات التي توفّر خدمة يوفّرها account/123، استخدِم providerId = 123.
  • accountIdAlias: الاسم المعرِّف لرقم تعريف الحساب الذي تم ضبطه للعلاقة.
  • service(...): الخدمة التي يتم تقديمها كجزء من العلاقة يمكنك تضمين عدة دوال service(...) في دالة relationship(...) واحدة.

فلاتر الخدمة

يمكنك استخدام دالة service(...) لإجراء المزيد من الفلترة للحسابات استنادًا إلى حالة علاقاتها وأنواع الخدمات التي تقدّمها تلك العلاقات:

  • externalAccountId: رقم تعريف الحساب الخارجي لمقدّم الخدمة للحساب الذي يقدّم له خدمة.
  • handshakeState: حالة اتفاقية الخدمة بين حسابَين تقبل القيم التالية:
    • PENDING
    • APPROVED
  • type: نوع الخدمة التي يوفّرها مقدّم الخدمة تقبل القيم التالية:
    • ACCOUNT_MANAGEMENT يدير مقدّم الخدمة الحساب.
    • ACCOUNT_AGGREGATION الموفّر هو عارض للحساب.

أمثلة

في ما يلي بعض الأمثلة على الفلاتر التي يمكنك تجربتها.

فلترة الحسابات التي تحتوي على أسماء معروضة تتضمّن "متجر" ومقدّمي الخدمات الذين لديهم رقم التعريف "123":

accountName = "*store*" AND relationship(providerId = 123)

فلترة جميع الحسابات الفرعية للحساب "123":

relationship(providerId = 123 AND service(type = "ACCOUNT_AGGREGATION"))

فلترة الحسابات التي تتضمّن خدمات إدارة حسابات موافَق عليها:

relationship(service(handshakeState = "APPROVED" AND type = "ACCOUNT_MANAGEMENT"))

فلترة الحسابات التي تتضمّن علاقة لها عنوان بديل محدّد وتكون العلاقة مرتبطة بخدمة لها معرّف حساب خارجي محدّد

relationship(accountIdAlias = "alias" AND service(externalAccountId = "extAcctId"))

يوضّح المثال التالي كيفية استخدام حزمة ListAccountsRequest لاسترداد قائمة مفلتَرة للحسابات.

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.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1beta.AccountsServiceClient.ListAccountsPagedResponse;
import com.google.shopping.merchant.accounts.v1beta.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1beta.ListAccountsRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to filter the accounts the user making the request has access to. */
public class FilterAccountsSample {

  public static void filterAccounts(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();

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

      // Filter for accounts with display names containing "store" and a provider with the ID "123":
      String filter = "accountName = \"*store*\" AND relationship(providerId = 123)";

      // Filter for all subaccounts of account "123":
      // String filter2 = "relationship(providerId = 123 AND service(type =
      // \"ACCOUNT_AGGREGATION\"))";

      // String filter3 = "relationship(service(handshakeState = \"APPROVED\" AND type =
      // \"ACCOUNT_MANAGEMENT\") AND providerId = 123)";

      ListAccountsRequest request = ListAccountsRequest.newBuilder().setFilter(filter).build();

      System.out.println("Sending list accounts request with filter:");
      ListAccountsPagedResponse response = accountsServiceClient.listAccounts(request);

      int count = 0;

      // Iterates over all rows in all pages and prints the sub-account
      // in each row.
      // `response.iterateAll()` automatically uses the `nextPageToken` and recalls the
      // request to fetch all pages of data.
      for (Account account : response.iterateAll()) {
        System.out.println(account);
        count++;
      }
      System.out.print("The following count of elements were returned: ");
      System.out.println(count);
    } catch (Exception e) {
      System.out.println(e);
    }
  }

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

    filterAccounts(config);
  }
}

الخطوات التالية

  • لمزيد من المعلومات عن فلترة الحسابات، يُرجى الاطّلاع على بنية فلترة.