Broker.class.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. require_once 'Config/Settings.class.php';
  3. require_once 'Config/Database.class.php';
  4. // includes the autoloader for libraries installed with composer
  5. require __DIR__ . '/External/Braintree/lib/autoload.php';
  6. /**
  7. *
  8. */
  9. abstract class Broker {
  10. //
  11. protected $Name = "";
  12. protected $Database;
  13. protected $DatabaseConnection;
  14. protected $Config = null;
  15. /**
  16. *
  17. */
  18. public function __construct($name) {
  19. $this->Name = $name;
  20. // create database handle
  21. $this->Database = new \Config\Database('imagingx_docassyst');
  22. try {
  23. $this->DatabaseConnection = $this->Database->getConnection();
  24. }
  25. catch (Exception $e) {
  26. throw $e;
  27. }
  28. // read config
  29. $statement = $this->DatabaseConnection->prepare(
  30. "SELECT config FROM broker WHERE name = '$this->Name'"
  31. );
  32. $statement->execute();
  33. $results = $statement->fetchAll(\PDO::FETCH_ASSOC);
  34. if(count($results) == 0) {
  35. throw new \Exception("BraintreeBroker init failed");
  36. }
  37. else {
  38. $this->Config = json_decode($results[0]['config']);
  39. }
  40. $this->init();
  41. }
  42. /**
  43. *
  44. */
  45. abstract protected function init();
  46. /**
  47. *
  48. */
  49. abstract public function getToken($User);
  50. /**
  51. *
  52. */
  53. abstract public function submit($User, $token, $amount);
  54. }