[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace Balanced; 4 5 use Balanced\Resource; 6 use \RESTful\URISpec; 7 8 /** 9 * Represents an account bank account. 10 * 11 * You can create these via Balanced\Marketplace::bank_accounts::create or 12 * Balanced\Marketplace::createBankAccount. Associate them with a buyer or 13 * merchant one creation via Balanced\Marketplace::createBuyer or 14 * Balanced\Marketplace::createMerchant and with an existing buyer or merchant 15 * use Balanced\Account::addBankAccount. 16 * 17 * <code> 18 * $marketplace = \Balanced\Marketplace::mine(); 19 * 20 * $bank_account = $marketplace->bank_accounts->create(array( 21 * 'name' => 'name', 22 * 'account_number' => '11223344', 23 * 'bank_code' => '1313123', 24 * )); 25 * 26 * $account = $marketplace 27 * ->accounts 28 * ->query() 29 * ->filter(Account::f->email_address->eq('[email protected]')) 30 * ->one(); 31 * $account->addBankAccount($bank_account->uri); 32 * </code> 33 */ 34 class BankAccount extends Resource 35 { 36 protected static $_uri_spec = null; 37 38 public static function init() 39 { 40 self::$_uri_spec = new URISpec('bank_accounts', 'id', '/v1'); 41 self::$_registry->add(get_called_class()); 42 } 43 44 /** 45 * Credit a bank account. 46 * 47 * @param int amount Amount to credit in USD pennies. 48 * @param string description Optional description of the credit. 49 * @param string appears_on_statement_as Optional description of the credit as it will appears on the customer's billing statement. 50 * 51 * @return \Balanced\Credit 52 * 53 * <code> 54 * $bank_account = new \Balanced\BankAccount(array( 55 * 'account_number' => '12341234', 56 * 'name' => 'Fit Finlay', 57 * 'bank_code' => '325182797', 58 * 'type' => 'checking', 59 * )); 60 * 61 * $credit = $bank_account->credit(123, 'something descriptive'); 62 * </code> 63 */ 64 public function credit( 65 $amount, 66 $description = null, 67 $meta = null, 68 $appears_on_statement_as = null) 69 { 70 if (!property_exists($this, 'account') || $this->account == null) { 71 $credit = $this->credits->create(array( 72 'amount' => $amount, 73 'description' => $description, 74 )); 75 } else { 76 $credit = $this->account->credit( 77 $amount, 78 $description, 79 $meta, 80 $this->uri, 81 $appears_on_statement_as 82 ); 83 } 84 return $credit; 85 } 86 87 public function verify() 88 { 89 $response = self::getClient()->post( 90 $this->verifications_uri, null 91 ); 92 $verification = new BankAccountVerification(); 93 $verification->_objectify($response->body); 94 return $verification; 95 } 96 } 97 98 /** 99 * Represents an verification for a bank account which is a pre-requisite if 100 * you want to create debits using the associated bank account. The side-effect 101 * of creating a verification is that 2 random amounts will be deposited into 102 * the account which must then be confirmed via the confirm method to ensure 103 * that you have access to the bank account in question. 104 * 105 * You can create these via Balanced\Marketplace::bank_accounts::verify. 106 * 107 * <code> 108 * $marketplace = \Balanced\Marketplace::mine(); 109 * 110 * $bank_account = $marketplace->bank_accounts->create(array( 111 * 'name' => 'name', 112 * 'account_number' => '11223344', 113 * 'bank_code' => '1313123', 114 * )); 115 * 116 * $verification = $bank_account->verify(); 117 * </code> 118 */ 119 class BankAccountVerification extends Resource { 120 121 public function confirm($amount1, $amount2) { 122 $this->amount_1 = $amount1; 123 $this->amount_2 = $amount2; 124 $this->save(); 125 return $this; 126 } 127 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |