UserSignup.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ dPR1VQaNgoNQIicZDY/mfJXML8p89ljHg8Z/av4Z17Y=
  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. * user signup fee class
  14. */
  15. namespace Ppb\Service\Fees;
  16. use Ppb\Service;
  17. class UserSignup extends Service\Fees
  18. {
  19. /**
  20. *
  21. * fees to be included
  22. *
  23. * @var array
  24. */
  25. protected $_fees = array(
  26. self::SIGNUP => 'User Signup Fee',
  27. );
  28. /**
  29. *
  30. * total amount to be paid after the calculate method is called
  31. *
  32. * @var float
  33. */
  34. protected $_totalAmount;
  35. /**
  36. *
  37. * redirect to login page after signup fee payment
  38. *
  39. * @var array
  40. */
  41. protected $_redirect = array(
  42. 'module' => 'members',
  43. 'controller' => 'user',
  44. 'action' => 'login',
  45. );
  46. /**
  47. *
  48. * class constructor
  49. *
  50. * @param integer|string|\Ppb\Db\Table\Row\User $user the user that will be paying and for which the signup action will apply
  51. */
  52. public function __construct($user = null)
  53. {
  54. parent::__construct();
  55. if ($user !== null) {
  56. $this->setUser($user);
  57. }
  58. }
  59. /**
  60. *
  61. * activate the affected user
  62. *
  63. * @param bool $ipn true if payment is completed, false otherwise
  64. * @param array $post array keys: {user_id}
  65. * @return \Ppb\Service\Fees\UserSignup
  66. */
  67. public function callback($ipn, array $post)
  68. {
  69. $usersService = new Service\Users();
  70. $user = $usersService->findBy('id', $post['user_id']);
  71. $flag = ($ipn) ? 1 : 0;
  72. $paymentStatus = ($ipn) ? 'confirmed' : 'failed';
  73. $user->save(array(
  74. 'active' => $flag,
  75. 'payment_status' => $paymentStatus,
  76. ));
  77. return $this;
  78. }
  79. /**
  80. *
  81. * get the signup fee value (tax included)
  82. *
  83. * @return float
  84. */
  85. public function getTotalAmount()
  86. {
  87. return $this->getFeeAmount('signup');
  88. }
  89. }