StoreSubscription.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ uT7+9MDkesDrcDyQbct3pVKRoqyt4XOF+2gtjSnILCw=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2014 Online Ventures Software LTD & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.0
  11. */
  12. /**
  13. * store subscription fee class
  14. */
  15. namespace Ppb\Service\Fees;
  16. use Ppb\Service,
  17. Ppb\Db\Table\Row\StoreSubscription as StoreSubscriptionModel;
  18. class StoreSubscription extends Service\Fees
  19. {
  20. /**
  21. *
  22. * fees to be included
  23. *
  24. * @var array
  25. */
  26. protected $_fees = array(
  27. self::USER_VERIFICATION => 'Store Subscription Fee',
  28. );
  29. /**
  30. *
  31. * store subscription model
  32. *
  33. * @var \Ppb\Db\Table\Row\StoreSubscription
  34. */
  35. protected $_subscription;
  36. /**
  37. *
  38. * completed payment redirect path
  39. *
  40. * @var array
  41. */
  42. protected $_redirect = array(
  43. 'module' => 'members',
  44. 'controller' => 'store',
  45. 'action' => 'setup'
  46. );
  47. /**
  48. *
  49. * class constructor
  50. *
  51. * @param integer|string|\Ppb\Db\Table\Row\User $user the user that will be paying and for which the signup action will apply
  52. */
  53. public function __construct($user = null)
  54. {
  55. parent::__construct();
  56. if ($user !== null) {
  57. $this->setUser($user);
  58. $this->setSubscription();
  59. }
  60. }
  61. /**
  62. *
  63. * get store subscription model
  64. *
  65. * @return \Ppb\Db\Table\Row\StoreSubscription
  66. */
  67. public function getSubscription()
  68. {
  69. return $this->_subscription;
  70. }
  71. /**
  72. *
  73. * set store subscription model
  74. *
  75. * @param \Ppb\Db\Table\Row\StoreSubscription $subscription
  76. * @return $this
  77. */
  78. public function setSubscription(StoreSubscriptionModel $subscription = null)
  79. {
  80. if (!$subscription instanceof StoreSubscriptionModel) {
  81. $subscription = $this->_user->findParentRow('\Ppb\Db\Table\StoresSubscriptions');
  82. }
  83. $this->_subscription = $subscription;
  84. return $this;
  85. }
  86. /**
  87. *
  88. * activate the affected user
  89. *
  90. * @param bool $ipn true if payment is completed, false otherwise
  91. * @param array $post array keys: {user_id, subscription_id}
  92. * @return $this
  93. */
  94. public function callback($ipn, array $post)
  95. {
  96. $usersService = new Service\Users();
  97. $user = $usersService->findBy('id', $post['user_id']);
  98. $flag = ($ipn) ? 1 : 0;
  99. if (count($user) > 0) {
  100. $user->updateStoreSubscription($flag, $post['subscription_id']);
  101. }
  102. return $this;
  103. }
  104. /**
  105. *
  106. * get subscription fee amount
  107. *
  108. * @return float
  109. */
  110. public function getTotalAmount()
  111. {
  112. if ($this->_subscription instanceof StoreSubscriptionModel) {
  113. return $this->_addTax($this->_subscription->getData('price'));
  114. }
  115. return null;
  116. }
  117. }