<?php
$customer = (new Customer)
->setDescriptiveNameUnwrapped($this->parameters->get('name'))
->setTimeZoneUnwrapped($this->parameters->get('dateTimeZone'))
->setCurrencyCodeUnwrapped($this->parameters->get('currencyCode'));
$mccCustomerId = env('MCC_CLIENT_CUSTOMER_ID');
$result = $this->getCustomerServiceClient()->createCustomerClient(
$mccCustomerId,
$customer
);
$customerIdCreated = \basename($result->getResourceName());
$clientPaymentsAccountId = env('MCC_CLIENT_PAYMENTS_ACCOUNT_ID');
$billingSetup = (new BillingSetup())
->setPaymentsAccountUnwrapped("customers/$customerIdCreated/paymentsAccounts/$clientPaymentsAccountId")
->setStartDateTimeUnwrapped(date('Y-m-d H:i:s'))
->setStartTimeType(TimeType::NOW)
;
$billingSetupOperation = (new BillingSetupOperation)
->setCreate($billingSetup);
$billingSetupResult = $this->getBillingSetupServiceClient()->mutateBillingSetup(
$customerIdCreated,
$billingSetupOperation
)->getResult();
$billingSetupResource = $billingSetupResult->getResourceName();
$accountBudgetProposal = (new AccountBudgetProposal())
->setBillingSetupUnwrapped($billingSetupResource)
->setProposedNameUnwrapped('Proposal for customer ' . $customerIdCreated)
->setProposalType(AccountBudgetProposalType::CREATE)
->setProposedStartTimeType(TimeType::NOW)
->setProposedEndTimeType(TimeType::FOREVER)
->setApprovedSpendingLimitType(SpendingLimitType::INFINITE)
->setProposedSpendingLimitMicrosUnwrapped(0)
;
$accountBudgetProposalOperation =
(new AccountBudgetProposalOperation)->setCreate($accountBudgetProposal);
$accountBudgetProposalResult = $this->getAccountBudgetProposalServiceClient()
->mutateAccountBudgetProposal(
$customerIdCreated,
$accountBudgetProposalOperation
);