예제 #1
0
 public function testShouldUseDefaultFactoryToCreateInternalRuleBasedOnGivenCountryCodeWhenFactoryIsNotDefined()
 {
     $countryCode = 'DE';
     $bank = '123456';
     $rule = new BankAccount($countryCode, $bank);
     $this->assertInstanceOf('Respect\\Validation\\Rules\\Locale\\GermanBankAccount', $rule->getValidatable());
 }
 public function update(BankAccount $ba)
 {
     if (!isset($this->identityMap[$ba])) {
         throw new MapperException('Object has no ID, cannot update.');
     }
     $this->db->exec(sprintf('UPDATE bankaccount SET balance = %f WHERE id = %d;', $ba->getBalance(), $this->identityMap[$ba]));
 }
예제 #3
0
 /**
  * @covers BankAccount::getBalance
  * @group balanceIsInitiallyZero
  * @group specification
  */
 public function testBalanceIsInitiallyZero()
 {
     /* @Given a fresh bank account */
     $ba = new BankAccount();
     /* @When I ask it for its balance */
     $balance = $ba->getBalance();
     /* @Then I should get 0 */
     $this->assertEquals(0, $balance);
 }
 public function testAccountBalanceWithdrawals()
 {
     $bank_account = new BankAccount('15934903649620486', $this->pdo);
     $bank_account->withdrawMoney(100);
     $bank_account = new BankAccount('15936487230215067', $this->pdo);
     $bank_account->withdrawMoney(230);
     $bank_account = new BankAccount('12348612357236185', $this->pdo);
     $bank_account->withdrawMoney(24);
     $xml_dataset = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__) . '/_files/bank-account-after-withdrawals.xml');
     PHPUnit_Extensions_Database_TestCase::assertDataSetsEqual($xml_dataset, $this->tester->getConnection()->createDataSet());
 }
예제 #5
0
 public function __construct($name, TaxIdNumber $taxIdNumber, Address $address, BankAccount $account)
 {
     $this->name = $name;
     $this->taxIdNumber = (string) $taxIdNumber;
     $this->postalCode = $address->getPostalCode();
     $this->street = $address->getStreet();
     $this->city = $address->getCity();
     $this->country = $address->getCountry();
     $this->bankName = $account->getBankName();
     $this->bankNumber = $account->getBankNumber();
     $this->bicCode = $account->getBicCode();
 }
예제 #6
0
 public function testDepositShouldRegisterWithAfipWhenAmoutGreaterThanAHundred()
 {
     // arrange
     $account = new BankAccount('Nicolas');
     $value = 500;
     $afipMock = $this->getMock('Afip', array('registerTransaction'));
     $afipMock->expects($this->once())->method('registerTransaction')->with($this->equalTo('Nicolas'), $this->equalTo($value));
     $account->setAfip($afipMock);
     $amountToTransfer = 500;
     // act
     $account->deposit(500);
     // assert
     $this->assertEquals($amountToTransfer, $account->getBalance());
 }
예제 #7
0
 public function __construct($name, TaxIdNumber $taxIdNumber, Address $address, BankAccount $account)
 {
     if (!$name) {
         throw new \InvalidArgumentException('Name is required');
     }
     $this->name = $name;
     $this->taxIdNumber = (string) $taxIdNumber;
     $this->postalCode = $address->getPostalCode();
     $this->street = $address->getStreet();
     $this->city = $address->getCity();
     $this->country = $address->getCountry();
     $this->bankName = $account->getBankName();
     $this->bankNumber = $account->getBankNumber();
     $this->bicCode = $account->getBicCode();
 }
 public function setUp()
 {
     parent::setUp();
     $bankAccount = new BankAccount();
     $bankAccount->setType(BankAccount::TYPE_NORMAL);
     $bankAccount->setBankName('ミツイスミトモ');
     $bankAccount->setBankCode('0009');
     $bankAccount->setBranchName('アカサカ');
     $bankAccount->setBranchCode('825');
     $bankAccount->setHolderName('スラビ');
     $bankAccount->setNumber('9876543');
     $bankAccount->setCompanyCode('1234560789');
     $this->transaction = new MoneyTransferTransaction();
     $this->transaction->setDestinationBankAccount($bankAccount);
     $this->transaction->setAmount(15234);
 }
 public function testValidationFailsOnNon10DigitCompanyCodes()
 {
     $this->account->setCompanyCode('01234567890');
     $this->assertSame('01234567890', $this->account->getCompanyCode());
     $violations = Validator::validateBankAccount($this->account, null);
     $this->assertTrue(count($violations) === 1);
     $this->assertTrue(count($violations->get('companyCode')) === 1);
     $this->account->setCompanyCode('012345678');
     $this->assertSame('012345678', $this->account->getCompanyCode());
     $violations = Validator::validateBankAccount($this->account, null);
     $this->assertTrue(count($violations) === 1);
     $this->assertTrue(count($violations->get('companyCode')) === 1);
     $this->account->setCompanyCode('0123456789');
     $this->assertSame('0123456789', $this->account->getCompanyCode());
     $violations = Validator::validateBankAccount($this->account, null);
     $this->assertTrue(count($violations) === 1);
     $this->assertTrue(count($violations->get('companyCode')) === 1);
     $this->account->setCompanyCode('0123456789');
     $this->assertSame('0123456789', $this->account->getCompanyCode());
     $violations = Validator::validateBankAccount($this->account, null);
     $this->assertTrue(count($violations) === 0);
     //Not required.
     $this->account->setCompanyCode('');
     $this->assertSame('', $this->account->getCompanyCode());
     $violations = Validator::validateBankAccount($this->account, null);
     $this->assertTrue(count($violations) === 0);
     //Not required.
     $this->account->setCompanyCode(null);
     $this->assertSame(null, $this->account->getCompanyCode());
     $violations = Validator::validateBankAccount($this->account, null);
     $this->assertTrue(count($violations) === 0);
 }
예제 #10
0
파일: locking.php 프로젝트: bermi/akelos
 public function test_should_lock_optimistically()
 {
     $Account1 = new BankAccount(array('balance' => 2000));
     $this->assertEqual($Account1->lock_version, 1, 'Version attribute initially starts at 1.');
     $Account1->save();
     $this->assertEqual($Account1->lock_version, 1, 'We are now on Version 1.');
     $Account2 = new BankAccount($Account1->getId());
     $this->assertEqual($Account2->lock_version, 1, 'We reloaded Version 1.');
     $Account1->balance = 5;
     $Account1->save();
     $this->assertEqual($Account1->lock_version, 2, 'We are now on Version 2.');
     $Account2->balance = 3000000;
     $this->assertUpcomingError('Attempted to update a stale object');
     $this->assertFalse($Account2->save(), 'We cant save because version number is wrong.');
     $Account1->balance = 1000;
     $this->assertTrue($Account1->save());
     $Account3 = new BankAccount($Account1->getId());
     $this->assertEqual($Account3->balance, 1000);
     $this->assertEqual($Account3->lock_version, 3, 'We are now on Version 3.');
 }
 public function setUp()
 {
     parent::setUp();
     $senderBankAccount = new BankAccount();
     $senderBankAccount->setType(BankAccount::TYPE_NORMAL);
     $senderBankAccount->setBankName('ミツイスミトモ');
     $senderBankAccount->setBankCode('0009');
     $senderBankAccount->setBranchName('アカサカ');
     $senderBankAccount->setBranchCode('825');
     $senderBankAccount->setHolderName('スラビ');
     $senderBankAccount->setNumber('9876543');
     $senderBankAccount->setCompanyCode('1234560789');
     $this->transferRequest = new TransferRequest();
     $this->transferRequest->setType(TransferRequest::TYPE_GENERAL);
     $this->transferRequest->setSourceBankAccount($senderBankAccount);
     $this->transferRequest->setDate(\DateTime::createFromFormat('Y-m-d', '2016-02-25'));
     $receiverBankAccount = new BankAccount();
     $receiverBankAccount->setType(BankAccount::TYPE_NORMAL);
     $receiverBankAccount->setBankName('トウキョウトミン');
     $receiverBankAccount->setHolderName('テストー.カブシキガイシャ');
     //Note: using a normal dot/dash in this example
     $receiverBankAccount->setBankCode('0137');
     $receiverBankAccount->setBranchName('シブヤ');
     $receiverBankAccount->setBranchCode('031');
     $receiverBankAccount->setNumber('1231990');
     $receiverTransaction = new MoneyTransferTransaction();
     $receiverTransaction->setDestinationBankAccount($receiverBankAccount);
     $receiverTransaction->setAmount(1103661);
     $this->transferRequest->addTransaction($receiverTransaction);
     $receiverBankAccount = new BankAccount();
     $receiverBankAccount->setType(BankAccount::TYPE_NORMAL);
     $receiverBankAccount->setBankName('ベツバンク');
     $receiverBankAccount->setHolderName('ヒトノナマエ');
     //Note: using a normal dot/dash in this example
     $receiverBankAccount->setBankCode('0132');
     $receiverBankAccount->setBranchName('イケブクロ');
     $receiverBankAccount->setBranchCode('021');
     $receiverBankAccount->setNumber('1331990');
     $receiverTransaction = new MoneyTransferTransaction();
     $receiverTransaction->setDestinationBankAccount($receiverBankAccount);
     $receiverTransaction->setAmount(657856);
     $this->transferRequest->addTransaction($receiverTransaction);
 }
예제 #12
0
 public function vault_add_bank_account($paydata)
 {
     $status = '';
     $result = '';
     $o_bank_account = new BankAccount();
     $o_bank_account->setName($paydata['first_name'] . " " . $paydata['last_name']);
     $o_bank_account->setAccountNumber($paydata['account_number']);
     $o_bank_account->setRoutingNumber($paydata['routing_number']);
     if ($paydata['bank_acct_type'] == "Savings") {
         $o_bank_account->setAccountType(BankAccount::$XS_BA_TYPE_SAVINGS);
     } else {
         $o_bank_account->setAccountType(BankAccount::$XS_BA_TYPE_CHECKING);
     }
     $o_billing_address = new Address(Address::$XS_ADDRESS_NAME_BILLING);
     $o_billing_address->setLine1($paydata['billing_address1']);
     if (!empty($paydata['billing_address2'])) {
         $o_billing_address->setLine2($paydata['billing_address2']);
     } else {
         $o_billing_address->setLine2(" ");
     }
     $o_billing_address->setCity($paydata['billing_city']);
     if (!empty($paydata['billing_state_id'])) {
         $States = new State();
         $billing_state = $States->findById($paydata['billing_state_id']);
         $billing_state = $billing_state['State']['abbr'];
     }
     $o_billing_address->setState($billing_state);
     $o_billing_address->setZipcode($property['billing_zip']);
     $o_billing_address->setCountry("USA");
     $o_bank_account->setBillingAddress($o_billing_address);
     if ($paydata['usertype'] == 2) {
         $o_bcpc = new BaseCommerceClient(RENTSQUARE_PARTNER_USER, RENTSQUARE_PARTNER_PASS, RENTSQUARE_PARTNER_KEY);
     } else {
         $o_bcpc = new BaseCommerceClient(RENTSQUARE_MERCH_USER, RENTSQUARE_MERCH_PASS, RENTSQUARE_MERCH_KEY);
     }
     $o_bcpc->setSandbox(BC_SANDBOXVALUE);
     $o_bank_account = $o_bcpc->addBankAccount($o_bank_account);
     $status = $o_bank_account->getStatus();
     if ($status == BankAccount::$XS_BA_STATUS_FAILED) {
         // Fail
         $status = 0;
         $result = $o_bank_account->getMessages();
     } else {
         if ($status == BankAccount::$XS_BA_STATUS_ACTIVE) {
             // Success
             $status = 1;
             $result = $o_bank_account->getToken();
         }
     }
     return array($status, $result);
 }
예제 #13
0
        return 'Balance' . $this->balance;
        // same result when return 'balance'.$this->balance;
    }
    public function withdrawn($amount)
    {
        // displaybalance is method
        if ($this->balance < $amount) {
            echo 'not enough money';
            // HERE U CAN ALSO USE THROWING EXCEPTIONS
        } else {
            $this->balance = $this->balance - $amount;
            // same result when return 'balance'.$this->balance;
        }
    }
    public function Deposit($amount)
    {
        $this->balance = $this->balance + $amount;
    }
}
class SavingAccount extends BankAccount
{
}
$piyush = new BankAccount();
$piyush->Deposit(100);
$piyush->Withdrawn(20);
$piyush_saving = new SavingAccount();
$piyush_saving->Deposit(300);
echo $piyush->DisplayBalance() . '<br>';
echo $piyush_saving->DisplayBalance();
?>
 
<?php

class BankAccount
{
    public $balance = 0;
    public function DisplayBalance()
    {
        return 'Balance: ' . $this->balance . '<br/>';
    }
    public function Withdraw($amount)
    {
        if ($this->balance < $amount) {
            echo 'Not enough money.<br/>';
        } else {
            $this->balance = $this->balance - $amount;
        }
    }
    public function Deposit($amount)
    {
        $this->balance = $this->balance + $amount;
    }
}
$alex = new BankAccount();
$billy = new BankAccount();
$alex->Deposit(100);
$billy->Deposit(15);
$alex->Withdraw(20);
$billy->Withdraw(5);
echo $alex->DisplayBalance();
echo $billy->DisplayBalance();
예제 #15
0
 /**
  * Builds a BankAccount PHP object from the passed in json object.
  * 
  * @param  $vo_json - The json representation of the object to be built.
  * @return A BankAccount object with fields based on the input json object.
  * @author Ryan Murphy <*****@*****.**>
  * @author Steven Wright <*****@*****.**>
  */
 static function buildFromJSON($vo_json)
 {
     $o_bank_account = new BankAccount();
     if (array_key_exists("bank_account_name", $vo_json)) {
         $o_bank_account->setName($vo_json["bank_account_name"]);
     }
     if (array_key_exists("bank_account_alias", $vo_json)) {
         $o_bank_account->setAlias($vo_json["bank_account_alias"]);
     }
     if (array_key_exists("bank_account_account_number", $vo_json)) {
         $o_bank_account->setAccountNumber($vo_json["bank_account_account_number"]);
     }
     if (array_key_exists("bank_account_routing_number", $vo_json)) {
         $o_bank_account->setRoutingNumber($vo_json["bank_account_routing_number"]);
     }
     if (array_key_exists("bank_account_token", $vo_json)) {
         $o_bank_account->setToken($vo_json["bank_account_token"]);
     }
     if (array_key_exists("bank_account_billing_address", $vo_json)) {
         $o_bank_account->setBillingAddress(Address::buildFromJSON($vo_json["bank_account_billing_address"]));
     }
     if (array_key_exists('bank_account_status', $vo_json)) {
         if (gettype($vo_json['bank_account_status']) === "array ") {
             $o_status = (array) $vo_json['bank_account_status'];
             if (array_key_exists('bank_account_status_name', $o_status)) {
                 $o_bank_account->setStatus($o_status['bank_account_status_name']);
             }
         } else {
             $o_bank_account->setStatus($vo_json['bank_account_status']);
         }
     }
     if (array_key_exists('bank_account_type', $vo_json)) {
         if (gettype($vo_json['bank_account_type']) === "array") {
             $o_type = (array) $vo_json['bank_account_type'];
             if (array_key_exists('bank_account_type_name', $o_type)) {
                 $o_bank_account->setAccountType($o_type['bank_account_type_name']);
             }
         } else {
             $o_bank_account->setAccountType($vo_json['bank_account_type']);
         }
     }
     return $o_bank_account;
 }
예제 #16
0
 /**
  * @depends testDepositingMoneyWorks
  * @covers  BankAccount::withdrawMoney
  */
 public function testWithdrawingMoneyWorks(BankAccount $ba)
 {
     $ba->withdrawMoney(1);
     $this->assertEquals(0, $ba->getBalance());
 }
예제 #17
0
 public function actionAddBankAccount()
 {
     Yii::import('application.extensions.vendor.autoload', true);
     Httpful\Bootstrap::init();
     Balanced\Bootstrap::init();
     Balanced\Settings::$api_key = Yii::app()->params['balancedAPISecret'];
     $outcome = array('success' => 0);
     $transaction = Yii::app()->db->beginTransaction();
     try {
         if (isset($_POST['data']) && isset($_POST['merchantData'])) {
             $data = json_decode($_POST['data']);
             $merchantData = json_decode($_POST['merchantData']);
             $uri = $data->uri;
             $user = $this->getUser();
             if ($user->bankAccount != null) {
                 $bankAccount = $user->bankAccount;
                 $balancedBankAccount = Balanced\BankAccount::get($bankAccount->URI);
                 $balancedBankAccount->delete();
                 $bankAccount->Active = 0;
                 $bankAccount->save();
             }
             $account = new BankAccount();
             $account->User_ID = $user->User_ID;
             $account->URI = $uri;
             if ($account->save()) {
                 $balancedAccount = $this->getUserAccount();
                 $balancedAccount->addBankAccount($uri);
                 if (!in_array('merchant', $balancedAccount->roles)) {
                     $balancedAccount->promoteToMerchant($merchantData);
                 }
                 $outcome = array('success' => 1, 'BankAccount_ID' => $account->BankAccount_ID);
             } else {
                 $outcome = array('success' => 0, 'Errors' => $account->getErrors());
             }
         }
         $transaction->commit();
     } catch (Balanced\Errors\IdentityVerificationFailed $error) {
         $transaction->rollback();
         /* could not identify this account. */
         $outcome = array('success' => 0, 'Errors' => "redirect merchant to:" . $error->redirect_uri . "\n");
     } catch (Balanced\Errors\HTTPError $error) {
         $transaction->rollback();
         /* TODO: handle 400 and 409 exceptions as required */
         $outcome = array('success' => 0, 'Errors' => print_r($error, true));
     } catch (Exception $error) {
         $transaction->rollback();
         $outcome = array('success' => 0, 'Errors' => print_r($error, true));
     }
     echo CJSON::encode($outcome);
 }
예제 #18
0
 public function addBankAccount(BankAccount $l)
 {
     $this->collBankAccounts[] = $l;
     $l->setDepartment($this);
 }
예제 #19
0
{
    public $balance = 0;
    public function DisplayBalance()
    {
        return "Balance: " . $this->balance;
    }
    public function Withdraw($amount)
    {
        if ($this->balance < $amount) {
            echo "Not enough money.<br>";
        } else {
            $this->balance = $this->balance - $amount;
        }
    }
    public function Deposit($amount)
    {
        $this->balance = $this->balance + $amount;
    }
}
// new instane of class
$charles = new BankAccount();
$alex = new BankAccount();
//Deposit money
$charles->Deposit(13000);
$alex->Deposit(3000);
//Withdraw money
$charles->Withdraw(1200);
$alex->Withdraw(100);
//display the balance
echo $charles->DisplayBalance() . "<br>";
echo $alex->DisplayBalance();
<?php

//object
class BankAccount
{
    //property
    public $balance = 0;
    //can be accessed anywhere inside of your code
    //private $balance = 0;//cant be accessed outside of class whatsoever
    //protected $balance = 0;//can only be accessed within the class, so methods can access
    //method
    public function DisplayBalance()
    {
        return 'Balance: ' . $this->balance;
    }
}
//create new instance of class BankAccount
$alex = new BankAccount();
//echo out properties within class or run/use methods within class
echo $alex->DisplayBalance();
예제 #21
0
<?php

class BankAccount
{
    public $balance = 0;
    public function DisplayBalance($amount)
    {
        return $this->balance + $amount;
    }
}
$user1 = new BankAccount();
$user2 = new BankAccount();
echo $user1->DisplayBalance(1000) . '<br>';
echo $user1->DisplayBalance(3000);
<?php

class BankAccount
{
    private $balance = 0;
    function makeDeposit($amount)
    {
        // Add to the current balance
        $this->balance += $amount;
        echo '<br>Deposited: $' . number_format($amount, 2);
    }
    function makeWithdrawal($amount)
    {
        // Subtract from the current balance
        $this->balance -= $amount;
        echo '<br>Withdrew: $' . number_format($amount, 2);
    }
    function getBalance()
    {
        echo '<br>Current Balance: $' . number_format($this->balance, 2);
    }
}
$myAccount = new BankAccount();
$myAccount->makeDeposit(100.0);
$myAccount->makeWithdrawal(40.0);
$myAccount->getBalance();
예제 #23
0
 /**
  * 
  * deletes a bank account from the system
  * 
  * @param vs_token the bank accounts token
  * @return  the updated deleted bank account
  * @throws BaseCommerceClientException if invalid credentials were given or if there was an internal server error. Please contact tech support if there is an internal server error.
  * @author Rob Kurst <*****@*****.**>
  */
 public function deleteBankAccount($vs_token)
 {
     $triple_des = new TripleDESService($this->is_key);
     $o_query = array();
     $o_query['gateway_username'] = $this->is_gateway_username;
     $o_query['gateway_password'] = $this->is_gateway_password;
     $o_query['payload'] = $triple_des->encrypt($vs_token);
     $s_query = json_encode($o_query);
     $response = $this->do_post_request('/pcms/?f=API_deleteBankAccountV4', $s_query, $triple_des, 0);
     $vo_ba = BankAccount::buildFromJSON($response["bank_account"]);
     if (array_key_exists("exception", $response) && !is_null($response['exception'])) {
         foreach ($response['exception'] as $s_key => $s_error) {
             $vo_ba->addMessage($s_error);
         }
     }
     return $vo_ba;
 }
예제 #24
0
 public function testBalanceIsInitiallyZero()
 {
     $ba = new BankAccount();
     $balance = $ba->getBalance();
     $this->assertEquals(0, $balance);
 }
예제 #25
0
class BankAccount
{
    // BankAccount   is object
    public $balance = 10.5;
    // balance is property
    public function DisplayBalance()
    {
        // displaybalance is method
        return 'Balance' . $this->balance;
        // same result when return 'balance'.$this->balance;
    }
    public function withdrawn($amount)
    {
        // displaybalance is method
        if ($this->balance < $amount) {
            echo 'not enough money';
            // HERE U CAN ALSO USE THROWING EXCEPTIONS
        } else {
            $this->balance = $this->balance - $amount;
            // same result when return 'balance'.$this->balance;
        }
    }
}
//new instance of class
$piyush = new BankAccount();
//withdrawn
$piyush->withdrawn(20);
//displaying instance
echo $piyush->DisplayBalance();
//  echo $piyush-> DisplayBalance();
예제 #26
0
 public function test_deposit()
 {
     $ba = new BankAccount();
     $ba->deposit(100);
     $this->assertEquals(100, $ba->getBalance());
 }
예제 #27
0
            echo "Error: insufficient funds!<br>\n";
        }
    }
    function print_log()
    {
        $attr = array("date", "operation", "amount", "old_balance", "new_balance");
        echo "<table>";
        for ($i = 0; $i < count($this->_log); $i++) {
            echo "<tr>";
            for ($j = 0; $j < count($attr); $j++) {
                echo "<td>" . $this->_log[$i][$attr[$j]] . "</td>";
            }
            echo "</tr>";
        }
        echo "</table>";
    }
}
// test
$ba = new BankAccount("my name", 1000);
echo "Balance: " . $ba->get_balance() . "<br>\n";
$ba->deposit(200);
$ba->deposit(300);
echo "Balance: " . $ba->get_balance() . "<br>\n";
$ba->withdraw(500);
echo "Balance: " . $ba->get_balance() . "<br>\n";
$ba->withdraw(2000);
$ba->print_log();
?>
</body>
</html>
예제 #28
0
        return $this->bankBalance;
    }
    /**
     * Remove some money from your account
     * @param float $amount How much you want to remove
     * @return float
     * @throws Exception
     */
    public function withdraw($amount)
    {
        if ($this->bankBalance < $amount) {
            // An exception is a PHP class that can be extended and worked with in a diverse number of ways
            throw new Exception('You can\'t withdraw ' . $amount);
        }
        $this->bankBalance -= $amount;
        return $this->bankBalance;
    }
}
// Because we have the potential of throwing an exception, all of the code that may throw an exception should be wrapped in a try tag
// The try could be placed in the withdraw function but this is bad design because in more complicated structures you want each method to
// only perform 1 function and route all exceptions through 1 place
try {
    $myAccount = new BankAccount();
    $myAccount->owner = 'Jared';
    $myAccount->deposit(12345);
    $myAccount->withdraw(100000);
} catch (Exception $e) {
    echo 'An error occurred: ' . $e->getMessage();
}
echo '<pre>';
print_r($myAccount);
예제 #29
0
    /**
     *How much money this person has
     *@var float
     */
    public $bankBalance;
    public function deposit($amount)
    {
        $this->bankBalance += $amount;
        return $this->bankBalance;
    }
    public function withdraw($amount)
    {
        if ($this->bankBalance >= $amount) {
            $this->bankBalance -= $amount;
            return $this->bankBalance;
        } else {
            throw new Exception('Insufficient funds');
        }
    }
}
try {
    $myAccount = new BankAccount();
    $myAccount->owner = 'Samir';
    $myAccount->bankBalance = 200;
    $myAccount->deposit(10);
    $myAccount->withdraw(300);
} catch (Exception $e) {
    echo 'An error occurred: ' . $e->getMessage();
}
echo "<pre>";
var_dump($myAccount);
예제 #30
0
 /**
  * Create a merchant account.
  *
  * Unlike buyers the identity of a merchant must be established before
  * the account can function as a merchant (i.e. be credited). A merchant
  * can be either a person or a business. Either way that information is
  * represented as an associative array and passed as the merchant parameter
  * when creating the merchant account.
  *
  * For a person the array looks like this:
  *
  * <code>
  * array(
  *     'type' => 'person',
  *     'name' => 'William James',
  *     'tax_id' => '393-48-3992',
  *     'street_address' => '167 West 74th Street',
  *     'postal_code' => '10023',
  *     'dob' => '1842-01-01',
  *     'phone_number' => '+16505551234',
  *     'country_code' => 'USA'
  *     )
  * </code>
  *
  * For a business the array looks like this:
  *
  * <code>
  * array(
  *     'type' => 'business',
  *     'name' => 'Levain Bakery',
  *     'tax_id' => '253912384',
  *     'street_address' => '167 West 74th Street',
  *     'postal_code' => '10023',
  *     'phone_number' => '+16505551234',
  *     'country_code' => 'USA',
  *     'person' => array(
  *         'name' => 'William James',
  *         'tax_id' => '393483992',
  *         'street_address' => '167 West 74th Street',
  *         'postal_code' => '10023',
  *         'dob' => '1842-01-01',
  *         'phone_number' => '+16505551234',
  *         'country_code' => 'USA',
  *         )
  *     )
  * </code>
  *
  * In some cases the identity of the merchant, person or business, cannot
  * be verified in which case a \infiniteLabs\BalancedPayments\Exceptions\HTTPError is thrown:
  *
  * <code>
  * $identity = array(
  *     'type' => 'business',
  *     'name' => 'Levain Bakery',
  *     'tax_id' => '253912384',
  *     'street_address' => '167 West 74th Street',
  *     'postal_code' => '10023',
  *     'phone_number' => '+16505551234',
  *     'country_code' => 'USA',
  *     'person' => array(
  *         'name' => 'William James',
  *         'tax_id' => '393483992',
  *         'street_address' => '167 West 74th Street',
  *         'postal_code' => '10023',
  *         'dob' => '1842-01-01',
  *         'phone_number' => '+16505551234',
  *         'country_code' => 'USA',
  *         ),
  *     );
  *
  *  try {
  *      $merchant = \infiniteLabs\BalancedPayments\Marketplace::mine()->createMerchant(
  *          '*****@*****.**',
  *          $identity,
  *          );
  *  catch (\infiniteLabs\BalancedPayments\Exceptions\HTTPError $e) {
  *      if ($e->code != 300) {
  *          throw $e;
  *      }
  *      print e->response->header['Location'] // this is where merchant must signup
  *  }
  * </code>
  *
  * Once the merchant has completed signup you can use the resulting URI to
  * create an account for them on your marketplace:
  *
  * <code>
  * $merchant = self::$marketplace->createMerchant(
  *     '*****@*****.**',
  *     null,
  *     null,
  *     $merchant_uri
  *     );
  * </coe>
  *
  * @param string email_address Optional email address. There can only be one account with this email address.
  * @param array[string]mixed merchant Associative array describing the merchants identity.
  * @param string $bank_account_uri Optional URI referencing a bank account to associate with this account.
  * @param string $merchant_uri URI of a merchant created via the redirection sign-up flow.
  * @param string $name Optional name of the merchant.
  * @param array[string]string meta Optional metadata to associate with the account.
  *
  * @return \infiniteLabs\BalancedPayments\Account
  */
 public function createMerchant($email_address = null, $merchant = null, $bank_account_href = null, $name = null, $meta = null)
 {
     $params = array('email_address' => $email_address, 'name' => $name, 'meta' => $meta);
     if ($merchant) {
         $params = array_merge($params, $merchant);
     }
     $customer = $this->customers->create();
     if ($bank_account_href) {
         $bank_account = BankAccount::get($bank_account_href);
         $bank_account->associateToCustomer($customer);
     }
     return $customer;
 }