Esempio n. 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('uom' => array(Models::UnitOfMeasure(), Models::UnitOfMeasure2(), Models::UnitOfMeasure2()), 'product' => Models::MonthlyRecurringProduct(), 'pricingComponentTierLists' => array(Models::PricingComponentTiers(), Models::PricingComponentTiers2(), Models::PricingComponentTiers2()));
     $created = array('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']);
     self::$models = $models;
     self::$created = $created;
 }
Esempio n. 2
0
 public static function initStatics()
 {
     self::$_resourcePath = new Bf_ResourcePath('units-of-measure', 'unitOfMeasure');
 }
Esempio n. 3
0
$cardLast4Digits = 00;
$authorizeNetToken = new Bf_AuthorizeNetToken(array('accountID' => $createdAccID, 'customerProfileID' => $customerProfileID, 'customerPaymentProfileID' => $customerPaymentProfileID, 'lastFourDigits' => $cardLast4Digits));
$createdAuthorizeNetToken = Bf_AuthorizeNetToken::create($authorizeNetToken);
$createdAuthorizeNetTokenID = $createdAuthorizeNetToken->id;
$paymentMethod = new Bf_PaymentMethod(array('linkID' => $createdAuthorizeNetTokenID, 'accountID' => $createdAccID, 'name' => 'Authorize.Net', 'description' => 'Pay via Authorize.Net', 'gateway' => 'authorizeNet', 'userEditable' => 0, 'priority' => 100, 'reusable' => 1));
$createdPaymentMethod = Bf_PaymentMethod::create($paymentMethod);
$createdPaymentMethodID = $createdPaymentMethod->id;
$paymentMethods = array($createdPaymentMethod);
// add these payment methods to our model of the created account
$createdAcc->paymentMethods = $paymentMethods;
// save changes to real account
$createdAcc = $createdAcc->save();
var_export($createdAcc);
//-- Make unit of measure
$uom = new Bf_UnitOfMeasure(array('name' => 'Devices', 'displayedAs' => 'Devices', 'roundingScheme' => 'UP'));
$createdUom = Bf_UnitOfMeasure::create($uom);
$createdUomID = $createdUom->id;
//-- Make product
$product = new Bf_Product(array('productType' => 'non-recurring', 'state' => 'prod', 'name' => 'Month of Paracetamoxyfrusebendroneomycin', 'description' => 'It can cure the common cold, and being struck by lightning', 'durationPeriod' => 'days', 'duration' => 28));
$createdProduct = Bf_Product::create($product);
$createdProductID = $createdProduct->id;
//-- Make product rate plan
//-- Make pricing components for product rate plan
//-- Make tiers for pricing component
$tier = new Bf_PricingComponentTier(array('lowerThreshold' => 1, 'upperThreshold' => 1, 'pricingType' => 'unit', 'price' => 1));
$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;