actions_stripe.class.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 not used. 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. $langs->load("stripe@stripe");
  28. /**
  29. * Class Actions Stripe Connect
  30. */
  31. class ActionsStripeconnect
  32. {
  33. /**
  34. * @var DoliDB Database handler.
  35. */
  36. public $db;
  37. private $config = array();
  38. // For Hookmanager return
  39. public $resprints;
  40. public $results = array();
  41. /**
  42. * Constructor
  43. *
  44. * @param DoliDB $db Database handler
  45. */
  46. public function __construct($db)
  47. {
  48. $this->db = $db;
  49. }
  50. /**
  51. * formObjectOptions
  52. *
  53. * @param array $parameters Parameters
  54. * @param Object $object Object
  55. * @param string $action Action
  56. * @return bool
  57. */
  58. public function formObjectOptions($parameters, &$object, &$action)
  59. {
  60. global $db, $conf, $user, $langs, $form;
  61. if (!empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) {
  62. $service = 'StripeTest';
  63. dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
  64. } else {
  65. $service = 'StripeLive';
  66. }
  67. if (is_array($parameters) && !empty($parameters)) {
  68. foreach ($parameters as $key => $value) {
  69. $key = $value;
  70. }
  71. }
  72. if (is_object($object) && $object->element == 'societe') {
  73. $this->resprints .= '<tr><td>';
  74. $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
  75. $this->resprints .= $langs->trans('StripeCustomer');
  76. $this->resprints .= '<td><td class="right">';
  77. // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
  78. $this->resprints .= '</td></tr></table>';
  79. $this->resprints .= '</td>';
  80. $this->resprints .= '<td colspan="3">';
  81. $stripe = new Stripe($this->db);
  82. if ($stripe->getStripeAccount($service) && $object->client != 0) {
  83. $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
  84. $this->resprints .= $customer->id;
  85. } else {
  86. $this->resprints .= $langs->trans("NoStripe");
  87. }
  88. $this->resprints .= '</td></tr>';
  89. } elseif (is_object($object) && $object->element == 'member') {
  90. $this->resprints .= '<tr><td>';
  91. $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
  92. $this->resprints .= $langs->trans('StripeCustomer');
  93. $this->resprints .= '<td><td class="right">';
  94. $this->resprints .= '</td></tr></table>';
  95. $this->resprints .= '</td>';
  96. $this->resprints .= '<td colspan="3">';
  97. $stripe = new Stripe($this->db);
  98. if ($stripe->getStripeAccount($service) && $object->fk_soc > 0) {
  99. $object->fetch_thirdparty();
  100. $customer = $stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
  101. $this->resprints .= $customer->id;
  102. } else {
  103. $this->resprints .= $langs->trans("NoStripe");
  104. }
  105. $this->resprints .= '</td></tr>';
  106. $this->resprints .= '<tr><td>';
  107. $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
  108. $this->resprints .= $langs->trans('SubscriptionStripe');
  109. $this->resprints .= '<td><td class="right">';
  110. $this->resprints .= '</td></tr></table>';
  111. $this->resprints .= '</td>';
  112. $this->resprints .= '<td colspan="3">';
  113. $stripe = new Stripe($this->db);
  114. if (7 == 4) {
  115. $object->fetch_thirdparty();
  116. $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
  117. $this->resprints .= $customer->id;
  118. } else {
  119. $this->resprints .= $langs->trans("NoStripe");
  120. }
  121. $this->resprints .= '</td></tr>';
  122. } elseif (is_object($object) && $object->element == 'adherent_type') {
  123. $this->resprints .= '<tr><td>';
  124. $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
  125. $this->resprints .= $langs->trans('PlanStripe');
  126. $this->resprints .= '<td><td class="right">';
  127. // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
  128. $this->resprints .= '</td></tr></table>';
  129. $this->resprints .= '</td>';
  130. $this->resprints .= '<td colspan="3">';
  131. $stripe = new Stripe($this->db);
  132. if (7 == 4) {
  133. $object->fetch_thirdparty();
  134. $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
  135. $this->resprints .= $customer->id;
  136. } else {
  137. $this->resprints .= $langs->trans("NoStripe");
  138. }
  139. $this->resprints .= '</td></tr>';
  140. }
  141. return 0;
  142. }
  143. /**
  144. * addMoreActionsButtons
  145. *
  146. * @param array $parameters Parameters
  147. * @param Object $object Object
  148. * @param string $action action
  149. * @return int 0
  150. */
  151. public function addMoreActionsButtons($parameters, &$object, &$action)
  152. {
  153. global $db, $conf, $user, $langs, $form;
  154. if (is_object($object) && $object->element == 'facture') {
  155. // On verifie si la facture a des paiements
  156. $sql = 'SELECT pf.amount';
  157. $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
  158. $sql .= ' WHERE pf.fk_facture = '.((int) $object->id);
  159. $totalpaid = 0;
  160. $result = $this->db->query($sql);
  161. if ($result) {
  162. $i = 0;
  163. $num = $this->db->num_rows($result);
  164. while ($i < $num) {
  165. $objp = $this->db->fetch_object($result);
  166. $totalpaid += $objp->amount;
  167. $i++;
  168. }
  169. } else {
  170. dol_print_error($this->db, '');
  171. }
  172. $resteapayer = $object->total_ttc - $totalpaid;
  173. // Request a direct debit order
  174. if ($object->statut > Facture::STATUS_DRAFT && $object->statut < Facture::STATUS_ABANDONED && $object->paye == 0) {
  175. $stripe = new Stripe($this->db);
  176. if ($resteapayer > 0) {
  177. if ($stripe->getStripeAccount($conf->entity)) { // a modifier avec droit stripe
  178. $langs->load("withdrawals");
  179. 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>';
  180. } else {
  181. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
  182. }
  183. } elseif ($resteapayer == 0) {
  184. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
  185. }
  186. } else {
  187. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
  188. }
  189. } elseif (is_object($object) && $object->element == 'invoice_supplier') {
  190. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
  191. } elseif (is_object($object) && $object->element == 'member') {
  192. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeAutoSubscription")).'">'.$langs->trans("StripeAutoSubscription").'</a>';
  193. }
  194. return 0;
  195. }
  196. }