Esempio n. 1
0
 /**
  * Gets (by name or ID) Bf_ProductRatePlans belonging to a Bf_Product by name or ID
  * @param union[string ($id | $name) | Bf_Product $entity] $product The Product whose rate plans you wish to GET. <string>: ID or name of the Bf_Product. <Bf_Product>: The Bf_Product.
  * @param union[string ($id | $name) | Bf_ProductRatePlan $entity] $ratePlan The ProductRatePlan that you wish to GET from that Product. <string>: ID or name of the Bf_ProductRatePlan. <Bf_ProductRatePlan>: The Bf_ProductRatePlan.
  * @return Bf_ProductRatePlan
  */
 public static function getByProductAndRatePlanID($product, $ratePlan, $queryParams = array(), $customClient = NULL)
 {
     $productID = Bf_Product::getIdentifier($product);
     $ratePlanID = Bf_ProductRatePlan::getIdentifier($ratePlan);
     $endpoint = sprintf("product/%s/rate-plan/%s", rawurlencode($productID), rawurlencode($ratePlanID));
     return static::getFirst($endpoint, $queryParams, $customClient);
 }
Esempio n. 2
0
 /**
  * Assigns to this Bf_Coupon a Bf_ProductRatePlan and Bf_Product.
  * @param union[string ($id | $name) | Bf_ProductRatePlan $ratePlan] The product discounted by the coupon. <string>: ID or name of the Bf_ProductRatePlan. <Bf_ProductRatePlan>: The Bf_ProductRatePlan.
  * @param union[string ($id | $name) | Bf_Product $entity | NULL] (Default: NULL) The product discounted by the coupon. <string>: ID or name of the Bf_Product. <Bf_Product>: The Bf_Product. <NULL>: Fetch first result for Bf_ProductRatePlan (if identifying rate plan by name, please ensure this rate plan's name is unique), and use its Bf_Product.
  * @return Bf_Coupon The modified coupon model.
  */
 public function setRatePlan($ratePlan, $product = NULL)
 {
     if (is_null($product)) {
         // get rate plan
         $ratePlanEntity = Bf_ProductRatePlan::fetchIfNecessary($ratePlan);
         $product = $ratePlanEntity->productID;
     }
     $productIdentifier = Bf_Product::getIdentifier($product);
     $ratePlanIdentifier = Bf_ProductRatePlan::getIdentifier($ratePlan);
     $this->product = $productIdentifier;
     $this->productRatePlan = $ratePlanIdentifier;
     return $this;
 }
Esempio n. 3
0
 /**
  * Retrieves a quote for the price of the specified quantities of pricing components of the product rate plan
  * @param union[string | Bf_ProductRatePlan] Reference to rate plan <string>: ID of the Bf_ProductRatePlan. <Bf_ProductRatePlan>: The Bf_ProductRatePlan entity.
  * @param array[string => number] $namesToValues The map of pricing component names to quantities
  * Example:
  * array(
  * 	'Bandwidth' => 102,
  * 	'CPU' => 10
  * )
  * @param array $quoteOptions (Default: All keys set to their respective default values) Encapsulates the following optional parameters:
  *	* @param array (Default: array()) $..['couponCodes'] List of coupon codes to be applied in the quote
  *	* @param string_ENUM['InitialPeriod', 'RecurringPeriod', 'Upgrade'] (Default: 'InitialPeriod') $..['quoteFor']
  *	*
  *	* 	<InitialPeriod> (Default)
  *	*
  *	*	<RecurringPeriod>
  *	*
  *	* 	<Upgrade>
  *	*
  *	* @param boolean (Default: true) $..['prorated']
  *	* @param boolean (Default: false) $..['free']
  *	* @param union[string | Bf_Subscription] (Default: NULL) $..['subscription'] Reference to some subscription for whom the quote is producted. <string>: ID of the Bf_Subscription. <Bf_Subscription>: The Bf_Subscription entity.
  * @return Bf_APIQuote The price quote
  */
 public static function getQuote($ratePlan, array $namesToValues, array $quoteOptions = array('couponCodes' => array(), 'quoteFor' => 'InitialPeriod', 'prorated' => true, 'free' => false, 'subscription' => NULL))
 {
     $inputOptions = $quoteOptions;
     // $ratePlanFetched = Bf_ProductRatePlan::fetchIfNecessary($ratePlan);
     $ratePlanID = Bf_ProductRatePlan::getIdentifier($ratePlan);
     $mappings = array_map(function ($name, $value) {
         return new Bf_QuoteRequestValue(array('pricingComponent' => $name, 'quantity' => $value));
     }, array_keys($namesToValues), $namesToValues);
     $stateParams = static::mergeUserArgsOverNonNullDefaults(__METHOD__, array('quantities' => $mappings, 'productRatePlan' => $ratePlanID), $inputOptions);
     static::mutateKeysByStaticLambdas($stateParams, array('subscription' => array('Bf_Subscription', 'getIdentifier')));
     $requestEntity = new Bf_QuoteRequest($stateParams);
     $endpoint = '';
     $responseEntity = Bf_APIQuote::getClassName();
     $constructedEntity = static::postEntityAndGrabFirst($endpoint, $requestEntity, $responseEntity);
     return $constructedEntity;
 }
Esempio n. 4
0
 /**
  * Synchronously migrates the subscription to the specified plan.
  * @see scheduleMigratePlan()
  * @return Bf_MigrationResponse The migration result.
  */
 public function migratePlan(array $namesToValues, $newPlan, array $migrationOptions = array('renameSubscription' => NULL, 'pricingBehaviour' => 'DifferenceProRated', 'invoicingType' => 'Aggregated', 'dryRun' => false))
 {
     $inputOptions = $migrationOptions;
     $planID = Bf_ProductRatePlan::getIdentifier($newPlan);
     $subscriptionID = Bf_Subscription::getIdentifier($this);
     $mappings = array_map(function ($name, $value) {
         return new Bf_PricingComponentMigrationValue(array('pricingComponent' => $name, 'value' => $value));
     }, array_keys($namesToValues), $namesToValues);
     $stateParams = static::mergeUserArgsOverNonNullDefaults(__METHOD__, array('mappings' => $mappings, 'productRatePlan' => $planID), $inputOptions);
     static::renameKey($stateParams, 'renameSubscription', 'nextSubscriptionName');
     $requestEntity = new Bf_MigrationRequest($stateParams);
     $endpoint = sprintf("%s/migrate", rawurlencode($subscriptionID));
     $responseEntity = Bf_MigrationResponse::getClassName();
     $constructedEntity = static::postEntityAndGrabFirst($endpoint, $requestEntity, $responseEntity);
     return $constructedEntity;
 }