NEW Accept anonmymous events (no user assigned)

NEW Online payment now record the payment on invoices
This commit is contained in:
Laurent Destailleur 2018-03-04 19:39:46 +01:00
parent d8b2d1f8c2
commit 864edce665
17 changed files with 382 additions and 86 deletions

View File

@ -48,9 +48,11 @@ $MAXAGENDA=$conf->global->AGENDA_EXT_NB;
// List of aviable colors
$colorlist=array('BECEDD','DDBECE','BFDDBE','F598B4','F68654','CBF654','A4A4A5');
/*
* Actions
*/
if ($actionsave)
{
$db->begin();

View File

@ -667,11 +667,12 @@ class BlockedLog
return -2;
}
if (empty($this->action) || empty($this->fk_user) || empty($this->user_fullname)) {
if (empty($this->action)) {
$this->error=$langs->trans("BadParameterWhenCallingCreateOfBlockedLog");
dol_syslog($this->error, LOG_WARNING);
return -3;
}
if (empty($this->fk_user)) $this->user_fullname='(Anonymous)';
$this->date_creation = dol_now();

View File

@ -212,7 +212,7 @@ class ActionComm extends CommonObject
$now=dol_now();
// Check parameters
if (empty($this->userownerid))
if (! isset($this->userownerid) || $this->userownerid === '') // $this->userownerid may be 0 (anonymous event) of > 0
{
dol_syslog("You tried to create an event but mandatory property ownerid was not defined", LOG_WARNING);
$this->errors[]='ErrorPropertyUserowneridNotDefined';

View File

@ -88,11 +88,11 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
if (empty($reshook))
{
if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes'))
if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes'))
{
$error = 0;
$datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
$datepaye = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
$paiement_id = 0;
$totalpayment = 0;
$multicurrency_totalpayment = 0;

View File

@ -209,9 +209,10 @@ class Paiement extends CommonObject
$total = $totalamount_converted; // Maybe use price2num with MT for the converted value
$mtotal = $totalamount;
}
$note = ($this->note_public?$this->note_public:$this->note);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (entity, ref, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_creat)";
$sql.= " VALUES (".$conf->entity.", '".$this->ref."', '". $this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', '".$total."', '".$mtotal."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.")";
$sql.= " VALUES (".$conf->entity.", '".$this->ref."', '". $this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', '".$total."', '".$mtotal."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($note)."', ".$user->id.")";
dol_syslog(get_class($this)."::Create insert paiement", LOG_DEBUG);
$resql = $this->db->query($sql);

View File

@ -17,9 +17,9 @@
*/
/**
* \file htdocs/compta/paiement/avalider.php
* \file htdocs/compta/paiement/tovalidate.php
* \ingroup compta
* \brief Page liste des paiements a valider des factures clients
* \brief Page list payment to validate. Visible in menu when option BILL_ADD_PAYMENT_VALIDATION is on.
*/
require '../../main.inc.php';

View File

@ -3421,7 +3421,8 @@ class Form
}
else
{
print $langs->trans("NoActiveBankAccountDefined");
if ($statut == 0) print $langs->trans("NoActiveBankAccountDefined");
else print $langs->trans("NoBankAccountFound");
}
}
else {

View File

@ -818,7 +818,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
{
$newmenu->add("/compta/paiement/avalider.php?leftmenu=customers_bills_tovalid",$langs->trans("MenuToValid"),2,$user->rights->facture->lire,'',$mainmenu,'customer_bills_tovalid');
$newmenu->add("/compta/paiement/tovalidate.php?leftmenu=customers_bills_tovalid",$langs->trans("MenuToValid"),2,$user->rights->facture->lire,'',$mainmenu,'customer_bills_tovalid');
}
$newmenu->add("/compta/paiement/rapport.php?leftmenu=customers_bills_reports",$langs->trans("Reportings"),2,$user->rights->facture->lire,'',$mainmenu,'customers_bills_reports');

View File

@ -708,6 +708,7 @@ CoreErrorTitle=System error
CoreErrorMessage=Sorry, an error occurred. Contact your system administrator to check the logs or disable $dolibarr_main_prod=1 to get more information.
CreditCard=Credit card
ValidatePayment=Validate payment
CreditOrDebitCard=Credit or debit card
FieldsWithAreMandatory=Fields with <b>%s</b> are mandatory
FieldsWithIsForPublic=Fields with <b>%s</b> are shown on public list of members. If you don't want this, check off the "public" box.
AccordingToGeoIPDatabase=(according to GeoIP convertion)

View File

@ -30,4 +30,5 @@ ErrorCode=Error Code
ErrorSeverityCode=Error Severity Code
OnlinePaymentSystem=Online payment system
PaypalLiveEnabled=Paypal live enabled (otherwise test/sandbox mode)
PaypalImportPayment=Import Paypal payments
PaypalImportPayment=Import Paypal payments
PostActionAfterPayment=Post actions after payments

View File

@ -55,6 +55,8 @@ if ($action == 'setvalue' && $user->admin)
$result=dolibarr_set_const($db, "PAYBOX_PBX_IDENTIFIANT",GETPOST('PAYBOX_PBX_IDENTIFIANT','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR",GETPOST('ONLINE_PAYMENT_CREDITOR','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS",GETPOST('PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS','int'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL",GETPOST('ONLINE_PAYMENT_CSS_URL','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
@ -183,6 +185,15 @@ print '<br>'.$langs->trans("Example").': '.$mysoc->name;
print '</td></tr>';
if (! empty($conf->banque->enabled))
{
print '<tr class="oddeven"><td>';
print $langs->trans("BankAccount").'</td><td>';
print $form->select_comptes($conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS, 'PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
print '</td></tr>';
}
print '<tr class="oddeven"><td>';
print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
print '<input size="64" type="text" name="ONLINE_PAYMENT_CSS_URL" value="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'">';

View File

@ -55,6 +55,8 @@ if ($action == 'setvalue' && $user->admin)
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR",GETPOST('ONLINE_PAYMENT_CREDITOR','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS",GETPOST('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS','int'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY",GETPOST('PAYPAL_API_INTEGRAL_OR_PAYPALONLY','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL",GETPOST('ONLINE_PAYMENT_CSS_URL','alpha'),'chaine',0,'',$conf->entity);
@ -210,6 +212,13 @@ print '<input size="64" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.$con
print ' &nbsp; '.$langs->trans("Example").': '.$mysoc->name;
print '</td></tr>';
if (! empty($conf->banque->enabled))
{
print '<tr class="oddeven"><td>';
print $langs->trans("BankAccount").'</td><td>';
print $form->select_comptes($conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS, 'PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
print '</td></tr>';
}
print '<tr class="oddeven"><td>';
print $langs->trans("CSSUrlForPaymentForm").'</td><td>';

View File

@ -192,7 +192,7 @@ function getPaypalPaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_f
* @param string $returnURL Url to use if payment is OK
* @param string $cancelURL Url to use if payment is KO
* @param string $tag Full tag
* @return void
* @return string No return (a redirect is done) if OK, or Error message if KO
*/
function print_paypal_redirect($paymentAmount,$currencyCodeType,$paymentType,$returnURL,$cancelURL,$tag)
{
@ -272,11 +272,20 @@ function print_paypal_redirect($paymentAmount,$currencyCodeType,$paymentType,$re
$ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
$ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
echo $langs->trans('SetExpressCheckoutAPICallFailed') . "<br>\n";
echo $langs->trans('DetailedErrorMessage') . ": " . $ErrorLongMsg."<br>\n";
echo $langs->trans('ShortErrorMessage') . ": " . $ErrorShortMsg."<br>\n";
echo $langs->trans('ErrorCode') . ": " . $ErrorCode."<br>\n";
echo $langs->trans('ErrorSeverityCode') . ": " . $ErrorSeverityCode."<br>\n";
if ($ErrorCode == 10729)
{
$mesg.= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n";
}
else
{
$mesg = $langs->trans('SetExpressCheckoutAPICallFailed') . "<br>\n";
$mesg.= $langs->trans('DetailedErrorMessage') . ": " . $ErrorLongMsg."<br>\n";
$mesg.= $langs->trans('ShortErrorMessage') . ": " . $ErrorShortMsg."<br>\n";
$mesg.= $langs->trans('ErrorCode') . ": " . $ErrorCode."<br>\n";
$mesg.= $langs->trans('ErrorSeverityCode') . ": " . $ErrorSeverityCode."<br>\n";
}
return $mesg;
}
}
@ -300,6 +309,7 @@ function print_paypal_redirect($paymentAmount,$currencyCodeType,$paymentType,$re
* phoneNum: the phoneNum entered on the merchant's site
* email: the buyer email
* desc: Product description
* See https://developer.paypal.com/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/
*
* @param double $paymentAmount Payment amount
* @param string $currencyCodeType Currency
@ -307,8 +317,8 @@ function print_paypal_redirect($paymentAmount,$currencyCodeType,$paymentType,$re
* @param string $returnURL Return Url
* @param string $cancelURL Cancel Url
* @param string $tag Full tag
* @param string $solutionType Type
* @param string $landingPage Landing page
* @param string $solutionType Type ('Mark' or 'Sole')
* @param string $landingPage Landing page ('Login' or 'Billing')
* @param string $shipToName Ship to name
* @param string $shipToStreet Ship to street
* @param string $shipToCity Ship to city
@ -327,38 +337,86 @@ function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType,
// Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
//declaring of global variables
global $conf, $langs;
global $conf, $langs, $mysoc;
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
$nvpstr = '';
$nvpstr = $nvpstr . "&AMT=". urlencode($paymentAmount); // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
$nvpstr = $nvpstr . "&PAYMENTACTION=" . urlencode($paymentType); // PAYMENTACTION deprecated by paypal -> PAYMENTREQUEST_n_PAYMENTACTION
$nvpstr = $nvpstr . "&VERSION=98.0";
$nvpstr = $nvpstr . "&RETURNURL=" . urlencode($returnURL);
$nvpstr = $nvpstr . "&CANCELURL=" . urlencode($cancelURL);
$nvpstr = $nvpstr . "&CURRENCYCODE=" . urlencode($currencyCodeType); // CURRENCYCODE deprecated by paypal -> PAYMENTREQUEST_n_CURRENCYCODE
$nvpstr = $nvpstr . "&ADDROVERRIDE=1";
//$nvpstr = $nvpstr . "&ALLOWNOTE=0";
$nvpstr = $nvpstr . "&SHIPTONAME=" . urlencode($shipToName); // SHIPTONAME deprecated by paypal -> PAYMENTREQUEST_n_SHIPTONAME
$nvpstr = $nvpstr . "&SHIPTOSTREET=" . urlencode($shipToStreet); //
$nvpstr = $nvpstr . "&SHIPTOSTREET2=" . urlencode($shipToStreet2);
$nvpstr = $nvpstr . "&SHIPTOCITY=" . urlencode($shipToCity);
$nvpstr = $nvpstr . "&SHIPTOSTATE=" . urlencode($shipToState);
$nvpstr = $nvpstr . "&SHIPTOCOUNTRYCODE=" . urlencode($shipToCountryCode);
$nvpstr = $nvpstr . "&SHIPTOZIP=" . urlencode($shipToZip);
$nvpstr = $nvpstr . "&PHONENUM=" . urlencode($phoneNum);
if (! empty($conf->global->PAYPAL_ALLOW_NOTES))
{
$nvpstr = $nvpstr . "&ALLOWNOTE=0";
}
if (empty($conf->global->PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS))
{
$nvpstr = $nvpstr . "&NOSHIPPING=1"; // An empty or not complete shipping address will be accepted
}
else
{
$nvpstr = $nvpstr . "&NOSHIPPING=0"; // A valid shipping address is required (full required fields mandatory)
}
$nvpstr = $nvpstr . "&SOLUTIONTYPE=" . urlencode($solutionType);
$nvpstr = $nvpstr . "&LANDINGPAGE=" . urlencode($landingPage);
//$nvpstr = $nvpstr . "&CUSTOMERSERVICENUMBER=" . urlencode($tag); // Hotline phone number
$nvpstr = $nvpstr . "&INVNUM=" . urlencode($tag);
if (! empty($email)) $nvpstr = $nvpstr . "&EMAIL=" . urlencode($email);
if (! empty($desc)) $nvpstr = $nvpstr . "&DESC=" . urlencode($desc); // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
if (! empty($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER))
{
$nvpstr = $nvpstr . "&CUSTOMERSERVICENUMBER=" . urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER); // Hotline phone number
}
$paypalprefix = 'PAYMENTREQUEST_0_';
//$paypalprefix = '';
if (! empty($paypalprefix) && $paymentType == 'Sole') $paymentType='Sale';
$nvpstr = $nvpstr . "&AMT=". urlencode($paymentAmount); // Total for all elements
$nvpstr = $nvpstr . "&".$paypalprefix."INVNUM=" . urlencode($tag);
$nvpstr = $nvpstr . "&".$paypalprefix."AMT=". urlencode($paymentAmount); // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
$nvpstr = $nvpstr . "&".$paypalprefix."ITEMAMT=". urlencode($paymentAmount); // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
$nvpstr = $nvpstr . "&".$paypalprefix."PAYMENTACTION=" . urlencode($paymentType); // PAYMENTACTION deprecated by paypal -> PAYMENTREQUEST_n_PAYMENTACTION
$nvpstr = $nvpstr . "&".$paypalprefix."CURRENCYCODE=" . urlencode($currencyCodeType); // CURRENCYCODE deprecated by paypal -> PAYMENTREQUEST_n_CURRENCYCODE
$nvpstr = $nvpstr . "&".$paypalprefix."L_PAYMENTREQUEST_0_QTY0=1";
$nvpstr = $nvpstr . "&".$paypalprefix."L_PAYMENTREQUEST_0_AMT0=".urlencode($paymentAmount);
$nvpstr = $nvpstr . "&".$paypalprefix."L_PAYMENTREQUEST_0_NAME0=".urlencode($desc);
$nvpstr = $nvpstr . "&".$paypalprefix."L_PAYMENTREQUEST_0_NUMBER0=0";
$nvpstr = $nvpstr . "&".$paypalprefix."SHIPTONAME=" . urlencode($shipToName); // SHIPTONAME deprecated by paypal -> PAYMENTREQUEST_n_SHIPTONAME
$nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOSTREET=" . urlencode($shipToStreet); //
$nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOSTREET2=" . urlencode($shipToStreet2);
$nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOCITY=" . urlencode($shipToCity);
$nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOSTATE=" . urlencode($shipToState);
$nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOCOUNTRYCODE=" . urlencode($shipToCountryCode);
$nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOZIP=" . urlencode($shipToZip);
$nvpstr = $nvpstr . "&".$paypalprefix."PHONENUM=" . urlencode($phoneNum);
if (! empty($email)) $nvpstr = $nvpstr . "&".$paypalprefix."EMAIL=" . urlencode($email); // EMAIL deprecated by paypal -> PAYMENTREQUEST_n_EMAIL
if (! empty($desc)) $nvpstr = $nvpstr . "&".$paypalprefix."DESC=" . urlencode($desc); // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
if (! empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo)
{
global $dolibarr_main_url_root;
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
$urllogo=$urlwithroot."/viewimage.php?modulepart=mycompany&file=".$mysoc->logo;
$nvpstr = $nvpstr . "&LOGOIMG=" . urlencode($urllogo);
}
if (! empty($conf->global->PAYPAL_BRANDNAME))
{
$nvpstr = $nvpstr . "&BRANDNAME=" . urlencode($conf->global->PAYPAL_BRANDNAME); // BRANDNAME
}
if (! empty($conf->global->PAYPAL_NOTETOBUYER))
{
$nvpstr = $nvpstr . "&NOTETOBUYER=" . urlencode($conf->global->PAYPAL_NOTETOBUYER); // PAYPAL_NOTETOBUYER
}
$_SESSION["FinalPaymentAmt"] = $paymentAmount;
$_SESSION["currencyCodeType"] = $currencyCodeType;
$_SESSION["PaymentType"] = $paymentType;
$_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR ']; // Payer ip
$_SESSION["PaymentType"] = $paymentType; // 'Mark', 'Sole'
$_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR']; // Payer ip
//'---------------------------------------------------------------------------------------------------------------
//' Make the API call to PayPal

View File

@ -264,6 +264,7 @@ else if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$param
* Actions
*/
// Action dopayment is called after choosing the payment mode
if ($action == 'dopayment')
{
if ($paymentmethod == 'paypal')
@ -310,6 +311,7 @@ if ($action == 'dopayment')
dol_syslog("PAYPAL_API_KO: $PAYPAL_API_KO", LOG_DEBUG);
dol_syslog("PAYPAL_API_PRICE: $PAYPAL_API_PRICE", LOG_DEBUG);
dol_syslog("PAYPAL_API_DEVISE: $PAYPAL_API_DEVISE", LOG_DEBUG);
// All those fields may be empty when making a payment for a free amount for example
dol_syslog("shipToName: $shipToName", LOG_DEBUG);
dol_syslog("shipToStreet: $shipToStreet", LOG_DEBUG);
dol_syslog("shipToCity: $shipToCity", LOG_DEBUG);
@ -327,9 +329,10 @@ if ($action == 'dopayment')
//$_SESSION["FinalPaymentAmt"]=$PAYPAL_API_PRICE;
// A redirect is added if API call successfull
print_paypal_redirect($PAYPAL_API_PRICE,$PAYPAL_API_DEVISE,$PAYPAL_PAYMENT_TYPE,$PAYPAL_API_OK,$PAYPAL_API_KO, $FULLTAG);
$mesg = print_paypal_redirect($PAYPAL_API_PRICE,$PAYPAL_API_DEVISE,$PAYPAL_PAYMENT_TYPE,$PAYPAL_API_OK,$PAYPAL_API_KO, $FULLTAG);
exit;
// If we are here, it means the Paypal redirect was not done, so we show error message
$action = '';
}
}
@ -379,10 +382,12 @@ if ($action == 'dopayment')
// Called when choosing Stripe mode, after the 'dopayment'
if ($action == 'charge')
{
$amountstripe = $amount;
// Correct the amount according to unit of currency
// See https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support
$arrayzerounitcurrency=array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
if (! in_array($currency, $arrayzerounitcurrency)) $amount=$amount * 100;
if (! in_array($currency, $arrayzerounitcurrency)) $amountstripe=$amountstripe * 100;
dol_syslog("POST keys : ".join(',', array_keys($_POST)), LOG_DEBUG, 0, '_stripe');
dol_syslog("POST values: ".join(',', $_POST), LOG_DEBUG, 0, '_stripe');
@ -411,7 +416,7 @@ if ($action == 'charge')
dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe');
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => price2num($amount, 'MU'),
'amount' => price2num($amountstripe, 'MU'),
'currency' => $currency,
'description' => 'Stripe payment: '.$FULLTAG,
'metadata' => array("FULLTAG" => $FULLTAG, 'Recipient' => $mysoc->name),
@ -850,7 +855,7 @@ if ($source == 'invoice')
print '</td></tr>'."\n";
// Amount
print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Amount");
print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("PaymentAmount");
if (empty($amount) && empty($object->paye)) print ' ('.$langs->trans("ToComplete").')';
print '</td><td class="CTableRow'.($var?'1':'2').'">';
if (empty($object->paye))
@ -1432,7 +1437,7 @@ if (preg_match('/^dopayment/',$action))
<div class="form-row left">
<label for="card-element">
Credit or debit card
'.$langs->trans("CreditOrDebitCard").'
</label>
<div id="card-element">
<!-- a Stripe Element will be inserted here. -->
@ -1442,7 +1447,7 @@ if (preg_match('/^dopayment/',$action))
<div id="card-errors" role="alert"></div>
</div>
<br>
<button class="button" id="buttontopay">'.$langs->trans("ValidatePayment").'</button>
<button class="butAction" id="buttontopay">'.$langs->trans("ValidatePayment").'</button>
<img id="hourglasstopay" class="hidden" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/working.gif'.'">
</td></tr></tbody></table>

View File

@ -44,13 +44,7 @@ if (! empty($conf->paypal->enabled))
require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';
}
$langs->load("main");
$langs->load("other");
$langs->load("dict");
$langs->load("bills");
$langs->load("companies");
$langs->load("paybox");
$langs->load("paypal");
$langs->loadLangs(array("main","other","dict","bills","companies","paybox","paypal"));
// Clean parameters
if (! empty($conf->paypal->enabled))
@ -130,6 +124,8 @@ $object = new stdClass(); // For triggers
* View
*/
$now = dol_now();
dol_syslog("Callback url when a payment was done. query_string=".(dol_escape_htmltag($_SERVER["QUERY_STRING"])?dol_escape_htmltag($_SERVER["QUERY_STRING"]):'')." script_uri=".(dol_escape_htmltag($_SERVER["SCRIPT_URI"])?dol_escape_htmltag($_SERVER["SCRIPT_URI"]):''), LOG_DEBUG, 0, '_payment');
$tracepost = "";
@ -183,7 +179,7 @@ if ($urllogo)
if (! empty($conf->paypal->enabled))
{
if ($paymentmethod == 'paypal')
if ($paymentmethod == 'paypal') // We call this page only if payment is ok on payment system
{
if ($PAYPALTOKEN)
{
@ -251,28 +247,187 @@ if (! empty($conf->paypal->enabled))
if (! empty($conf->paybox->enabled))
{
if ($paymentmethod == 'paybox') $ispaymentok = true; // We call this page only if payment is ok
if ($paymentmethod == 'paybox') $ispaymentok = true; // We call this page only if payment is ok on payment system
}
if (! empty($conf->stripe->enabled))
{
if ($paymentmethod == 'stripe') $ispaymentok = true; // We call this page only if payment is ok
if ($paymentmethod == 'stripe') $ispaymentok = true; // We call this page only if payment is ok on payment system
}
// If data not provided from back url, search them into the session env
if (empty($ipaddress)) $ipaddress = $_SESSION['ipaddress'];
if (empty($TRANSACTIONID)) $TRANSACTIONID = $_SESSION['TRANSACTIONID'];
if (empty($FinalPaymentAmt)) $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
if (empty($paymentType)) $paymentType = $_SESSION["paymentType"];
$fulltag = $FULLTAG;
$tmptag=dolExplodeIntoArray($fulltag,'.','=');
// Make complementary actions
$ispostactionok = 0;
$postactionmessages = array();
if ($ispaymentok)
{
if (in_array('MEM', array_keys($tmptag)))
{
// Record subscription
include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
$member = new Adherent($db);
$result = $member->fetch(0, $tmptag['MEM']);
if ($result)
{
if (empty($paymentType)) $paymentType = 'CB';
$paymentTypeId = dol_getIdFromCode($db, $paymentType,'c_paiement','code','id',1);
if (! empty($FinalPaymentAmt) && $paymentTypeId > 0)
{
}
else
{
$postactionmessages[] = 'Failed to get a valid value for "amount paid" or "payment type" to record the payment of subscription for member '.$tmptag['MEM'];
$ispostactionok = -1;
}
}
else
{
$postactionmessages[] = 'Member for subscription payed '.$tmptag['MEM'].' was not found';
$ispostactionok = -1;
}
}
elseif (in_array('INV', array_keys($tmptag)))
{
// Record payment
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$invoice = new Facture($db);
$result = $invoice->fetch(0, $tmptag['INV']);
if ($result)
{
$FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
$paymentTypeId = 0;
if ($paymentmethod == 'paybox') $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
if ($paymentmethod == 'paypal') $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
if ($paymentmethod == 'stripe') $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
if (empty($paymentTypeId))
{
$paymentType = $_SESSION["paymentType"];
if (empty($paymentType)) $paymentType = 'CB';
$paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
}
$currencyCodeType = $_SESSION['currencyCodeType'];
if (! empty($FinalPaymentAmt) && $paymentTypeId > 0)
{
// Creation of payment line
include_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
$paiement = new Paiement($db);
$paiement->datepaye = $now;
if ($currencyCodeType == $conf->currency)
{
$paiement->amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id
}
else
{
$paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching
$postactionmessages[] = 'Payment was done in a different currency that currency expected of company';
$ispostactionok = -1;
$error++; // Not yet supported
}
$paiement->paiementid = $paymentTypeId;
$paiement->num_paiement = '';
$paiement->note_public = 'Online payment using '.$paymentmethod.' from '.$ipaddress.' - Transaction ID = '.$TRANSACTIONID;
if (! $error)
{
$paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents
if ($paiement_id < 0)
{
$postactionmessages[] = $paiement->error.' '.join("<br>\n", $paiement->errors);
$ispostactionok = -1;
$error++;
}
else
{
$postactionmessages[] = 'Payment created';
$ispostactionok=1;
}
}
if (! $error && ! empty($conf->banque->enabled))
{
$bankaccountid = 0;
if ($paymentmethod == 'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
if ($paymentmethod == 'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
if ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
if ($bankaccountid > 0)
{
$label='(CustomerInvoicePayment)';
if ($invoice->type == Facture::TYPE_CREDIT_NOTE) $label='(CustomerInvoicePaymentBack)'; // Refund of a credit note
$result=$paiement->addPaymentToBank($user,'payment',$label, $bankaccountid, '', '');
if ($result < 0)
{
$postactionmessages[] = $paiement->error.' '.joint("<br>\n", $paiement->errors);
$ispostactionok = -1;
$error++;
}
else
{
$postactionmessages[] = 'Bank entry of payment created';
$ispostactionok=1;
}
}
else
{
$postactionmessages[] = 'Setup of bank account to use in module '.$paymentmethod.' was not set. Not way to record the payment.';
$ispostactionok = -1;
$error++;
}
}
if (! $error)
{
$db->commit();
}
else
{
$db->rollback();
}
}
else
{
$postactionmessages[] = 'Failed to get a valid value for "amount paid" ('.$FinalPaymentAmt.') or "payment type" ('.$paymentType.') to record the payment of invoice '.$tmptag['INV'];
$ispostactionok = -1;
}
}
else
{
$postactionmessages[] = 'Invoice payed '.$tmptag['INV'].' was not found';
$ispostactionok = -1;
}
}
else
{
// Nothing done
}
}
if ($ispaymentok)
{
// Get on url call
$fulltag = $FULLTAG;
$onlinetoken = empty($PAYPALTOKEN)?$_SESSION['onlinetoken']:$PAYPALTOKEN;
$payerID = empty($PAYPALPAYERID)?$_SESSION['payerID']:$PAYPALPAYERID;
// Set by newpayment.php
$paymentType = $_SESSION['PaymentType'];
$currencyCodeType = $_SESSION['currencyCodeType'];
$FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
// From env
$ipaddress = $_SESSION['ipaddress'];
$TRANSACTIONID = $_SESSION['TRANSACTIONID'];
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
@ -296,6 +451,10 @@ if ($ispaymentok)
// Send an email
if ($sendemail)
{
$companylangs = new Translate('', $conf);
$companylangs->setDefaultLang($mysoc->default_lang);
$companylangs->loadLangs(array('main','members','bills','paypal','paybox'));
$sendto=$sendemail;
$from=$conf->global->MAILING_EMAIL_FROM;
// Define $urlwithroot
@ -317,25 +476,56 @@ if ($ispaymentok)
else $appli.=" ".DOL_VERSION;
$urlback=$_SERVER["REQUEST_URI"];
$topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewOnlinePaymentReceived");
$topic='['.$appli.'] '.$companylangs->transnoentitiesnoconv("NewOnlinePaymentReceived");
$content="";
if (! empty($tmptag['MEM']))
if (in_array('MEM', array_keys($tmptag)))
{
$langs->load("members");
$url=$urlwithroot."/adherents/card_subscriptions.php?rowid=".$tmptag['MEM'];
$content.=$langs->trans("PaymentSubscription")."<br>\n";
$content.=$langs->trans("MemberId").': '.$tmptag['MEM']."<br>\n";
$content.=$langs->trans("Link").': <a href="'.$url.'">'.$url.'</a>'."<br>\n";
$content.='<strong>'.$companylangs->trans("PaymentSubscription")."</strong><br><br>\n";
$content.=$companylangs->trans("MemberId").': <strong>'.$tmptag['MEM']."</strong><br>\n";
$content.=$companylangs->trans("Link").': <a href="'.$url.'">'.$url.'</a>'."<br>\n";
}
elseif (in_array('INV', array_keys($tmptag)))
{
$url=$urlwithroot."/compta/facture/card.php?ref=".$tmptag['INV'];
$content.='<strong>'.$companylangs->trans("Payment")."</strong><br><br>\n";
$content.=$companylangs->trans("Invoice").': <strong>'.$tmptag['INV']."</strong><br>\n";
//$content.=$companylangs->trans("ThirdPartyId").': '.$tmptag['CUS']."<br>\n";
$content.=$companylangs->trans("Link").': <a href="'.$url.'">'.$url.'</a>'."<br>\n";
}
else
{
$content.=$langs->transnoentitiesnoconv("NewOnlinePaymentReceived")."<br>\n";
$content.=$companylangs->transnoentitiesnoconv("NewOnlinePaymentReceived")."<br>\n";
}
$content.=$companylangs->transnoentities("PostActionAfterPayment").' : ';
if ($ispostactionok > 0)
{
//$topic.=' ('.$companylangs->transnoentitiesnoconv("Status").' '.$companylangs->transnoentitiesnoconv("OK").')';
$content.='<font color="green">'.$companylangs->transnoentitiesnoconv("OK").'</font>';
}
elseif ($ispostactionok == 0)
{
$content.=$companylangs->transnoentitiesnoconv("None");
}
else
{
$topic.=($ispostactionok ? '' : ' ('.$companylangs->trans("WarningPostActionErrorAfterPayment").')');
$content.='<font color="red">'.$companylangs->transnoentitiesnoconv("Error").'</font>';
}
$content.='<br>'."\n";
foreach($postactionmessages as $postactionmessage)
{
$content.=' * '.$postactionmessage.'<br>'."\n";
}
$content.='<br>'."\n";
$content.="<br>\n";
$content.=$langs->transnoentitiesnoconv("TechnicalInformation").":<br>\n";
$content.=$langs->transnoentitiesnoconv("OnlinePaymentSystem").': '.$paymentmethod."<br>\n";
$content.=$langs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
$content.="tag=".$fulltag."\ntoken=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
$content.='<u>'.$companylangs->transnoentitiesnoconv("TechnicalInformation").":</u><br>\n";
$content.=$companylangs->transnoentitiesnoconv("OnlinePaymentSystem").': <strong>'.$paymentmethod."</strong><br>\n";
$content.=$companylangs->transnoentitiesnoconv("TransactionId").': <strong>'.$TRANSACTIONID."</strong><br>\n";
$content.=$companylangs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
$content.="<br>\n";
$content.="tag=".$fulltag."<br>\ntoken=".$onlinetoken."<br>\npaymentType=".$paymentType."<br>\ncurrencycodeType=".$currencyCodeType."<br>\npayerId=".$payerID."<br>\nipaddress=".$ipaddress."<br>\nFinalPaymentAmt=".$FinalPaymentAmt."<br>\n";
$ishtml=dol_textishtml($content); // May contain urls
@ -356,15 +546,12 @@ if ($ispaymentok)
else
{
// Get on url call
$fulltag = $FULLTAG;
$onlinetoken = empty($PAYPALTOKEN)?$_SESSION['onlinetoken']:$PAYPALTOKEN;
$onlinetoken = empty($PAYPALTOKEN)?$_SESSION['onlinetoken']:$PAYPALTOKEN;
$payerID = empty($PAYPALPAYERID)?$_SESSION['payerID']:$PAYPALPAYERID;
// Set by newpayment.php
$paymentType = $_SESSION['PaymentType'];
$currencyCodeType = $_SESSION['currencyCodeType'];
$FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
// From env
$ipaddress = $_SESSION['ipaddress'];
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
@ -389,12 +576,14 @@ else
if ($paymentmethod == 'paybox' && ! empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYBOX_PAYONLINE_SENDEMAIL;
if ($paymentmethod == 'stripe' && ! empty($conf->global->STRIPE_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->STRIPE_PAYONLINE_SENDEMAIL;
$tmptag=dolExplodeIntoArray($fulltag,'.','=');
// Send an email
if ($sendemail)
{
$sendto=$sendemail;
$companylangs = new Translate('', $conf);
$companylangs->setDefaultLang($mysoc->default_lang);
$companylangs->loadLangs(array('main','members','bills','paypal','paybox'));
$sendto=$sendemail;
$from=$conf->global->MAILING_EMAIL_FROM;
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
@ -415,14 +604,17 @@ else
else $appli.=" ".DOL_VERSION;
$urlback=$_SERVER["REQUEST_URI"];
$topic='['.$appli.'] '.$langs->transnoentitiesnoconv("ValidationOfPaymentFailed");
$topic='['.$appli.'] '.$companylangs->transnoentitiesnoconv("ValidationOfPaymentFailed");
$content="";
$content.=$langs->transnoentitiesnoconv("PaymentSystemConfirmPaymentPageWasCalledButFailed")."\n";
$content.="\n";
$content.=$langs->transnoentitiesnoconv("TechnicalInformation").":\n";
$content.=$langs->transnoentitiesnoconv("OnlinePaymentSystem").': '.$paymentmethod."\n";
$content.=$langs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."\n";
$content.="tag=".$fulltag."\ntoken=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
$content.='<font color="orange">'.$companylangs->transnoentitiesnoconv("PaymentSystemConfirmPaymentPageWasCalledButFailed")."</font>\n";
$content.="<br>\n";
$content.='<u>'.$companylangs->transnoentitiesnoconv("TechnicalInformation").":</u><br>\n";
$content.=$companylangs->transnoentitiesnoconv("OnlinePaymentSystem").': <strong>'.$paymentmethod."</strong><br>\n";
$content.=$companylangs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
$content.="<br>\n";
$content.="tag=".$fulltag."<br>\ntoken=".$onlinetoken."<br>\npaymentType=".$paymentType."<br>\ncurrencycodeType=".$currencyCodeType."<br>\npayerId=".$payerID."<br>\nipaddress=".$ipaddress."<br>\nFinalPaymentAmt=".$FinalPaymentAmt."<br>\n";
$ishtml=dol_textishtml($content); // May contain urls
@ -448,6 +640,10 @@ print "\n</div>\n";
htmlPrintOnlinePaymentFooter($mysoc,$langs,0,$suffix);
// Clean session variables to avoid duplicate actions if post is resent
unset($_SESSION["FinalPaymentAmt"]);
unset($_SESSION["TRANSACTIONID"]);
llxFooter('', 'public');
$db->close();

View File

@ -250,7 +250,7 @@ if (GETPOST('action','aZ09') == 'dopayment')
//$_SESSION["FinalPaymentAmt"]=$PAYPAL_API_PRICE;
// A redirect is added if API call successfull
print_paypal_redirect($PAYPAL_API_PRICE,$PAYPAL_API_DEVISE,$PAYPAL_PAYMENT_TYPE,$PAYPAL_API_OK,$PAYPAL_API_KO, $FULLTAG);
$mesg = print_paypal_redirect($PAYPAL_API_PRICE,$PAYPAL_API_DEVISE,$PAYPAL_PAYMENT_TYPE,$PAYPAL_API_OK,$PAYPAL_API_KO, $FULLTAG);
exit;
}

View File

@ -56,7 +56,9 @@ if ($action == 'setvalue' && $user->admin)
$result=dolibarr_set_const($db, "STRIPE_LIVE_SECRET_KEY",GETPOST('STRIPE_LIVE_SECRET_KEY','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR",GETPOST('ONLINE_PAYMENT_CREDITOR','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_PAYMENTS",GETPOST('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS','int'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL",GETPOST('ONLINE_PAYMENT_CSS_URL','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM",GETPOST('ONLINE_PAYMENT_MESSAGE_FORM','alpha'),'chaine',0,'',$conf->entity);
@ -195,6 +197,14 @@ print '<input size="64" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.$con
print ' &nbsp; '.$langs->trans("Example").': '.$mysoc->name;
print '</td></tr>';
if (! empty($conf->banque->enabled))
{
print '<tr class="oddeven"><td>';
print $langs->trans("BankAccount").'</td><td>';
print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS, 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
print '</td></tr>';
}
print '<tr class="oddeven"><td>';
print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
print '<input size="64" type="text" name="ONLINE_PAYMENT_CSS_URL" value="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'">';