[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/externals/balanced-php/src/Balanced/ -> Credit.php (source)

   1  <?php
   2  
   3  namespace Balanced;
   4  
   5  use Balanced\Resource;
   6  use \RESTful\URISpec;
   7  
   8  /**
   9   * Represents an account credit transaction.
  10   * 
  11   * You create these using Balanced\Account::credit.
  12   * 
  13   * <code>
  14   * $marketplace = \Balanced\Marketplace::mine();
  15   * 
  16   * $account = $marketplace
  17   *     ->accounts
  18   *     ->query()
  19   *     ->filter(Account::f->email_address->eq('[email protected]'))
  20   *     ->one();
  21   * 
  22   * $credit = $account->credit(
  23   *     100,
  24   *     'how it '
  25   *     array(
  26   *         'my_id': '112233'
  27   *         )
  28   *     );
  29   * </code>
  30   */
  31  class Credit extends Resource
  32  {
  33      protected static $_uri_spec = null;
  34  
  35      public static function init()
  36      {
  37          self::$_uri_spec = new URISpec('credits', 'id', '/v1');
  38          self::$_registry->add(get_called_class());
  39      }
  40      
  41      /**
  42       * Credit an unstored bank account.
  43       *
  44       * @param int amount Amount to credit in USD pennies.
  45       * @param string description Optional description of the credit.
  46       * @param mixed bank_account Associative array describing a bank account to credit. The bank account will *not* be stored.
  47       *
  48       * @return \Balanced\Credit
  49       *  
  50       * <code>
  51       * $credit = \Balanced\Credit::bankAccount(
  52       *     123,
  53       *     array(
  54       *     'account_number' => '12341234',
  55       *     'name' => 'Fit Finlay',
  56       *     'bank_code' => '325182797',
  57       *     'type' => 'checking',
  58       *     ),
  59       *     'something descriptive');
  60       * </code>
  61       */
  62      public static function bankAccount(
  63          $amount,
  64          $bank_account,
  65          $description = null)
  66      {
  67          $credit = new Credit(array(
  68             'amount' => $amount,
  69             'bank_account' => $bank_account,
  70             'description' => $description
  71          ));
  72          $credit->save();
  73          return $credit;
  74      }
  75  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1