Standardize the way online payments are working.

Removed the trigger file of PAYPAL module that stored data that was not
used by Dolibarr. The trigger event still exists, but if an external
module need action on it, it must provides itself its trigger file.
This commit is contained in:
Laurent Destailleur 2017-05-13 21:10:56 +02:00
parent 3c87399fac
commit 955c9f4217
11 changed files with 78 additions and 243 deletions

View File

@ -16,6 +16,8 @@ Following changes may create regression for some external modules, but were nece
* Removed CommonObject::displayMarginInfos (was deprecated in 3.8). Use same method into
html.formmargin.class.php
* Removed Societe::set_commnucation_level (was deprecated in 4.0). Was not used.
* Removed the trigger file of PAYPAL module that stored data that was not used by Dolibarr. The trigger event still
exists, but if an external module need action on it, it must provides itself its trigger file.
***** ChangeLog for 5.0.2 compared to 5.0.1 *****
FIX: #6468 + Fix missing translation

View File

@ -1,112 +0,0 @@
<?php
/* Copyright (C) 2011-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file /htdocs/core/triggers/interface_20_modPaypal_PaypalWorkflow.class.php
* \ingroup paypal
* \brief Trigger file for paypal workflow
*/
require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
/**
* Class of triggers for paypal module
*/
class InterfacePaypalWorkflow extends DolibarrTriggers
{
public $picto = 'paypal@paypal';
public $family = 'paypal';
public $description = "Triggers of this module allows to manage paypal workflow";
public $version = self::VERSION_DOLIBARR;
/**
* Function called when a Dolibarrr business event is done.
* All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
*
* @param string $action Event action code
* @param Object $object Object
* @param User $user Object user
* @param Translate $langs Object langs
* @param conf $conf Object conf
* @return int <0 if KO, 0 if no triggered ran, >0 if OK
*/
public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
{
// Mettre ici le code a executer en reaction de l'action
// Les donnees de l'action sont stockees dans $object
if ($action == 'PAYPAL_PAYMENT_OK')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". source=".$object->source." ref=".$object->ref);
if (! empty($object->source))
{
if ($object->source == 'membersubscription')
{
//require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherents.class.php';
// TODO add subscription treatment
}
else
{
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
$soc = new Societe($this->db);
// Parse element/subelement (ex: project_task)
$element = $path = $filename = $object->source;
if (preg_match('/^([^_]+)_([^_]+)/i',$object->source,$regs))
{
$element = $path = $regs[1];
$filename = $regs[2];
}
// For compatibility
if ($element == 'order') {
$path = $filename = 'commande';
}
if ($element == 'invoice') {
$path = 'compta/facture'; $filename = 'facture';
}
dol_include_once('/'.$path.'/class/'.$filename.'.class.php');
$classname = ucfirst($filename);
$obj = new $classname($this->db);
$ret = $obj->fetch('',$object->ref);
if ($ret < 0) return -1;
// Add payer id
$soc->setValueFrom('ref_int', $object->payerID, 'societe', $obj->socid);
// Add transaction id
$obj->setValueFrom('ref_int',$object->resArray["TRANSACTIONID"]);
}
}
else
{
// TODO add free tag treatment
}
}
return 0;
}
}

View File

@ -1,113 +0,0 @@
<?php
/* Copyright (C) 2011-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file /htdocs/core/triggers/interface_20_modStripe_StripeWorkflow.class.php
* \ingroup stripe
* \brief Trigger file for stripe workflow
*/
require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
/**
* Class of triggers for stripe module
*/
class InterfaceStripeWorkflow extends DolibarrTriggers
{
public $picto = 'stripe@stripe';
public $family = 'stripe';
public $description = "Triggers of this module allows to manage stripe workflow";
public $version = self::VERSION_DOLIBARR;
/**
* Function called when a Dolibarrr business event is done.
* All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
*
* @param string $action Event action code
* @param Object $object Object
* @param User $user Object user
* @param Translate $langs Object langs
* @param conf $conf Object conf
* @return int <0 if KO, 0 if no triggered ran, >0 if OK
*/
public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
{
// Mettre ici le code a executer en reaction de l'action
// Les donnees de l'action sont stockees dans $object
if ($action == 'STRIPE_PAYMENT_OK')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". source=".$object->source." ref=".$object->ref);
if (! empty($object->source))
{
if ($object->source == 'membersubscription')
{
//require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherents.class.php';
// TODO add subscription treatment
}
else
{
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
$soc = new Societe($this->db);
// Parse element/subelement (ex: project_task)
$element = $path = $filename = $object->source;
if (preg_match('/^([^_]+)_([^_]+)/i',$object->source,$regs))
{
$element = $path = $regs[1];
$filename = $regs[2];
}
// For compatibility
if ($element == 'order') {
$path = $filename = 'commande';
}
if ($element == 'invoice') {
$path = 'compta/facture'; $filename = 'facture';
}
dol_include_once('/'.$path.'/class/'.$filename.'.class.php');
$classname = ucfirst($filename);
$obj = new $classname($this->db);
$ret = $obj->fetch('',$object->ref);
if ($ret < 0) return -1;
// Add payer id
$soc->setValueFrom('ref_int', $object->payerID, 'societe', $obj->socid);
// Add transaction id
$obj->setValueFrom('ref_int',$object->resArray["TRANSACTIONID"]);
}
}
else
{
// TODO add free tag treatment
}
}
return 0;
}
}

View File

@ -93,16 +93,22 @@ llxHeader();
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans("PayBoxSetup"),$linkback,'title_setup');
print $langs->trans("PayBoxDesc")."<br>\n";
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT."/paybox/admin/paybox.php";
$head[$h][1] = $langs->trans("PayBox");
$head[$h][2] = 'payboxaccount';
$h++;
print '<br>';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="setvalue">';
dol_fiche_head(null, 'payboxaccount', '');
dol_fiche_head($head, 'payboxaccount', '', -1);
$var=true;
print $langs->trans("PayBoxDesc")."<br>\n";
print '<br>';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
@ -131,7 +137,6 @@ print '<input size="32" type="text" name="PAYBOX_PBX_IDENTIFIANT" value="'.$conf
print '<br>'.$langs->trans("Example").': 2 ('.$langs->trans("Test").')';
print '</td></tr>';
$var=true;
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("UsageParameter").'</td>';
print '<td>'.$langs->trans("Value").'</td>';

View File

@ -121,7 +121,6 @@ print '<br>';
print '<table class="noborder" width="100%">';
// Account Parameters
$var=true;
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("AccountParameter").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
@ -160,7 +159,6 @@ print $form->selectarray("PAYPAL_SSLVERSION",array('1'=> $langs->trans('TLSv1'),
print '</td></tr>';
// Usage Parameters
$var=true;
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("UsageParameter").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
@ -220,7 +218,6 @@ print '<input size="32" type="email" name="PAYPAL_PAYONLINE_SENDEMAIL" value="'.
print ' &nbsp; '.$langs->trans("Example").': myemail@myserver.com';
print '</td></tr>';
$var=true;
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
print '<td>'.$langs->trans("Value").'</td>';

View File

@ -50,6 +50,7 @@ $langs->load("paypal");
$langs->load("stripe");
$object = new stdClass(); // For triggers
/*
@ -71,6 +72,14 @@ foreach($_POST as $k => $v) $tracepost .= "{$k} - {$v}\n";
dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_paybox');
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($db);
$result=$interface->run_triggers('PAYBOX_PAYMENT_OK',$object,$user,$langs,$conf);
if ($result < 0) { $error++; $errors=$interface->errors; }
// Fin appel triggers
// Send an email
if (! empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL))
{

View File

@ -60,6 +60,9 @@ $FULLTAG=GETPOST('FULLTAG');
if (empty($FULLTAG)) $FULLTAG=GETPOST('fulltag');
$object = new stdClass(); // For triggers
/*
* Actions
*/
@ -113,6 +116,7 @@ print $langs->trans("YourPaymentHasBeenRecorded")."<br><br>\n";
if (! empty($conf->global->PAYBOX_MESSAGE_OK)) print $conf->global->PAYBOX_MESSAGE_OK;
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($db);

View File

@ -69,6 +69,9 @@ if (! empty($conf->paybox->enabled)) $validpaymentmethod['paybox']='paybox';
if (empty($validpaymentmethod)) accessforbidden('', 0, 0, 1);
$object = new stdClass(); // For triggers
/*
* Actions
*/
@ -87,6 +90,14 @@ foreach($_POST as $k => $v) $tracepost .= "{$k} - {$v}\n";
dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_payment');
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($db);
$result=$interface->run_triggers('PAYMENTONLINE_PAYMENT_KO',$object,$user,$langs,$conf);
if ($result < 0) { $error++; $errors=$interface->errors; }
// Fin appel triggers
// Send an email
if (! empty($conf->paypal->enabled))
{

View File

@ -128,6 +128,9 @@ $PAYMENTSTATUS=$TRANSACTIONID=$TAXAMT=$NOTE='';
$ErrorCode=$ErrorShortMsg=$ErrorLongMsg=$ErrorSeverityCode='';
$object = new stdClass(); // For triggers
/*
@ -191,8 +194,6 @@ if (! empty($conf->paypal->enabled))
$ack = strtoupper($resArray["ACK"]);
if ($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
{
$object = new stdClass();
$object->source = $source;
$object->ref = $ref;
$object->payerID = $payerID;
@ -244,11 +245,16 @@ if ($ispaymentok)
print $langs->trans("ThisIsTransactionId",$TRANSACTIONID)."<br><br>\n";
if (! empty($conf->global->PAYMENT_MESSAGE_OK)) print $conf->global->PAYMENT_MESSAGE_OK;
$sendemail = '';
if (! empty($conf->global->PAYMENTONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYMENTONLINE_SENDEMAIL;
// TODO Remove local option to keep only the generic one ?
if ($paymentmethod == 'paypal' && ! empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYPAL_PAYONLINE_SENDEMAIL;
if ($paymentmethod == 'paybox' && ! empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYBOX_PAYONLINE_SENDEMAIL;
// Send an email
if (! empty($conf->global->PAYMENTONLINE_SENDEMAIL))
if ($sendemail)
{
$sendto=$conf->global->PAYMENTONLINE_SENDEMAIL;
$sendto=$sendemail;
$from=$conf->global->MAILING_EMAIL_FROM;
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
@ -269,10 +275,11 @@ if ($ispaymentok)
}
else
{
$content.=$langs->transnoentitiesnoconv("NewPaypalPaymentReceived")."<br>\n";
$content.=$langs->transnoentitiesnoconv("NewOnlinePaymentReceived")."<br>\n";
}
$content.="<br>\n";
$content.=$langs->transnoentitiesnoconv("TechnicalInformation").":<br>\n";
$content.=$langs->transnoentitiesnoconv("PaymentSystem").': '.$paymentmethod."<br>\n";
$content.=$langs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
$content.="tag=".$fulltag." token=".$token." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
@ -310,11 +317,16 @@ else
if ($mysoc->email) print "\nPlease, send a screenshot of this page to ".$mysoc->email."<br>\n";
$sendemail = '';
if (! empty($conf->global->PAYMENTONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYMENTONLINE_SENDEMAIL;
// TODO Remove local option to keep only the generic one ?
if ($paymentmethod == 'paypal' && ! empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYPAL_PAYONLINE_SENDEMAIL;
if ($paymentmethod == 'paybox' && ! empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYBOX_PAYONLINE_SENDEMAIL;
// Send an email
if (! empty($conf->global->PAYMENTONLINE_SENDEMAIL))
if ($sendemail)
{
$sendto=$conf->global->PAYMENTONLINE_SENDEMAIL;
$sendto=$sendemail;
$from=$conf->global->MAILING_EMAIL_FROM;
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
@ -327,6 +339,7 @@ else
$content.=$langs->transnoentitiesnoconv("PaypalConfirmPaymentPageWasCalledButFailed")."\n";
$content.="\n";
$content.=$langs->transnoentitiesnoconv("TechnicalInformation").":\n";
$content.=$langs->transnoentitiesnoconv("PaymentSystem").': '.$paymentmethod."<br>\n";
$content.=$langs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."\n";
$content.="tag=".$fulltag."\ntoken=".$token." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;

View File

@ -61,6 +61,9 @@ $FULLTAG=GETPOST('FULLTAG');
if (empty($FULLTAG)) $FULLTAG=GETPOST('fulltag');
$object = new stdClass(); // For triggers
/*
* Actions
*/
@ -79,6 +82,14 @@ foreach($_POST as $k => $v) $tracepost .= "{$k} - {$v}\n";
dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_paypal');
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($db);
$result=$interface->run_triggers('PAYPAL_PAYMENT_KO',$object,$user,$langs,$conf);
if ($result < 0) { $error++; $errors=$interface->errors; }
// Fin appel triggers
// Send an email
if (! empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL))
{

View File

@ -92,6 +92,9 @@ $FULLTAG=GETPOST('FULLTAG');
if (empty($FULLTAG)) $FULLTAG=GETPOST('fulltag');
$object = new stdClass(); // For triggers
/*
* Actions
*/
@ -151,8 +154,6 @@ if ($PAYPALTOKEN)
$ack = strtoupper($resArray["ACK"]);
if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
{
$object = new stdClass();
$object->source = $source;
$object->ref = $ref;
$object->payerID = $payerID;
@ -226,7 +227,14 @@ if ($PAYPALTOKEN)
}
else
{
//Display a user friendly Error on the page using any of the following error information returned by PayPal
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($db);
$result=$interface->run_triggers('PAYPAL_PAYMENT_KO',$object,$user,$langs,$conf);
if ($result < 0) { $error++; $errors=$interface->errors; }
// Fin appel triggers
//Display a user friendly Error on the page using any of the following error information returned by PayPal
$ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
$ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
$ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);