Ejemplo n.º 1
0
 protected function doUnserialize(array $json)
 {
     // consult parent for further unserialization
     parent::doUnserialize($json);
     $this->unserializeArrayEntities('subscriptions', Bf_Subscription::getClassName(), $json);
     $this->unserializeArrayEntities('invoices', Bf_Invoice::getClassName(), $json);
 }
Ejemplo n.º 2
0
 protected function doUnserialize(array $json)
 {
     // consult parent for further unserialization
     parent::doUnserialize($json);
     $this->unserializeEntity('newSubscription', Bf_Subscription::getClassName(), $json);
     $this->unserializeEntity('previousSubscription', Bf_Subscription::getClassName(), $json);
 }
Ejemplo n.º 3
0
 public static function getApplicableCouponsForSubscription($subscription, $options = NULL, $customClient = NULL)
 {
     $subscriptionID = Bf_Subscription::getIdentifier($subscription);
     $endpoint = sprintf("%s/applicable-coupons", rawurlencode($subscriptionID));
     $responseEntity = Bf_Coupon::getClassName();
     return static::getCollection($endpoint, $options, $customClient, $responseEntity);
 }
Ejemplo n.º 4
0
 public static function makeRequiredEntities()
 {
     $useExistingOrMakeNew = function ($entityClass, $model) {
         $name = $model->name;
         try {
             if ($entityClass === Bf_ProductRatePlan::getClassName()) {
                 $existing = Bf_ProductRatePlan::getByProductAndRatePlanID($model->productID, $name);
             } else {
                 $existing = $entityClass::getByID($name);
             }
             if ($existing) {
                 return $existing;
             }
         } catch (Bf_NoMatchingEntityException $e) {
             return $entityClass::create($model);
         }
     };
     $models = array('account' => Models::Account(), 'uom' => array(Models::UnitOfMeasure(), Models::UnitOfMeasure2(), Models::UnitOfMeasure2()), 'product' => Models::MonthlyRecurringProduct(), 'pricingComponentTierLists' => array(Models::PricingComponentTiers(), Models::PricingComponentTiers2(), Models::PricingComponentTiers2()));
     $created = array('account' => Bf_Account::create($models['account']), 'uom' => array($useExistingOrMakeNew(Bf_UnitOfMeasure::getClassName(), $models['uom'][0]), $useExistingOrMakeNew(Bf_UnitOfMeasure::getClassName(), $models['uom'][1])), 'product' => $useExistingOrMakeNew(Bf_Product::getClassName(), $models['product']));
     // having created product, make rate plan for it
     $models['pricingComponents'] = array(Models::PricingComponent($created['uom'][0], $models['pricingComponentTierLists'][0]), Models::PricingComponent2($created['uom'][1], $models['pricingComponentTierLists'][1]), Models::PricingComponent3($created['uom'][1], $models['pricingComponentTierLists'][1]));
     $models['ratePlan'] = Models::ProductRatePlan($created['product'], $models['pricingComponents']);
     $created['ratePlan'] = $useExistingOrMakeNew(Bf_ProductRatePlan::getClassName(), $models['ratePlan']);
     $models['subscription'] = Models::Subscription($created['ratePlan'], $created['account']);
     $created['subscription'] = Bf_Subscription::create($models['subscription']);
     return $created;
 }
Ejemplo n.º 5
0
 /**
  * Parses into a BillForward timestamp the actioning time for some amendment
  * @param union[int $timestamp | string_ENUM['Immediate' | 'ServerNow', 'ClientNow', 'AtPeriodEnd']] (Default: 'Immediate') When to action the amendment
  *
  *  int
  *  Schedule the amendment to occur at the specified UNIX timestamp.
  *  Examples:
  *  	* time()
  *  	* 1431704624
  *  	* Bf_BillingEntity::makeUTCTimeFromBillForwardDate('2015-04-23T17:13:37Z')
  *
  *	string (within ENUM)
  *  <Immediate> (Default) | <ServerNow>
  *  Perform the amendment now (synchronously where possible). Actioning time is set to BillForward's 'now' at the time it parses the request.
  *
  *  <ClientNow>
  *  Schedule the amendment for 'now' according to this client's clock (which will likely be in the past by the time the request reaches BillForward).
  *  
  *  <AtPeriodEnd>
  *  Schedule the amendment to occur at the end of the subscription's current billing period.
  *
  *  string (outside ENUM)
  *  Schedule the amendment to occur at the specified BillForward-formatted timestamp.
  *  Examples:
  *  	* '2015-04-23T17:13:37Z'
  *  	* Bf_BillingEntity::makeBillForwardDate(time())
  *  	* Bf_BillingEntity::makeBillForwardDate(1431704624)
  *
  * @param union[NULL | union[string $id | Bf_Subscription $entity]] (Default: NULL) (Optional unless 'AtPeriodEnd' actioningTime specified) Reference to subscription <string>: $id of the Bf_Subscription. <Bf_Subscription>: The Bf_Subscription entity.
  * @return string The BillForward-formatted time.
  */
 public static function parseActioningTime($actioningTime, $subscription = NULL)
 {
     $intSpecified = NULL;
     switch ($actioningTime) {
         case 'ServerNow':
         case 'Immediate':
             return NULL;
         case 'AtPeriodEnd':
             // we need to consult subscription
             if (is_null($subscription)) {
                 throw new Bf_EmptyArgumentException('Failed to consult subscription to ascertain AtPeriodEnd time, because a null reference was provided to the subscription.');
             }
             $subscriptionFetched = Bf_Subscription::fetchIfNecessary($subscription);
             return $subscriptionFetched->getCurrentPeriodEnd();
         case 'ClientNow':
             $intSpecified = time();
         default:
             if (is_int($actioningTime)) {
                 $intSpecified = $actioningTime;
             }
             if (!is_null($intSpecified)) {
                 return Bf_BillingEntity::makeBillForwardDate($intSpecified);
             }
             if (is_string($actioningTime)) {
                 return $actioningTime;
             }
     }
     return NULL;
 }
Ejemplo n.º 6
0
 public function testGetAll()
 {
     $subscriptions = Bf_Subscription::getAll();
     $firstSub = $subscriptions[0];
     $expected = Bf_Subscription::getResourcePath()->getEntityName();
     $actual = $firstSub['@type'];
     $this->assertEquals($expected, $actual, "Type of any returned entity matches known value.");
 }
Ejemplo n.º 7
0
 public static function applyCouponToSubscription(Bf_Coupon $coupon, $subscription)
 {
     $subscriptionID = Bf_Subscription::getIdentifier($subscription);
     // make new Bf_Coupon using only the `couponCode` param
     $requestEntity = new Bf_Coupon(array('couponCode' => $coupon->couponCode), $coupon->getClient());
     $endpoint = sprintf("%s/coupons", rawurlencode($subscriptionID));
     $responseEntity = Bf_Coupon::getClassName();
     $constructedEntity = static::postEntityAndGrabFirst($endpoint, $requestEntity, $responseEntity);
     return $constructedEntity;
 }
Ejemplo n.º 8
0
 /**
  * Fetches Bf_Subscriptions for this Bf_ProductRatePlan.
  * @return Bf_Subscription[]
  */
 public function getSubscriptions($options = NULL, $customClient = NULL)
 {
     return Bf_Subscription::getByRatePlanID($this->id, $options, $customClient);
 }
Ejemplo n.º 9
0
 /**
  * Gets Bf_Invoices for a given Bf_Subscription
  * @param union[string | Bf_Subscription] $subscription Reference to subscription <string>: $id of the Bf_Subscription. <Bf_Subscription>: The Bf_Subscription entity.
  * @return Bf_Invoice[]
  */
 public static function getForSubscription($subscription, $options = NULL, $customClient = NULL)
 {
     $subscriptionID = Bf_Subscription::getIdentifier($subscription);
     $endpoint = sprintf("subscription/%s", rawurlencode($subscriptionID));
     return static::getCollection($endpoint, $options, $customClient);
 }
Ejemplo n.º 10
0
 /**
  * Gets a list of subscriptions to which the specified coupon code has been applied.
  * Expects a 'base' coupon code.
  * @param string The Coupon code on which to search.
  * @return Bf_Subscription[] The fetched subscriptions.
  */
 public static function getSubscriptionApplicationsForBaseCode($baseCode, $options = NULL, $customClient = NULL)
 {
     // empty IDs are no good!
     if (!$baseCode) {
         throw new Bf_EmptyArgumentException("Cannot lookup empty coupon base code!");
     }
     $endpoint = sprintf("%s/subscriptions", rawurlencode($baseCode));
     $responseEntity = Bf_Subscription::getClassName();
     return static::getCollection($endpoint, $options, $customClient, $responseEntity);
 }
Ejemplo n.º 11
0
 /**
  * Fetches Bf_Subscriptions for this Bf_Account.
  * @return Bf_Subscription[]
  */
 public function getSubscriptions($options = NULL, $customClient = NULL)
 {
     return Bf_Subscription::getForAccount($this->id, $options, $customClient);
 }
Ejemplo n.º 12
0
 public static function initStatics()
 {
     self::$_resourcePath = new Bf_ResourcePath('subscriptions', 'subscription');
 }
Ejemplo n.º 13
0
 /**
  * Removes a payment method from use by the specified subscription
  * @param union[string $id | Bf_Subscription $subscription] The Bf_Subscription to which the Bf_Coupon should be applied. <string>: ID of the Bf_Subscription. <Bf_Subscription>: The Bf_Subscription.
  * @return Bf_PaymentMethod The removed payment method.
  */
 public function removeFromSubscription($subscription)
 {
     return Bf_Subscription::removePaymentMethodFromSubscription($this, $subscription);
 }
Ejemplo n.º 14
0
 /**
  * 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;
 }
Ejemplo n.º 15
0
$tiers = array($tier);
$pricingComponentsArray = array(new Bf_PricingComponent(array('@type' => 'flatPricingComponent', 'chargeModel' => 'flat', 'name' => 'Devices used', 'description' => 'How many devices you use, I guess', 'unitOfMeasureID' => $createdUomID, 'chargeType' => 'subscription', 'upgradeMode' => 'immediate', 'downgradeMode' => 'immediate', 'defaultQuantity' => 10, 'tiers' => $tiers)));
$prp = new Bf_ProductRatePlan(array('currency' => 'USD', 'name' => getUsualPrpName(), 'pricingComponents' => $pricingComponentsArray, 'productID' => $createdProductID));
$createdPrp = Bf_ProductRatePlan::create($prp);
$createdProductRatePlanID = $createdPrp->id;
$createdPricingComponentID = $createdPrp->pricingComponents[0]->id;
//-- Make pricing component value instance of pricing component
$prc = new Bf_PricingComponentValue(array('pricingComponentID' => $createdPricingComponentID, 'value' => 2, 'crmID' => ''));
$pricingComponentValuesArray = array($prc);
//-- Make Bf_PaymentMethodSubscriptionLinks
// refer by ID to our payment method.
$paymentMethodReference = new Bf_PaymentMethod(array('id' => $createdPaymentMethodID));
$paymentMethodSubscriptionLink = new Bf_PaymentMethodSubscriptionLink(array('paymentMethod' => $paymentMethodReference, 'organizationID' => $firstOrgID));
$paymentMethodSubscriptionLinks = array($paymentMethodSubscriptionLink);
//-- Provision subscription
$sub = new Bf_Subscription(array('type' => 'Subscription', 'productID' => $createdProductID, 'productRatePlanID' => $createdProductRatePlanID, 'accountID' => $createdAccID, 'name' => 'Memorable Bf_Subscription', 'description' => 'Memorable Bf_Subscription Description', 'paymentMethodSubscriptionLinks' => $paymentMethodSubscriptionLinks, 'pricingComponentValues' => $pricingComponentValuesArray));
$createdSub = Bf_Subscription::create($sub);
// activate provisioned subscription
$createdSub->activate();
echo "\n";
echo sprintf("\$usualLoginAccountID = '%s';\n", $foundLoginAccount->id);
echo sprintf("\$usualLoginUserID = '%s';\n", $foundLoginAccount->userID);
echo sprintf("\$usualOrganisationID = '%s';\n", $firstOrgID);
echo sprintf("\$usualAccountID = '%s';\n", $createdAccID);
echo sprintf("\$usualPaymentMethodLinkID = '%s';\n", $createdAuthorizeNetTokenID);
echo sprintf("\$usualPaymentMethodID = '%s';\n", $createdPaymentMethodID);
echo sprintf("\$usualProductID = '%s';\n", $createdProductID);
echo sprintf("\$usualProductRatePlanID = '%s';\n", $createdProductRatePlanID);
echo sprintf("\$usualPricingComponentID = '%s';\n", $createdPricingComponentID);
echo sprintf("\$usualSubscriptionID = '%s';\n", $createdSub->id);
echo sprintf("\$usualUnitOfMeasureID = '%s';\n", $createdUomID);