Settlement.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace smladeoye\paystack;
  3. use yii\base\Component;
  4. class Settlement extends Component
  5. {
  6. /** @var array holds the default paystack component settlement operation configuration */
  7. private $settlement = array(
  8. 'baseUrl'=>'/settlement',
  9. 'beforeSend'=>array(),
  10. 'afterSend'=>array()
  11. );
  12. /*Constructor method to setup paystack component, settlement operation configurations
  13. * @param $paystack, Paystack instance
  14. *@param config, Yii2 default object configuration array
  15. */
  16. public function __construct(Paystack $paystack, $config = [])
  17. {
  18. $this->attachBehavior('Resources',array('class'=> Resources::className()));
  19. $this->setPaystack($paystack);
  20. $this->settlement = array_replace($this->settlement,$paystack->settlement);
  21. $this->setConfig($this->settlement);
  22. parent::__construct($config);
  23. }
  24. /** fetch all settlements
  25. * @param $from string
  26. * @param $to string
  27. * @return $this
  28. */
  29. public function fetchAll($from = null,$to = null, $subaccount = null)
  30. {
  31. $options = array();
  32. if (is_array($from))
  33. {
  34. $this->setRequestOptions($from);
  35. }
  36. else
  37. {
  38. if ($from)
  39. $options['from'] = $from;
  40. if ($to)
  41. $options['to'] = $to;
  42. if ($subaccount)
  43. $options['subaccount'] = $subaccount;
  44. $this->setRequestOptions($options);
  45. }
  46. $this->sendRequest(Paystack::OP_SETTLEMENT_LIST);
  47. $this->setResponseOptions();
  48. return $this;
  49. }
  50. }