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; }
/** * @depends testAddDefaultPaymentMethod */ public function testUpdateCascade() { // print_r("\nCreated account:\n\n"); // var_export(self::$createdAccount); //--Add a Profile to an existing Account $accountID = self::$createdAccount->id; $fetchedAccount = Bf_Account::getByID($accountID); // print_r("\nFetched account:\n\n"); // var_export($fetchedAccount); $firstPaymentMethod = $fetchedAccount->paymentMethods[0]; $expected1 = true; $actual1 = $firstPaymentMethod->defaultPaymentMethod; $this->assertEquals($expected1, $actual1, "Payment method begins as default before update of account."); $originalName = $fetchedAccount->profile->firstName; $newName = 'Sanae'; $fetchedAccount->profile->firstName = $newName; $updatedAccount = $fetchedAccount->save(); // print_r("\nUpdated account:\n\n"); // var_export($updatedAccount); $expected2 = $newName; $actual2 = $updatedAccount->profile->firstName; $this->assertEquals($expected2, $actual2, "Nested entity change introduced correctly by cascade update."); $firstPaymentMethodAfterUpdate = $updatedAccount->paymentMethods[0]; $expected3 = true; $actual3 = $firstPaymentMethodAfterUpdate->defaultPaymentMethod; $this->assertEquals($expected3, $actual3, "Payment method remains as default after update of account."); }
public static function setUpBeforeClass() { TestBase::initialize(); $someEntities = Bf_Account::getAll(array('records' => 1)); $anEntity = $someEntities[0]; self::$anOrganizationID = $anEntity->organizationID; }
public function testGetProfileViaAccount() { $account = self::$created['account']; $accountID = $account->id; $fetchedAccount = Bf_Account::getByID($accountID); $profile = $fetchedAccount->profile; $expected = $accountID; $actual = $profile->accountID; $this->assertEquals($expected, $actual, "Field on fetched entity matches known value."); }
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."); }
/** * @depends testCreateAddressDirectly */ public function testUpdateAddressIndirectly() { $account = self::$entities['account']; $updatedAccount = Bf_Account::getByID($account->id); $profile = $updatedAccount->profile; $addresses = $profile->addresses; $firstAddress = $addresses[0]; $address = $firstAddress; $cityBefore = $address->city; $uniqueString = time(); $newCity = "Neo Tokyo {$uniqueString}"; $address->city = $newCity; $updatedProfile = $profile->save(); $updatedAddresses = $updatedProfile->getAddresses(); $updatedFirstAddress = $updatedAddresses[0]; $updatedAddress = $updatedFirstAddress; $cityAfter = $updatedAddress->city; $this->assertNotEquals($cityBefore, $cityAfter, "Asserting that address's city name changes after update."); $expected = $newCity; $actual = $cityAfter; $this->assertEquals($expected, $actual, "Asserting that address's city name changes to expected string after update."); }
/** * Gets Bf_Invoices for a given Bf_Account * @param union[string | Bf_Account] $account Reference to account <string>: $id of the Bf_Account. <Bf_Account>: The Bf_Account entity. * @return Bf_Invoice[] */ public static function getForAccount($account, $options = NULL, $customClient = NULL) { $accountID = Bf_Account::getIdentifier($account); $endpoint = sprintf("account/%s", rawurlencode($accountID)); return static::getCollection($endpoint, $options, $customClient); }
/** * Synchronously advances the account's subscriptions through time. * @param array $advancementOptions (Default: All keys set to their respective default values) Encapsulates the following optional parameters: * * @param boolean (Default: false) $..['dryRun'] Whether to forego persisting the effected changes. * * @param boolean (Default: false) $..['skipIntermediatePeriods'] * * @param boolean (Default: true) $..['handleAmendments'] * * @param string_ENUM['SingleAttempt', 'FollowDunning', 'None'] (Default: 'SingleAttempt') $..['executionStrategy'] * * * * <SingleAttempt> (Default) * * * * <FollowDunning> * * * * <None> * * * * @param boolean (Default: false) $..['freezeOnCompletion'] * * @param {@see Bf_BillingEntity::parseTimeRequestFromTime(mixed)} $..['from'] From when to advance time * * @param {@see Bf_BillingEntity::parseTimeRequestToTime(mixed)} $..['to'] Until when to advance time * * @param integer (Default: NULL) (Non-null value of param requires that $..['to'] be NULL instead) $..['periods'] * @return Bf_AccountTimeResponse The results of advancing the account's subscription through time. */ public function advance(array $advancementOptions = array('dryRun' => false, 'skipIntermediatePeriods' => false, 'handleAmendments' => true, 'executionStrategy' => 'SingleAttempt', 'freezeOnCompletion' => false, 'from' => NULL, 'to' => 'CurrentPeriodEnd', 'periods' => NULL)) { $inputOptions = $advancementOptions; $accountID = Bf_Account::getIdentifier($this); $stateParams = static::mergeUserArgsOverNonNullDefaults(__METHOD__, array(), $inputOptions); static::mutateKeysByStaticLambdas($stateParams, array('from' => 'parseTimeRequestFromTime', 'to' => 'parseTimeRequestToTime'), array('from' => array(NULL), 'to' => array(NULL))); $requestEntity = new Bf_TimeRequest($stateParams); $endpoint = sprintf("%s/advance", rawurlencode($accountID)); $responseEntity = Bf_AccountTimeResponse::getClassName(); $constructedEntity = static::postEntityAndGrabFirst($endpoint, $requestEntity, $responseEntity); return $constructedEntity; }
public function testUpdateWithProfile() { //--Add a Profile to an existing Account // construct default model of new account $account = new Bf_Account(); // create modeled account via API $createdAccount = Bf_Account::create($account); $newEmail = '*****@*****.**'; // construct model of profile $profile = new Bf_Profile(array('organizationID' => $createdAccount->organizationID, 'accountID' => $createdAccount->id, 'email' => $newEmail, 'firstName' => 'Test')); // associate profile with account $createdAccount->profile = $profile; // save changes to account $createdAccount->save(); $expected = $newEmail; $actual = $createdAccount->profile->email; $this->assertEquals($expected, $actual, "Nested entity introduced correctly."); }
// 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; $savedOrg = $firstOrg->save(); //-- Make account with expected profile $email = getUsualAccountsProfileEmail(); $profile = new Bf_Profile(array('email' => $email, 'firstName' => 'Test')); $account = new Bf_Account(array('profile' => $profile)); $createdAcc = Bf_Account::create($account); $createdAccID = $createdAcc->id; //-- make payment method, and associate it with account //-- make Authorize.net token to associate payment method to // FILL IN WITH YOUR AUTHORIZE.NET CUSTOMER PROFILE ID $customerProfileID = 00; // FILL IN WITH YOUR AUTHORIZE.NET CUSTOMER PAYMENT PROFILE ID $customerPaymentProfileID = 00; // FILL IN WITH YOUR AUTHORIZE.NET CUSTOMER'S CARD LAST 4 DIGITS // this 'last 4 digits of credit card number' field (currently optional) is required for refunds $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);