/** * Gets Bf_Notifications that occurred during the given time range. Optionally, the search can be constrained (by ID) to a specific webhook. * Time range is at granularity of seconds, and is exclusive of timeStart but inclusive of timeEnd * i.e. 'Second at which notification was created' > $timeStart * && 'Second at which notification was created' <= $timeEnd * As with all GETs, by default 10 records are returned, so use the `options` field if you want to page through using for example array('records' => 10, `offset`=30) * @param union[int|string] <int>: Unix timestamp (for example generated by time()). <string>: UTC ISO8601 string * @param union[int|string|NULL] (Default: NULL) <int>: Unix timestamp (for example generated by time()). <string>: UTC ISO8601 string. <NULL>: Interpreted as 'Now'. * @param union[string $id | Bf_Webhook $entity | NULL] (Default: NULL) The webhook for which you wish to GET notifications. <string>: ID of the Bf_Webhook. <Bf_Webhook>: The Bf_Webhook. <NULL>: GET notifications of all types. * @return Bf_Notification[] */ public static function getForTimeRange($timeStart, $timeEnd = NULL, $webhook = NULL, $options = NULL, $customClient = NULL) { if (is_null($timeEnd)) { $timeEnd = time(); } $webhookID = is_null($webhook) ? NULL : Bf_Webhook::getIdentifier($webhook); // empty IDs are no good! if (!$timeStart) { throw new Bf_EmptyArgumentException("Cannot lookup empty start time!"); } if (!$timeEnd) { throw new Bf_EmptyArgumentException("Cannot lookup empty end time!"); } if (is_int($timeStart)) { $timeStart = Bf_BillingEntity::makeBillForwardDate($timeStart); } if (is_int($timeEnd)) { $timeEnd = Bf_BillingEntity::makeBillForwardDate($timeEnd); } // path param expects format like: '2015-04-23T11:05:53' $timeStart = rtrim($timeStart, "Z"); $timeEnd = rtrim($timeEnd, "Z"); $endpoint = sprintf("%s/%s%s", $timeStart, $timeEnd, is_null($webhookID) ? "" : sprintf("/%s", rawurlencode($webhookID))); return static::getCollection($endpoint, $options, $customClient); }
protected function doUnserialize(array $json) { // consult parent for further unserialization parent::doUnserialize($json); $this->unserializeEntity('request', Bf_AddChargeRequest::getClassName(), $json); $this->unserializeEntity('invoice', Bf_Invoice::getClassName(), $json); $this->unserializeArrayEntities('charges', Bf_SubscriptionCharge::getClassName(), $json); }
public function testEdit() { //-- Find the account we login with (assume first found with associated user) // order by userID so that we are likely to see our login user's account $accounts = Bf_Account::getAll(array('order_by' => 'userID')); $foundLoginAccount = NULL; foreach ($accounts as $account) { if (array_key_exists('userID', $account)) { $foundLoginAccount = $account; break; } } if (is_null($foundLoginAccount)) { throw new \Exception('Login account not found.'); } //-- Get the organization we log in with (assume first found) $orgs = Bf_Organisation::getMine(); $firstOrg = $orgs[0]; $firstOrgID = $firstOrg->id; // echo "\nInitial Org from API:\n\n"; // var_export($firstOrg); // we are going to add an API configuration for Authorize.Net $configType = "AuthorizeNetConfiguration"; // Create (upon our organisation) API configuration for Authorize.net $AuthorizeNetLoginID = '4X8R8UAawK67'; $AuthorizeNetTransactionKey = '3Udsn9w8G29qNt3Q'; // model of Authorize.Net credentials $apiConfiguration = new Bf_ApiConfiguration(array("@type" => $configType, "APILoginID" => $AuthorizeNetLoginID, "transactionKey" => $AuthorizeNetTransactionKey, "environment" => "Sandbox")); // when there are no api configurations, possibly there is no array altogether if (!is_array($firstOrg->apiConfigurations)) { $firstOrg->apiConfigurations = array(); } // we are going to remove any existing API configurations of the current type $prunedConfigs = array(); foreach ($firstOrg->apiConfigurations as $config) { if ($config['@type'] !== $configType) { array_push($prunedConfigs, $config); } } // add to our organization the model of the Authorize.Net credentials array_push($prunedConfigs, $apiConfiguration); $firstOrg->apiConfigurations = $prunedConfigs; // echo "\n\nEdited model Org:\n\n"; // var_export($firstOrg); $savedOrg = $firstOrg->save(); // echo "\n\nResponse from API after updating Org:\n\n"; // var_export($savedOrg); $newConfig = Bf_BillingEntity::fromCollectionFindFirstWhoMatchesProperties($savedOrg->apiConfigurations, array('@type' => 'AuthorizeNetConfiguration')); $expected = $AuthorizeNetLoginID; $actual = $newConfig->APILoginID; $this->assertEquals($expected, $actual, "Entity field matches known value."); }
/** * Returns (if existent; otherwise NULL) the Bf_PricingComponent who has properties matching those * provided. * @param array the Bf_PricingComponent properties upon which to match * @return Bf_PricingComponent The matching Bf_PricingComponent (if any; otherwise NULL) */ public function getPricingComponentWithProperties(array $properties) { $pricingComponents = $this->getPricingComponents(); return Bf_BillingEntity::fromCollectionFindFirstWhoMatchesProperties($pricingComponents, $properties); }
protected function doUnserialize(array $json) { // consult parent for further unserialization parent::doUnserialize($json); $this->unserializeArrayEntities('responses', Bf_TimeResponse::getClassName(), $json); }
/** * Removes coupon by the specified code. * @param string The Coupon code to remove. * @return Bf_Coupon The removed coupon. */ public static function removeCouponCode($couponCode, $queryParams = array()) { // empty IDs are no good! if (!$couponCode) { throw new Bf_EmptyArgumentException("Cannot lookup empty coupon code!"); } $endpoint = rawurlencode($couponCode); $client = Bf_BillingEntity::getSingletonClient(); $retiredEntity = static::retireAndGrabFirst($endpoint, NULL, $client, NULL, $queryParams); return $retiredEntity; }
protected function doUnserialize(array $json) { // consult parent for further unserialization parent::doUnserialize($json); $this->unserializeArrayEntities('requests', Bf_PricingComponentValueAndIDRequest::getClassName(), $json); }
/** * Returns (if existent) the Bf_PricingComponentValue corresponding to the * 'BF_PricingComponent (consistent) ID'. * @param string the Bf_PricingComponent ID upon which to match * @return Bf_PricingComponentValue The matching Bf_PricingComponentValue (if any) */ public function getValueOfPricingComponentWithID($pricingComponentID) { $properties = array('pricingComponentID' => $pricingComponentID); $pricingComponentValues = $this->getPricingComponentValues(); return Bf_BillingEntity::fromCollectionFindFirstWhoMatchesProperties($pricingComponentValues, $properties); }
/** * Parses into a BillForward timestamp the Bf_TimeRequest 'From' time * @param union[int $timestamp | string_ENUM['Now', 'CurrentPeriodEnd']] (Default: 'Immediate') When to action the amendment * * int * 'From' the specified UNIX timestamp. * Examples: * * time() * * 1431704624 * * Bf_BillingEntity::makeUTCTimeFromBillForwardDate('2015-04-23T17:13:37Z') * * string (within ENUM) * <Immediate> (Default) * 'To' the time at which the request reaches the server * * <ClientNow> * 'To' the current time by this client's clock. * * <CurrentPeriodEnd> * 'To' 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 'CurrentPeriodEnd' 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 parseTimeRequestToTime($fromTime, $subscription = NULL) { $intSpecified = NULL; switch ($fromTime) { case 'ServerNow': case 'Immediate': return NULL; case 'CurrentPeriodEnd': // we need to consult subscription if (is_null($subscription)) { throw new Bf_EmptyArgumentException('Failed to consult subscription to ascertain CurrentPeriodEnd 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($fromTime)) { $intSpecified = $fromTime; } if (!is_null($intSpecified)) { return Bf_BillingEntity::makeBillForwardDate($intSpecified); } if (is_string($fromTime)) { return $fromTime; } } return NULL; }
protected function doUnserialize(array $json) { // consult parent for further unserialization parent::doUnserialize($json); $this->unserializeArrayEntities('requests', Bf_AddChargeRequest::getClassName(), $json); }
/** * 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; }