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 testEnsureGatewayExists */ public function testCreateWithProfile() { $createdAccount = Bf_Account::create(Models::Account()); $actual = $createdAccount->profile; $this->assertNotNull($actual, "Nested entity introduced correctly."); self::$createdAccount = $createdAccount; }
public static function makeRequiredEntities() { $models = array('account' => Models::AccountWithJustProfile()); $created = array('account' => Bf_Account::create($models['account'])); self::$models = $models; self::$created = $created; }
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);