From 998254d9c6426bd22980b6ccb332012650f43f8f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 May 2017 16:17:00 +0200 Subject: [PATCH] Finish rewrite and debug of module Stripe. --- htdocs/core/modules/modStripe.class.php | 2 +- htdocs/langs/en_US/paypal.lang | 9 +- htdocs/langs/en_US/stripe.lang | 1 + htdocs/public/paybox/paymentko.php | 110 ++++++++----- htdocs/public/paybox/paymentok.php | 12 +- htdocs/public/payment/newpayment.php | 2 +- htdocs/public/payment/paymentko.php | 165 ++++++++++++++------ htdocs/public/payment/paymentok.php | 80 ++++++++-- htdocs/public/paypal/paymentko.php | 103 ++++++------ htdocs/public/paypal/paymentok.php | 27 ++-- htdocs/public/stripe/newpayment.php | 81 ++++++++-- htdocs/public/stripe/paymentko.php | 165 ++++++++++++++++++++ htdocs/public/stripe/paymentok.php | 199 ++++++++++++++++++++++++ htdocs/stripe/admin/stripe.php | 20 ++- htdocs/stripe/lib/stripe.lib.php | 1 + 15 files changed, 781 insertions(+), 196 deletions(-) create mode 100644 htdocs/public/stripe/paymentko.php create mode 100644 htdocs/public/stripe/paymentok.php diff --git a/htdocs/core/modules/modStripe.class.php b/htdocs/core/modules/modStripe.class.php index 4f4b15fa0a4..e7e20be5b83 100644 --- a/htdocs/core/modules/modStripe.class.php +++ b/htdocs/core/modules/modStripe.class.php @@ -65,7 +65,7 @@ class modStripe extends DolibarrModules $this->picto='stripe@stripe'; // Data directories to create when module is enabled. - $this->dirs = array('/stripe/temp'); + $this->dirs = array(); // Config pages. Put here list of php page names stored in admmin directory used to setup module. $this->config_page_url = array("stripe.php@stripe"); diff --git a/htdocs/langs/en_US/paypal.lang b/htdocs/langs/en_US/paypal.lang index 3c699527018..63999f31234 100644 --- a/htdocs/langs/en_US/paypal.lang +++ b/htdocs/langs/en_US/paypal.lang @@ -16,15 +16,16 @@ ThisIsTransactionId=This is id of transaction: %s PAYPAL_ADD_PAYMENT_URL=Add the url of Paypal payment when you send a document by mail PredefinedMailContentLink=You can click on the secure link below to make your payment (PayPal) if it is not already done.\n\n%s\n\n YouAreCurrentlyInSandboxMode=You are currently in the "sandbox" mode -NewPaypalPaymentReceived=New Paypal payment received -NewPaypalPaymentFailed=New Paypal payment tried but failed +NewOnlinePaymentReceived=New online payment received +NewOnlinePaymentFailed=New online payment tried but failed PAYPAL_PAYONLINE_SENDEMAIL=EMail to warn after a payment (success or not) ReturnURLAfterPayment=Return URL after payment -ValidationOfPaypalPaymentFailed=Validation of Paypal payment failed -PaypalConfirmPaymentPageWasCalledButFailed=Payment confirmation page for Paypal was called by Paypal but confirmation failed +ValidationOfOnlinePaymentFailed=Validation of online payment failed +PaymentSystemConfirmPaymentPageWasCalledButFailed=Payment confirmation page was called by payment system returned an error SetExpressCheckoutAPICallFailed=SetExpressCheckout API call failed. DoExpressCheckoutPaymentAPICallFailed=DoExpressCheckoutPayment API call failed. DetailedErrorMessage=Detailed Error Message ShortErrorMessage=Short Error Message ErrorCode=Error Code ErrorSeverityCode=Error Severity Code +OnlinePaymentSystem=Online payment system \ No newline at end of file diff --git a/htdocs/langs/en_US/stripe.lang b/htdocs/langs/en_US/stripe.lang index 3f85dc2d544..68b853ac25b 100644 --- a/htdocs/langs/en_US/stripe.lang +++ b/htdocs/langs/en_US/stripe.lang @@ -9,6 +9,7 @@ ThisScreenAllowsYouToPay=This screen allow you to make an online payment to %s. ThisIsInformationOnPayment=This is information on payment to do ToComplete=To complete YourEMail=Email to receive payment confirmation +STRIPE_PAYONLINE_SENDEMAIL=EMail to warn after a payment (success or not) Creditor=Creditor PaymentCode=Payment code StripeDoPayment=Go on payment diff --git a/htdocs/public/paybox/paymentko.php b/htdocs/public/paybox/paymentko.php index be5b388f6ed..9cc8a07ea70 100644 --- a/htdocs/public/paybox/paymentko.php +++ b/htdocs/public/paybox/paymentko.php @@ -20,7 +20,6 @@ * \file htdocs/public/paybox/paymentko.php * \ingroup paybox * \brief File to show page after a failed payment - * \author Laurent Destailleur */ define("NOLOGIN",1); // This means this output page does not require to be logged. @@ -52,6 +51,8 @@ $langs->load("stripe"); $object = new stdClass(); // For triggers +$paymentmethod='paybox'; + /* * Actions @@ -72,51 +73,74 @@ 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)) +if (! empty($_SESSION['ipaddress'])) // To avoid to make action twice { - $sendto=$conf->global->PAYBOX_PAYONLINE_SENDEMAIL; - $from=$conf->global->MAILING_EMAIL_FROM; - - // Define link to login card - $appli=constant('DOL_APPLICATION_TITLE'); - if (! empty($conf->global->MAIN_APPLICATION_TITLE)) - { - $appli=$conf->global->MAIN_APPLICATION_TITLE; - if (preg_match('/\d\.\d/', $appli)) - { - if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core - } - else $appli.=" ".DOL_VERSION; - } - else $appli.=" ".DOL_VERSION; - - $urlback=$_SERVER["REQUEST_URI"]; - $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewPayboxPaymentFailed"); - $content=$langs->transnoentitiesnoconv("NewPayboxPaymentFailed")."\n".$fulltag; - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($topic, $sendto, $from, $content); - - $result=$mailfile->sendfile(); - if ($result) - { - dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_paybox'); - } - else - { - dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_paybox'); - } + // 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["Payment_Amount"]; + // From env + $ipaddress = $_SESSION['ipaddress']; + + // 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 + $sendemail = ''; + if (! empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYBOX_PAYONLINE_SENDEMAIL; + + if ($sendemail) + { + $sendto=$sendemail; + $from=$conf->global->MAILING_EMAIL_FROM; + + // Define link to login card + $appli=constant('DOL_APPLICATION_TITLE'); + if (! empty($conf->global->MAIN_APPLICATION_TITLE)) + { + $appli=$conf->global->MAIN_APPLICATION_TITLE; + if (preg_match('/\d\.\d/', $appli)) + { + if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core + } + else $appli.=" ".DOL_VERSION; + } + else $appli.=" ".DOL_VERSION; + + $urlback=$_SERVER["REQUEST_URI"]; + $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewOnlinePaymentFailed"); + $content=""; + $content.=$langs->transnoentitiesnoconv("ValidationOfOnlinePaymentFailed")."\n"; + $content.="\n"; + $content.=$langs->transnoentitiesnoconv("TechnicalInformation").":\n"; + $content.=$langs->transnoentitiesnoconv("OnlinePaymentSystem").': '.$paymentmethod."
\n"; + $content.=$langs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."\n"; + $content.="tag=".$fulltag."\npaymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt; + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($topic, $sendto, $from, $content); + + $result=$mailfile->sendfile(); + if ($result) + { + dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_paybox'); + } + else + { + dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_paybox'); + } + } + + unset($_SESSION['ipaddress']); } - $head=''; if (! empty($conf->global->PAYBOX_CSS_URL)) $head=''."\n"; diff --git a/htdocs/public/paybox/paymentok.php b/htdocs/public/paybox/paymentok.php index 0e91189e242..b59034b774e 100644 --- a/htdocs/public/paybox/paymentok.php +++ b/htdocs/public/paybox/paymentok.php @@ -20,7 +20,6 @@ * \file htdocs/public/paybox/paymentok.php * \ingroup paybox * \brief File to show page after a successful payment - * \author Laurent Destailleur */ define("NOLOGIN",1); // This means this output page does not require to be logged. @@ -62,6 +61,8 @@ if (empty($FULLTAG)) $FULLTAG=GETPOST('fulltag'); $object = new stdClass(); // For triggers +$paymentmethod='paybox'; + /* * Actions @@ -97,7 +98,7 @@ print '
'."\n"; // Get on url call /* -$token = $PAYBOXTOKEN; +$onlinetoken = $PAYBOXTOKEN; */ $fulltag = $FULLTAG; /*$payerID = $PAYBOXPAYERID; @@ -108,7 +109,7 @@ $FinalPaymentAmt = $_SESSION["Payment_Amount"]; // From env $ipaddress = $_SESSION['ipaddress']; -dol_syslog("Call newpaymentok with token=".$token." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag); +dol_syslog("Call newpaymentok with token=".$onlinetoken." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag); */ @@ -149,7 +150,7 @@ if (! empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) else $appli.=" ".DOL_VERSION; $urlback=$_SERVER["REQUEST_URI"]; - $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewPayboxPaymentReceived"); + $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewOnlinePaymentReceived"); $tmptag=dolExplodeIntoArray($fulltag,'.','='); $content=""; if (! empty($tmptag['MEM'])) @@ -162,10 +163,11 @@ if (! empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) } else { - $content.=$langs->transnoentitiesnoconv("NewPayboxPaymentReceived")."
\n"; + $content.=$langs->transnoentitiesnoconv("NewOnlinePaymentReceived")."
\n"; } $content.="
\n"; $content.=$langs->transnoentitiesnoconv("TechnicalInformation").":
\n"; + $content.=$langs->transnoentitiesnoconv("OnlinePaymentSystem").': '.$paymentmethod."
\n"; $content.=$langs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."
\n"; $content.="tag=".$fulltag."
\n"; diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 744f477782e..788321b6212 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -114,7 +114,7 @@ $ref=$REF=GETPOST('ref','alpha'); $TAG=GETPOST("tag",'alpha'); $FULLTAG=GETPOST("fulltag",'alpha'); // fulltag is tag with more informations $SECUREKEY=GETPOST("securekey"); // Secure key -if ($paymentmethod) $FULLTAG.=($FULLTAG?'.':'').'PM='.$paymentmethod; +if ($paymentmethod && ! preg_match('/'.preg_quote('PM='.$paymentmethod,'/').'/', $FULLTAG)) $FULLTAG.=($FULLTAG?'.':'').'PM='.$paymentmethod; if (! empty($SOURCE)) { diff --git a/htdocs/public/payment/paymentko.php b/htdocs/public/payment/paymentko.php index 6ce1c3badfa..9abcfcf2c58 100644 --- a/htdocs/public/payment/paymentko.php +++ b/htdocs/public/payment/paymentko.php @@ -23,7 +23,6 @@ * \brief File to show page after a failed payment. * This page is called by payment system with url provided to it competed with parameter TOKEN=xxx * This token can be used to get more informations. - * \author Laurent Destailleur */ define("NOLOGIN",1); // This means this output page does not require to be logged. @@ -53,16 +52,40 @@ $langs->load("companies"); $langs->load("paybox"); $langs->load("paypal"); -$PAYPALTOKEN=GETPOST('TOKEN'); -if (empty($PAYPALTOKEN)) $PAYPALTOKEN=GETPOST('token'); -$PAYPALPAYERID=GETPOST('PAYERID'); -if (empty($PAYPALPAYERID)) $PAYPALPAYERID=GETPOST('PayerID'); +if (! empty($conf->paypal->enabled)) +{ + $PAYPALTOKEN=GETPOST('TOKEN'); + if (empty($PAYPALTOKEN)) $PAYPALTOKEN=GETPOST('token'); + $PAYPALPAYERID=GETPOST('PAYERID'); + if (empty($PAYPALPAYERID)) $PAYPALPAYERID=GETPOST('PayerID'); +} +// TODO Other payment method + $FULLTAG=GETPOST('FULLTAG'); if (empty($FULLTAG)) $FULLTAG=GETPOST('fulltag'); + +// Detect $paymentmethod +$paymentmethod=''; +if (preg_match('/PM=([^\.]+)/', $FULLTAG, $reg)) +{ + $paymentmethod=$reg[1]; +} +if (empty($paymentmethod)) +{ + dol_print_error(null, 'The back url does not contains a parameter fulltag that should help us to find the payment method used'); + exit; +} +else +{ + dol_syslog("paymentmethod=".$paymentmethod); +} + + $validpaymentmethod=array(); if (! empty($conf->paypal->enabled)) $validpaymentmethod['paypal']='paypal'; if (! empty($conf->paybox->enabled)) $validpaymentmethod['paybox']='paybox'; +if (! empty($conf->stripe->enabled)) $validpaymentmethod['stripe']='stripe'; // Security check @@ -90,50 +113,94 @@ 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)) +if (! empty($_SESSION['ipaddress'])) // To avoid to make action twice { - if (! empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL)) - { - // Get on url call - $token = $PAYPALTOKEN; - $fulltag = $FULLTAG; - $payerID = $PAYPALPAYERID; - // Set by newpayment.php - $paymentType = $_SESSION['PaymentType']; - $currencyCodeType = $_SESSION['currencyCodeType']; - $FinalPaymentAmt = $_SESSION["Payment_Amount"]; - // From env - $ipaddress = $_SESSION['ipaddress']; - - - $sendto=$conf->global->PAYPAL_PAYONLINE_SENDEMAIL; - $from=$conf->global->MAILING_EMAIL_FROM; - - $urlback=$_SERVER["REQUEST_URI"]; - $topic='['.$conf->global->MAIN_APPLICATION_TITLE.'] '.$langs->transnoentitiesnoconv("NewPaypalPaymentFailed"); - $content=$langs->transnoentitiesnoconv("NewPaypalPaymentFailed")."\ntag=".$fulltag."\ntoken=".$token." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt; - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($topic, $sendto, $from, $content); - - $result=$mailfile->sendfile(); - if ($result) - { - dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment'); - } - else - { - dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment'); - } - } + // 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["Payment_Amount"]; + // From env + $ipaddress = $_SESSION['ipaddress']; + + // 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 + $sendemail = ''; + if (! empty($conf->paypal->enabled)) + { + if (! empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL)) + { + $sendemail = $conf->global->PAYPAL_PAYONLINE_SENDEMAIL; + } + } + // Send an email + if (! empty($conf->paybox->enabled)) + { + if (! empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) + { + $sendemail = $conf->global->PAYBOX_PAYONLINE_SENDEMAIL; + } + } + // Send an email + if (! empty($conf->stripe->enabled)) + { + if (! empty($conf->global->STRIPE_PAYONLINE_SENDEMAIL)) + { + $sendemail = $conf->global->STRIPE_PAYONLINE_SENDEMAIL; + } + } + + if ($sendemail) + { + $from=$conf->global->MAILING_EMAIL_FROM; + $sendto=$sendemail; + + // Define link to login card + $appli=constant('DOL_APPLICATION_TITLE'); + if (! empty($conf->global->MAIN_APPLICATION_TITLE)) + { + $appli=$conf->global->MAIN_APPLICATION_TITLE; + if (preg_match('/\d\.\d/', $appli)) + { + if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core + } + else $appli.=" ".DOL_VERSION; + } + else $appli.=" ".DOL_VERSION; + + $urlback=$_SERVER["REQUEST_URI"]; + $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewOnlinePaymentFailed"); + $content=""; + $content.=$langs->transnoentitiesnoconv("ValidationOfOnlinePaymentFailed")."\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; + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($topic, $sendto, $from, $content); + + $result=$mailfile->sendfile(); + if ($result) + { + dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment'); + } + else + { + dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment'); + } + } + + unset($_SESSION['ipaddress']); } $head=''; @@ -150,7 +217,7 @@ print ''."\n"; print '
'."\n"; print $langs->trans("YourPaymentHasNotBeenRecorded")."

"; -if (! empty($conf->global->PAYPAL_MESSAGE_KO)) print $conf->global->PAYPAL_MESSAGE_KO; +if (! empty($conf->global->PAYMENT_MESSAGE_KO)) print $conf->global->PAYMENT_MESSAGE_KO; print "\n
\n"; diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index c1b4329c7be..26022dcd4f8 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -23,7 +23,6 @@ * \brief File to show page after a successful payment * This page is called by payment system with url provided to it completed with parameter TOKEN=xxx * This token can be used to get more informations. - * \author Laurent Destailleur */ define("NOLOGIN",1); // This means this output page does not require to be logged. @@ -88,10 +87,10 @@ if (! empty($conf->paypal->enabled)) if (empty($PAYPALTOKEN)) $PAYPALTOKEN=GETPOST('token'); $PAYPALPAYERID=GETPOST('PAYERID'); if (empty($PAYPALPAYERID)) $PAYPALPAYERID=GETPOST('PayerID'); - $FULLTAG=GETPOST('FULLTAG'); - if (empty($FULLTAG)) $FULLTAG=GETPOST('fulltag'); } +$FULLTAG=GETPOST('FULLTAG'); +if (empty($FULLTAG)) $FULLTAG=GETPOST('fulltag'); $source=GETPOST('source'); $ref=GETPOST('ref'); @@ -116,6 +115,7 @@ else $validpaymentmethod=array(); if (! empty($conf->paypal->enabled)) $validpaymentmethod['paypal']='paypal'; if (! empty($conf->paybox->enabled)) $validpaymentmethod['paybox']='paybox'; +if (! empty($conf->stripe->enabled)) $validpaymentmethod['stripe']='stripe'; // Security check if (empty($validpaymentmethod)) accessforbidden('', 0, 0, 1); @@ -169,7 +169,7 @@ if (! empty($conf->paypal->enabled)) if ($PAYPALTOKEN) { // Get on url call - $token = $PAYPALTOKEN; + $onlinetoken = $PAYPALTOKEN; $fulltag = $FULLTAG; $payerID = $PAYPALPAYERID; // Set by newpayment.php @@ -179,17 +179,17 @@ if (! empty($conf->paypal->enabled)) // From env $ipaddress = $_SESSION['ipaddress']; - dol_syslog("Call paymentok with token=".$token." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_paypal'); + dol_syslog("Call paymentok with token=".$onlinetoken." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_paypal'); // Validate record if (! empty($paymentType)) { dol_syslog("We call GetExpressCheckoutDetails", LOG_DEBUG, 0, '_payment'); - $resArray=getDetails($token); + $resArray=getDetails($onlinetoken); //var_dump($resarray); - dol_syslog("We call DoExpressCheckoutPayment token=".$token." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_payment'); - $resArray=confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag); + dol_syslog("We call DoExpressCheckoutPayment token=".$onlinetoken." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_payment'); + $resArray=confirmPayment($onlinetoken, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag); $ack = strtoupper($resArray["ACK"]); if ($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING") @@ -233,6 +233,17 @@ if (! empty($conf->paypal->enabled)) 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["Payment_Amount"]; + // From env + $ipaddress = $_SESSION['ipaddress']; + // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($db); @@ -250,6 +261,7 @@ if ($ispaymentok) // 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; + if ($paymentmethod == 'stripe' && ! empty($conf->global->STRIPE_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->STRIPE_PAYONLINE_SENDEMAIL; // Send an email if ($sendemail) @@ -261,8 +273,21 @@ if ($ispaymentok) $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 + // Define link to login card + $appli=constant('DOL_APPLICATION_TITLE'); + if (! empty($conf->global->MAIN_APPLICATION_TITLE)) + { + $appli=$conf->global->MAIN_APPLICATION_TITLE; + if (preg_match('/\d\.\d/', $appli)) + { + if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core + } + else $appli.=" ".DOL_VERSION; + } + else $appli.=" ".DOL_VERSION; + $urlback=$_SERVER["REQUEST_URI"]; - $topic='['.$conf->global->MAIN_APPLICATION_TITLE.'] '.$langs->transnoentitiesnoconv("NewPaypalPaymentReceived"); + $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewOnlinePaymentReceived"); $tmptag=dolExplodeIntoArray($fulltag,'.','='); $content=""; if (! empty($tmptag['MEM'])) @@ -279,9 +304,9 @@ if ($ispaymentok) } $content.="
\n"; $content.=$langs->transnoentitiesnoconv("TechnicalInformation").":
\n"; - $content.=$langs->transnoentitiesnoconv("PaymentSystem").': '.$paymentmethod."
\n"; + $content.=$langs->transnoentitiesnoconv("OnlinePaymentSystem").': '.$paymentmethod."
\n"; $content.=$langs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."
\n"; - $content.="tag=".$fulltag." token=".$token." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt; + $content.="tag=".$fulltag."\ntoken=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt; $ishtml=dol_textishtml($content); // May contain urls @@ -301,6 +326,17 @@ if ($ispaymentok) } else { + // 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["Payment_Amount"]; + // From env + $ipaddress = $_SESSION['ipaddress']; + // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($db); @@ -322,6 +358,7 @@ else // 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; + if ($paymentmethod == 'stripe' && ! empty($conf->global->STRIPE_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->STRIPE_PAYONLINE_SENDEMAIL; // Send an email if ($sendemail) @@ -333,15 +370,28 @@ else $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 + // Define link to login card + $appli=constant('DOL_APPLICATION_TITLE'); + if (! empty($conf->global->MAIN_APPLICATION_TITLE)) + { + $appli=$conf->global->MAIN_APPLICATION_TITLE; + if (preg_match('/\d\.\d/', $appli)) + { + if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core + } + else $appli.=" ".DOL_VERSION; + } + else $appli.=" ".DOL_VERSION; + $urlback=$_SERVER["REQUEST_URI"]; - $topic='['.$conf->global->MAIN_APPLICATION_TITLE.'] '.$langs->transnoentitiesnoconv("ValidationOfPaypalPaymentFailed"); + $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("ValidationOfPaymentFailed"); $content=""; - $content.=$langs->transnoentitiesnoconv("PaypalConfirmPaymentPageWasCalledButFailed")."\n"; + $content.=$langs->transnoentitiesnoconv("PaymentSystemConfirmPaymentPageWasCalledButFailed")."\n"; $content.="\n"; $content.=$langs->transnoentitiesnoconv("TechnicalInformation").":\n"; - $content.=$langs->transnoentitiesnoconv("PaymentSystem").': '.$paymentmethod."
\n"; + $content.=$langs->transnoentitiesnoconv("OnlinePaymentSystem").': '.$paymentmethod."\n"; $content.=$langs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."\n"; - $content.="tag=".$fulltag."\ntoken=".$token." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt; + $content.="tag=".$fulltag."\ntoken=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt; $ishtml=dol_textishtml($content); // May contain urls diff --git a/htdocs/public/paypal/paymentko.php b/htdocs/public/paypal/paymentko.php index e432db2e317..a4e3c0a83ca 100644 --- a/htdocs/public/paypal/paymentko.php +++ b/htdocs/public/paypal/paymentko.php @@ -23,7 +23,6 @@ * \brief File to show page after a failed payment. * This page is called by paypal with url provided to payal competed with parameter TOKEN=xxx * This token can be used to get more informations. - * \author Laurent Destailleur */ define("NOLOGIN",1); // This means this output page does not require to be logged. @@ -63,6 +62,8 @@ if (empty($FULLTAG)) $FULLTAG=GETPOST('fulltag'); $object = new stdClass(); // For triggers +$paymentmethod='paypal'; + /* * Actions @@ -81,61 +82,73 @@ $tracepost = ""; 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)) +if (! empty($_SESSION['ipaddress'])) // To avoid to make action twice { // Get on url call - $token = $PAYPALTOKEN; $fulltag = $FULLTAG; - $payerID = $PAYPALPAYERID; + $onlinetoken = empty($PAYPALTOKEN)?$_SESSION['onlinetoken']:$PAYPALTOKEN; + $payerID = empty($PAYPALPAYERID)?$_SESSION['payerID']:$PAYPALPAYERID; // Set by newpayment.php $paymentType = $_SESSION['PaymentType']; $currencyCodeType = $_SESSION['currencyCodeType']; $FinalPaymentAmt = $_SESSION["Payment_Amount"]; // From env $ipaddress = $_SESSION['ipaddress']; + + // 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 + $sendemail = ''; + if (! empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYPAL_PAYONLINE_SENDEMAIL; - $sendto=$conf->global->PAYPAL_PAYONLINE_SENDEMAIL; - $from=$conf->global->MAILING_EMAIL_FROM; - - // Define link to login card - $appli=constant('DOL_APPLICATION_TITLE'); - if (! empty($conf->global->MAIN_APPLICATION_TITLE)) - { - $appli=$conf->global->MAIN_APPLICATION_TITLE; - if (preg_match('/\d\.\d/', $appli)) - { - if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core - } - else $appli.=" ".DOL_VERSION; - } - else $appli.=" ".DOL_VERSION; - - $urlback=$_SERVER["REQUEST_URI"]; - $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewPaypalPaymentFailed"); - $content=$langs->transnoentitiesnoconv("NewPaypalPaymentFailed")."\ntag=".$fulltag."\ntoken=".$token." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt; - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($topic, $sendto, $from, $content); - - $result=$mailfile->sendfile(); - if ($result) - { - dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_paypal'); - } - else - { - dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_paypal'); - } + if ($sendemail) + { + $sendto=$sendemail; + $from=$conf->global->MAILING_EMAIL_FROM; + + // Define link to login card + $appli=constant('DOL_APPLICATION_TITLE'); + if (! empty($conf->global->MAIN_APPLICATION_TITLE)) + { + $appli=$conf->global->MAIN_APPLICATION_TITLE; + if (preg_match('/\d\.\d/', $appli)) + { + if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core + } + else $appli.=" ".DOL_VERSION; + } + else $appli.=" ".DOL_VERSION; + + $urlback=$_SERVER["REQUEST_URI"]; + $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewOnlinePaymentFailed"); + $content=""; + $content.=$langs->transnoentitiesnoconv("ValidationOfOnlinePaymentFailed")."\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; + + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($topic, $sendto, $from, $content); + + $result=$mailfile->sendfile(); + if ($result) + { + dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_paypal'); + } + else + { + dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_paypal'); + } + } + + unset($_SESSION['ipaddress']); } diff --git a/htdocs/public/paypal/paymentok.php b/htdocs/public/paypal/paymentok.php index e3f2ed201e5..d98a6085e3e 100644 --- a/htdocs/public/paypal/paymentok.php +++ b/htdocs/public/paypal/paymentok.php @@ -23,7 +23,6 @@ * \brief File to show page after a successful payment * This page is called by paypal with url provided to payal completed with parameter TOKEN=xxx * This token can be used to get more informations. - * \author Laurent Destailleur */ define("NOLOGIN",1); // This means this output page does not require to be logged. @@ -94,6 +93,8 @@ if (empty($FULLTAG)) $FULLTAG=GETPOST('fulltag'); $object = new stdClass(); // For triggers +$paymentmethod='paypal'; + /* * Actions @@ -128,7 +129,7 @@ print '
'."\n"; if ($PAYPALTOKEN) { // Get on url call - $token = $PAYPALTOKEN; + $onlinetoken = $PAYPALTOKEN; $fulltag = $FULLTAG; $payerID = $PAYPALPAYERID; // Set by newpayment.php @@ -138,18 +139,18 @@ if ($PAYPALTOKEN) // From env $ipaddress = $_SESSION['ipaddress']; - dol_syslog("Call paymentok with token=".$token." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_paypal'); + dol_syslog("Call paymentok with token=".$onlinetoken." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_paypal'); // Validate record if (! empty($paymentType)) { dol_syslog("We call GetExpressCheckoutDetails", LOG_DEBUG, 0, '_paypal'); - $resArray=getDetails($token); + $resArray=getDetails($onlinetoken); //var_dump($resarray); - dol_syslog("We call DoExpressCheckoutPayment token=".$token." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_paypal'); - $resArray=confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag); + dol_syslog("We call DoExpressCheckoutPayment token=".$onlinetoken." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_paypal'); + $resArray=confirmPayment($onlinetoken, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag); $ack = strtoupper($resArray["ACK"]); if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING") @@ -202,7 +203,7 @@ if ($PAYPALTOKEN) else $appli.=" ".DOL_VERSION; $urlback=$_SERVER["REQUEST_URI"]; - $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewPaypalPaymentReceived"); + $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewOnlinePaymentReceived"); $tmptag=dolExplodeIntoArray($fulltag,'.','='); $content=""; if (! empty($tmptag['MEM'])) @@ -215,12 +216,13 @@ if ($PAYPALTOKEN) } else { - $content.=$langs->transnoentitiesnoconv("NewPaypalPaymentReceived")."
\n"; + $content.=$langs->transnoentitiesnoconv("NewOnlinePaymentReceived")."
\n"; } $content.="
\n"; $content.=$langs->transnoentitiesnoconv("TechnicalInformation").":
\n"; + $content.=$langs->transnoentitiesnoconv("OnlinePaymentSystem").': '.$paymentmethod."
\n"; $content.=$langs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."
\n"; - $content.="tag=".$fulltag." token=".$token." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt; + $content.="tag=".$fulltag."\ntoken=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt; $ishtml=dol_textishtml($content); // May contain urls @@ -285,13 +287,14 @@ if ($PAYPALTOKEN) else $appli.=" ".DOL_VERSION; $urlback=$_SERVER["REQUEST_URI"]; - $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("ValidationOfPaypalPaymentFailed"); + $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("ValidationOfPaymentFailed"); $content=""; - $content.=$langs->transnoentitiesnoconv("PaypalConfirmPaymentPageWasCalledButFailed")."\n"; + $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=".$token." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt; + $content.="tag=".$fulltag."\ntoken=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt; $ishtml=dol_textishtml($content); // May contain urls diff --git a/htdocs/public/stripe/newpayment.php b/htdocs/public/stripe/newpayment.php index 7578be73745..5975d349fe4 100644 --- a/htdocs/public/stripe/newpayment.php +++ b/htdocs/public/stripe/newpayment.php @@ -98,7 +98,7 @@ $ref=$REF=GETPOST('ref','alpha'); $TAG=GETPOST("tag",'alpha'); $FULLTAG=GETPOST("fulltag",'alpha'); // fulltag is tag with more informations $SECUREKEY=GETPOST("securekey"); // Secure key -$FULLTAG.=($FULLTAG?'.':'').'PM=stripe'; +if (! preg_match('/'.preg_quote('PM=stripe','/').'/', $FULLTAG)) $FULLTAG.=($FULLTAG?'.':'').'PM=stripe'; if (! empty($SOURCE)) { @@ -185,7 +185,7 @@ if (! empty($conf->global->STRIPE_SECURITY_TOKEN)) * Actions */ -if ($action == 'dopayment') // We click on button Create payment that lead on this page +if ($action == 'dopayment') // We click on button Create payment { if (GETPOST('newamount')) $amount = GETPOST('newamount'); else @@ -197,25 +197,37 @@ if ($action == 'dopayment') // We click on button Create payment that lead on if ($action == 'charge') { - dol_syslog("POST keys : ".join(',', array_keys($_POST))); - dol_syslog("POST values: ".join(',', $_POST)); + // 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; - $token = GETPOST("stripeToken"); - $email = GETPOST("stripeEmail"); + dol_syslog("POST keys : ".join(',', array_keys($_POST)), LOG_DEBUG, 0, '_stripe'); + dol_syslog("POST values: ".join(',', $_POST), LOG_DEBUG, 0, '_stripe'); + + $stripeToken = GETPOST("stripeToken",'alpha'); + $email = GETPOST("stripeEmail",'alpha'); + dol_syslog("stripeToken = ".$stripeToken, LOG_DEBUG, 0, '_stripe'); + dol_syslog("stripeEmail = ".$stripeEmail, LOG_DEBUG, 0, '_stripe'); + + $error = 0; + try { + dol_syslog("Create customer", LOG_DEBUG, 0, '_stripe'); $customer = \Stripe\Customer::create(array( 'email' => $email, - 'card' => $token + 'card' => $stripeToken // TODO )); + dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe'); $charge = \Stripe\Charge::create(array( 'customer' => $customer->id, 'amount' => price2num($amount, 'MU'), - 'currency' => $conf->currency, - // TODO - 'description' => 'Invoice payment N: '.$ref + 'currency' => $currency, + 'description' => 'Stripe payment: '.$FULLTAG, + 'statement_descriptor' => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 6, 'right', 'UTF-8', 1).' '.$FULLTAG, 22, 'right', 'UTF-8', 1) // 22 chars )); } catch(\Stripe\Error\Card $e) { // Since it's a decline, \Stripe\Error\Card will be caught @@ -229,39 +241,73 @@ if ($action == 'charge') print('Param is:' . $err['param'] . "\n"); print('Message is:' . $err['message'] . "\n"); + $error++; setEventMessages($e->getMessage(), null, 'errors'); + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); $action=''; } catch (\Stripe\Error\RateLimit $e) { // Too many requests made to the API too quickly + $error++; + dol_syslog($e->getMessage(), 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'); 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'); 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'); 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'); 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'); setEventMessages($e->getMessage(), null, 'errors'); $action=''; } - // TODO - dol_syslog("Action Pay."); + $_SESSION["onlinetoken"] = $stripeToken; + $_SESSION["FinalPaymentAmt"] = $amount; + $_SESSION["currencyCodeType"] = $currency; + $_SESSION["paymentType"] = ''; + $_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR']; // Payer ip + $_SESSION['payerID'] = is_object($customer)?$customer->id:''; + $_SESSION['TRANSACTIONID'] = is_object($charge)?$charge->id:''; + dol_syslog("Action charge stripe result=".$error." ip=".$_SESSION['ipaddress'], 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("Now call the redirect to paymentok or paymentko", LOG_DEBUG, 0, '_stripe'); + + if ($error) + { + header("Location: ".DOL_URL_ROOT.'/public/stripe/paymentko.php?FULLTAG='.urlencode($FULLTAG)); + exit; + } + else + { + header("Location: ".DOL_URL_ROOT.'/public/stripe/paymentok.php?FULLTAG='.urlencode($FULLTAG)); + exit; + } } @@ -1046,11 +1092,16 @@ if (preg_match('/^dopayment/',$action)) print ''."\n"; print ''."\n"; print ''."\n"; - print ''."\n"; - print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; print ''."\n"; print ''; - + print ''."\n"; + print ''."\n"; + print ' '; print ''; print ''; print ''; print ''; print '
diff --git a/htdocs/public/stripe/paymentko.php b/htdocs/public/stripe/paymentko.php new file mode 100644 index 00000000000..01000939b37 --- /dev/null +++ b/htdocs/public/stripe/paymentko.php @@ -0,0 +1,165 @@ + +* + * 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 . + */ + +/** + * \file htdocs/public/stripe/paymentko.php + * \ingroup core + * \brief File to show page after a failed payment. + * This page is called by payment system with url provided to it competed with parameter FULLTAG=xxx + * More data like token are saved into session. This token can be used to get more informations. + */ + +define("NOLOGIN",1); // This means this output page does not require to be logged. +define("NOCSRFCHECK",1); // We accept to go on this page from external web site. + +// For MultiCompany module. +// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php +// TODO This should be useless. Because entity must be retreive from object ref and not from url. +$entity=(! empty($_GET['entity']) ? (int) $_GET['entity'] : (! empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); +if (is_numeric($entity)) define("DOLENTITY", $entity); + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; + +$langs->load("main"); +$langs->load("other"); +$langs->load("dict"); +$langs->load("bills"); +$langs->load("companies"); +$langs->load("paybox"); +$langs->load("paypal"); +$langs->load("stripe"); + +$FULLTAG=GETPOST('FULLTAG'); +if (empty($FULLTAG)) $FULLTAG=GETPOST('fulltag'); + +// Security check +if (empty($conf->stripe->enabled)) accessforbidden('',0,0,1); + +$object = new stdClass(); // For triggers + +$paymentmethod='stripe'; + + +/* + * Actions + */ + + + + +/* + * View + */ + +dol_syslog("Callback url when a PayPal payment was canceled. query_string=".(empty($_SERVER["QUERY_STRING"])?'':$_SERVER["QUERY_STRING"])." script_uri=".(empty($_SERVER["SCRIPT_URI"])?'':$_SERVER["SCRIPT_URI"]), LOG_DEBUG, 0, '_stripe'); + +$tracepost = ""; +foreach($_POST as $k => $v) $tracepost .= "{$k} - {$v}\n"; +dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_stripe'); + +if (! empty($_SESSION['ipaddress'])) // To avoid to make action twice +{ + $fulltag = $FULLTAG; + $onlinetoken = empty($PAYPALTOKEN)?$_SESSION['onlinetoken']:$PAYPALTOKEN; + $payerID = empty($PAYPALPAYERID)?$_SESSION['payerID']:$PAYPALPAYERID; + $currencyCodeType = $_SESSION['currencyCodeType']; + $paymentType = $_SESSION['paymentType']; + $FinalPaymentAmt = $_SESSION['FinalPaymentAmt']; + $ipaddress = $_SESSION['ipaddress']; + + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($db); + $result=$interface->run_triggers('STRIPE_PAYMENT_KO',$object,$user,$langs,$conf); + if ($result < 0) { $error++; $errors=$interface->errors; } + // Fin appel triggers + + // Send an email + $sendemail = ''; + if (! empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->PAYPAL_PAYONLINE_SENDEMAIL; + + if ($sendemail) + { + // Get on url call + $sendto=$sendemail; + $from=$conf->global->MAILING_EMAIL_FROM; + + // Define link to login card + $appli=constant('DOL_APPLICATION_TITLE'); + if (! empty($conf->global->MAIN_APPLICATION_TITLE)) + { + $appli=$conf->global->MAIN_APPLICATION_TITLE; + if (preg_match('/\d\.\d/', $appli)) + { + if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core + } + else $appli.=" ".DOL_VERSION; + } + else $appli.=" ".DOL_VERSION; + + $urlback=$_SERVER["REQUEST_URI"]; + $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewOnlinePaymentFailed"); + $content=""; + $content.=$langs->transnoentitiesnoconv("ValidationOfOnlinePaymentFailed")."\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; + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($topic, $sendto, $from, $content); + + $result=$mailfile->sendfile(); + if ($result) + { + dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_stripe'); + } + else + { + dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_stripe'); + } + } + + unset($_SESSION['ipaddress']); +} + +$head=''; +if (! empty($conf->global->STRIPE_CSS_URL)) $head=''."\n"; + +$conf->dol_hide_topmenu=1; +$conf->dol_hide_leftmenu=1; + +llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody'); + + +// Show ko message +print ''."\n"; +print '
'."\n"; +print $langs->trans("YourPaymentHasNotBeenRecorded")."

"; + +if (! empty($conf->global->STRIPE_MESSAGE_KO)) print $conf->global->STRIPE_MESSAGE_KO; +print "\n
\n"; + + +htmlPrintOnlinePaymentFooter($mysoc,$langs); + + +llxFooter('', 'public'); + +$db->close(); diff --git a/htdocs/public/stripe/paymentok.php b/htdocs/public/stripe/paymentok.php new file mode 100644 index 00000000000..4eede2e9544 --- /dev/null +++ b/htdocs/public/stripe/paymentok.php @@ -0,0 +1,199 @@ + + * + * 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 . + */ + +/** + * \file htdocs/public/stripe/paymentok.php + * \ingroup core + * \brief File to show page after a successful payment + * This page is called by payment system with url provided to it completed with parameter FULLTAG=xxx + * More data like token are saved into session. This token can be used to get more informations. + */ + +define("NOLOGIN",1); // This means this output page does not require to be logged. +define("NOCSRFCHECK",1); // We accept to go on this page from external web site. + +// For MultiCompany module. +// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php +// TODO This should be useless. Because entity must be retreive from object ref and not from url. +$entity=(! empty($_GET['entity']) ? (int) $_GET['entity'] : (! empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); +if (is_numeric($entity)) define("DOLENTITY", $entity); + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; + +$langs->load("main"); +$langs->load("other"); +$langs->load("dict"); +$langs->load("bills"); +$langs->load("companies"); +$langs->load("paybox"); +$langs->load("paypal"); + +$FULLTAG=GETPOST('FULLTAG'); +if (empty($FULLTAG)) $FULLTAG=GETPOST('fulltag'); +$source=GETPOST('source'); +$ref=GETPOST('ref'); + +// Security check +if (empty($conf->stripe->enabled)) accessforbidden('', 0, 0, 1); + + +$ispaymentok = false; +// If payment is ok +$PAYMENTSTATUS=$TRANSACTIONID=$TAXAMT=$NOTE=''; +// If payment is ko +$ErrorCode=$ErrorShortMsg=$ErrorLongMsg=$ErrorSeverityCode=''; + + +$object = new stdClass(); // For triggers + +$paymentmethod='stripe'; + + +/* + * Actions + */ + + + +/* + * View + */ + +dol_syslog("Callback url when a payment was done. query_string=".(empty($_SERVER["QUERY_STRING"])?'':$_SERVER["QUERY_STRING"])." script_uri=".(empty($_SERVER["SCRIPT_URI"])?'':$_SERVER["SCRIPT_URI"]), LOG_DEBUG, 0, '_stripe'); + +$tracepost = ""; +foreach($_POST as $k => $v) $tracepost .= "{$k} - {$v}\n"; +dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_stripe'); + +$head=''; +if (! empty($conf->global->STRIPE_CSS_URL)) $head=''."\n"; + +$conf->dol_hide_topmenu=1; +$conf->dol_hide_leftmenu=1; + +llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody'); + + + +// Show message +print ''."\n"; +print '
'."\n"; + +$ispaymentok = true; // We call this page if payment is ok +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["Payment_Amount"]; + // From env + $ipaddress = $_SESSION['ipaddress']; + $TRANSACTIONID = $_SESSION['TRANSACTIONID']; + + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($db); + $result=$interface->run_triggers('STRIPE_PAYMENT_OK',$object,$user,$langs,$conf); + if ($result < 0) { $error++; $errors=$interface->errors; } + // Fin appel triggers + + + print $langs->trans("YourPaymentHasBeenRecorded")."
\n"; + print $langs->trans("ThisIsTransactionId",$TRANSACTIONID)."

\n"; + if (! empty($conf->global->STRIPE_MESSAGE_OK)) print $conf->global->STRIPE_MESSAGE_OK; + + $sendemail = ''; + if (! empty($conf->global->STRIPE_PAYONLINE_SENDEMAIL)) $sendemail=$conf->global->STRIPE_PAYONLINE_SENDEMAIL; + + // Send an email + if ($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)); + $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 + + // Define link to login card + $appli=constant('DOL_APPLICATION_TITLE'); + if (! empty($conf->global->MAIN_APPLICATION_TITLE)) + { + $appli=$conf->global->MAIN_APPLICATION_TITLE; + if (preg_match('/\d\.\d/', $appli)) + { + if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core + } + else $appli.=" ".DOL_VERSION; + } + else $appli.=" ".DOL_VERSION; + + $urlback=$_SERVER["REQUEST_URI"]; + $topic='['.$appli.'] '.$langs->transnoentitiesnoconv("NewOnlinePaymentReceived"); + $tmptag=dolExplodeIntoArray($fulltag,'.','='); + $content=""; + if (! empty($tmptag['MEM'])) + { + $langs->load("members"); + $url=$urlwithroot."/adherents/card_subscriptions.php?rowid=".$tmptag['MEM']; + $content.=$langs->trans("PaymentSubscription")."
\n"; + $content.=$langs->trans("MemberId").': '.$tmptag['MEM']."
\n"; + $content.=$langs->trans("Link").': '.$url.''."
\n"; + } + else + { + $content.=$langs->transnoentitiesnoconv("NewOnlinePaymentReceived")."
\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; + + $ishtml=dol_textishtml($content); // May contain urls + + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml); + + $result=$mailfile->sendfile(); + if ($result) + { + dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_stripe'); + } + else + { + dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_stripe'); + } + } +} + + +print "\n
\n"; + + +htmlPrintOnlinePaymentFooter($mysoc,$langs); + + +llxFooter('', 'public'); + +$db->close(); diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 484b7537755..6ca9073a9df 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -63,6 +63,8 @@ if ($action == 'setvalue' && $user->admin) if (! $result > 0) $error++; $result=dolibarr_set_const($db, "STRIPE_MESSAGE_KO",GETPOST('STRIPE_MESSAGE_KO','alpha'),'chaine',0,'',$conf->entity); if (! $result > 0) $error++; + $result=dolibarr_set_const($db, "STRIPE_PAYONLINE_SENDEMAIL",GETPOST('STRIPE_PAYONLINE_SENDEMAIL'),'chaine',0,'',$conf->entity); + if (! $result > 0) $error++; if (! $error) { @@ -148,25 +150,25 @@ print '
'; print ''.$langs->trans("STRIPE_TEST_PUBLISHABLE_KEY").''; print ''; -print '
'.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx'; +print '   '.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx'; print '
'; print ''.$langs->trans("STRIPE_TEST_SECRET_KEY").''; print ''; -print '
'.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx'; +print '   '.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx'; print '
'; print ''.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").''; print ''; -print '
'.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx'; +print '   '.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx'; print '
'; print ''.$langs->trans("STRIPE_LIVE_SECRET_KEY").''; print ''; -print '
'.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx'; +print '   '.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx'; print '
'; @@ -182,13 +184,13 @@ print "\n"; print ''; print $langs->trans("VendorName").''; print ''; -print '
'.$langs->trans("Example").': '.$mysoc->name; +print '   '.$langs->trans("Example").': '.$mysoc->name; print ''; print ''; print $langs->trans("CSSUrlForPaymentForm").''; print ''; -print '
'.$langs->trans("Example").': http://mysite/mycss.css'; +print '   '.$langs->trans("Example").': http://mysite/mycss.css'; print ''; print ''; @@ -203,6 +205,12 @@ $doleditor=new DolEditor('STRIPE_MESSAGE_KO',$conf->global->STRIPE_MESSAGE_KO,'' $doleditor->Create(); print ''; +print ''; +print $langs->trans("STRIPE_PAYONLINE_SENDEMAIL").''; +print ''; +print '   '.$langs->trans("Example").': myemail@myserver.com'; +print ''; + print ''; dol_fiche_end(); diff --git a/htdocs/stripe/lib/stripe.lib.php b/htdocs/stripe/lib/stripe.lib.php index 5f0b1bd0404..fbafd47c3ab 100644 --- a/htdocs/stripe/lib/stripe.lib.php +++ b/htdocs/stripe/lib/stripe.lib.php @@ -73,6 +73,7 @@ function showStripePaymentUrl($type,$ref) $out.=img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePayment",$servicename).'
'; $url=getStripePaymentUrl(0,$type,$ref); $out.='
'; + $out.=ajax_autoselect("stripeurl", 0); return $out; }