Example #1
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;
 }