/** * Returns a Bf_AmendmentPriceRequest model with 'componentValues' mapped to the input key-value pairs. * @param array List of pricing component properties; array(array('name' => 'Bandwidth usage'), array('name' => 'CPU usage')) * @param array List of values to assign to respective pricing components; array(103, 2) * @param string (option 1) The ID of the subscription for which to generate a price request * @param Bf_Subscription (option 2) The model of the subscription for which to generate an upgrade price request; provide this to avoid fetching from API * @return Bf_AmendmentPriceRequest The constructed Bf_AmendmentPriceRequest */ public static function forPricingComponentsByProperties(array $propertiesList, array $valuesList, $subscriptionID = null, Bf_Subscription $subscriptionModel = null) { if (!is_array($propertiesList)) { throw new Bf_MalformedInputException('Expected input to be an array (a list of entity property maps). Instead received: ' + $propertiesList); } if (!is_array($valuesList)) { throw new Bf_MalformedInputException('Expected input to be an array (a list of integer values). Instead received: ' + $valuesList); } $subscription; if (is_null($subscriptionModel)) { if (is_null($subscriptionID)) { throw new Bf_EmptyArgumentException('Received null subscription, and null subscription ID.'); } // fetch from API $subscription = Bf_Subscription::getByID($subscriptionID); } else { $subscription = $subscriptionModel; } $componentValues = array(); $productRatePlan = $subscription->getProductRatePlan(); foreach ($propertiesList as $key => $value) { if (!is_array($value)) { throw new Bf_MalformedInputException('Expected each element of input array to be an array (a map of expected properties on entity, to values). Instead received: ' + $value); } $pricingComponent = $productRatePlan->getPricingComponentWithProperties($value); $updatedPricingComponentValue = new Bf_PricingComponentValue(array('pricingComponentID' => $pricingComponent->id, 'value' => $valuesList[$key])); array_push($componentValues, $updatedPricingComponentValue); } $model = new Bf_AmendmentPriceRequest(array('subscription' => $subscription, 'componentValues' => $componentValues, 'asOfDate' => Bf_BillingEntity::makeBillForwardDate(time()))); return $model; }