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.");
 }
示例#2
0
 /**
  * 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);
 }
示例#3
0
 /**
  * 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);
 }