interface_modPaypal_PaypalWorkflow.class.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file /htdocs/core/triggers/interface_modPaypal_PaypalWorkflow.class.php
  19. * \ingroup paypal
  20. * \brief Trigger file for paypal workflow
  21. */
  22. /**
  23. * \class InterfacePaypalWorkflow
  24. * \brief Class of triggers for paypal module
  25. */
  26. class InterfacePaypalWorkflow
  27. {
  28. var $db;
  29. /**
  30. * Constructor
  31. * @param DB Database handler
  32. */
  33. function InterfacePaypalWorkflow($DB)
  34. {
  35. $this->db = $DB ;
  36. $this->name = preg_replace('/^Interface/i','',get_class($this));
  37. $this->family = "paypal";
  38. $this->description = "Triggers of this module allows to manage paypal workflow";
  39. $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version
  40. $this->picto = 'paypal@paypal';
  41. }
  42. /**
  43. * \brief Renvoi nom du lot de triggers
  44. * \return string Nom du lot de triggers
  45. */
  46. function getName()
  47. {
  48. return $this->name;
  49. }
  50. /**
  51. * \brief Renvoi descriptif du lot de triggers
  52. * \return string Descriptif du lot de triggers
  53. */
  54. function getDesc()
  55. {
  56. return $this->description;
  57. }
  58. /**
  59. * \brief Renvoi version du lot de triggers
  60. * \return string Version du lot de triggers
  61. */
  62. function getVersion()
  63. {
  64. global $langs;
  65. $langs->load("admin");
  66. if ($this->version == 'development') return $langs->trans("Development");
  67. elseif ($this->version == 'experimental') return $langs->trans("Experimental");
  68. elseif ($this->version == 'dolibarr') return DOL_VERSION;
  69. elseif ($this->version) return $this->version;
  70. else return $langs->trans("Unknown");
  71. }
  72. /**
  73. * Fonction appelee lors du declenchement d'un evenement Dolibarr.
  74. * D'autres fonctions run_trigger peuvent etre presentes dans core/triggers
  75. *
  76. * @param string $action Code de l'evenement
  77. * @param CommonObject $object Objet concerne
  78. * @param User $user Objet user
  79. * @param Translate $lang Objet lang
  80. * @param Conf $conf Objet conf
  81. * @return int <0 if fatal error, 0 si nothing done, >0 if ok
  82. */
  83. function run_trigger($action,$object,$user,$langs,$conf)
  84. {
  85. // Mettre ici le code a executer en reaction de l'action
  86. // Les donnees de l'action sont stockees dans $object
  87. if ($action == 'PAYPAL_PAYMENT_OK')
  88. {
  89. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". source=".$object->source." ref=".$object->ref);
  90. require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
  91. $soc = new Societe($this->db);
  92. // Parse element/subelement (ex: project_task)
  93. $element = $path = $filename = $object->source;
  94. if (preg_match('/^([^_]+)_([^_]+)/i',$object->source,$regs))
  95. {
  96. $element = $path = $regs[1];
  97. $filename = $regs[2];
  98. }
  99. // For compatibility
  100. if ($element == 'order') { $path = $filename = 'commande'; }
  101. if ($element == 'invoice') { $path = 'compta/facture'; $filename = 'facture'; }
  102. dol_include_once('/'.$path.'/class/'.$filename.'.class.php');
  103. $classname = ucfirst($filename);
  104. $obj = new $classname($this->db);
  105. $ret = $obj->fetch('',$object->ref);
  106. if ($ret < 0) return -1;
  107. // Add payer id
  108. $soc->setValueFrom('ref_int', $object->payerID, 'societe', $obj->socid);
  109. // Add transaction id
  110. $obj->setValueFrom('ref_int',$object->resArray["TRANSACTIONID"]);
  111. }
  112. return 0;
  113. }
  114. }
  115. ?>