actions_stripe.class.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /* Copyright (C) 2009-2016 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
  4. * Copyright (C) 2014 Philippe Grand <philippe.grand@atoo-net.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. // TODO File of hooks not used yet. To remove ?
  21. /**
  22. * \file htdocs/stripe/class/actions_stripe.class.php
  23. * \ingroup stripe
  24. * \brief File Class actionsstripeconnect
  25. */
  26. require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php';
  28. /**
  29. * Class Actions Stripe Connect
  30. */
  31. class ActionsStripeconnect extends CommonHookActions
  32. {
  33. /**
  34. * @var DoliDB Database handler.
  35. */
  36. public $db;
  37. private $config = array();
  38. /**
  39. * Constructor
  40. *
  41. * @param DoliDB $db Database handler
  42. */
  43. public function __construct($db)
  44. {
  45. $this->db = $db;
  46. }
  47. /**
  48. * formObjectOptions
  49. *
  50. * @param array $parameters Parameters
  51. * @param Object $object Object
  52. * @param string $action Action
  53. * @return bool
  54. */
  55. public function formObjectOptions($parameters, &$object, &$action)
  56. {
  57. global $conf, $langs;
  58. if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE') || GETPOST('forcesandbox', 'alpha'))) {
  59. $service = 'StripeTest';
  60. dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
  61. } else {
  62. $service = 'StripeLive';
  63. }
  64. if (is_array($parameters) && !empty($parameters)) {
  65. foreach ($parameters as $key => $value) {
  66. $key = $value;
  67. }
  68. }
  69. if (is_object($object) && $object->element == 'societe') {
  70. $this->resprints .= '<tr><td>';
  71. $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
  72. $this->resprints .= $langs->trans('StripeCustomer');
  73. $this->resprints .= '<td><td class="right">';
  74. // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
  75. $this->resprints .= '</td></tr></table>';
  76. $this->resprints .= '</td>';
  77. $this->resprints .= '<td colspan="3">';
  78. $stripe = new Stripe($this->db);
  79. if ($stripe->getStripeAccount($service) && $object->client != 0) {
  80. $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
  81. $this->resprints .= $customer->id;
  82. } else {
  83. $this->resprints .= $langs->trans("NoStripe");
  84. }
  85. $this->resprints .= '</td></tr>';
  86. } elseif (is_object($object) && $object->element == 'member') {
  87. $this->resprints .= '<tr><td>';
  88. $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
  89. $this->resprints .= $langs->trans('StripeCustomer');
  90. $this->resprints .= '<td><td class="right">';
  91. $this->resprints .= '</td></tr></table>';
  92. $this->resprints .= '</td>';
  93. $this->resprints .= '<td colspan="3">';
  94. $stripe = new Stripe($this->db);
  95. if ($stripe->getStripeAccount($service) && $object->fk_soc > 0) {
  96. $object->fetch_thirdparty();
  97. $customer = $stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
  98. $this->resprints .= $customer->id;
  99. } else {
  100. $this->resprints .= $langs->trans("NoStripe");
  101. }
  102. $this->resprints .= '</td></tr>';
  103. $this->resprints .= '<tr><td>';
  104. $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
  105. $this->resprints .= $langs->trans('SubscriptionStripe');
  106. $this->resprints .= '<td><td class="right">';
  107. $this->resprints .= '</td></tr></table>';
  108. $this->resprints .= '</td>';
  109. $this->resprints .= '<td colspan="3">';
  110. $stripe = new Stripe($this->db);
  111. if (7 == 4) {
  112. $object->fetch_thirdparty();
  113. $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
  114. $this->resprints .= $customer->id;
  115. } else {
  116. $this->resprints .= $langs->trans("NoStripe");
  117. }
  118. $this->resprints .= '</td></tr>';
  119. } elseif (is_object($object) && $object->element == 'adherent_type') {
  120. $this->resprints .= '<tr><td>';
  121. $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
  122. $this->resprints .= $langs->trans('PlanStripe');
  123. $this->resprints .= '<td><td class="right">';
  124. // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
  125. $this->resprints .= '</td></tr></table>';
  126. $this->resprints .= '</td>';
  127. $this->resprints .= '<td colspan="3">';
  128. $stripe = new Stripe($this->db);
  129. if (7 == 4) {
  130. $object->fetch_thirdparty();
  131. $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
  132. $this->resprints .= $customer->id;
  133. } else {
  134. $this->resprints .= $langs->trans("NoStripe");
  135. }
  136. $this->resprints .= '</td></tr>';
  137. }
  138. return 0;
  139. }
  140. /**
  141. * addMoreActionsButtons
  142. *
  143. * @param array $parameters Parameters
  144. * @param Object $object Object
  145. * @param string $action action
  146. * @return int 0
  147. */
  148. public function addMoreActionsButtons($parameters, &$object, &$action)
  149. {
  150. global $conf, $langs;
  151. if (is_object($object) && $object->element == 'facture') {
  152. // On verifie si la facture a des paiements
  153. $sql = 'SELECT pf.amount';
  154. $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
  155. $sql .= ' WHERE pf.fk_facture = '.((int) $object->id);
  156. $totalpaid = 0;
  157. $result = $this->db->query($sql);
  158. if ($result) {
  159. $i = 0;
  160. $num = $this->db->num_rows($result);
  161. while ($i < $num) {
  162. $objp = $this->db->fetch_object($result);
  163. $totalpaid += $objp->amount;
  164. $i++;
  165. }
  166. } else {
  167. dol_print_error($this->db, '');
  168. }
  169. $resteapayer = $object->total_ttc - $totalpaid;
  170. // Request a direct debit order
  171. if ($object->statut > Facture::STATUS_DRAFT && $object->statut < Facture::STATUS_ABANDONED && $object->paye == 0) {
  172. $stripe = new Stripe($this->db);
  173. if ($resteapayer > 0) {
  174. if ($stripe->getStripeAccount($conf->entity)) { // a modifier avec droit stripe
  175. $langs->load("withdrawals");
  176. print '<a class="butActionDelete" href="'.dol_buildpath('/stripeconnect/payment.php?facid='.$object->id.'&action=create', 1).'" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
  177. } else {
  178. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
  179. }
  180. } elseif ($resteapayer == 0) {
  181. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
  182. }
  183. } else {
  184. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
  185. }
  186. } elseif (is_object($object) && $object->element == 'invoice_supplier') {
  187. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
  188. } elseif (is_object($object) && $object->element == 'member') {
  189. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeAutoSubscription")).'">'.$langs->trans("StripeAutoSubscription").'</a>';
  190. }
  191. return 0;
  192. }
  193. }