Google Shopping Merchant Loyalty Customers V1 Client - Class LoyaltyCustomerMatchServiceClient (0.1.1)

Reference documentation and code samples for the Google Shopping Merchant Loyalty Customers V1 Client class LoyaltyCustomerMatchServiceClient.

Service Description: Manages customer loyalty program memberships for merchants.

This service allows all merchants, including non-advertisers, to share their first-party customer data of loyalty program members. Google uses this data to personalize organic free listing shopping experiences, in compliance with the Merchant Center Terms of Service.

The service follows a non-standard, imperative pattern, exposing a single ManageLoyaltyCustomerMatch method rather than conventional resource identifiers and CRUD operations. This design protects user privacy by preventing the discovery of a customer's presence or membership status through standard GET or LIST methods.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

Namespace

Google \ Shopping \ Merchant \ LoyaltyCustomers \ V1 \ Client

Methods

__construct

Constructor.

Parameters
Name Description
options array|Google\ApiCore\Options\ClientOptions

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials Google\Auth\FetchAuthTokenInterface|Google\ApiCore\CredentialsWrapper

This option should only be used with a pre-constructed Google\Auth\FetchAuthTokenInterface or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. Important: If you are providing a path to a credentials file, or a decoded credentials file as a PHP array, this usage is now DEPRECATED. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. It is recommended to create the credentials explicitly use Google\Auth\Credentials\ServiceAccountCredentials; use Google\Shopping\Merchant\LoyaltyCustomers\V1\LoyaltyCustomerMatchServiceClient; $creds = new ServiceAccountCredentials($scopes, $json); $options = new LoyaltyCustomerMatchServiceClient(['credentials' => $creds]); https://cloud.google.com/docs/authentication/external/externally-sourced-credentials

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|Google\ApiCore\Transport\TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

↳ logger false|Psr\Log\LoggerInterface

A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 'GOOGLE_SDK_PHP_LOGGING' environment flag

↳ universeDomain string

The service domain for the client. Defaults to 'googleapis.com'.

manageLoyaltyCustomerMatch

Manages (inserts, updates, or removes) a customer's loyalty tier information.

This method serves as a single interface for all changes to a customer's loyalty status. The specific action (insert, update, or remove) is determined by the current state of the merchant-to-customer association and the loyalty_tier value provided in the request.

Operation Logic:

  • Upsert (Insert/Update): Providing any valid tier other than NON_MEMBER will associate the customer with that tier. If an association already exists, it will be updated; otherwise, a new one will be created.
  • Removal: Setting loyalty_tier to NON_MEMBER will remove any existing loyalty association for the customer.

Privacy Note: To protect user privacy, this method consistently returns a 200 OK status with a default LoyaltyCustomer response if the customer's identifier cannot be matched to a Google account or if the user has not opted into loyalty personalization.

The async variant is LoyaltyCustomerMatchServiceClient::manageLoyaltyCustomerMatchAsync() .

Parameters
Name Description
request Google\Shopping\Merchant\LoyaltyCustomers\V1\ManageLoyaltyCustomerMatchRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Shopping\Merchant\LoyaltyCustomers\V1\ManageLoyaltyCustomerMatchResponse
Example
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\LoyaltyCustomers\V1\Client\LoyaltyCustomerMatchServiceClient;
use Google\Shopping\Merchant\LoyaltyCustomers\V1\LoyaltyCustomer;
use Google\Shopping\Merchant\LoyaltyCustomers\V1\LoyaltyCustomer\LoyaltyTier;
use Google\Shopping\Merchant\LoyaltyCustomers\V1\ManageLoyaltyCustomerMatchRequest;
use Google\Shopping\Merchant\LoyaltyCustomers\V1\ManageLoyaltyCustomerMatchResponse;
use Google\Shopping\Merchant\LoyaltyCustomers\V1\UserIdentifier;

/**
 * @param string $formattedParent            The parent account where this loyalty customer will be handled.
 *                                           Format: `accounts/{account}`
 *                                           Please see {@see LoyaltyCustomerMatchServiceClient::accountName()} for help formatting this field.
 * @param int    $loyaltyCustomerLoyaltyTier The tier label of the loyalty tier the customer belongs to.
 */
function manage_loyalty_customer_match_sample(
    string $formattedParent,
    int $loyaltyCustomerLoyaltyTier
): void {
    // Create a client.
    $loyaltyCustomerMatchServiceClient = new LoyaltyCustomerMatchServiceClient();

    // Prepare the request message.
    $loyaltyCustomerUserIdentifier = new UserIdentifier();
    $loyaltyCustomer = (new LoyaltyCustomer())
        ->setUserIdentifier($loyaltyCustomerUserIdentifier)
        ->setLoyaltyTier($loyaltyCustomerLoyaltyTier);
    $request = (new ManageLoyaltyCustomerMatchRequest())
        ->setParent($formattedParent)
        ->setLoyaltyCustomer($loyaltyCustomer);

    // Call the API and handle any network failures.
    try {
        /** @var ManageLoyaltyCustomerMatchResponse $response */
        $response = $loyaltyCustomerMatchServiceClient->manageLoyaltyCustomerMatch($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = LoyaltyCustomerMatchServiceClient::accountName('[ACCOUNT]');
    $loyaltyCustomerLoyaltyTier = LoyaltyTier::LOYALTY_TIER_UNSPECIFIED;

    manage_loyalty_customer_match_sample($formattedParent, $loyaltyCustomerLoyaltyTier);
}

manageLoyaltyCustomerMatchAsync

Parameters
Name Description
request Google\Shopping\Merchant\LoyaltyCustomers\V1\ManageLoyaltyCustomerMatchRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Shopping\Merchant\LoyaltyCustomers\V1\ManageLoyaltyCustomerMatchResponse>

static::accountName

Formats a string containing the fully-qualified path to represent a account resource.

Parameter
Name Description
account string
Returns
Type Description
string The formatted account resource.

static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • account: accounts/{account}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
Name Description
formattedName string

The formatted name string

template ?string

Optional name of template to match

Returns
Type Description
array An associative array from name component IDs to component values.