Google Cloud Billing V1 Client - Class CloudBillingClient (1.8.0)

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. Sample code to get started:

$cloudBillingClient = new CloudBillingClient();
try {
    $billingAccount = new BillingAccount();
    $response = $cloudBillingClient->createBillingAccount($billingAccount);
} finally {
    $cloudBillingClient->close();
}

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.

This service has a new (beta) implementation. See Google\Cloud\Billing\V1\Client\CloudBillingClient to use the new surface.

Namespace

Google \ Cloud \ Billing \ V1

Methods

__construct

Constructor.

Parameters
NameDescription
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.

Parameters
NameDescription
billingAccount Google\Cloud\Billing\V1\BillingAccount

Required. The billing account resource to create. Currently CreateBillingAccount only supports subaccount creation, so any created billing accounts must be under a provided parent billing account.

optionalArgs array

Optional.

↳ parent string

Optional. The parent to create a billing account from. Format: - organizations/{organization_id}, for example, organizations/12345678 - billingAccounts/{billing_account_id}, for example, billingAccounts/012345-567890-ABCDEF

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

/**
 * 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 any non-scalar elements to be passed along with the request.
    $billingAccount = new BillingAccount();

    // Call the API and handle any network failures.
    try {
        /** @var BillingAccount $response */
        $response = $cloudBillingClient->createBillingAccount($billingAccount);
        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.

Parameters
NameDescription
name string

Required. The resource name of the billing account to retrieve. For example, billingAccounts/012345-567890-ABCDEF.

optionalArgs 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
TypeDescription
Google\Cloud\Billing\V1\BillingAccount
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\BillingAccount;
use Google\Cloud\Billing\V1\CloudBillingClient;

/**
 * @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();

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

Parameters
NameDescription
resource string

REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

optionalArgs array

Optional.

↳ options GetPolicyOptions

OPTIONAL: A GetPolicyOptions object for specifying options to GetIamPolicy.

↳ 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
TypeDescription
Google\Cloud\Iam\V1\Policy
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\CloudBillingClient;
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();

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

Parameters
NameDescription
name string

Required. The resource name of the project for which billing information is retrieved. For example, projects/tokyo-rain-123.

optionalArgs 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
TypeDescription
Google\Cloud\Billing\V1\ProjectBillingInfo
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\CloudBillingClient;
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();

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

Parameters
NameDescription
optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ filter string

Options for how to filter the returned billing accounts. This only supports filtering for subaccounts under a single provided parent billing account. (for example, master_billing_account=billingAccounts/012345-678901-ABCDEF). Boolean algebra and other fields are not currently supported.

↳ parent string

Optional. The parent resource to list billing accounts from. Format: - organizations/{organization_id}, for example, organizations/12345678 - billingAccounts/{billing_account_id}, for example, billingAccounts/012345-567890-ABCDEF

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

/**
 * 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();

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

        /** @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.

Parameters
NameDescription
name string

Required. The resource name of the billing account associated with the projects that you want to list. For example, billingAccounts/012345-567890-ABCDEF.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ 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
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Billing\V1\CloudBillingClient;
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();

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

        /** @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.

Parameters
NameDescription
name string

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

destinationParent string

Required. The resource name of the Organization to reparent the billing account under. Must be of the form organizations/{organization_id}.

optionalArgs 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
TypeDescription
Google\Cloud\Billing\V1\BillingAccount
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\BillingAccount;
use Google\Cloud\Billing\V1\CloudBillingClient;

/**
 * @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 reparent
 *                                           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();

    // Call the API and handle any network failures.
    try {
        /** @var BillingAccount $response */
        $response = $cloudBillingClient->moveBillingAccount($formattedName, $formattedDestinationParent);
        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.

Parameters
NameDescription
resource string

REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

policy Google\Cloud\Iam\V1\Policy

REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.

optionalArgs array

Optional.

↳ updateMask FieldMask

OPTIONAL: A FieldMask specifying which fields of the policy to modify. Only the fields in the mask will be modified. If no mask is provided, the following default mask is used: paths: "bindings, etag"

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

/**
 * @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 any non-scalar elements to be passed along with the request.
    $policy = new Policy();

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

Parameters
NameDescription
resource string

REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.

permissions string[]

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.

optionalArgs 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
TypeDescription
Google\Cloud\Iam\V1\TestIamPermissionsResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\CloudBillingClient;
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 any non-scalar elements to be passed along with the request.
    $permissions = [$permissionsElement,];

    // Call the API and handle any network failures.
    try {
        /** @var TestIamPermissionsResponse $response */
        $response = $cloudBillingClient->testIamPermissions($resource, $permissions);
        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.

Parameters
NameDescription
name string

Required. The name of the billing account resource to be updated.

account Google\Cloud\Billing\V1\BillingAccount

Required. The billing account resource to replace the resource on the server.

optionalArgs array

Optional.

↳ updateMask FieldMask

The update mask applied to the resource. Only "display_name" is currently supported.

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

/**
 * @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 any non-scalar elements to be passed along with the request.
    $account = new BillingAccount();

    // Call the API and handle any network failures.
    try {
        /** @var BillingAccount $response */
        $response = $cloudBillingClient->updateBillingAccount($formattedName, $account);
        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.

Parameters
NameDescription
name string

Required. The resource name of the project associated with the billing information that you want to update. For example, projects/tokyo-rain-123.

optionalArgs array

Optional.

↳ projectBillingInfo ProjectBillingInfo

The new billing information for the project. Output-only fields are ignored; thus, you can leave empty all fields except billing_account_name.

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

/**
 * @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();

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

static::billingAccountName

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

Parameter
NameDescription
billingAccount string
Returns
TypeDescription
stringThe formatted billing_account resource.

static::organizationName

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

Parameter
NameDescription
organization string
Returns
TypeDescription
stringThe formatted organization resource.

static::organizationBillingAccountName

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

Parameters
NameDescription
organization string
billingAccount string
Returns
TypeDescription
stringThe formatted organization_billing_account resource.

static::projectName

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

Parameter
NameDescription
project string
Returns
TypeDescription
stringThe formatted project resource.

static::projectBillingInfoName

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

Parameter
NameDescription
project string
Returns
TypeDescription
stringThe 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
NameDescription
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
TypeDescription
arrayAn associative array from name component IDs to component values.

Constants

SERVICE_NAME

Value: 'google.cloud.billing.v1.CloudBilling'

The name of the service.

SERVICE_ADDRESS

Value: 'cloudbilling.googleapis.com'

The default address of the service.

DEFAULT_SERVICE_PORT

Value: 443

The default port of the service.

CODEGEN_NAME

Value: 'gapic'

The name of the code generator, to be included in the agent header.