1
0

BxBaseModPaymentProvider.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BasePayment Base classes for Payment like modules
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. interface iBxBaseModPaymentProvider
  12. {
  13. public function initializeCheckout($iPendingId, $aCartInfo);
  14. public function finalizeCheckout(&$aData);
  15. public function finalizedCheckout();
  16. }
  17. class BxBaseModPaymentProvider extends BxDol
  18. {
  19. protected $MODULE;
  20. protected $_oModule;
  21. protected $_sLangsPrefix;
  22. protected $_iId;
  23. protected $_sName;
  24. protected $_sCaption;
  25. protected $_sPrefix;
  26. protected $_aOptions;
  27. protected $_bRedirectOnResult;
  28. protected $_sLogFile;
  29. function __construct($aConfig)
  30. {
  31. parent::__construct();
  32. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  33. $this->_sLangsPrefix = $this->_oModule->_oConfig->getPrefix('langs');
  34. $this->_iId = (int)$aConfig['id'];
  35. $this->_sName = $aConfig['name'];
  36. $this->_sCaption = _t($aConfig['caption']);
  37. $this->_sPrefix = $aConfig['option_prefix'];
  38. $this->_aOptions = !empty($aConfig['options']) ? $aConfig['options'] : array();
  39. $this->_bRedirectOnResult = false;
  40. }
  41. public function getReturnUrl()
  42. {
  43. return $this->_oModule->_oConfig->getUrl('URL_RETURN');
  44. }
  45. public function getReturnDataUrl($iVendorId)
  46. {
  47. return $this->_oModule->_oConfig->getUrl('URL_RETURN_DATA') . $this->_sName . '/' . $iVendorId;
  48. }
  49. public function getNotifyUrl($iVendorId)
  50. {
  51. return $this->_oModule->_oConfig->getUrl('URL_NOTIFY') . $this->_sName . '/' . $iVendorId;
  52. }
  53. /**
  54. * TODO: Check whether the method is needed or not.
  55. * Is used on success only.
  56. */
  57. public function needRedirect()
  58. {
  59. return $this->_bRedirectOnResult;
  60. }
  61. public function finalizedCheckout() {}
  62. protected function getOptionsByPending($iPendingId)
  63. {
  64. $aPending = $this->_oModule->_oDb->getPending(array(
  65. 'type' => 'id',
  66. 'id' => (int)$iPendingId
  67. ));
  68. return $this->_oModule->_oDb->getOptions((int)$aPending['seller_id'], $this->_iId);
  69. }
  70. protected function getOption($sName)
  71. {
  72. return isset($this->_aOptions[$this->_sPrefix . $sName]) ? $this->_aOptions[$this->_sPrefix . $sName]['value'] : "";
  73. }
  74. /**
  75. *
  76. * Writes $contents to a log file specified in the bp_options file or, if missing,
  77. * defaults to a standard filename of 'bplog.txt'.
  78. *
  79. * @param mixed $contents
  80. * @return
  81. * @throws Exception $e
  82. *
  83. */
  84. protected function log($sContents)
  85. {
  86. try {
  87. if($this->_sLogFile != '')
  88. $file = $this->_sLogFile;
  89. else
  90. $file = dirname(__FILE__) . '/bx_pp_' . $this->_sName . '.log';
  91. file_put_contents($file, date('m-d H:i:s').": ", FILE_APPEND);
  92. if (is_array($sContents))
  93. $sContents = var_export($sContents, true);
  94. else if (is_object($sContents))
  95. $sContents = json_encode($sContents);
  96. file_put_contents($file, $sContents."\n", FILE_APPEND);
  97. }
  98. catch (Exception $e) {
  99. echo 'Error: ' . $e->getMessage();
  100. }
  101. }
  102. }
  103. /** @} */