NEW Add more complete error messages in log on stripe payments

This commit is contained in:
Laurent Destailleur 2019-04-03 17:53:24 +02:00
parent ebd3a04f7f
commit 83cf0dabae
2 changed files with 25 additions and 11 deletions

View File

@ -422,6 +422,7 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
dol_syslog("POST vatnumber = ".$vatnumber, LOG_DEBUG, 0, '_stripe');
$error = 0;
$errormessage = '';
try {
$metadata = array(
@ -555,60 +556,71 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
print('Message is:' . $err['message'] . "\n");
$error++;
dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
$errormessage="ErrorCard ".$e->getMessage()." err=".var_export($err, true);
dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
setEventMessages($e->getMessage(), null, 'errors');
$action='';
} catch (\Stripe\Error\RateLimit $e) {
// Too many requests made to the API too quickly
$error++;
dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
$errormessage="ErrorRateLimit ".$e->getMessage();
dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
setEventMessages($e->getMessage(), null, 'errors');
$action='';
} catch (\Stripe\Error\InvalidRequest $e) {
// Invalid parameters were supplied to Stripe's API
$error++;
dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
$errormessage="ErrorInvalidRequest ".$e->getMessage();
dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
setEventMessages($e->getMessage(), null, 'errors');
$action='';
} catch (\Stripe\Error\Authentication $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
$error++;
dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
$errormessage="ErrorAuthentication ".$e->getMessage();
dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
setEventMessages($e->getMessage(), null, 'errors');
$action='';
} catch (\Stripe\Error\ApiConnection $e) {
// Network communication with Stripe failed
$error++;
dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
$errormessage="ErrorApiConnection ".$e->getMessage();
dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
setEventMessages($e->getMessage(), null, 'errors');
$action='';
} catch (\Stripe\Error\Base $e) {
// Display a very generic error to the user, and maybe send
// yourself an email
$error++;
dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
$errormessage="ErrorBase ".$e->getMessage();
dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
setEventMessages($e->getMessage(), null, 'errors');
$action='';
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
$error++;
dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe');
$errormessage="ErrorException ".$e->getMessage();
dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
setEventMessages($e->getMessage(), null, 'errors');
$action='';
}
$remoteip = getUserRemoteIP();
$_SESSION["onlinetoken"] = $stripeToken;
$_SESSION["FinalPaymentAmt"] = $amount;
$_SESSION["currencyCodeType"] = $currency;
$_SESSION["paymentType"] = '';
$_SESSION['ipaddress'] = getUserRemoteIP(); // Payer ip
$_SESSION['ipaddress'] = ($remoteip?$remoteip:'unknown'); // Payer ip
$_SESSION['payerID'] = is_object($customer)?$customer->id:'';
$_SESSION['TRANSACTIONID'] = is_object($charge)?$charge->id:'';
$_SESSION['errormessage'] = $errormessage;
dol_syslog("Action charge stripe result=".$error." ip=".$_SESSION['ipaddress'], LOG_DEBUG, 0, '_stripe');
dol_syslog("Action charge stripe ip=".$remoteip, LOG_DEBUG, 0, '_stripe');
dol_syslog("onlinetoken=".$_SESSION["onlinetoken"]." FinalPaymentAmt=".$_SESSION["FinalPaymentAmt"]." currencyCodeType=".$_SESSION["currencyCodeType"]." payerID=".$_SESSION['payerID']." TRANSACTIONID=".$_SESSION['TRANSACTIONID'], LOG_DEBUG, 0, '_stripe');
dol_syslog("FULLTAG=".$FULLTAG, LOG_DEBUG, 0, '_stripe');
dol_syslog("error=".$error." errormessage=".$errormessage, LOG_DEBUG, 0, '_stripe');
dol_syslog("Now call the redirect to paymentok or paymentko", LOG_DEBUG, 0, '_stripe');
if ($error)

View File

@ -107,7 +107,7 @@ $object = new stdClass(); // For triggers
* View
*/
dol_syslog("Callback url when an online payment is canceled. query_string=".(empty($_SERVER["QUERY_STRING"])?'':$_SERVER["QUERY_STRING"])." script_uri=".(empty($_SERVER["SCRIPT_URI"])?'':$_SERVER["SCRIPT_URI"]), LOG_DEBUG, 0, '_payment');
dol_syslog("Callback url when an online payment is refused or canceled. query_string=".(empty($_SERVER["QUERY_STRING"])?'':$_SERVER["QUERY_STRING"])." script_uri=".(empty($_SERVER["SCRIPT_URI"])?'':$_SERVER["SCRIPT_URI"]), LOG_DEBUG, 0, '_payment');
$tracepost = "";
foreach($_POST as $k => $v) $tracepost .= "{$k} - {$v}\n";
@ -126,6 +126,7 @@ if (! empty($_SESSION['ipaddress'])) // To avoid to make action twice
$FinalPaymentAmt = $_SESSION['FinalPaymentAmt'];
// From env
$ipaddress = $_SESSION['ipaddress'];
$errormessage = $_SESSION['errormessage'];
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
@ -173,8 +174,9 @@ if (! empty($_SESSION['ipaddress'])) // To avoid to make action twice
$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.=$companylangs->transnoentitiesnoconv("Error").': '.$errormessage."<br>\n";
$content.="<br>\n";
$content.="tag=".$fulltag."\ntoken=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
$content.="tag=".$fulltag." token=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
$ishtml=dol_textishtml($content); // May contain urls