Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [CommerceConsumerProcurement] add Order modification RPCs and License Management Service #7729

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file modified CommerceConsumerProcurement/metadata/V1/ProcurementService.php
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudcommerceconsumerprocurement_v1_generated_ConsumerProcurementService_CancelOrder_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Commerce\Consumer\Procurement\V1\CancelOrderRequest;
use Google\Cloud\Commerce\Consumer\Procurement\V1\Client\ConsumerProcurementServiceClient;
use Google\Cloud\Commerce\Consumer\Procurement\V1\Order;
use Google\Rpc\Status;

/**
* Cancels an existing
* [Order][google.cloud.commerce.consumer.procurement.v1.Order]. Every product
* procured in the Order will be cancelled.
*
* @param string $name The resource name of the order.
*/
function cancel_order_sample(string $name): void
{
// Create a client.
$consumerProcurementServiceClient = new ConsumerProcurementServiceClient();

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

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $consumerProcurementServiceClient->cancelOrder($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
/** @var Order $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->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]';

cancel_order_sample($name);
}
// [END cloudcommerceconsumerprocurement_v1_generated_ConsumerProcurementService_CancelOrder_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudcommerceconsumerprocurement_v1_generated_ConsumerProcurementService_ModifyOrder_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Commerce\Consumer\Procurement\V1\Client\ConsumerProcurementServiceClient;
use Google\Cloud\Commerce\Consumer\Procurement\V1\ModifyOrderRequest;
use Google\Cloud\Commerce\Consumer\Procurement\V1\Order;
use Google\Rpc\Status;

/**
* Modifies an existing
* [Order][google.cloud.commerce.consumer.procurement.v1.Order] resource.
*
* @param string $name Name of the order to update.
*/
function modify_order_sample(string $name): void
{
// Create a client.
$consumerProcurementServiceClient = new ConsumerProcurementServiceClient();

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

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $consumerProcurementServiceClient->modifyOrder($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
/** @var Order $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->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]';

modify_order_sample($name);
}
// [END cloudcommerceconsumerprocurement_v1_generated_ConsumerProcurementService_ModifyOrder_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudcommerceconsumerprocurement_v1_generated_LicenseManagementService_Assign_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Commerce\Consumer\Procurement\V1\AssignRequest;
use Google\Cloud\Commerce\Consumer\Procurement\V1\AssignResponse;
use Google\Cloud\Commerce\Consumer\Procurement\V1\Client\LicenseManagementServiceClient;

/**
* Assigns a license to a user.
*
* @param string $parent License pool name.
* @param string $usernamesElement Username.
* Format: `name&#64;domain.com`.
*/
function assign_sample(string $parent, string $usernamesElement): void
{
// Create a client.
$licenseManagementServiceClient = new LicenseManagementServiceClient();

// Prepare the request message.
$usernames = [$usernamesElement,];
$request = (new AssignRequest())
->setParent($parent)
->setUsernames($usernames);

// Call the API and handle any network failures.
try {
/** @var AssignResponse $response */
$response = $licenseManagementServiceClient->assign($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
{
$parent = '[PARENT]';
$usernamesElement = '[USERNAMES]';

assign_sample($parent, $usernamesElement);
}
// [END cloudcommerceconsumerprocurement_v1_generated_LicenseManagementService_Assign_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudcommerceconsumerprocurement_v1_generated_LicenseManagementService_EnumerateLicensedUsers_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Commerce\Consumer\Procurement\V1\Client\LicenseManagementServiceClient;
use Google\Cloud\Commerce\Consumer\Procurement\V1\EnumerateLicensedUsersRequest;
use Google\Cloud\Commerce\Consumer\Procurement\V1\LicensedUser;

/**
* Enumerates all users assigned a license.
*
* @param string $parent License pool name.
*/
function enumerate_licensed_users_sample(string $parent): void
{
// Create a client.
$licenseManagementServiceClient = new LicenseManagementServiceClient();

// Prepare the request message.
$request = (new EnumerateLicensedUsersRequest())
->setParent($parent);

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

/** @var LicensedUser $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
{
$parent = '[PARENT]';

enumerate_licensed_users_sample($parent);
}
// [END cloudcommerceconsumerprocurement_v1_generated_LicenseManagementService_EnumerateLicensedUsers_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START cloudcommerceconsumerprocurement_v1_generated_LicenseManagementService_GetLicensePool_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Commerce\Consumer\Procurement\V1\Client\LicenseManagementServiceClient;
use Google\Cloud\Commerce\Consumer\Procurement\V1\GetLicensePoolRequest;
use Google\Cloud\Commerce\Consumer\Procurement\V1\LicensePool;

/**
* Gets the license pool.
*
* @param string $name The name of the license pool to get.
* Format: `billingAccounts/{billing_account}/orders/{order}/licensePool`
*/
function get_license_pool_sample(string $name): void
{
// Create a client.
$licenseManagementServiceClient = new LicenseManagementServiceClient();

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

// Call the API and handle any network failures.
try {
/** @var LicensePool $response */
$response = $licenseManagementServiceClient->getLicensePool($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]';

get_license_pool_sample($name);
}
// [END cloudcommerceconsumerprocurement_v1_generated_LicenseManagementService_GetLicensePool_sync]
Loading
Loading