public override int GetHashCode()
        {
            int hash = 1;

            if (CustomerId.Length != 0)
            {
                hash ^= CustomerId.GetHashCode();
            }
            if (BillingSetup.Length != 0)
            {
                hash ^= BillingSetup.GetHashCode();
            }
            if (IssueYear.Length != 0)
            {
                hash ^= IssueYear.GetHashCode();
            }
            if (IssueMonth != global::Google.Ads.GoogleAds.V6.Enums.MonthOfYearEnum.Types.MonthOfYear.Unspecified)
            {
                hash ^= IssueMonth.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Esempio n. 2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (CustomerId.Length != 0)
            {
                hash ^= CustomerId.GetHashCode();
            }
            if (BillingSetup.Length != 0)
            {
                hash ^= BillingSetup.GetHashCode();
            }
            if (IssueYear.Length != 0)
            {
                hash ^= IssueYear.GetHashCode();
            }
            if (IssueMonth != 0)
            {
                hash ^= IssueMonth.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates and returns a new Billing Setup instance with complete payment details. One of
        /// paymentsAccountId or paymentsProfileId must be provided.
        /// </summary>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="paymentsAccountId">Optional payments account ID to attach to the new
        ///     billing setup. Must be formatted as "1234-5678-9012-3456".</param>
        /// <param name="paymentsProfileId">Optional payments profile ID to attach to a new payments
        ///     account and to the new billing setup. Must be formatted as "1234-5678-9012".</param>
        /// <returns>A new BillingSetup instance with complete payment details.</returns>
        /// <exception cref="Exception">Generic exception if no payment details have been
        ///     provided.</exception>
        private BillingSetup CreateBillingSetup(long customerId, string paymentsAccountId,
                                                string paymentsProfileId)
        {
            BillingSetup billingSetup = new BillingSetup();

            // Sets the appropriate payments account field.
            if (paymentsAccountId != null)
            {
                // If a payments account id has been provided, set PaymentsAccount to its resource
                // name. You can list available payments accounts via the PaymentsAccountService's
                // ListPaymentsAccounts method.
                billingSetup.PaymentsAccount =
                    ResourceNames.PaymentsAccount(customerId, paymentsAccountId);
            }
            else if (paymentsProfileId != null)
            {
                // Otherwise, create a new payments account by setting the PaymentsAccountInfo
                // field. See https://support.google.com/google-ads/answer/7268503 for information
                // about payments profiles.
                billingSetup.PaymentsAccountInfo = new BillingSetup.Types.PaymentsAccountInfo()
                {
                    PaymentsAccountName = "Payments Account #" + ExampleUtilities.GetRandomString(),
                    PaymentsProfileId   = paymentsProfileId
                };
            }
            else
            {
                throw new Exception("No paymentsAccountId or paymentsProfileId provided.");
            }

            return(billingSetup);
        }
Esempio n. 4
0
 /// <summary>Snippet for GetBillingSetup</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetBillingSetup()
 {
     // Create client
     BillingSetupServiceClient billingSetupServiceClient = BillingSetupServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER_ID]/billingSetups/[BILLING_SETUP_ID]";
     // Make the request
     BillingSetup response = billingSetupServiceClient.GetBillingSetup(resourceName);
 }
 /// <summary>Snippet for GetBillingSetup</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetBillingSetupResourceNames()
 {
     // Create client
     BillingSetupServiceClient billingSetupServiceClient = BillingSetupServiceClient.Create();
     // Initialize request argument(s)
     BillingSetupName resourceName = BillingSetupName.FromCustomerBillingSetup("[CUSTOMER_ID]", "[BILLING_SETUP_ID]");
     // Make the request
     BillingSetup response = billingSetupServiceClient.GetBillingSetup(resourceName);
 }
Esempio n. 6
0
        /// <summary>Snippet for GetBillingSetupAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetBillingSetupResourceNamesAsync()
        {
            // Create client
            BillingSetupServiceClient billingSetupServiceClient = await BillingSetupServiceClient.CreateAsync();

            // Initialize request argument(s)
            BillingSetupName resourceName = BillingSetupName.FromCustomerBillingSetup("[CUSTOMER]", "[BILLING_SETUP]");
            // Make the request
            BillingSetup response = await billingSetupServiceClient.GetBillingSetupAsync(resourceName);
        }
Esempio n. 7
0
        /// <summary>Snippet for GetBillingSetupAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetBillingSetupAsync()
        {
            // Create client
            BillingSetupServiceClient billingSetupServiceClient = await BillingSetupServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/billingSetups/[BILLING_SETUP]";
            // Make the request
            BillingSetup response = await billingSetupServiceClient.GetBillingSetupAsync(resourceName);
        }
Esempio n. 8
0
 /// <summary>Snippet for GetBillingSetup</summary>
 public void GetBillingSetup()
 {
     // Snippet: GetBillingSetup(string, CallSettings)
     // Create client
     BillingSetupServiceClient billingSetupServiceClient = BillingSetupServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/billingSetups/[BILLING_SETUP]";
     // Make the request
     BillingSetup response = billingSetupServiceClient.GetBillingSetup(resourceName);
     // End snippet
 }
 /// <summary>Snippet for GetBillingSetup</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetBillingSetupRequestObject()
 {
     // Create client
     BillingSetupServiceClient billingSetupServiceClient = BillingSetupServiceClient.Create();
     // Initialize request argument(s)
     GetBillingSetupRequest request = new GetBillingSetupRequest
     {
         ResourceNameAsBillingSetupName = BillingSetupName.FromCustomerBillingSetup("[CUSTOMER]", "[BILLING_SETUP]"),
     };
     // Make the request
     BillingSetup response = billingSetupServiceClient.GetBillingSetup(request);
 }
Esempio n. 10
0
        /// <summary>Snippet for GetBillingSetupAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetBillingSetupRequestObjectAsync()
        {
            // Create client
            BillingSetupServiceClient billingSetupServiceClient = await BillingSetupServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetBillingSetupRequest request = new GetBillingSetupRequest
            {
                ResourceNameAsBillingSetupName = BillingSetupName.FromCustomerBillingSetup("[CUSTOMER_ID]", "[BILLING_SETUP_ID]"),
            };
            // Make the request
            BillingSetup response = await billingSetupServiceClient.GetBillingSetupAsync(request);
        }
Esempio n. 11
0
        /// <summary>Snippet for GetBillingSetupAsync</summary>
        public async Task GetBillingSetupAsync()
        {
            // Snippet: GetBillingSetupAsync(string, CallSettings)
            // Additional: GetBillingSetupAsync(string, CancellationToken)
            // Create client
            BillingSetupServiceClient billingSetupServiceClient = await BillingSetupServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/billingSetups/[BILLING_SETUP]";
            // Make the request
            BillingSetup response = await billingSetupServiceClient.GetBillingSetupAsync(resourceName);

            // End snippet
        }
Esempio n. 12
0
        /// <summary>Snippet for GetBillingSetupAsync</summary>
        public async Task GetBillingSetupResourceNamesAsync()
        {
            // Snippet: GetBillingSetupAsync(BillingSetupName, CallSettings)
            // Additional: GetBillingSetupAsync(BillingSetupName, CancellationToken)
            // Create client
            BillingSetupServiceClient billingSetupServiceClient = await BillingSetupServiceClient.CreateAsync();

            // Initialize request argument(s)
            BillingSetupName resourceName = BillingSetupName.FromCustomerBillingSetup("[CUSTOMER]", "[BILLING_SETUP]");
            // Make the request
            BillingSetup response = await billingSetupServiceClient.GetBillingSetupAsync(resourceName);

            // End snippet
        }
Esempio n. 13
0
        /// <summary>
        /// Sets the starting and ending date times for the new billing setup. Queries the
        /// customer's account to see if there are any approved billing setups. If there are any,
        /// the new billing setup starting date time is set to one day after the last. If not, the
        /// billing setup is set to start immediately. The ending date is set to one day after the
        /// starting date time.
        /// </summary>
        /// <param name="googleAdsService">The Google Ads service client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="billingSetup">The instance of BillingSetup whose starting date time will
        ///     be set.</param>
        private void SetBillingSetupStartDateTime(GoogleAdsServiceClient googleAdsService,
                                                  long customerId, BillingSetup billingSetup)
        {
            // The query to search existing approved billing setups in the end date time descending
            // order.
            // See GetBillingSetup.cs for a more detailed example of requesting billing setup
            // information.
            string query = @"
                SELECT billing_setup.end_date_time
                FROM billing_setup
                WHERE billing_setup.status = 'APPROVED'
                ORDER BY billing_setup.end_date_time DESC
                LIMIT 1";

            // Issues a search request.
            PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> searchResponse =
                googleAdsService.Search(customerId.ToString(), query);

            if (searchResponse.Any())
            {
                // Retrieves the ending date time of the last billing setup.
                string lastEndingDateTimeString = searchResponse.First().BillingSetup.EndDateTime;

                // A null ending date time indicates that the current billing setup is set to run
                // indefinitely. Billing setups cannot overlap, so throw an exception in this case.
                if (lastEndingDateTimeString == null)
                {
                    throw new Exception("Cannot set starting and ending date times for " +
                                        "the new billing setup; the latest existing billing " +
                                        "setup is set to run indefinitely.");
                }

                DateTime lastEndingDateTime = DateTime.Parse(lastEndingDateTimeString);

                // Sets the new billing setup to start one day after the ending date time.
                billingSetup.StartDateTime = lastEndingDateTime.AddDays(1).ToString("yyyy-MM-dd");

                // Sets the new billing setup to end one day after the starting date time.
                billingSetup.EndDateTime = lastEndingDateTime.AddDays(2).ToString("yyyy-MM-dd");
            }
            else
            {
                // Otherwise, the only acceptable start time is TimeType.Now.
                billingSetup.StartTimeType = TimeType.Now;

                // Sets the new billing setup to end tomorrow.
                billingSetup.EndDateTime = DateTime.Today.AddDays(1).ToString("yyyy-MM-dd");
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Runs the code example. Either a payments account ID or a payments profile ID
        /// must be provided for the example to run successfully. If both are provided, only the
        /// payments account ID will be used.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="paymentsAccountId">Optional payments account ID to attach to the new
        ///     billing setup. Must be formatted as "1234-5678-9012-3456".</param>
        /// <param name="paymentsProfileId">Optional payments profile ID to attach to a new payments
        ///     account and to the new billing setup. Must be formatted as "1234-5678-9012".</param>
        public void Run(GoogleAdsClient client, long customerId, string paymentsAccountId,
                        string paymentsProfileId)
        {
            // Gets the GoogleAdsServiceClient.
            GoogleAdsServiceClient googleAdsService = client.GetService(
                Services.V4.GoogleAdsService);

            // Gets the BillingSetupServiceClient.
            BillingSetupServiceClient billingSetupServiceClient =
                client.GetService(Services.V4.BillingSetupService);

            try
            {
                // Constructs a new billing setup.
                BillingSetup billingSetup =
                    CreateBillingSetup(customerId, paymentsAccountId, paymentsProfileId);

                SetBillingSetupStartDateTime(googleAdsService, customerId, billingSetup);

                // Creates the billing setup operation.
                BillingSetupOperation operation = new BillingSetupOperation()
                {
                    Create = billingSetup
                };

                // Issues a mutate request to add the billing setup.
                MutateBillingSetupResponse billingResponse =
                    billingSetupServiceClient.MutateBillingSetup(customerId.ToString(), operation);

                Console.WriteLine("Added new billing setup with resource name: " +
                                  $"{billingResponse.Result.ResourceName}");
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
            catch (Exception e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Trace: {e.StackTrace}");
            }
        }
Esempio n. 15
0
        public async Task GetBillingSetupAsync2()
        {
            Mock <BillingSetupService.BillingSetupServiceClient> mockGrpcClient = new Mock <BillingSetupService.BillingSetupServiceClient>(MockBehavior.Strict);
            GetBillingSetupRequest request = new GetBillingSetupRequest
            {
                ResourceName = new BillingSetupName("[CUSTOMER]", "[BILLING_SETUP]").ToString(),
            };
            BillingSetup expectedResponse = new BillingSetup
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetBillingSetupAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <BillingSetup>(Task.FromResult(expectedResponse), null, null, null, null));
            BillingSetupServiceClient client = new BillingSetupServiceClientImpl(mockGrpcClient.Object, null);
            BillingSetup response            = await client.GetBillingSetupAsync(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Esempio n. 16
0
        public void GetBillingSetup2()
        {
            Mock <BillingSetupService.BillingSetupServiceClient> mockGrpcClient = new Mock <BillingSetupService.BillingSetupServiceClient>(MockBehavior.Strict);
            GetBillingSetupRequest request = new GetBillingSetupRequest
            {
                ResourceName = new BillingSetupName("[CUSTOMER]", "[BILLING_SETUP]").ToString(),
            };
            BillingSetup expectedResponse = new BillingSetup
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetBillingSetup(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            BillingSetupServiceClient client = new BillingSetupServiceClientImpl(mockGrpcClient.Object, null);
            BillingSetup response            = client.GetBillingSetup(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        /// <summary>
        /// Sets the starting date time for the new billing setup. Queries the customer's account
        /// to see if there are any approved billing setups. If there are any, the new billing setup
        /// may have a starting date time of any day in the future. If not, the billing setup must
        /// be set to start immediately.
        /// </summary>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="googleAdsService">The Google Ads service client.</param>
        /// <param name="billingSetup">The instance of BillingSetup whose starting date time will
        ///     be set.</param>
        private void SetBillingSetupStartDateTime(long customerId, GoogleAdsServiceClient
                                                  googleAdsService, BillingSetup billingSetup)
        {
            // Query to see if there are any existing approved billing setups. See
            // GetBillingSetup.cs for a more detailed example of requesting billing setup
            // information.
            string query = @"
                SELECT billing_setup.end_date_time
                FROM billing_setup
                WHERE billing_setup.status = 'APPROVED'
                ORDER BY billing_setup.end_date_time DESC";

            PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> searchResponse =
                googleAdsService.Search(customerId.ToString(), query);

            if (searchResponse.Any())
            {
                // If there are any existing approved billing setups, the new billing setup can
                // start immediately after the last.
                string lastEndingDateTimeString = searchResponse.First().BillingSetup.EndDateTime;

                // Check if the existing billing setup has no end date (i.e., is set to run
                // indefinitely).
                if (lastEndingDateTimeString == null)
                {
                    throw new Exception("Cannot set ending date time for the new " +
                                        "billing setup; the latest existing billing setup is set " +
                                        "to run indefinitely.");
                }

                DateTime lastEndingDateTime = DateTime.Parse(lastEndingDateTimeString);
                billingSetup.StartDateTime = lastEndingDateTime.AddDays(1).ToString("yyyy-MM-dd");
                billingSetup.EndDateTime   = lastEndingDateTime.AddDays(2).ToString("yyyy-MM-dd");
            }
            else
            {
                // If there are no existing approved billing setups, the only acceptable start time
                // is TimeType.Now.
                billingSetup.StartTimeType = TimeType.Now;
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        public void Run(GoogleAdsClient client, long customerId)
        {
            // Get the GoogleAdsServiceClient.
            GoogleAdsServiceClient googleAdsService = client.GetService(
                Services.V2.GoogleAdsService);

            // Define a GAQL query to retrieve all billing setup information.
            string searchQuery = @"
                SELECT
                    billing_setup.id,
                    billing_setup.status,
                    billing_setup.payments_account,
                    billing_setup.payments_account_info.payments_account_id,
                    billing_setup.payments_account_info.payments_account_name,
                    billing_setup.payments_account_info.payments_profile_id,
                    billing_setup.payments_account_info.payments_profile_name,
                    billing_setup.payments_account_info.secondary_payments_profile_id
                FROM billing_setup";

            // Creates a request that will retrieve all billing setups using pages of the specified
            // page size.
            SearchGoogleAdsRequest request = new SearchGoogleAdsRequest()
            {
                PageSize   = PAGE_SIZE,
                Query      = searchQuery,
                CustomerId = customerId.ToString()
            };

            try
            {
                PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> searchPagedResponse =
                    googleAdsService.Search(request);

                foreach (SearchGoogleAdsResponse response in searchPagedResponse.AsRawResponses())
                {
                    foreach (GoogleAdsRow googleAdsRow in response.Results)
                    {
                        BillingSetup billingSetup = googleAdsRow.BillingSetup;
                        Console.WriteLine("Billing setup with ID '{0}', status '{1}', " +
                                          "payments account '{2}', payments account Id '{3}', " +
                                          "payments account name '{4}', payments profile id '{5}', " +
                                          "payments profile name '{6}', secondary payments profile id '{7}'.",
                                          billingSetup.Id,
                                          billingSetup.Status,
                                          billingSetup.PaymentsAccount,
                                          billingSetup.PaymentsAccountInfo.PaymentsAccountId,
                                          billingSetup.PaymentsAccountInfo.PaymentsAccountName,
                                          billingSetup.PaymentsAccountInfo.PaymentsProfileId,
                                          billingSetup.PaymentsAccountInfo.PaymentsProfileName,
                                          billingSetup.PaymentsAccountInfo.SecondaryPaymentsProfileId);
                    }
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        public void Run(GoogleAdsClient client, long customerId)
        {
            // Get the GoogleAdsServiceClient.
            GoogleAdsServiceClient googleAdsService = client.GetService(
                Services.V5.GoogleAdsService);

            // Define a GAQL query to retrieve all billing setup information.
            string searchQuery = @"
                SELECT
                    billing_setup.id,
                    billing_setup.status,
                    billing_setup.payments_account,
                    billing_setup.payments_account_info.payments_account_id,
                    billing_setup.payments_account_info.payments_account_name,
                    billing_setup.payments_account_info.payments_profile_id,
                    billing_setup.payments_account_info.payments_profile_name,
                    billing_setup.payments_account_info.secondary_payments_profile_id
                FROM billing_setup";

            // Creates a request that will retrieve all billing setups using pages of the specified
            // page size.
            SearchGoogleAdsRequest request = new SearchGoogleAdsRequest()
            {
                PageSize   = PAGE_SIZE,
                Query      = searchQuery,
                CustomerId = customerId.ToString()
            };

            try
            {
                PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> searchPagedResponse =
                    googleAdsService.Search(request);

                foreach (SearchGoogleAdsResponse response in searchPagedResponse.AsRawResponses())
                {
                    foreach (GoogleAdsRow googleAdsRow in response.Results)
                    {
                        BillingSetup billingSetup = googleAdsRow.BillingSetup;
                        Console.WriteLine($"Billing setup with ID '{billingSetup.Id}'has status " +
                                          $"status '{billingSetup.Status}'.");

                        // A missing billing setup will have no payments account information.
                        if (billingSetup.PaymentsAccount != null)
                        {
                            Console.WriteLine(
                                $"\tPayments account: {billingSetup.PaymentsAccount}\n" +
                                "\tPayments account Id: " +
                                $"{billingSetup.PaymentsAccountInfo.PaymentsAccountId}\n" +
                                "\tPayments account name: " +
                                $"{billingSetup.PaymentsAccountInfo.PaymentsAccountName}\n" +
                                "\tPayments profile id: " +
                                $"{billingSetup.PaymentsAccountInfo.PaymentsProfileId}\n" +
                                "\tPayments profile name: " +
                                $"{billingSetup.PaymentsAccountInfo.PaymentsProfileName}\n" +
                                "\tSecondary payments profile id: " +
                                $"{billingSetup.PaymentsAccountInfo.SecondaryPaymentsProfileId}");
                        }
                        else
                        {
                            Console.WriteLine("Payments account details missing or incomplete.");
                        }
                    }
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }