BraintreeSubscription

Braintree Subscription module.

Defined (1)

The class is defined in the following location(s).

/includes/lib/Braintree/lib/Braintree/Subscription.php  
  1. class Subscription extends Base 
  2. const ACTIVE = 'Active'; 
  3. const CANCELED = 'Canceled'; 
  4. const EXPIRED = 'Expired'; 
  5. const PAST_DUE = 'Past Due'; 
  6. const PENDING = 'Pending'; 
  7.  
  8. // Subscription Sources 
  9. const API = 'api'; 
  10. const CONTROL_PANEL = 'control_panel'; 
  11. const RECURRING = 'recurring'; 
  12.  
  13. /** 
  14. * @ignore 
  15. */ 
  16. public static function factory($attributes) 
  17. $instance = new self(); 
  18. $instance->_initialize($attributes); 
  19.  
  20. return $instance; 
  21.  
  22. /** 
  23. * @ignore 
  24. */ 
  25. protected function _initialize($attributes) 
  26. $this->_attributes = $attributes; 
  27.  
  28. $addOnArray = []; 
  29. if (isset($attributes['addOns'])) { 
  30. foreach ($attributes['addOns'] AS $addOn) { 
  31. $addOnArray[] = AddOn::factory($addOn); 
  32. $this->_attributes['addOns'] = $addOnArray; 
  33.  
  34. $discountArray = []; 
  35. if (isset($attributes['discounts'])) { 
  36. foreach ($attributes['discounts'] AS $discount) { 
  37. $discountArray[] = Discount::factory($discount); 
  38. $this->_attributes['discounts'] = $discountArray; 
  39.  
  40. if (isset($attributes['descriptor'])) { 
  41. $this->_set('descriptor', new Descriptor($attributes['descriptor'])); 
  42.  
  43. $statusHistory = []; 
  44. if (isset($attributes['statusHistory'])) { 
  45. foreach ($attributes['statusHistory'] AS $history) { 
  46. $statusHistory[] = new Subscription\StatusDetails($history); 
  47. $this->_attributes['statusHistory'] = $statusHistory; 
  48.  
  49. $transactionArray = []; 
  50. if (isset($attributes['transactions'])) { 
  51. foreach ($attributes['transactions'] AS $transaction) { 
  52. $transactionArray[] = Transaction::factory($transaction); 
  53. $this->_attributes['transactions'] = $transactionArray; 
  54.  
  55. /** 
  56. * returns a string representation of the customer 
  57. * @return string 
  58. */ 
  59. public function __toString() 
  60. $excludedAttributes = ['statusHistory']; 
  61.  
  62. $displayAttributes = []; 
  63. foreach($this->_attributes as $key => $val) { 
  64. if (!in_array($key, $excludedAttributes)) { 
  65. $displayAttributes[$key] = $val; 
  66.  
  67. return __CLASS__ . '[' . 
  68. Util::attributesToString($displayAttributes) .']'; 
  69.  
  70.  
  71. // static methods redirecting to gateway 
  72.  
  73. public static function create($attributes) 
  74. return Configuration::gateway()->subscription()->create($attributes); 
  75.  
  76. public static function find($id) 
  77. return Configuration::gateway()->subscription()->find($id); 
  78.  
  79. public static function search($query) 
  80. return Configuration::gateway()->subscription()->search($query); 
  81.  
  82. public static function fetch($query, $ids) 
  83. return Configuration::gateway()->subscription()->fetch($query, $ids); 
  84.  
  85. public static function update($subscriptionId, $attributes) 
  86. return Configuration::gateway()->subscription()->update($subscriptionId, $attributes); 
  87.  
  88. public static function retryCharge($subscriptionId, $amount = null) 
  89. return Configuration::gateway()->subscription()->retryCharge($subscriptionId, $amount); 
  90.  
  91. public static function cancel($subscriptionId) 
  92. return Configuration::gateway()->subscription()->cancel($subscriptionId);