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; }
$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);