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; }
/** * 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); }
/** * @depends testCreate */ public function testGetByID() { $product = self::$createdProduct; $productId = $product->id; $fetchedProduct = Bf_Product::getById($productId); $description = $fetchedProduct->description; $expected = self::$productDescription; $actual = $description; $this->assertEquals($expected, $actual, "Product's description matches known value."); }
/** * 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; }
public static function initStatics() { self::$_resourcePath = new Bf_ResourcePath('products', 'product'); }
/** * Gets Bf_Subscriptions for a given product ID * @param union[string | Bf_Product] $product The Bf_Product to which the Bf_Coupon should be applied. <string>: ID of the Bf_Product. <Bf_Product>: The Bf_Product. * @return Bf_Subscription[] */ public static function getByProductID($product, $options = NULL, $customClient = NULL) { $product = Bf_Product::getIdentifier($product); $endpoint = sprintf("product/%s", rawurlencode($product)); return static::getCollection($endpoint, $options, $customClient); }
$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; //-- Make pricing component value instance of pricing component $prc = new Bf_PricingComponentValue(array('pricingComponentID' => $createdPricingComponentID, 'value' => 2, 'crmID' => '')); $pricingComponentValuesArray = array($prc); //-- Make Bf_PaymentMethodSubscriptionLinks