Google Cloud Billing V1 Client - Class CloudBillingClient (2.0.0-RC1)

Reference documentation and code samples for the Google Cloud Billing V1 Client class CloudBillingClient.

Service Description: Retrieves the Google Cloud Console billing accounts and associates them with projects.

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 \ Cloud \ Billing \ V1 \ Client

Methods

__construct

Constructor.

Parameters
Name Description
options array

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 string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ 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|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.

createBillingAccount

This method creates billing subaccounts.

Google Cloud resellers should use the Channel Services APIs, accounts.customers.create and accounts.customers.entitlements.create.

When creating a subaccount, the current authenticated user must have the billing.accounts.update IAM permission on the parent account, which is typically given to billing account administrators. This method will return an error if the parent account has not been provisioned for subaccounts.

The async variant is Google\Cloud\Billing\V1\Client\CloudBillingClient::createBillingAccountAsync() .

Parameters
Name Description
request Google\Cloud\Billing\V1\CreateBillingAccountRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings 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\Cloud\Billing\V1\BillingAccount
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\BillingAccount;
use Google\Cloud\Billing\V1\Client\CloudBillingClient;
use Google\Cloud\Billing\V1\CreateBillingAccountRequest;

/**
 * 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 create_billing_account_sample(): void
{
    // Create a client.
    $cloudBillingClient = new CloudBillingClient();

    // Prepare the request message.
    $billingAccount = new BillingAccount();
    $request = (new CreateBillingAccountRequest())
        ->setBillingAccount($billingAccount);

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

getBillingAccount

Gets information about a billing account. The current authenticated user must be a viewer of the billing account.

The async variant is Google\Cloud\Billing\V1\Client\CloudBillingClient::getBillingAccountAsync() .

Parameters
Name Description
request Google\Cloud\Billing\V1\GetBillingAccountRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings 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\Cloud\Billing\V1\BillingAccount
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\BillingAccount;
use Google\Cloud\Billing\V1\Client\CloudBillingClient;
use Google\Cloud\Billing\V1\GetBillingAccountRequest;

/**
 * @param string $formattedName The resource name of the billing account to retrieve. For
 *                              example, `billingAccounts/012345-567890-ABCDEF`. Please see
 *                              {@see CloudBillingClient::billingAccountName()} for help formatting this field.
 */
function get_billing_account_sample(string $formattedName): void
{
    // Create a client.
    $cloudBillingClient = new CloudBillingClient();

    // Prepare the request message.
    $request = (new GetBillingAccountRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var BillingAccount $response */
        $response = $cloudBillingClient->getBillingAccount($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
{
    $formattedName = CloudBillingClient::billingAccountName('[BILLING_ACCOUNT]');

    get_billing_account_sample($formattedName);
}

getIamPolicy

Gets the access control policy for a billing account.

The caller must have the billing.accounts.getIamPolicy permission on the account, which is often given to billing account viewers.

The async variant is Google\Cloud\Billing\V1\Client\CloudBillingClient::getIamPolicyAsync() .

Parameters
Name Description
request Google\Cloud\Iam\V1\GetIamPolicyRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings 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\Cloud\Iam\V1\Policy
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\Client\CloudBillingClient;
use Google\Cloud\Iam\V1\GetIamPolicyRequest;
use Google\Cloud\Iam\V1\Policy;

/**
 * @param string $resource REQUIRED: The resource for which the policy is being requested.
 *                         See the operation documentation for the appropriate value for this field.
 */
function get_iam_policy_sample(string $resource): void
{
    // Create a client.
    $cloudBillingClient = new CloudBillingClient();

    // Prepare the request message.
    $request = (new GetIamPolicyRequest())
        ->setResource($resource);

    // Call the API and handle any network failures.
    try {
        /** @var Policy $response */
        $response = $cloudBillingClient->getIamPolicy($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
{
    $resource = '[RESOURCE]';

    get_iam_policy_sample($resource);
}

getProjectBillingInfo

Gets the billing information for a project. The current authenticated user must have the resourcemanager.projects.get permission for the project, which can be granted by assigning the Project Viewer role.

The async variant is Google\Cloud\Billing\V1\Client\CloudBillingClient::getProjectBillingInfoAsync() .

Parameters
Name Description
request Google\Cloud\Billing\V1\GetProjectBillingInfoRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings 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\Cloud\Billing\V1\ProjectBillingInfo
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\Client\CloudBillingClient;
use Google\Cloud\Billing\V1\GetProjectBillingInfoRequest;
use Google\Cloud\Billing\V1\ProjectBillingInfo;

/**
 * @param string $formattedName The resource name of the project for which billing information is
 *                              retrieved. For example, `projects/tokyo-rain-123`. Please see
 *                              {@see CloudBillingClient::projectName()} for help formatting this field.
 */
function get_project_billing_info_sample(string $formattedName): void
{
    // Create a client.
    $cloudBillingClient = new CloudBillingClient();

    // Prepare the request message.
    $request = (new GetProjectBillingInfoRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var ProjectBillingInfo $response */
        $response = $cloudBillingClient->getProjectBillingInfo($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
{
    $formattedName = CloudBillingClient::projectName('[PROJECT]');

    get_project_billing_info_sample($formattedName);
}

listBillingAccounts

Lists the billing accounts that the current authenticated user has permission to view.

The async variant is Google\Cloud\Billing\V1\Client\CloudBillingClient::listBillingAccountsAsync() .

Parameters
Name Description
request Google\Cloud\Billing\V1\ListBillingAccountsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings 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\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Billing\V1\BillingAccount;
use Google\Cloud\Billing\V1\Client\CloudBillingClient;
use Google\Cloud\Billing\V1\ListBillingAccountsRequest;

/**
 * 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 list_billing_accounts_sample(): void
{
    // Create a client.
    $cloudBillingClient = new CloudBillingClient();

    // Prepare the request message.
    $request = new ListBillingAccountsRequest();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $cloudBillingClient->listBillingAccounts($request);

        /** @var BillingAccount $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

listProjectBillingInfo

Lists the projects associated with a billing account. The current authenticated user must have the billing.resourceAssociations.list IAM permission, which is often given to billing account viewers.

The async variant is Google\Cloud\Billing\V1\Client\CloudBillingClient::listProjectBillingInfoAsync() .

Parameters
Name Description
request Google\Cloud\Billing\V1\ListProjectBillingInfoRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings 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\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Billing\V1\Client\CloudBillingClient;
use Google\Cloud\Billing\V1\ListProjectBillingInfoRequest;
use Google\Cloud\Billing\V1\ProjectBillingInfo;

/**
 * @param string $formattedName The resource name of the billing account associated with the
 *                              projects that you want to list. For example,
 *                              `billingAccounts/012345-567890-ABCDEF`. Please see
 *                              {@see CloudBillingClient::billingAccountName()} for help formatting this field.
 */
function list_project_billing_info_sample(string $formattedName): void
{
    // Create a client.
    $cloudBillingClient = new CloudBillingClient();

    // Prepare the request message.
    $request = (new ListProjectBillingInfoRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $cloudBillingClient->listProjectBillingInfo($request);

        /** @var ProjectBillingInfo $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->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
{
    $formattedName = CloudBillingClient::billingAccountName('[BILLING_ACCOUNT]');

    list_project_billing_info_sample($formattedName);
}

moveBillingAccount

Changes which parent organization a billing account belongs to.

The async variant is Google\Cloud\Billing\V1\Client\CloudBillingClient::moveBillingAccountAsync() .

Parameters
Name Description
request Google\Cloud\Billing\V1\MoveBillingAccountRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings 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\Cloud\Billing\V1\BillingAccount
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\BillingAccount;
use Google\Cloud\Billing\V1\Client\CloudBillingClient;
use Google\Cloud\Billing\V1\MoveBillingAccountRequest;

/**
 * @param string $formattedName              The resource name of the billing account to move.
 *                                           Must be of the form `billingAccounts/{billing_account_id}`.
 *                                           The specified billing account cannot be a subaccount, since a subaccount
 *                                           always belongs to the same organization as its parent account. Please see
 *                                           {@see CloudBillingClient::billingAccountName()} for help formatting this field.
 * @param string $formattedDestinationParent The resource name of the Organization to move
 *                                           the billing account under.
 *                                           Must be of the form `organizations/{organization_id}`. Please see
 *                                           {@see CloudBillingClient::organizationName()} for help formatting this field.
 */
function move_billing_account_sample(
    string $formattedName,
    string $formattedDestinationParent
): void {
    // Create a client.
    $cloudBillingClient = new CloudBillingClient();

    // Prepare the request message.
    $request = (new MoveBillingAccountRequest())
        ->setName($formattedName)
        ->setDestinationParent($formattedDestinationParent);

    // Call the API and handle any network failures.
    try {
        /** @var BillingAccount $response */
        $response = $cloudBillingClient->moveBillingAccount($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
{
    $formattedName = CloudBillingClient::billingAccountName('[BILLING_ACCOUNT]');
    $formattedDestinationParent = CloudBillingClient::organizationName('[ORGANIZATION]');

    move_billing_account_sample($formattedName, $formattedDestinationParent);
}

setIamPolicy

Sets the access control policy for a billing account. Replaces any existing policy.

The caller must have the billing.accounts.setIamPolicy permission on the account, which is often given to billing account administrators.

The async variant is Google\Cloud\Billing\V1\Client\CloudBillingClient::setIamPolicyAsync() .

Parameters
Name Description
request Google\Cloud\Iam\V1\SetIamPolicyRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings 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\Cloud\Iam\V1\Policy
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\Client\CloudBillingClient;
use Google\Cloud\Iam\V1\Policy;
use Google\Cloud\Iam\V1\SetIamPolicyRequest;

/**
 * @param string $resource REQUIRED: The resource for which the policy is being specified.
 *                         See the operation documentation for the appropriate value for this field.
 */
function set_iam_policy_sample(string $resource): void
{
    // Create a client.
    $cloudBillingClient = new CloudBillingClient();

    // Prepare the request message.
    $policy = new Policy();
    $request = (new SetIamPolicyRequest())
        ->setResource($resource)
        ->setPolicy($policy);

    // Call the API and handle any network failures.
    try {
        /** @var Policy $response */
        $response = $cloudBillingClient->setIamPolicy($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
{
    $resource = '[RESOURCE]';

    set_iam_policy_sample($resource);
}

testIamPermissions

Tests the access control policy for a billing account. This method takes the resource and a set of permissions as input and returns the subset of the input permissions that the caller is allowed for that resource.

The async variant is Google\Cloud\Billing\V1\Client\CloudBillingClient::testIamPermissionsAsync() .

Parameters
Name Description
request Google\Cloud\Iam\V1\TestIamPermissionsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings 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\Cloud\Iam\V1\TestIamPermissionsResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\Client\CloudBillingClient;
use Google\Cloud\Iam\V1\TestIamPermissionsRequest;
use Google\Cloud\Iam\V1\TestIamPermissionsResponse;

/**
 * @param string $resource           REQUIRED: The resource for which the policy detail is being requested.
 *                                   See the operation documentation for the appropriate value for this field.
 * @param string $permissionsElement The set of permissions to check for the `resource`. Permissions with
 *                                   wildcards (such as '*' or 'storage.*') are not allowed. For more
 *                                   information see
 *                                   [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
 */
function test_iam_permissions_sample(string $resource, string $permissionsElement): void
{
    // Create a client.
    $cloudBillingClient = new CloudBillingClient();

    // Prepare the request message.
    $permissions = [$permissionsElement,];
    $request = (new TestIamPermissionsRequest())
        ->setResource($resource)
        ->setPermissions($permissions);

    // Call the API and handle any network failures.
    try {
        /** @var TestIamPermissionsResponse $response */
        $response = $cloudBillingClient->testIamPermissions($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
{
    $resource = '[RESOURCE]';
    $permissionsElement = '[PERMISSIONS]';

    test_iam_permissions_sample($resource, $permissionsElement);
}

updateBillingAccount

Updates a billing account's fields.

Currently the only field that can be edited is display_name. The current authenticated user must have the billing.accounts.update IAM permission, which is typically given to the administrator of the billing account.

The async variant is Google\Cloud\Billing\V1\Client\CloudBillingClient::updateBillingAccountAsync() .

Parameters
Name Description
request Google\Cloud\Billing\V1\UpdateBillingAccountRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings 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\Cloud\Billing\V1\BillingAccount
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\BillingAccount;
use Google\Cloud\Billing\V1\Client\CloudBillingClient;
use Google\Cloud\Billing\V1\UpdateBillingAccountRequest;

/**
 * @param string $formattedName The name of the billing account resource to be updated. Please see
 *                              {@see CloudBillingClient::billingAccountName()} for help formatting this field.
 */
function update_billing_account_sample(string $formattedName): void
{
    // Create a client.
    $cloudBillingClient = new CloudBillingClient();

    // Prepare the request message.
    $account = new BillingAccount();
    $request = (new UpdateBillingAccountRequest())
        ->setName($formattedName)
        ->setAccount($account);

    // Call the API and handle any network failures.
    try {
        /** @var BillingAccount $response */
        $response = $cloudBillingClient->updateBillingAccount($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
{
    $formattedName = CloudBillingClient::billingAccountName('[BILLING_ACCOUNT]');

    update_billing_account_sample($formattedName);
}

updateProjectBillingInfo

Sets or updates the billing account associated with a project. You specify the new billing account by setting the billing_account_name in the ProjectBillingInfo resource to the resource name of a billing account.

Associating a project with an open billing account enables billing on the project and allows charges for resource usage. If the project already had a billing account, this method changes the billing account used for resource usage charges.

Note: Incurred charges that have not yet been reported in the transaction history of the Google Cloud Console might be billed to the new billing account, even if the charge occurred before the new billing account was assigned to the project.

The current authenticated user must have ownership privileges for both the project and the billing account.

You can disable billing on the project by setting the billing_account_name field to empty. This action disassociates the current billing account from the project. Any billable activity of your in-use services will stop, and your application could stop functioning as expected. Any unbilled charges to date will be billed to the previously associated account. The current authenticated user must be either an owner of the project or an owner of the billing account for the project.

Note that associating a project with a closed billing account will have much the same effect as disabling billing on the project: any paid resources used by the project will be shut down. Thus, unless you wish to disable billing, you should always call this method with the name of an open billing account.

The async variant is Google\Cloud\Billing\V1\Client\CloudBillingClient::updateProjectBillingInfoAsync() .

Parameters
Name Description
request Google\Cloud\Billing\V1\UpdateProjectBillingInfoRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings 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\Cloud\Billing\V1\ProjectBillingInfo
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\Client\CloudBillingClient;
use Google\Cloud\Billing\V1\ProjectBillingInfo;
use Google\Cloud\Billing\V1\UpdateProjectBillingInfoRequest;

/**
 * @param string $name The resource name of the project associated with the billing
 *                     information that you want to update. For example,
 *                     `projects/tokyo-rain-123`.
 */
function update_project_billing_info_sample(string $name): void
{
    // Create a client.
    $cloudBillingClient = new CloudBillingClient();

    // Prepare the request message.
    $request = (new UpdateProjectBillingInfoRequest())
        ->setName($name);

    // Call the API and handle any network failures.
    try {
        /** @var ProjectBillingInfo $response */
        $response = $cloudBillingClient->updateProjectBillingInfo($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
{
    $name = '[NAME]';

    update_project_billing_info_sample($name);
}

createBillingAccountAsync

Parameters
Name Description
request Google\Cloud\Billing\V1\CreateBillingAccountRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getBillingAccountAsync

Parameters
Name Description
request Google\Cloud\Billing\V1\GetBillingAccountRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getIamPolicyAsync

Parameters
Name Description
request Google\Cloud\Iam\V1\GetIamPolicyRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getProjectBillingInfoAsync

Parameters
Name Description
request Google\Cloud\Billing\V1\GetProjectBillingInfoRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

listBillingAccountsAsync

Parameters
Name Description
request Google\Cloud\Billing\V1\ListBillingAccountsRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

listProjectBillingInfoAsync

Parameters
Name Description
request Google\Cloud\Billing\V1\ListProjectBillingInfoRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

moveBillingAccountAsync

Parameters
Name Description
request Google\Cloud\Billing\V1\MoveBillingAccountRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

setIamPolicyAsync

Parameters
Name Description
request Google\Cloud\Iam\V1\SetIamPolicyRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

testIamPermissionsAsync

Parameters
Name Description
request Google\Cloud\Iam\V1\TestIamPermissionsRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

updateBillingAccountAsync

Parameters
Name Description
request Google\Cloud\Billing\V1\UpdateBillingAccountRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

updateProjectBillingInfoAsync

Parameters
Name Description
request Google\Cloud\Billing\V1\UpdateProjectBillingInfoRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

static::billingAccountName

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

Parameter
Name Description
billingAccount string
Returns
Type Description
string The formatted billing_account resource.

static::organizationName

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

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

static::organizationBillingAccountName

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

Parameters
Name Description
organization string
billingAccount string
Returns
Type Description
string The formatted organization_billing_account resource.

static::projectName

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

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

static::projectBillingInfoName

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

Parameter
Name Description
project string
Returns
Type Description
string The formatted project_billing_info 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

  • billingAccount: billingAccounts/{billing_account}
  • organization: organizations/{organization}
  • organizationBillingAccount: organizations/{organization}/billingAccounts/{billing_account}
  • project: projects/{project}
  • projectBillingInfo: projects/{project}/billingInfo

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.