/** * Returns a Bf_PriceRequest model with 'updatedPricingComponentValues' 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 product rate plan for which to generate a price request * @param Bf_ProductRatePlan (option 2) The model of the product rate plan for which to generate a price request; provide this to avoid fetching from API * @return Bf_PriceRequest The constructed Bf_PriceRequest */ public static function forPricingComponentsByProperties(array $propertiesList, array $valuesList, $productRatePlanID = null, Bf_ProductRatePlan $productRatePlanModel = 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); } $productRatePlan; if (is_null($productRatePlanModel)) { if (is_null($productRatePlanID)) { throw new Bf_EmptyArgumentException('Received null product rate plan, and null product rate plan ID.'); } // fetch from API $productRatePlan = Bf_ProductRatePlan::getByID($productRatePlanID); } else { $productRatePlan = $productRatePlanModel; } $updatedPricingComponentValues = array(); 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($updatedPricingComponentValues, $updatedPricingComponentValue); } $model = new Bf_PriceRequest(array('productRatePlanID' => $productRatePlan->id, 'productID' => $productRatePlan->productID, 'updatedPricingComponentValues' => $updatedPricingComponentValues)); return $model; }
public function testGetByID() { $ratePlan = self::$created['ratePlan']; $ratePlanId = $ratePlan->id; $fetchedRatePlan = Bf_ProductRatePlan::getByID($ratePlanId); $expected = Bf_ProductRatePlan::getResourcePath()->getEntityName(); $actual = $fetchedRatePlan['@type']; $this->assertEquals($expected, $actual, "Type of any returned entity matches known value."); }
/** * Gets this Bf_Subscription's associated Bf_ProductRatePlan. * @return Bf_ProductRatePlan */ public function getProductRatePlan() { // if this is just a model made on our end, we might not have the serialized rate plan yet // alternatively: newer BillForward may omit serialized rate plan and necessitate a fetch if (!$this->productRatePlan) { if (!$this->productRatePlanID) { throw new Bf_PreconditionFailedException("This Bf_Subscription has neither a 'productRatePlan' specified, nor a 'productRatePlanID' by which to obtain said productRatePlan."); } $this->productRatePlan = Bf_ProductRatePlan::getByID($this->productRatePlanID); } return $this->productRatePlan; }