Plan.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Braintree;
  3. class Plan extends Base
  4. {
  5. public static function factory($attributes)
  6. {
  7. $instance = new self();
  8. $instance->_initialize($attributes);
  9. return $instance;
  10. }
  11. protected function _initialize($attributes)
  12. {
  13. $this->_attributes = $attributes;
  14. $addOnArray = [];
  15. if (isset($attributes['addOns'])) {
  16. foreach ($attributes['addOns'] AS $addOn) {
  17. $addOnArray[] = AddOn::factory($addOn);
  18. }
  19. }
  20. $this->_attributes['addOns'] = $addOnArray;
  21. $discountArray = [];
  22. if (isset($attributes['discounts'])) {
  23. foreach ($attributes['discounts'] AS $discount) {
  24. $discountArray[] = Discount::factory($discount);
  25. }
  26. }
  27. $this->_attributes['discounts'] = $discountArray;
  28. $planArray = [];
  29. if (isset($attributes['plans'])) {
  30. foreach ($attributes['plans'] AS $plan) {
  31. $planArray[] = self::factory($plan);
  32. }
  33. }
  34. $this->_attributes['plans'] = $planArray;
  35. }
  36. // static methods redirecting to gateway
  37. public static function all()
  38. {
  39. return Configuration::gateway()->plan()->all();
  40. }
  41. }
  42. class_alias('Braintree\Plan', 'Braintree_Plan');