diff --git a/htdocs/core/lib/payments.lib.php b/htdocs/core/lib/payments.lib.php index d6c62ea1079..df97b133522 100644 --- a/htdocs/core/lib/payments.lib.php +++ b/htdocs/core/lib/payments.lib.php @@ -227,7 +227,7 @@ function getOnlinePaymentUrl($mode, $type, $ref='', $amount='9.99', $freetag='yo * @param Object $object Object related to payment * @return void */ -function htmlPrintOnlinePaymentFooter($fromcompany,$langs,$addformmessage=0,$suffix='',$object=null) +function htmlPrintOnlinePaymentFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null) { global $conf; diff --git a/htdocs/public/paybox/newpayment.php b/htdocs/public/paybox/newpayment.php index bd27554c500..3dc990c30f4 100644 --- a/htdocs/public/paybox/newpayment.php +++ b/htdocs/public/paybox/newpayment.php @@ -43,811 +43,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; // Security check if (empty($conf->paybox->enabled)) accessforbidden('',0,0,1); -$langs->load("main"); -$langs->load("other"); -$langs->load("dict"); -$langs->load("bills"); -$langs->load("companies"); -$langs->load("errors"); -$langs->load("paybox"); - -// Input are: -// type ('invoice','order','contractline'), -// id (object id), -// amount (required if id is empty), -// tag (a free text, required if type is empty) -// currency (iso code) - -$suffix=GETPOST("suffix",'alpha'); -$amount=price2num(GETPOST("amount")); -if (! GETPOST("currency",'alpha')) $currency=$conf->currency; -else $currency=GETPOST("currency",'alpha'); - -if (! GETPOST('action','aZ09')) -{ - if (! GETPOST("amount") && ! GETPOST("source")) - { - dol_print_error('',$langs->trans('ErrorBadParameters')." - amount or source"); - exit; - } - if (is_numeric($amount) && ! GETPOST("tag") && ! GETPOST("source")) - { - dol_print_error('',$langs->trans('ErrorBadParameters')." - tag or source"); - exit; - } - if (GETPOST("source") && ! GETPOST("ref")) - { - dol_print_error('',$langs->trans('ErrorBadParameters')." - ref"); - exit; - } -} - -// 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 - -$urlok=$urlwithroot.'/public/paybox/paymentok.php?'; -$urlko=$urlwithroot.'/public/paybox/paymentko.php?'; - -// Complete urls -$SOURCE=GETPOST("source",'alpha'); -$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=paybox'; - -if (! empty($SOURCE)) -{ - $urlok.='source='.urlencode($SOURCE).'&'; - $urlko.='source='.urlencode($SOURCE).'&'; -} -if (! empty($REF)) -{ - $urlok.='ref='.urlencode($REF).'&'; - $urlko.='ref='.urlencode($REF).'&'; -} -if (!empty($TAG)) -{ - $urlok.='tag='.urlencode($TAG).'&'; - $urlko.='tag='.urlencode($TAG).'&'; -} -if (!empty($FULLTAG)) -{ - $urlok.='fulltag='.urlencode($FULLTAG).'&'; - $urlko.='fulltag='.urlencode($FULLTAG).'&'; -} -$urlok=preg_replace('/&$/','',$urlok); // Remove last & -$urlko=preg_replace('/&$/','',$urlko); // Remove last & - -// Check security token -$valid=true; -if (! empty($conf->global->PAYMENT_SECURITY_TOKEN)) -{ - if (! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) - { - if ($SOURCE && $REF) $token = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $SOURCE . $REF, 2); // Use the source in the hash to avoid duplicates if the references are identical - else $token = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2); - } - else - { - $token = $conf->global->PAYMENT_SECURITY_TOKEN; - } - if ($SECUREKEY != $token) - { - if (empty($conf->global->PAYMENT_SECURITY_ACCEPT_ANY_TOKEN)) $valid=false; // PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is for backward compatibility - else dol_syslog("Warning: PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is on", LOG_WARNING); - } - - if (! $valid) - { - print '
Bad value for key.
'; - //print 'SECUREKEY='.$SECUREKEY.' token='.$token.' valid='.$valid; - exit; - } -} - - -/* - * Actions - */ - -if (GETPOST('action','aZ09') == 'dopayment') -{ - $PRICE=price2num(GETPOST("newamount",'alpha'),'MT'); - $email=GETPOST("email"); - - $origfulltag=GETPOST("fulltag",'alpha'); - - $mesg=''; - if (empty($PRICE) || ! is_numeric($PRICE)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount")); - elseif (empty($email)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("YourEMail")); - elseif (! isValidEMail($email)) $mesg=$langs->trans("ErrorBadEMail",$email); - elseif (! $origfulltag) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentCode")); - elseif (dol_strlen($urlok) > 150) $mesg='Error urlok too long '.$urlok; - elseif (dol_strlen($urlko) > 150) $mesg='Error urlko too long '.$urlko; - - if (empty($mesg)) - { - dol_syslog("newpayment.php call paybox api and do redirect", LOG_DEBUG); - - print_paybox_redirect($PRICE, $conf->currency, $email, $urlok, $urlko, $FULLTAG); - - session_destroy(); - exit; - } -} - - - -/* - * View - */ - -$head=''; -if (! empty($conf->global->ONLINE_PAYMENT_CSS_URL)) $head=''."\n"; - -$conf->dol_hide_topmenu=1; -$conf->dol_hide_leftmenu=1; - -llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody'); - -// Common variables -$creditor=$mysoc->name; -$paramcreditor='ONLINE_PAYMENT_CREDITOR_'.$suffix; -if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramcreditor; -else if (! empty($conf->global->ONLINE_PAYMENT_CREDITOR)) $creditor=$conf->global->ONLINE_PAYMENT_CREDITOR; - -// Check link validity -if (! empty($SOURCE) && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', ''))) -{ - $langs->load("errors"); - dol_print_error_email('BADREFINPAYMENTFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $SOURCE, $ref)); - llxFooter(); - $db->close(); - exit; -} - -print ''."\n"; -print '
'; -print '
'; -print ''; -print ''; -print ''; -print ''; -print "\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print "\n"; - -print ''."\n"; - -// Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo) -$width=0; -// Define logo and logosmall -$logosmall=$mysoc->logo_small; -$logo=$mysoc->logo; -$paramlogo='PAYMENT_LOGO_'.$suffix; -if (! empty($conf->global->$paramlogo)) $logosmall=$conf->global->$paramlogo; -else if (! empty($conf->global->PAYMENT_LOGO)) $logosmall=$conf->global->PAYMENT_LOGO; -//print ''."\n"; -// Define urllogo -$urllogo=''; -if (! empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) -{ - $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&file='.urlencode('thumbs/'.$logosmall); -} -elseif (! empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) -{ - $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&file='.urlencode($logo); - $width=96; -} -// Output html code for logo -if ($urllogo) -{ - print ''; - print ''; - print ''."\n"; -} - -// Output introduction text -$text=''; -if (! empty($conf->global->PAYMENT_NEWFORM_TEXT)) -{ - $langs->load("members"); - if (preg_match('/^\((.*)\)$/',$conf->global->PAYMENT_NEWFORM_TEXT,$reg)) $text.=$langs->trans($reg[1])."
\n"; - else $text.=$conf->global->PAYMENT_NEWFORM_TEXT."
\n"; - $text=''."\n"; -} -if (empty($text)) -{ - $text.=''."\n"; - $text.=''."\n"; -} -print $text; - -// Output payment summary form -print ''; -} -else -{ - dol_print_error_email('ERRORNEWPAYMENTPAYBOX'); -} - -print ''."\n"; - -print '

'.$text.'

'.$langs->trans("WelcomeOnPaymentPage").'
'.$langs->trans("ThisScreenAllowsYouToPay",$creditor).'

'; -print ''; -print ''."\n"; - -$found=false; -$error=0; -$var=false; - - - -// Free payment -if (! GETPOST("source") && $valid) -{ - $found=true; - $tag=GETPOST("tag"); - $fulltag=$tag; - - // Creditor - - print ''."\n"; - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // EMail - - print ''."\n"; -} - - -// Payment on customer order -if (GETPOST("source") == 'order' && $valid) -{ - $found=true; - $langs->load("orders"); - - require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; - - $order=new Commande($db); - $result=$order->fetch('',$ref); - if ($result < 0) - { - $mesg=$order->error; - $error++; - } - else - { - $result=$order->fetch_thirdparty($order->socid); - } - - $amount=$order->total_ttc; - if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); - $amount=price2num($amount); - - $fulltag='IR='.$order->ref.'.TPID='.$order->thirdparty->id; - //$fulltag.='.TP='.strtr($order->thirdparty->name,"-"," "); We disable this because url that will contains FULLTAG must be lower than 150 - if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } - $fulltag=dol_string_unaccent($fulltag); - - // Creditor - - print ''."\n"; - - // Debitor - - print ''."\n"; - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // EMail - - print ''."\n"; -} - - -// Payment on customer invoice -if (GETPOST("source") == 'invoice' && $valid) -{ - $found=true; - $langs->load("bills"); - - require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; - - $invoice=new Facture($db); - $result=$invoice->fetch('',$ref); - if ($result < 0) - { - $mesg=$invoice->error; - $error++; - } - else - { - $result=$invoice->fetch_thirdparty($invoice->socid); - } - - $amount=price2num($invoice->total_ttc - $invoice->getSommePaiement()); - if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); - $amount=price2num($amount); - - $fulltag='IR='.$invoice->ref.'.TPID='.$invoice->thirdparty->id; - //$fulltag.='.TP='.strtr($invoice->thirdparty->name,"-"," "); We disable this because url that will contains FULLTAG must be lower than 150 - if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } - $fulltag=dol_string_unaccent($fulltag); - - // Creditor - - print ''."\n"; - - // Debitor - - print ''."\n"; - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // EMail - - print ''."\n"; -} - -// Payment on contract line -if (GETPOST("source") == 'contractline' && $valid) -{ - $found=true; - $langs->load("contracts"); - - require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; - - $contractline=new ContratLigne($db); - $result=$contractline->fetch('',$ref); - if ($result < 0) - { - $mesg=$contractline->error; - $error++; - } - else - { - if ($contractline->fk_contrat > 0) - { - $contract=new Contrat($db); - $result=$contract->fetch($contractline->fk_contrat); - if ($result > 0) - { - $result=$contract->fetch_thirdparty($contract->socid); - } - else - { - $mesg=$contract->error; - $error++; - } - } - else - { - $mesg='ErrorRecordNotFound'; - $error++; - } - } - - $amount=$contractline->total_ttc; - if ($contractline->fk_product) - { - $product=new Product($db); - $result=$product->fetch($contractline->fk_product); - - // We define price for product (TODO Put this in a method in product class) - if (! empty($conf->global->PRODUIT_MULTIPRICES)) - { - $pu_ht = $product->multiprices[$contract->thirdparty->price_level]; - $pu_ttc = $product->multiprices_ttc[$contract->thirdparty->price_level]; - $price_base_type = $product->multiprices_base_type[$contract->thirdparty->price_level]; - } - else - { - $pu_ht = $product->price; - $pu_ttc = $product->price_ttc; - $price_base_type = $product->price_base_type; - } - - $amount=$pu_ttc; - if (empty($amount)) - { - dol_print_error('','ErrorNoPriceDefinedForThisProduct'); - exit; - } - } - if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); - $amount=price2num($amount); - - $fulltag='CLR='.$contractline->ref.'.CR='.$contract->ref.'.TPID='.$contract->thirdparty->id; - //$fulltag.='.TP='.strtr($contract->thirdparty->name,"-"," "); We disable this because url that will contains FULLTAG must be lower than 150 - if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } - $fulltag=dol_string_unaccent($fulltag); - - $qty=1; - if (GETPOST('qty')) $qty=GETPOST('qty'); - - // Creditor - - print ''."\n"; - - // Debitor - - print ''."\n"; - - // Quantity - - $label=$langs->trans("Quantity"); - $qty=1; - $duration=''; - if ($contractline->fk_product) - { - if ($product->isService() && $product->duration_value > 0) - { - $label=$langs->trans("Duration"); - - // TODO Put this in a global method - if ($product->duration_value > 1) - { - $dur=array("h"=>$langs->trans("Hours"),"d"=>$langs->trans("DurationDays"),"w"=>$langs->trans("DurationWeeks"),"m"=>$langs->trans("DurationMonths"),"y"=>$langs->trans("DurationYears")); - } - else - { - $dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("DurationDay"),"w"=>$langs->trans("DurationWeek"),"m"=>$langs->trans("DurationMonth"),"y"=>$langs->trans("DurationYear")); - } - $duration=$product->duration_value.' '.$dur[$product->duration_unit]; - } - } - print ''; - print ''."\n"; - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // EMail - - print ''."\n"; - -} - -// Payment on member subscription -if (GETPOST("source") == 'membersubscription' && $valid) -{ - $found=true; - $langs->load("members"); - - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; - - $member=new Adherent($db); - $result=$member->fetch('',$ref); - if ($result < 0) - { - $mesg=$member->error; - $error++; - } - else - { - $subscription=new Subscription($db); - } - - $amount=$subscription->total_ttc; - if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); - $amount=price2num($amount); - - $fulltag='MID='.$member->id; - //$fulltag.='.M='.dol_trunc(strtr($member->getFullName($langs),"-"," "),12); We disable this because url that will contains FULLTAG must be lower than 150 - if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } - $fulltag=dol_string_unaccent($fulltag); - - // Creditor - - print ''."\n"; - - // Debitor - - print ''."\n"; - - if ($member->last_subscription_date || $member->last_subscription_amount) - { - // Last subscription date - - print ''."\n"; - - // Last subscription amount - - print ''."\n"; - - if (empty($amount) && ! GETPOST('newamount','alpha')) $_GET['newamount']=$member->last_subscription_amount; - } - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // EMail - - print ''."\n"; -} - - - - -if (! $found && ! $mesg) $mesg=$langs->trans("ErrorBadParameters"); - -if ($mesg) print ''."\n"; - -print '
'.$langs->trans("ThisIsInformationOnPayment").' :
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - if (empty($amount) || ! is_numeric($amount)) - { - print ''; - print ''; - } - else { - print ''.price($amount).''; - print ''; - print ''; - } - - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("YourEMail"); - print ' ('.$langs->trans("ToComplete").')'; - print '
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("ThirdParty"); - print ''.$order->thirdparty->name.''; - - // Object - - $text=''.$langs->trans("PaymentOrderRef",$order->ref).''; - print '
'.$langs->trans("Designation"); - print ''.$text; - print ''; - print ''; - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - if (empty($amount) || ! is_numeric($amount)) - { - print ''; - print ''; - } - else { - print ''.price($amount).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("YourEMail"); - print ' ('.$langs->trans("ToComplete").')'; - $email=$order->thirdparty->email; - $email=(GETPOST("email")?GETPOST("email"):(isValidEmail($email)?$email:'')); - print '
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("ThirdParty"); - print ''.$invoice->thirdparty->name.''; - - // Object - - $text=''.$langs->trans("PaymentInvoiceRef",$invoice->ref).''; - print '
'.$langs->trans("Designation"); - print ''.$text; - print ''; - print ''; - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - if (empty($amount) || ! is_numeric($amount)) - { - print ''; - print ''; - } - else { - print ''.price($amount).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("YourEMail"); - print ' ('.$langs->trans("ToComplete").')'; - $email=$invoice->thirdparty->email; - $email=(GETPOST("email")?GETPOST("email"):(isValidEmail($email)?$email:'')); - print '
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("ThirdParty"); - print ''.$contract->thirdparty->name.''; - - // Object - - $text=''.$langs->trans("PaymentRenewContractId",$contract->ref,$contractline->ref).''; - if ($contractline->fk_product) - { - $text.='
'.$product->ref.($product->label?' - '.$product->label:''); - } - if ($contractline->description) $text.='
'.dol_htmlentitiesbr($contractline->description); - //if ($contractline->date_fin_validite) { - // $text.='
'.$langs->trans("DateEndPlanned").': '; - // $text.=dol_print_date($contractline->date_fin_validite); - //} - if ($contractline->date_fin_validite) - { - $text.='
'.$langs->trans("ExpiredSince").': '.dol_print_date($contractline->date_fin_validite); - } - - print '
'.$langs->trans("Designation"); - print ''.$text; - print ''; - print ''; - print '
'.$label.''.($duration?$duration:$qty).''; - print ''; - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - if (empty($amount) || ! is_numeric($amount)) - { - print ''; - print ''; - } - else { - print ''.price($amount).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("YourEMail"); - print ' ('.$langs->trans("ToComplete").')'; - $email=$contract->thirdparty->email; - $email=(GETPOST("email")?GETPOST("email"):(isValidEmail($email)?$email:'')); - print '
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("Member"); - print ''; - if ($member->morphy == 'mor' && ! empty($member->societe)) print $member->societe; - else print $member->getFullName($langs); - print ''; - - // Object - - $text=''.$langs->trans("PaymentSubscription").''; - print '
'.$langs->trans("Designation"); - print ''.$text; - print ''; - print ''; - print '
'.$langs->trans("LastSubscriptionDate"); - print ''.dol_print_date($member->last_subscription_date,'day'); - print '
'.$langs->trans("LastSubscriptionAmount"); - print ''.price($member->last_subscription_amount); - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - $valtoshow=''; - if (empty($amount) || ! is_numeric($amount)) - { - $valtoshow=price2num(GETPOST("newamount",'alpha'),'MT'); - // force default subscription amount to value defined into constant... - if (empty($valtoshow)) - { - if (! empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT)) { - if (! empty($conf->global->MEMBER_NEWFORM_AMOUNT)) { - $valtoshow = $conf->global->MEMBER_NEWFORM_AMOUNT; - } - } - else { - if (! empty($conf->global->MEMBER_NEWFORM_AMOUNT)) { - $amount = $conf->global->MEMBER_NEWFORM_AMOUNT; - } - } - } - } - if (empty($amount) || ! is_numeric($amount)) - { - //$valtoshow=price2num(GETPOST("newamount",'alpha'),'MT'); - if (! empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) $valtoshow=max($conf->global->MEMBER_MIN_AMOUNT,$valtoshow); - print ''; - print ''; - } - else { - $valtoshow=$amount; - if (! empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) $valtoshow=max($conf->global->MEMBER_MIN_AMOUNT,$valtoshow); - print ''.price($valtoshow).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("YourEMail"); - $email=$member->email; - $email=(GETPOST("email")?GETPOST("email"):(isValidEmail($email)?$email:'')); - if (empty($email)) print ' ('.$langs->trans("ToComplete").')'; - print '

'.$mesg.'
'."\n"; -print "\n"; - -if ($found && ! $error) // We are in a management option and no error -{ - print '
'; - //print '
'.$langs->trans("YouWillBeRedirectedOnPayBox").'...
'."\n"; -print '
'."\n"; -print '
'."\n"; -print '
'; - - -htmlPrintOnlinePaymentFooter($mysoc,$langs,1,$suffix); - - -llxFooter('', 'public'); - -$db->close(); +$newurl = $_SERVER['REQUEST_URI']; +$newurl = preg_replace('/\/paybox\/newpayment/', '/payment/newpayment', $newurl); +header("Location: ".$newurl.(preg_match('/\?/', $newurl)?'&':'?').'paymentmethod=paybox'); +exit; diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 4c244f9f403..ae7821b8841 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -84,7 +84,7 @@ if (! $action) } -$paymentmethod=''; +$paymentmethod=GETPOST('paymentmethod','alphanohtml')?GETPOST('paymentmethod','alphanohtml'):''; // Empty in most cases. Defined when a payment mode is forced $validpaymentmethod=array(); // Detect $paymentmethod @@ -155,7 +155,7 @@ $urlko=preg_replace('/&$/','',$urlko); // Remove last & // Find valid payment methods -if (! empty($conf->paypal->enabled)) +if ((empty($paymentmethod) || $paymentmethod == 'paypal') && ! empty($conf->paypal->enabled)) { require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php'; require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php'; @@ -184,7 +184,7 @@ if (! empty($conf->paypal->enabled)) $validpaymentmethod['paypal']='valid'; } -if (! empty($conf->paybox->enabled)) +if ((empty($paymentmethod) || $paymentmethod == 'paybox') && ! empty($conf->paybox->enabled)) { $langs->load("paybox"); @@ -193,7 +193,7 @@ if (! empty($conf->paybox->enabled)) $validpaymentmethod['paybox']='valid'; } -if (! empty($conf->stripe->enabled)) +if ((empty($paymentmethod) || $paymentmethod == 'stripe') && ! empty($conf->stripe->enabled)) { $langs->load("stripe"); @@ -237,7 +237,11 @@ if (! empty($conf->global->PAYMENT_SECURITY_TOKEN)) } } - +if (! empty($paymentmethod) && empty($validpaymentmethod[$paymentmethod])) +{ + print 'Payment module for payment method '.$paymentmethod.' is not active'; + exit; +} if (empty($validpaymentmethod)) { print 'No active payment module (Paypal, Stripe, Paybox, ...)'; @@ -609,11 +613,11 @@ if ($source && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_r // Show sandbox warning -if (! empty($conf->paypal->enabled) && (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))) // We can force sand box with param 'forcesandbox' +if ((empty($paymentmethod) || $paymentmethod == 'paypal') && ! empty($conf->paypal->enabled) && (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))) // We can force sand box with param 'forcesandbox' { dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Paypal'),'','warning'); } -if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha'))) +if ((empty($paymentmethod) || $paymentmethod == 'stripe') && ! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha'))) { dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning'); } @@ -1401,19 +1405,19 @@ if ($action != 'dopayment') { // Buttons for all payments registration methods - if (! empty($conf->paybox->enabled)) + if ((empty($paymentmethod) || $paymentmethod == 'paybox') && ! empty($conf->paybox->enabled)) { // If STRIPE_PICTO_FOR_PAYMENT is 'cb' we show a picto of a crdit card instead of paybox print '
'; } - if (! empty($conf->stripe->enabled)) + if ((empty($paymentmethod) || $paymentmethod == 'stripe') && ! empty($conf->stripe->enabled)) { // If STRIPE_PICTO_FOR_PAYMENT is 'cb' we show a picto of a crdit card instead of stripe print '
'; } - if (! empty($conf->paypal->enabled)) + if ((empty($paymentmethod) || $paymentmethod == 'paypal') && ! empty($conf->paypal->enabled)) { if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral'; diff --git a/htdocs/public/paypal/newpayment.php b/htdocs/public/paypal/newpayment.php index 24abc52526c..1a3ee3964ff 100644 --- a/htdocs/public/paypal/newpayment.php +++ b/htdocs/public/paypal/newpayment.php @@ -46,998 +46,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; // Security check if (empty($conf->paypal->enabled)) accessforbidden('',0,0,1); -$langs->load("main"); -$langs->load("other"); -$langs->load("dict"); -$langs->load("bills"); -$langs->load("companies"); -$langs->load("errors"); -$langs->load("paybox"); // File with generic data -$langs->load("paypal"); -$langs->load("stripe"); - -// Input are: -// type ('invoice','order','contractline'), -// id (object id), -// amount (required if id is empty), -// tag (a free text, required if type is empty) -// currency (iso code) - -$suffix=GETPOST("suffix",'alpha'); -$amount=price2num(GETPOST("amount")); -if (! GETPOST("currency",'alpha')) $currency=$conf->currency; -else $currency=GETPOST("currency",'alpha'); - -if (! GETPOST('action','aZ09')) -{ - if (! GETPOST("amount") && ! GETPOST("source")) - { - dol_print_error('',$langs->trans('ErrorBadParameters')." - amount or source"); - exit; - } - if (is_numeric($amount) && ! GETPOST("tag") && ! GETPOST("source")) - { - dol_print_error('',$langs->trans('ErrorBadParameters')." - tag or source"); - exit; - } - if (GETPOST("source") && ! GETPOST("ref")) - { - dol_print_error('',$langs->trans('ErrorBadParameters')." - ref"); - exit; - } -} - -// 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 - -$urlok=$urlwithroot.'/public/paypal/paymentok.php?'; -$urlko=$urlwithroot.'/public/paypal/paymentko.php?'; - -// Complete urls for post treatment -$SOURCE=GETPOST("source",'alpha'); -$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=paypal'; - -if (! empty($SOURCE)) -{ - $urlok.='source='.urlencode($SOURCE).'&'; - $urlko.='source='.urlencode($SOURCE).'&'; -} -if (! empty($REF)) -{ - $urlok.='ref='.urlencode($REF).'&'; - $urlko.='ref='.urlencode($REF).'&'; -} -if (! empty($TAG)) -{ - $urlok.='tag='.urlencode($TAG).'&'; - $urlko.='tag='.urlencode($TAG).'&'; -} -if (! empty($FULLTAG)) -{ - $urlok.='fulltag='.urlencode($FULLTAG).'&'; - $urlko.='fulltag='.urlencode($FULLTAG).'&'; -} -if (! empty($SECUREKEY)) -{ - $urlok.='securekey='.urlencode($SECUREKEY).'&'; - $urlko.='securekey='.urlencode($SECUREKEY).'&'; -} -if (! empty($entity)) -{ - $urlok.='entity='.urlencode($entity).'&'; - $urlko.='entity='.urlencode($entity).'&'; -} -$urlok=preg_replace('/&$/','',$urlok); // Remove last & -$urlko=preg_replace('/&$/','',$urlko); // Remove last & - -// Check parameters -$PAYPAL_API_OK=""; -if ($urlok) $PAYPAL_API_OK=$urlok; -$PAYPAL_API_KO=""; -if ($urlko) $PAYPAL_API_KO=$urlko; -if (empty($PAYPAL_API_USER)) -{ - dol_print_error('',"Paypal setup param PAYPAL_API_USER not defined"); - return -1; -} -if (empty($PAYPAL_API_PASSWORD)) -{ - dol_print_error('',"Paypal setup param PAYPAL_API_PASSWORD not defined"); - return -1; -} -if (empty($PAYPAL_API_SIGNATURE)) -{ - dol_print_error('',"Paypal setup param PAYPAL_API_SIGNATURE not defined"); - return -1; -} - -// Check security token -$valid=true; -if (! empty($conf->global->PAYPAL_SECURITY_TOKEN)) -{ - if (! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) - { - if ($SOURCE && $REF) $token = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $SOURCE . $REF, 2); // Use the source in the hash to avoid duplicates if the references are identical - else $token = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); - } - else - { - $token = $conf->global->PAYPAL_SECURITY_TOKEN; - } - if ($SECUREKEY != $token) - { - if (empty($conf->global->PAYMENT_SECURITY_ACCEPT_ANY_TOKEN)) $valid=false; // PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is for backward compatibility - else dol_syslog("Warning: PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is on", LOG_WARNING); - } - - if (! $valid) - { - print '
Bad value for key.
'; - //print 'SECUREKEY='.$SECUREKEY.' token='.$token.' valid='.$valid; - exit; - } -} - - - -/* - * Actions - */ - -if (GETPOST('action','aZ09') == 'dopayment') -{ - $PAYPAL_API_PRICE=price2num(GETPOST("newamount",'alpha'),'MT'); - $PAYPAL_PAYMENT_TYPE='Sale'; - - $origfulltag=GETPOST("fulltag",'alpha'); - $shipToName=GETPOST("shipToName"); - $shipToStreet=GETPOST("shipToStreet"); - $shipToCity=GETPOST("shipToCity"); - $shipToState=GETPOST("shipToState"); - $shipToCountryCode=GETPOST("shipToCountryCode"); - $shipToZip=GETPOST("shipToZip"); - $shipToStreet2=GETPOST("shipToStreet2"); - $phoneNum=GETPOST("phoneNum"); - $email=GETPOST("email"); - $desc=GETPOST("desc"); - - $mesg=''; - if (empty($PAYPAL_API_PRICE) || ! is_numeric($PAYPAL_API_PRICE)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount")); - //elseif (empty($EMAIL)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("YourEMail")); - //elseif (! isValidEMail($EMAIL)) $mesg=$langs->trans("ErrorBadEMail",$EMAIL); - elseif (! $origfulltag) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentCode")); - - //var_dump($_POST); - if (empty($mesg)) - { - dol_syslog("newpayment.php call paypal api and do redirect", LOG_DEBUG); - - // Other - $PAYPAL_API_DEVISE="USD"; - //if ($currency == 'EUR') $PAYPAL_API_DEVISE="EUR"; - //if ($currency == 'USD') $PAYPAL_API_DEVISE="USD"; - if (! empty($currency)) $PAYPAL_API_DEVISE=$currency; - - dol_syslog("Submit Paypal form", LOG_DEBUG); - dol_syslog("PAYPAL_API_USER: $PAYPAL_API_USER", LOG_DEBUG); - //dol_syslog("PAYPAL_API_PASSWORD: $PAYPAL_API_PASSWORD", LOG_DEBUG); // No password into log files - dol_syslog("PAYPAL_API_SIGNATURE: $PAYPAL_API_SIGNATURE", LOG_DEBUG); - dol_syslog("PAYPAL_API_SANDBOX: $PAYPAL_API_SANDBOX", LOG_DEBUG); - dol_syslog("PAYPAL_API_OK: $PAYPAL_API_OK", LOG_DEBUG); - 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); - dol_syslog("shipToName: $shipToName", LOG_DEBUG); - dol_syslog("shipToStreet: $shipToStreet", LOG_DEBUG); - dol_syslog("shipToCity: $shipToCity", LOG_DEBUG); - dol_syslog("shipToState: $shipToState", LOG_DEBUG); - dol_syslog("shipToCountryCode: $shipToCountryCode", LOG_DEBUG); - dol_syslog("shipToZip: $shipToZip", LOG_DEBUG); - dol_syslog("shipToStreet2: $shipToStreet2", LOG_DEBUG); - dol_syslog("phoneNum: $phoneNum", LOG_DEBUG); - dol_syslog("email: $email", LOG_DEBUG); - dol_syslog("desc: $desc", LOG_DEBUG); - - dol_syslog("SCRIPT_URI: ".(empty($_SERVER["SCRIPT_URI"])?'':$_SERVER["SCRIPT_URI"]), LOG_DEBUG); // If defined script uri must match domain of PAYPAL_API_OK and PAYPAL_API_KO - //$_SESSION["PaymentType"]=$PAYPAL_PAYMENT_TYPE; - //$_SESSION["currencyCodeType"]=$PAYPAL_API_DEVISE; - //$_SESSION["FinalPaymentAmt"]=$PAYPAL_API_PRICE; - - // A redirect is added if API call successfull - $mesg = print_paypal_redirect($PAYPAL_API_PRICE,$PAYPAL_API_DEVISE,$PAYPAL_PAYMENT_TYPE,$PAYPAL_API_OK,$PAYPAL_API_KO, $FULLTAG); - - exit; - } -} - - - -/* - * View - */ - -$head=''; -if (! empty($conf->global->ONLINE_PAYMENT_CSS_URL)) $head=''."\n"; - -$conf->dol_hide_topmenu=1; -$conf->dol_hide_leftmenu=1; - -llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody'); - -// Common variables -$creditor=$mysoc->name; -$paramcreditor='ONLINE_PAYMENT_CREDITOR_'.$suffix; -if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramcreditor; -else if (! empty($conf->global->ONLINE_PAYMENT_CREDITOR)) $creditor=$conf->global->ONLINE_PAYMENT_CREDITOR; - -// Check link validity -if (! empty($SOURCE) && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', ''))) -{ - $langs->load("errors"); - dol_print_error_email('BADREFINPAYMENTFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $SOURCE, $ref)); - llxFooter(); - $db->close(); - exit; -} - -if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha')) -{ - dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning'); -} - -print ''."\n"; -print '
'."\n"; -print '
'."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''; -print ''; -print "\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print "\n"; - -print ''."\n"; - -// Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo) -$width=0; -// Define logo and logosmall -$logosmall=$mysoc->logo_small; -$logo=$mysoc->logo; -$paramlogo='PAYMENT_LOGO_'.$suffix; -if (! empty($conf->global->$paramlogo)) $logosmall=$conf->global->$paramlogo; -else if (! empty($conf->global->PAYMENT_LOGO)) $logosmall=$conf->global->PAYMENT_LOGO; -//print ''."\n"; -// Define urllogo -$urllogo=''; -if (! empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) -{ - $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&file='.urlencode('thumbs/'.$logosmall); -} -elseif (! empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) -{ - $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&file='.urlencode($logo); - $width=96; -} -// Output html code for logo -if ($urllogo) -{ - print ''; - print ''; - print ''."\n"; -} - -// Output introduction text -$text=''; -if (! empty($conf->global->PAYMENT_NEWFORM_TEXT)) -{ - $langs->load("members"); - if (preg_match('/^\((.*)\)$/',$conf->global->PAYMENT_NEWFORM_TEXT,$reg)) $text.=$langs->trans($reg[1])."
\n"; - else $text.=$conf->global->PAYMENT_NEWFORM_TEXT."
\n"; - $text=''."\n"; -} -if (empty($text)) -{ - $text.=''."\n"; - $text.=''."\n"; -} -print $text; - -// Output payment summary form -print ''."\n"; - -print '

'.$text.'

'.$langs->trans("WelcomeOnPaymentPage").'
'.$langs->trans("ThisScreenAllowsYouToPay",$creditor).'

'; -print ''; -print ''."\n"; - -$found=false; -$error=0; -$var=false; - -// Free payment -if (! GETPOST("source")) -{ - $found=true; - $tag=GETPOST("tag"); - $fulltag=$tag; - - // Creditor - print ''."\n"; - - // Amount - print ''."\n"; - - // Tag - print ''."\n"; - - // We do not add fields shipToName, shipToStreet, shipToCity, shipToState, shipToCountryCode, shipToZip, shipToStreet2, phoneNum - // as they don't exists (buyer is unknown, tag is free). -} - - -// Payment on customer order -if (GETPOST("source") == 'order') -{ - $found=true; - $langs->load("orders"); - - require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; - - $order=new Commande($db); - $result=$order->fetch('',$ref); - if ($result < 0) - { - $mesg=$order->error; - $error++; - } - else - { - $result=$order->fetch_thirdparty($order->socid); - } - - if ($action != 'dopayment') // Do not change amount if we just click on first dopayment - { - $amount=$order->total_ttc; - if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); - $amount=price2num($amount); - } - - $fulltag='ORD='.$order->ref.'.CUS='.$order->thirdparty->id; - //$fulltag.='.NAM='.strtr($order->thirdparty->name,"-"," "); - if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } - $fulltag=dol_string_unaccent($fulltag); - - // Creditor - - print ''."\n"; - - // Debitor - - print ''."\n"; - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // Shipping address - $shipToName=$order->thirdparty->name; - $shipToStreet=$order->thirdparty->address; - $shipToCity=$order->thirdparty->town; - $shipToState=$order->thirdparty->state_code; - $shipToCountryCode=$order->thirdparty->country_code; - $shipToZip=$order->thirdparty->zip; - $shipToStreet2=''; - $phoneNum=$order->thirdparty->phone; - if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) - { - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - } - else - { - print ''."\n"; - } - print ''."\n"; - print 'ref.'">'."\n"; -} - - -// Payment on customer invoice -if (GETPOST("source") == 'invoice') -{ - $found=true; - $langs->load("bills"); - - require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; - - $invoice=new Facture($db); - $result=$invoice->fetch('',$ref); - if ($result < 0) - { - $mesg=$invoice->error; - $error++; - } - else - { - $result=$invoice->fetch_thirdparty($invoice->socid); - } - - if ($action != 'dopayment') // Do not change amount if we just click on first dopayment - { - $amount=price2num($invoice->total_ttc - $invoice->getSommePaiement()); - if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); - $amount=price2num($amount); - } - - $fulltag='INV='.$invoice->ref.'.CUS='.$invoice->thirdparty->id; - //$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," "); - if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } - $fulltag=dol_string_unaccent($fulltag); - - // Creditor - - print ''."\n"; - - // Debitor - - print ''."\n"; - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // Shipping address - $shipToName=$invoice->thirdparty->name; - $shipToStreet=$invoice->thirdparty->address; - $shipToCity=$invoice->thirdparty->town; - $shipToState=$invoice->thirdparty->state_code; - $shipToCountryCode=$invoice->thirdparty->country_code; - $shipToZip=$invoice->thirdparty->zip; - $shipToStreet2=''; - $phoneNum=$invoice->thirdparty->phone; - if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) - { - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - } - else - { - print ''."\n"; - } - print ''."\n"; - print 'ref.'">'."\n"; -} - -// Payment on contract line -if (GETPOST("source") == 'contractline') -{ - $found=true; - $langs->load("contracts"); - - require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; - - $contractline=new ContratLigne($db); - $result=$contractline->fetch('',$ref); - if ($result < 0) - { - $mesg=$contractline->error; - $error++; - } - else - { - if ($contractline->fk_contrat > 0) - { - $contract=new Contrat($db); - $result=$contract->fetch($contractline->fk_contrat); - if ($result > 0) - { - $result=$contract->fetch_thirdparty($contract->socid); - } - else - { - $mesg=$contract->error; - $error++; - } - } - else - { - $mesg='ErrorRecordNotFound'; - $error++; - } - } - - if ($action != 'dopayment') // Do not change amount if we just click on first dopayment - { - $amount=$contractline->total_ttc; - if ($contractline->fk_product) - { - $product=new Product($db); - $result=$product->fetch($contractline->fk_product); - - // We define price for product (TODO Put this in a method in product class) - if (! empty($conf->global->PRODUIT_MULTIPRICES)) - { - $pu_ht = $product->multiprices[$contract->thirdparty->price_level]; - $pu_ttc = $product->multiprices_ttc[$contract->thirdparty->price_level]; - $price_base_type = $product->multiprices_base_type[$contract->thirdparty->price_level]; - } - else - { - $pu_ht = $product->price; - $pu_ttc = $product->price_ttc; - $price_base_type = $product->price_base_type; - } - - $amount=$pu_ttc; - if (empty($amount)) - { - dol_print_error('','ErrorNoPriceDefinedForThisProduct'); - exit; - } - } - if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); - $amount=price2num($amount); - } - - $fulltag='COL='.$contractline->ref.'.CON='.$contract->ref.'.CUS='.$contract->thirdparty->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); - //$fulltag.='.NAM='.strtr($contract->thirdparty->name,"-"," "); - if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } - $fulltag=dol_string_unaccent($fulltag); - - $qty=1; - if (GETPOST('qty')) $qty=GETPOST('qty'); - - // Creditor - - print ''."\n"; - - // Debitor - - print ''."\n"; - - // Quantity - - $label=$langs->trans("Quantity"); - $qty=1; - $duration=''; - if ($contractline->fk_product) - { - if ($product->isService() && $product->duration_value > 0) - { - $label=$langs->trans("Duration"); - - // TODO Put this in a global method - if ($product->duration_value > 1) - { - $dur=array("h"=>$langs->trans("Hours"),"d"=>$langs->trans("DurationDays"),"w"=>$langs->trans("DurationWeeks"),"m"=>$langs->trans("DurationMonths"),"y"=>$langs->trans("DurationYears")); - } - else - { - $dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("DurationDay"),"w"=>$langs->trans("DurationWeek"),"m"=>$langs->trans("DurationMonth"),"y"=>$langs->trans("DurationYear")); - } - $duration=$product->duration_value.' '.$dur[$product->duration_unit]; - } - } - print ''; - print ''."\n"; - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // Shipping address - $shipToName=$contract->thirdparty->name; - $shipToStreet=$contract->thirdparty->address; - $shipToCity=$contract->thirdparty->town; - $shipToState=$contract->thirdparty->state_code; - $shipToCountryCode=$contract->thirdparty->country_code; - $shipToZip=$contract->thirdparty->zip; - $shipToStreet2=''; - $phoneNum=$contract->thirdparty->phone; - if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) - { - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - } - else - { - print ''."\n"; - } - print ''."\n"; - print 'ref.'">'."\n"; -} - -// Payment on member subscription -if (GETPOST("source") == 'membersubscription') -{ - $found=true; - $langs->load("members"); - - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; - - - $member=new Adherent($db); - $result=$member->fetch('',$ref); - if ($result < 0) - { - $mesg=$member->error; - $error++; - } - else - { - $subscription=new Subscription($db); - } - - if ($action != 'dopayment') // Do not change amount if we just click on first dopayment - { - $amount=$subscription->total_ttc; - if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); - $amount=price2num($amount); - } - - $fulltag='MEM='.$member->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); - if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } - $fulltag=dol_string_unaccent($fulltag); - - // Creditor - - print ''."\n"; - - // Debitor - - print ''."\n"; - - if ($member->last_subscription_date || $member->last_subscription_amount) - { - // Last subscription date - - print ''."\n"; - - // Last subscription amount - - print ''."\n"; - - if (empty($amount) && ! GETPOST('newamount','alpha')) $_GET['newamount']=$member->last_subscription_amount; - } - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // Shipping address - $shipToName=$member->getFullName($langs); - $shipToStreet=$member->address; - $shipToCity=$member->town; - $shipToState=$member->state_code; - $shipToCountryCode=$member->country_code; - $shipToZip=$member->zip; - $shipToStreet2=''; - $phoneNum=$member->phone; - if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) - { - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - } - else - { - print ''."\n"; - } - print ''."\n"; - print ''."\n"; -} - - - - -if (! $found && ! $mesg) $mesg=$langs->trans("ErrorBadParameters"); - -if ($mesg) print ''."\n"; - -print '
'.$langs->trans("ThisIsInformationOnPayment").' :
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - if (empty($amount) || ! is_numeric($amount)) - { - print ''; - print ''; - } - else { - print ''.price($amount).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("ThirdParty"); - print ''.$order->thirdparty->name.''; - - // Object - - $text=''.$langs->trans("PaymentOrderRef",$order->ref).''; - print '
'.$langs->trans("Designation"); - print ''.$text; - print ''; - print ''; - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - if (empty($amount) || ! is_numeric($amount)) - { - print ''; - print ''; - } - else { - print ''.price($amount).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("ThirdParty"); - print ''.$invoice->thirdparty->name.''; - - // Object - - $text=''.$langs->trans("PaymentInvoiceRef",$invoice->ref).''; - print '
'.$langs->trans("Designation"); - print ''.$text; - print ''; - print ''; - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - if (empty($amount) || ! is_numeric($amount)) - { - print ''; - print ''; - } - else { - print ''.price($amount).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("ThirdParty"); - print ''.$contract->thirdparty->name.''; - - // Object - - $text=''.$langs->trans("PaymentRenewContractId",$contract->ref,$contractline->ref).''; - if ($contractline->fk_product) - { - $text.='
'.$product->ref.($product->label?' - '.$product->label:''); - } - if ($contractline->description) $text.='
'.dol_htmlentitiesbr($contractline->description); - //if ($contractline->date_fin_validite) { - // $text.='
'.$langs->trans("DateEndPlanned").': '; - // $text.=dol_print_date($contractline->date_fin_validite); - //} - if ($contractline->date_fin_validite) - { - $text.='
'.$langs->trans("ExpiredSince").': '.dol_print_date($contractline->date_fin_validite); - } - - print '
'.$langs->trans("Designation"); - print ''.$text; - print ''; - print ''; - print '
'.$label.''.($duration?$duration:$qty).''; - print ''; - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - if (empty($amount) || ! is_numeric($amount)) - { - print ''; - print ''; - } - else { - print ''.price($amount).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("Member"); - print ''; - if ($member->morphy == 'mor' && ! empty($member->societe)) print $member->societe; - else print $member->getFullName($langs); - print ''; - - // Object - - $text=''.$langs->trans("PaymentSubscription").''; - print '
'.$langs->trans("Designation"); - print ''.$text; - print ''; - print ''; - print '
'.$langs->trans("LastSubscriptionDate"); - print ''.dol_print_date($member->last_subscription_date,'day'); - print '
'.$langs->trans("LastSubscriptionAmount"); - print ''.price($member->last_subscription_amount); - print '
'.$langs->trans("Amount"); - if (empty($amount)) - { - print ' ('.$langs->trans("ToComplete"); - if (! empty($conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO)) print ' - '.$langs->trans("SeeHere").''; - print ')'; - } - print ''; - $valtoshow=''; - if (empty($amount) || ! is_numeric($amount)) - { - $valtoshow=price2num(GETPOST("newamount",'alpha'),'MT'); - // force default subscription amount to value defined into constant... - if (empty($valtoshow)) - { - if (! empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT)) { - if (! empty($conf->global->MEMBER_NEWFORM_AMOUNT)) { - $valtoshow = $conf->global->MEMBER_NEWFORM_AMOUNT; - } - } - else { - if (! empty($conf->global->MEMBER_NEWFORM_AMOUNT)) { - $amount = $conf->global->MEMBER_NEWFORM_AMOUNT; - } - } - } - } - if (empty($amount) || ! is_numeric($amount)) - { - //$valtoshow=price2num(GETPOST("newamount",'alpha'),'MT'); - if (! empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) $valtoshow=max($conf->global->MEMBER_MIN_AMOUNT,$valtoshow); - print ''; - print ''; - } - else { - $valtoshow=$amount; - if (! empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) $valtoshow=max($conf->global->MEMBER_MIN_AMOUNT,$valtoshow); - print ''.price($valtoshow).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '

'.$mesg.'
'."\n"; -print "\n"; - -if ($found && ! $error) // We are in a management option and no error -{ - if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral'; - - if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral') - { - print '
'; - } - if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly') - { - print '
'; - } - print ''; -} -else -{ - dol_print_error_email('ERRORNEWPAYMENTPAYPAL'); -} - -print '
'."\n"; -print '
'."\n"; -print '
'."\n"; - - -print ''; - - -print '
'; - - - -htmlPrintOnlinePaymentFooter($mysoc,$langs,1,$suffix); - -llxFooter('', 'public'); - -$db->close(); +$newurl = $_SERVER['REQUEST_URI']; +$newurl = preg_replace('/\/paypal\/newpayment/', '/payment/newpayment', $newurl); +header("Location: ".$newurl.(preg_match('/\?/', $newurl)?'&':'?').'paymentmethod=paypal'); +exit; diff --git a/htdocs/public/stripe/newpayment.php b/htdocs/public/stripe/newpayment.php index 9291b2af615..5357f99dd3d 100644 --- a/htdocs/public/stripe/newpayment.php +++ b/htdocs/public/stripe/newpayment.php @@ -46,1225 +46,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; // Security check if (empty($conf->stripe->enabled)) accessforbidden('',0,0,1); -$langs->load("main"); -$langs->load("companies"); -$langs->load("other"); -$langs->load("paybox"); // File with generic data -$langs->load("paypal"); -$langs->load("stripe"); - -$action=GETPOST('action','alpha'); - -// Input are: -// type ('invoice','order','contractline'), -// id (object id), -// amount (required if id is empty), -// tag (a free text, required if type is empty) -// currency (iso code) - -$suffix=GETPOST("suffix",'alpha'); -$amount=price2num(GETPOST("amount")); -if (! GETPOST("currency",'alpha')) $currency=$conf->currency; -else $currency=GETPOST("currency",'alpha'); - -if (! $action) -{ - if (! GETPOST("amount") && ! GETPOST("source")) - { - dol_print_error('',$langs->trans('ErrorBadParameters')." - amount or source"); - exit; - } - if (is_numeric($amount) && ! GETPOST("tag") && ! GETPOST("source")) - { - dol_print_error('',$langs->trans('ErrorBadParameters')." - tag or source"); - exit; - } - if (GETPOST("source") && ! GETPOST("ref")) - { - dol_print_error('',$langs->trans('ErrorBadParameters')." - ref"); - exit; - } -} - -// 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 - -$urlok=$urlwithroot.'/public/stripe/paymentok.php?'; -$urlko=$urlwithroot.'/public/stripe/paymentko.php?'; - -// Complete urls for post treatment -$SOURCE=GETPOST("source",'alpha'); -$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 (! preg_match('/'.preg_quote('PM=stripe','/').'/', $FULLTAG)) $FULLTAG.=($FULLTAG?'.':'').'PM=stripe'; - -if (! empty($SOURCE)) -{ - $urlok.='source='.urlencode($SOURCE).'&'; - $urlko.='source='.urlencode($SOURCE).'&'; -} -if (! empty($REF)) -{ - $urlok.='ref='.urlencode($REF).'&'; - $urlko.='ref='.urlencode($REF).'&'; -} -if (! empty($TAG)) -{ - $urlok.='tag='.urlencode($TAG).'&'; - $urlko.='tag='.urlencode($TAG).'&'; -} -if (! empty($FULLTAG)) -{ - $urlok.='fulltag='.urlencode($FULLTAG).'&'; - $urlko.='fulltag='.urlencode($FULLTAG).'&'; -} -if (! empty($SECUREKEY)) -{ - $urlok.='securekey='.urlencode($SECUREKEY).'&'; - $urlko.='securekey='.urlencode($SECUREKEY).'&'; -} -if (! empty($entity)) -{ - $urlok.='entity='.urlencode($entity).'&'; - $urlko.='entity='.urlencode($entity).'&'; -} -$urlok=preg_replace('/&$/','',$urlok); // Remove last & -$urlko=preg_replace('/&$/','',$urlko); // Remove last & - -// Check parameters -/* -$STRIPE_API_OK=""; -if ($urlok) $STRIPE_API_OK=$urlok; -$STRIPE_API_KO=""; -if ($urlko) $STRIPE_API_KO=$urlko; -if (empty($STRIPE_API_USER)) -{ - dol_print_error('',"Paypal setup param STRIPE_API_USER not defined"); - return -1; -} -if (empty($STRIPE_API_PASSWORD)) -{ - dol_print_error('',"Paypal setup param STRIPE_API_PASSWORD not defined"); - return -1; -} -if (empty($STRIPE_API_SIGNATURE)) -{ - dol_print_error('',"Paypal setup param STRIPE_API_SIGNATURE not defined"); - return -1; -} -*/ - - -// Check security token -$valid=true; -if (! empty($conf->global->STRIPE_SECURITY_TOKEN)) -{ - if (! empty($conf->global->STRIPE_SECURITY_TOKEN_UNIQUE)) - { - if ($SOURCE && $REF) $token = dol_hash($conf->global->STRIPE_SECURITY_TOKEN . $SOURCE . $REF, 2); // Use the source in the hash to avoid duplicates if the references are identical - else $token = dol_hash($conf->global->STRIPE_SECURITY_TOKEN, 2); - } - else - { - $token = $conf->global->STRIPE_SECURITY_TOKEN; - } - if ($SECUREKEY != $token) - { - if (empty($conf->global->PAYMENT_SECURITY_ACCEPT_ANY_TOKEN)) $valid=false; // PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is for backward compatibility - else dol_syslog("Warning: PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is on", LOG_WARNING); - } - - if (! $valid) - { - print '
Bad value for key.
'; - //print 'SECUREKEY='.$SECUREKEY.' token='.$token.' valid='.$valid; - exit; - } -} - -// Common variables -$creditor=$mysoc->name; -$paramcreditor='ONLINE_PAYMENT_CREDITOR_'.$suffix; -if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramcreditor; -else if (! empty($conf->global->ONLINE_PAYMENT_CREDITOR)) $creditor=$conf->global->ONLINE_PAYMENT_CREDITOR; - - - -/* - * Actions - */ - -if ($action == 'dopayment') // We click on button Create payment -{ - if (GETPOST('newamount','alpha')) $amount = price2num(GETPOST('newamount','alpha'),'MT'); - else - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors'); - $action = ''; - } -} - -if ($action == 'charge') -{ - // 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; - - 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("email",'alpha'); - $vatnumber = GETPOST('vatnumber','alpha'); - - dol_syslog("stripeToken = ".$stripeToken, LOG_DEBUG, 0, '_stripe'); - dol_syslog("email = ".$email, LOG_DEBUG, 0, '_stripe'); - dol_syslog("vatnumber = ".$vatnumber, LOG_DEBUG, 0, '_stripe'); - - $error = 0; - - try { - dol_syslog("Create customer card profile", LOG_DEBUG, 0, '_stripe'); - $customer = \Stripe\Customer::create(array( - 'email' => $email, - 'description' => ($email?'Customer card profile for '.$email:null), - 'metadata' => array('ipaddress'=>$_SERVER['REMOTE_ADDR']), - 'business_vat_id' => ($vatnumber?$vatnumber:null), - 'source' => $stripeToken // source can be a token OR array('object'=>'card', 'exp_month'=>xx, 'exp_year'=>xxxx, 'number'=>xxxxxxx, 'cvc'=>xxx, 'name'=>'Cardholder's full name', zip ?) - )); - // TODO Add 'business_vat_id' ? - - dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe'); - $charge = \Stripe\Charge::create(array( - 'customer' => $customer->id, // Will reuse default source of this customer card profile - 'amount' => price2num($amount, 'MU'), - 'currency' => $currency, - 'description' => 'Stripe payment: '.$FULLTAG, - 'metadata' => array("FULLTAG" => $FULLTAG, 'Recipient' => $mysoc->name), - 'statement_descriptor' => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 6, 'right', 'UTF-8', 1).' '.$FULLTAG, 22, 'right', 'UTF-8', 1) // 22 chars that appears on bank receipt - )); - } catch(\Stripe\Error\Card $e) { - // Since it's a decline, \Stripe\Error\Card will be caught - $body = $e->getJsonBody(); - $err = $body['error']; - - print('Status is:' . $e->getHttpStatus() . "\n"); - print('Type is:' . $err['type'] . "\n"); - print('Code is:' . $err['code'] . "\n"); - // param is '' in this case - 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=''; - } - - $_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: ".$urlko); - exit; - } - else - { - header("Location: ".$urlok); - exit; - } - -} - - -/* - * View - */ - -$head=''; -if (! empty($conf->global->ONLINE_PAYMENT_CSS_URL)) $head=''."\n"; - -$conf->dol_hide_topmenu=1; -$conf->dol_hide_leftmenu=1; - -llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody'); - -// Check link validity -if (! empty($SOURCE) && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', ''))) -{ - $langs->load("errors"); - dol_print_error_email('BADREFINPAYMENTFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $SOURCE, $ref)); - llxFooter(); - $db->close(); - exit; -} - -if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha')) -{ - dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning'); -} - -print ''."\n"; -print '
'."\n"; -print '
'."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''; -print ''; -print "\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print ''."\n"; -print "\n"; - -print ''."\n"; - -// Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo) -$width=0; -// Define logo and logosmall -$logosmall=$mysoc->logo_small; -$logo=$mysoc->logo; -$paramlogo='PAYMENT_LOGO_'.$suffix; -if (! empty($conf->global->$paramlogo)) $logosmall=$conf->global->$paramlogo; -else if (! empty($conf->global->PAYMENT_LOGO)) $logosmall=$conf->global->PAYMENT_LOGO; -//print ''."\n"; -// Define urllogo -$urllogo=''; -if (! empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) -{ - $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&file='.urlencode('thumbs/'.$logosmall); -} -elseif (! empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) -{ - $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&file='.urlencode($logo); - $width=96; -} -// Output html code for logo -if ($urllogo) -{ - print ''; - print ''; - print ''."\n"; -} - -// Output introduction text -$text=''; -if (! empty($conf->global->PAYMENT_NEWFORM_TEXT)) -{ - $langs->load("members"); - if (preg_match('/^\((.*)\)$/',$conf->global->PAYMENT_NEWFORM_TEXT,$reg)) $text.=$langs->trans($reg[1])."
\n"; - else $text.=$conf->global->PAYMENT_NEWFORM_TEXT."
\n"; - $text=''."\n"; -} -if (empty($text)) -{ - $text.=''."\n"; - $text.=''."\n"; -} -print $text; - -// Output payment summary form -print ''."\n"; - -print '

'.$text.'

'.$langs->trans("WelcomeOnPaymentPage").'
'.$langs->trans("ThisScreenAllowsYouToPay",$creditor).'

'; -print ''; -print ''."\n"; - -$found=false; -$error=0; -$var=false; - -// Free payment -if (! GETPOST("source")) -{ - $found=true; - $tag=GETPOST("tag"); - $fulltag=$tag; - - // Creditor - print ''."\n"; - - // Amount - print ''."\n"; - - // Tag - - print ''."\n"; - - // We do not add fields shipToName, shipToStreet, shipToCity, shipToState, shipToCountryCode, shipToZip, shipToStreet2, phoneNum - // as they don't exists (buyer is unknown, tag is free). -} - - -// Payment on customer order -if (GETPOST("source") == 'order') -{ - $found=true; - $langs->load("orders"); - - require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; - - $order=new Commande($db); - $result=$order->fetch('',$ref); - if ($result < 0) - { - $mesg=$order->error; - $error++; - } - else - { - $result=$order->fetch_thirdparty($order->socid); - } - - if ($action != 'dopayment') // Do not change amount if we just click on first dopayment - { - $amount=$order->total_ttc; - if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); - $amount=price2num($amount); - } - - $fulltag='ORD='.$order->ref.'.CUS='.$order->thirdparty->id; - //$fulltag.='.NAM='.strtr($order->thirdparty->name,"-"," "); - if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } - $fulltag=dol_string_unaccent($fulltag); - - // Creditor - - print ''."\n"; - - // Debitor - - print ''."\n"; - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // Shipping address - $shipToName=$order->thirdparty->name; - $shipToStreet=$order->thirdparty->address; - $shipToCity=$order->thirdparty->town; - $shipToState=$order->thirdparty->state_code; - $shipToCountryCode=$order->thirdparty->country_code; - $shipToZip=$order->thirdparty->zip; - $shipToStreet2=''; - $phoneNum=$order->thirdparty->phone; - if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) - { - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - } - else - { - print ''."\n"; - } - print ''."\n"; - print ''."\n"; - print 'ref.'">'."\n"; -} - - -// Payment on customer invoice -if (GETPOST("source") == 'invoice') -{ - $found=true; - $langs->load("bills"); - - require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; - - $invoice=new Facture($db); - $result=$invoice->fetch('',$ref); - if ($result < 0) - { - $mesg=$invoice->error; - $error++; - } - else - { - $result=$invoice->fetch_thirdparty($invoice->socid); - } - - if ($action != 'dopayment') // Do not change amount if we just click on first dopayment - { - $amount=price2num($invoice->total_ttc - $invoice->getSommePaiement()); - if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); - $amount=price2num($amount); - } - - $fulltag='INV='.$invoice->ref.'.CUS='.$invoice->thirdparty->id; - //$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," "); - if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } - $fulltag=dol_string_unaccent($fulltag); - - // Creditor - - print ''."\n"; - - // Debitor - - print ''."\n"; - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // Shipping address - $shipToName=$invoice->thirdparty->name; - $shipToStreet=$invoice->thirdparty->address; - $shipToCity=$invoice->thirdparty->town; - $shipToState=$invoice->thirdparty->state_code; - $shipToCountryCode=$invoice->thirdparty->country_code; - $shipToZip=$invoice->thirdparty->zip; - $shipToStreet2=''; - $phoneNum=$invoice->thirdparty->phone; - if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) - { - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - } - else - { - print ''."\n"; - } - print ''."\n"; - print ''."\n"; - print 'ref.'">'."\n"; -} - -// Payment on contract line -if (GETPOST("source") == 'contractline') -{ - $found=true; - $langs->load("contracts"); - - require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; - - $contractline=new ContratLigne($db); - $result=$contractline->fetch('',$ref); - if ($result < 0) - { - $mesg=$contractline->error; - $error++; - } - else - { - if ($contractline->fk_contrat > 0) - { - $contract=new Contrat($db); - $result=$contract->fetch($contractline->fk_contrat); - if ($result > 0) - { - $result=$contract->fetch_thirdparty($contract->socid); - } - else - { - $mesg=$contract->error; - $error++; - } - } - else - { - $mesg='ErrorRecordNotFound'; - $error++; - } - } - - if ($action != 'dopayment') // Do not change amount if we just click on first dopayment - { - $amount=$contractline->total_ttc; - if ($contractline->fk_product) - { - $product=new Product($db); - $result=$product->fetch($contractline->fk_product); - - // We define price for product (TODO Put this in a method in product class) - if (! empty($conf->global->PRODUIT_MULTIPRICES)) - { - $pu_ht = $product->multiprices[$contract->thirdparty->price_level]; - $pu_ttc = $product->multiprices_ttc[$contract->thirdparty->price_level]; - $price_base_type = $product->multiprices_base_type[$contract->thirdparty->price_level]; - } - else - { - $pu_ht = $product->price; - $pu_ttc = $product->price_ttc; - $price_base_type = $product->price_base_type; - } - - $amount=$pu_ttc; - if (empty($amount)) - { - dol_print_error('','ErrorNoPriceDefinedForThisProduct'); - exit; - } - } - - if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); - $amount=price2num($amount); - } - - $fulltag='COL='.$contractline->ref.'.CON='.$contract->ref.'.CUS='.$contract->thirdparty->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); - //$fulltag.='.NAM='.strtr($contract->thirdparty->name,"-"," "); - if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } - $fulltag=dol_string_unaccent($fulltag); - - $qty=1; - if (GETPOST('qty')) $qty=GETPOST('qty'); - - // Creditor - - print ''."\n"; - - // Debitor - - print ''."\n"; - - // Quantity - - $label=$langs->trans("Quantity"); - $qty=1; - $duration=''; - if ($contractline->fk_product) - { - if ($product->isService() && $product->duration_value > 0) - { - $label=$langs->trans("Duration"); - - // TODO Put this in a global method - if ($product->duration_value > 1) - { - $dur=array("h"=>$langs->trans("Hours"),"d"=>$langs->trans("DurationDays"),"w"=>$langs->trans("DurationWeeks"),"m"=>$langs->trans("DurationMonths"),"y"=>$langs->trans("DurationYears")); - } - else - { - $dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("DurationDay"),"w"=>$langs->trans("DurationWeek"),"m"=>$langs->trans("DurationMonth"),"y"=>$langs->trans("DurationYear")); - } - $duration=$product->duration_value.' '.$dur[$product->duration_unit]; - } - } - print ''; - print ''."\n"; - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // Shipping address - $shipToName=$contract->thirdparty->name; - $shipToStreet=$contract->thirdparty->address; - $shipToCity=$contract->thirdparty->town; - $shipToState=$contract->thirdparty->state_code; - $shipToCountryCode=$contract->thirdparty->country_code; - $shipToZip=$contract->thirdparty->zip; - $shipToStreet2=''; - $phoneNum=$contract->thirdparty->phone; - if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) - { - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - } - else - { - print ''."\n"; - } - print ''."\n"; - print ''."\n"; - print 'ref.'">'."\n"; -} - -// Payment on member subscription -if (GETPOST("source") == 'membersubscription') -{ - $found=true; - $langs->load("members"); - - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; - - $member=new Adherent($db); - $result=$member->fetch('',$ref); - if ($result < 0) - { - $mesg=$member->error; - $error++; - } - else - { - $subscription=new Subscription($db); - } - - if ($action != 'dopayment') // Do not change amount if we just click on first dopayment - { - $amount=$subscription->total_ttc; - if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); - $amount=price2num($amount); - } - - $fulltag='MEM='.$member->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); - if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } - $fulltag=dol_string_unaccent($fulltag); - - // Creditor - - print ''."\n"; - - // Debitor - - print ''."\n"; - - if ($member->last_subscription_date || $member->last_subscription_amount) - { - // Last subscription date - - print ''."\n"; - - // Last subscription amount - - print ''."\n"; - - if (empty($amount) && ! GETPOST('newamount','alpha')) $_GET['newamount']=$member->last_subscription_amount; - } - - // Amount - - print ''."\n"; - - // Tag - - print ''."\n"; - - // Shipping address - $shipToName=$member->getFullName($langs); - $shipToStreet=$member->address; - $shipToCity=$member->town; - $shipToState=$member->state_code; - $shipToCountryCode=$member->country_code; - $shipToZip=$member->zip; - $shipToStreet2=''; - $phoneNum=$member->phone; - if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) - { - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - } - else - { - print ''."\n"; - } - print ''."\n"; - print ''."\n"; -} - - - -if (! $found && ! $mesg) $mesg=$langs->trans("ErrorBadParameters"); - -if ($mesg) print ''."\n"; - -print '
'.$langs->trans("ThisIsInformationOnPayment").' :
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - if (empty($amount) || ! is_numeric($amount)) - { - print ''; - print ''; - } - else { - print ''.price($amount).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("ThirdParty"); - print ''.$order->thirdparty->name.''; - - // Object - - $text=''.$langs->trans("PaymentOrderRef",$order->ref).''; - print '
'.$langs->trans("Designation"); - print ''.$text; - print ''; - print ''; - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - if (empty($amount) || ! is_numeric($amount)) - { - print ''; - print ''; - } - else { - print ''.price($amount).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("ThirdParty"); - print ''.$invoice->thirdparty->name.''; - - // Object - - $text=''.$langs->trans("PaymentInvoiceRef",$invoice->ref).''; - print '
'.$langs->trans("Designation"); - print ''.$text; - print ''; - print ''; - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - if (empty($amount) || ! is_numeric($amount)) - { - print ''; - print ''; - } - else { - print ''.price($amount).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("ThirdParty"); - print ''.$contract->thirdparty->name.''; - - // Object - - $text=''.$langs->trans("PaymentRenewContractId",$contract->ref,$contractline->ref).''; - if ($contractline->fk_product) - { - $text.='
'.$product->ref.($product->label?' - '.$product->label:''); - } - if ($contractline->description) $text.='
'.dol_htmlentitiesbr($contractline->description); - //if ($contractline->date_fin_validite) { - // $text.='
'.$langs->trans("DateEndPlanned").': '; - // $text.=dol_print_date($contractline->date_fin_validite); - //} - if ($contractline->date_fin_validite) - { - $text.='
'.$langs->trans("ExpiredSince").': '.dol_print_date($contractline->date_fin_validite); - } - - print '
'.$langs->trans("Designation"); - print ''.$text; - print ''; - print ''; - print '
'.$label.''.($duration?$duration:$qty).''; - print ''; - print '
'.$langs->trans("Amount"); - if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; - print ''; - if (empty($amount) || ! is_numeric($amount)) - { - print ''; - print ''; - } - else { - print ''.price($amount).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '
'.$langs->trans("Creditor"); - print ''.$creditor.''; - print ''; - print '
'.$langs->trans("Member"); - print ''; - if ($member->morphy == 'mor' && ! empty($member->societe)) print $member->societe; - else print $member->getFullName($langs); - print ''; - - // Object - - $text=''.$langs->trans("PaymentSubscription").''; - print '
'.$langs->trans("Designation"); - print ''.$text; - print ''; - print ''; - print '
'.$langs->trans("LastSubscriptionDate"); - print ''.dol_print_date($member->last_subscription_date,'day'); - print '
'.$langs->trans("LastSubscriptionAmount"); - print ''.price($member->last_subscription_amount); - print '
'.$langs->trans("Amount"); - if (empty($amount)) - { - print ' ('.$langs->trans("ToComplete"); - if (! empty($conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO)) print ' - '.$langs->trans("SeeHere").''; - print ')'; - } - print ''; - $valtoshow=''; - if (empty($amount) || ! is_numeric($amount)) - { - $valtoshow=price2num(GETPOST("newamount",'alpha'),'MT'); - // force default subscription amount to value defined into constant... - if (empty($valtoshow)) - { - if (! empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT)) { - if (! empty($conf->global->MEMBER_NEWFORM_AMOUNT)) { - $valtoshow = $conf->global->MEMBER_NEWFORM_AMOUNT; - } - } - else { - if (! empty($conf->global->MEMBER_NEWFORM_AMOUNT)) { - $amount = $conf->global->MEMBER_NEWFORM_AMOUNT; - } - } - } - } - if (empty($amount) || ! is_numeric($amount)) - { - //$valtoshow=price2num(GETPOST("newamount",'alpha'),'MT'); - if (! empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) $valtoshow=max($conf->global->MEMBER_MIN_AMOUNT,$valtoshow); - print ''; - print ''; - } - else { - $valtoshow=$amount; - if (! empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) $valtoshow=max($conf->global->MEMBER_MIN_AMOUNT,$valtoshow); - print ''.price($valtoshow).''; - print ''; - print ''; - } - // Currency - print ' '.$langs->trans("Currency".$currency).''; - print ''; - print '
'.$langs->trans("PaymentCode"); - print ''.$fulltag.''; - print ''; - print ''; - print '

'.$mesg.'
'."\n"; -print "\n"; - - -if ($action != 'dopayment') -{ - if ($found && ! $error) // We are in a management option and no error - { - print '
'; - } - else - { - dol_print_error_email('ERRORNEWPAYMENTSTRIPE'); - } -} - - -print '
'."\n"; -print '
'."\n"; -print '
'."\n"; -print '
'; - - -// Add more content on page for some services -if (preg_match('/^dopayment/',$action)) -{ - // Simple checkout - /* - print ''; - */ - - // Personalized checkout - print ''; - - print ' - -
-
'; - - 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 ' - -
- -
- -
- -
- - - -
-
- - -
- -
- - - - - - '; -} - - - -htmlPrintOnlinePaymentFooter($mysoc,$langs,1,$suffix); - -llxFooter('', 'public'); - -$db->close(); - +$newurl = $_SERVER['REQUEST_URI']; +$newurl = preg_replace('/\/stripe\/newpayment/', '/stripe/newpayment', $newurl); +header("Location: ".$newurl.(preg_match('/\?/', $newurl)?'&':'?').'paymentmethod=stripe'); +exit;