From 5497bfc1bb1415454c82d8784e26660aece80a84 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Oct 2010 23:20:49 +0000 Subject: [PATCH] Work on paypal module --- htdocs/paybox/admin/paybox.php | 8 +- htdocs/paybox/lib/paybox.lib.php | 6 +- htdocs/paypal/admin/paypal.php | 19 +- htdocs/paypal/expresscheckout.php | 82 ++++++ htdocs/paypal/lib/paypal.lib.php | 175 ++++-------- htdocs/paypal/paypalfunctions.php | 414 ++++++++++++++++++++++++++++ htdocs/public/paybox/newpayment.php | 51 ++-- htdocs/public/paypal/newpayment.php | 159 +++++++++-- 8 files changed, 722 insertions(+), 192 deletions(-) create mode 100644 htdocs/paypal/expresscheckout.php create mode 100644 htdocs/paypal/paypalfunctions.php diff --git a/htdocs/paybox/admin/paybox.php b/htdocs/paybox/admin/paybox.php index 921b24d5497..96ba8d3c7d2 100644 --- a/htdocs/paybox/admin/paybox.php +++ b/htdocs/paybox/admin/paybox.php @@ -167,26 +167,26 @@ print '
'; if ($conf->commande->enabled) { print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder",$servicename).':
'; - print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?amount=order&ref=order_ref'."
\n"; + print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?source=order&ref=order_ref'."
\n"; print '
'; } if ($conf->facture->enabled) { print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice",$servicename).':
'; - print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?amount=invoice&ref=invoice_ref'."
\n"; + print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?source=invoice&ref=invoice_ref'."
\n"; // print $langs->trans("SetupPayBoxToHavePaymentCreatedAutomatically",$langs->transnoentitiesnoconv("FeatureNotYetAvailable"))."
\n"; print '
'; } if ($conf->contrat->enabled) { print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine",$servicename).':
'; - print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?amount=contractline&ref=contractline_ref'."
\n"; + print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?source=contractline&ref=contractline_ref'."
\n"; print '
'; } if ($conf->adherent->enabled) { print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription",$servicename).':
'; - print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?amount=membersubscription&ref=member_ref'."
\n"; + print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?source=membersubscription&ref=member_ref'."
\n"; print '
'; } print $langs->trans("YouCanAddTagOnUrl"); diff --git a/htdocs/paybox/lib/paybox.lib.php b/htdocs/paybox/lib/paybox.lib.php index 3c02bce6487..0ef1af4838c 100755 --- a/htdocs/paybox/lib/paybox.lib.php +++ b/htdocs/paybox/lib/paybox.lib.php @@ -19,12 +19,10 @@ */ /** - * \file htdocs/paybox/paybox.lib.php + * \file htdocs/paybox/lib/paybox.lib.php * \brief Library for common paybox functions * \version $Id$ */ - - function llxHeaderPaybox($title, $head = "") { global $user, $conf, $langs; @@ -69,7 +67,7 @@ function print_paybox_redirect($PRICE,$CURRENCY,$EMAIL,$urlok,$urlko,$TAG) { global $conf, $langs, $db; - dol_syslog("Paypal.lib::print_paybox_redirect", LOG_DEBUG); + dol_syslog("Paybox.lib::print_paybox_redirect", LOG_DEBUG); // Clean parameters $PBX_IDENTIFIANT="2"; # Identifiant pour v2 test diff --git a/htdocs/paypal/admin/paypal.php b/htdocs/paypal/admin/paypal.php index 7b876230abf..efb331ec4b6 100644 --- a/htdocs/paypal/admin/paypal.php +++ b/htdocs/paypal/admin/paypal.php @@ -38,17 +38,10 @@ if (!$user->admin) if ($_POST["action"] == 'setvalue' && $user->admin) { - //$result=dolibarr_set_const($db, "PAYPAL_IBS_DEVISE",$_POST["PAYPAL_IBS_DEVISE"],'chaine',0,'',$conf->entity); $result=dolibarr_set_const($db, "PAYPAL_CSS_URL",$_POST["PAYPAL_CSS_URL"],'chaine',0,'',$conf->entity); -/* $result=dolibarr_set_const($db, "PAYPAL_CREDITOR",$_POST["PAYPAL_CREDITOR"],'chaine',0,'',$conf->entity); - $result=dolibarr_set_const($db, "PAYPAL_CGI_URL_V1",$_POST["PAYPAL_CGI_URL_V1"],'chaine',0,'',$conf->entity); - $result=dolibarr_set_const($db, "PAYPAL_CGI_URL_V2",$_POST["PAYPAL_CGI_URL_V2"],'chaine',0,'',$conf->entity); - $result=dolibarr_set_const($db, "PAYPAL_IBS_SITE",$_POST["PAYPAL_IBS_SITE"],'chaine',0,'',$conf->entity); - $result=dolibarr_set_const($db, "PAYPAL_IBS_RANG",$_POST["PAYPAL_IBS_RANG"],'chaine',0,'',$conf->entity); - $result=dolibarr_set_const($db, "PAYPAL_PBX_IDENTIFIANT",$_POST["PAYPAL_PBX_IDENTIFIANT"],'chaine',0,'',$conf->entity); -*/ + $result=dolibarr_set_const($db, "PAYPAL_API_SANDBOX",$_POST["PAYPAL_API_SANDBOX"],'chaine',0,'',$conf->entity); - $result=dolibarr_set_const($db, "PAYPAL_API_INTEGRAL",$_POST["PAYPAL_API_INTEGRAL"],'chaine',0,'',$conf->entity); + $result=dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY",$_POST["PAYPAL_API_INTEGRAL_OR_PAYPALONLY"],'chaine',0,'',$conf->entity); $result=dolibarr_set_const($db, "PAYPAL_API_USER",$_POST["PAYPAL_API_USER"],'chaine',0,'',$conf->entity); $result=dolibarr_set_const($db, "PAYPAL_API_PASSWORD",$_POST["PAYPAL_API_PASSWORD"],'chaine',0,'',$conf->entity); $result=dolibarr_set_const($db, "PAYPAL_API_SIGNATURE",$_POST["PAYPAL_API_SIGNATURE"],'chaine',0,'',$conf->entity); @@ -161,26 +154,26 @@ print '
'; if ($conf->commande->enabled) { print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder",$servicename).':
'; - print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?amount=order&ref=order_ref'."
\n"; + print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref=order_ref'."
\n"; print '
'; } if ($conf->facture->enabled) { print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice",$servicename).':
'; - print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?amount=invoice&ref=invoice_ref'."
\n"; + print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref=invoice_ref'."
\n"; // print $langs->trans("SetupPaypalToHavePaymentCreatedAutomatically",$langs->transnoentitiesnoconv("FeatureNotYetAvailable"))."
\n"; print '
'; } if ($conf->contrat->enabled) { print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine",$servicename).':
'; - print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?amount=contractline&ref=contractline_ref'."
\n"; + print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref=contractline_ref'."
\n"; print '
'; } if ($conf->adherent->enabled) { print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription",$servicename).':
'; - print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?amount=membersubscription&ref=member_ref'."
\n"; + print ''.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref=member_ref'."
\n"; print '
'; } print $langs->trans("YouCanAddTagOnUrl"); diff --git a/htdocs/paypal/expresscheckout.php b/htdocs/paypal/expresscheckout.php new file mode 100644 index 00000000000..31262c9fbf3 --- /dev/null +++ b/htdocs/paypal/expresscheckout.php @@ -0,0 +1,82 @@ +global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral'; + +// For payment with Paypal only +if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly') +{ + $resArray = CallShortcutExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL); +} +// For payment with Credit card or Paypal +if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral') +{ + $resArray = CallMarkExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL); +} +// For direct payment with credit card +if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'cconly') +{ + //$resArray = DirectPayment (...); +} + +$ack = strtoupper($resArray["ACK"]); +if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING") +{ + RedirectToPayPal ( $resArray["TOKEN"] ); +} +else +{ + //Display a user friendly Error on the page using any of the following error information returned by PayPal + $ErrorCode = urldecode($resArray["L_ERRORCODE0"]); + $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]); + $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]); + $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]); + + echo "SetExpressCheckout API call failed. "; + echo "Detailed Error Message: " . $ErrorLongMsg; + echo "Short Error Message: " . $ErrorShortMsg; + echo "Error Code: " . $ErrorCode; + echo "Error Severity Code: " . $ErrorSeverityCode; +} +?> \ No newline at end of file diff --git a/htdocs/paypal/lib/paypal.lib.php b/htdocs/paypal/lib/paypal.lib.php index e20381f628b..77c9486f0ff 100755 --- a/htdocs/paypal/lib/paypal.lib.php +++ b/htdocs/paypal/lib/paypal.lib.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2008-2010 Laurent Destailleur * Copyright (C) 2005-2007 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -19,12 +19,10 @@ */ /** - * \file htdocs/paypal/paypal.lib.php + * \file htdocs/paypal/lib/paypal.lib.php * \brief Library for common paypal functions * \version $Id$ */ - - function llxHeaderPaypal($title, $head = "") { global $user, $conf, $langs; @@ -68,90 +66,53 @@ function llxFooterPaypal() function print_paypal_redirect($PRICE,$CURRENCY,$EMAIL,$urlok,$urlko,$TAG) { global $conf, $langs, $db; + global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE; + global $PAYPAL_API_DEVISE, $PAYPAL_API_OK, $PAYPAL_API_KO; + global $PAYPAL_API_SANDBOX; - dol_syslog("Paypal.lib::print_paybox_redirect", LOG_DEBUG); + dol_syslog("Paypal.lib::print_paypal_redirect", LOG_DEBUG); // Clean parameters - $PBX_IDENTIFIANT="2"; # Identifiant pour v2 test - if ($conf->global->PAYBOX_PBX_IDENTIFIANT) $PBX_IDENTIFIANT=$conf->global->PAYBOX_PBX_IDENTIFIANT; - $IBS_SITE="1999888"; # Site test - if ($conf->global->PAYBOX_IBS_SITE) $IBS_SITE=$conf->global->PAYBOX_IBS_SITE; - $IBS_RANG="99"; # Rang test - if ($conf->global->PAYBOX_IBS_RANG) $IBS_RANG=$conf->global->PAYBOX_IBS_RANG; - $IBS_DEVISE="840"; # Currency (Dollar US by default) - if ($CURRENCY == 'EUR') $IBS_DEVISE="978"; - if ($CURRENCY == 'USD') $IBS_DEVISE="840"; + $PAYPAL_API_USER=""; + if ($conf->global->PAYPAL_API_USER) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER; + $PAYPAL_API_PASSWORD=""; + if ($conf->global->PAYPAL_API_PASSWORD) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD; + $PAYPAL_API_SIGNATURE=""; + if ($conf->global->PAYPAL_API_SIGNATURE) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE; + $PAYPAL_API_SANDBOX=""; + if ($conf->global->PAYPAL_API_SANDBOX) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX; - $URLPAYBOX=""; - if ($conf->global->PAYBOX_CGI_URL_V1) $URLPAYBOX=$conf->global->PAYBOX_CGI_URL_V1; - if ($conf->global->PAYBOX_CGI_URL_V2) $URLPAYBOX=$conf->global->PAYBOX_CGI_URL_V2; - - if (empty($IBS_DEVISE)) + if (empty($PAYPAL_API_USER)) { - dol_print_error('',"Paybox setup param PAYBOX_IBS_DEVISE not defined"); + dol_print_error('',"Paypal setup param PAYPAL_API_USER not defined"); return -1; } - if (empty($URLPAYBOX)) + if (empty($PAYPAL_API_PASSWORD)) { - dol_print_error('',"Paybox setup param PAYBOX_CGI_URL_V1 and PAYBOX_CGI_URL_V2 undefined"); + dol_print_error('',"Paypal setup param PAYPAL_API_PASSWORD not defined"); return -1; } - if (empty($IBS_SITE)) + if (empty($PAYPAL_API_SIGNATURE)) { - dol_print_error('',"Paybox setup param PAYBOX_IBS_SITE not defined"); - return -1; - } - if (empty($IBS_RANG)) - { - dol_print_error('',"Paybox setup param PAYBOX_IBS_RANG not defined"); + dol_print_error('',"Paypal setup param PAYPAL_API_SIGNATURE not defined"); return -1; } - // Definition des parametres vente produit pour paybox - $IBS_CMD=$TAG; - $IBS_TOTAL=$PRICE*100; # En centimes - $IBS_MODE=1; # Mode formulaire - $IBS_PORTEUR=$EMAIL; - $IBS_RETOUR="montant:M;ref:R;auto:A;trans:T"; # Format des parametres du get de validation en reponse (url a definir sous paybox) - //$IBS_TXT="
".$langsiso->trans("YouWillBeRedirectedOnPayBox")."
".$langsiso->trans("PleaseBePatient")."...
"; - $IBS_TXT=' '; // Use a space - $IBS_BOUTPI=$langs->trans("Wait"); - //$IBS_BOUTPI=''; - $IBS_EFFECTUE=$urlok; - $IBS_ANNULE=$urlko; - $IBS_REFUSE=$urlko; - $IBS_BKGD="#FFFFFF"; - $IBS_WAIT="2000"; - $IBS_LANG="GBR"; // By default GBR=english (FRA, GBR, ESP, ITA et DEU...) - if (preg_match('/^FR/i',$langs->defaultlang)) $IBS_LANG="FRA"; - if (preg_match('/^ES/i',$langs->defaultlang)) $IBS_LANG="ESP"; - if (preg_match('/^IT/i',$langs->defaultlang)) $IBS_LANG="ITA"; - if (preg_match('/^DE/i',$langs->defaultlang)) $IBS_LANG="DEU"; - if (preg_match('/^NL/i',$langs->defaultlang)) $IBS_LANG="NLD"; - if (preg_match('/^SE/i',$langs->defaultlang)) $IBS_LANG="SWE"; - $IBS_OUTPUT='E'; - $PBX_SOURCE='HTML'; - $PBX_TYPEPAIEMENT='CARTE'; + // Other + $PAYPAL_API_DEVISE="EUR"; + if ($CURRENCY == 'EUR') $PAYPAL_API_DEVISE="EUR"; + if ($CURRENCY == 'USD') $PAYPAL_API_DEVISE="USD"; + $PAYPAL_API_OK=$urlok; + $PAYPAL_API_KO=$urlko; - dol_syslog("Soumission Paybox", LOG_DEBUG); - dol_syslog("IBS_MODE: $IBS_MODE", LOG_DEBUG); - dol_syslog("IBS_SITE: $IBS_SITE", LOG_DEBUG); - dol_syslog("IBS_RANG: $IBS_RANG", LOG_DEBUG); - dol_syslog("IBS_TOTAL: $IBS_TOTAL", LOG_DEBUG); - dol_syslog("IBS_DEVISE: $IBS_DEVISE", LOG_DEBUG); - dol_syslog("IBS_CMD: $IBS_CMD", LOG_DEBUG); - dol_syslog("IBS_PORTEUR: $IBS_PORTEUR", LOG_DEBUG); - dol_syslog("IBS_RETOUR: $IBS_RETOUR", LOG_DEBUG); - dol_syslog("IBS_EFFECTUE: $IBS_EFFECTUE", LOG_DEBUG); - dol_syslog("IBS_ANNULE: $IBS_ANNULE", LOG_DEBUG); - dol_syslog("IBS_REFUSE: $IBS_REFUSE", LOG_DEBUG); - dol_syslog("IBS_BKGD: $IBS_BKGD", LOG_DEBUG); - dol_syslog("IBS_WAIT: $IBS_WAIT", LOG_DEBUG); - dol_syslog("IBS_LANG: $IBS_LANG", LOG_DEBUG); - dol_syslog("IBS_OUTPUT: $IBS_OUTPUT", LOG_DEBUG); - dol_syslog("PBX_IDENTIFIANT: $PBX_IDENTITIANT", LOG_DEBUG); - dol_syslog("PBX_SOURCE: $PBX_SOURCE", LOG_DEBUG); - dol_syslog("PBX_TYPEPAIEMENT: $PBX_TYPEPAIEMENT", LOG_DEBUG); + dol_syslog("Soumission Paypal", LOG_DEBUG); + dol_syslog("PAYPAL_API_USER: $PAYPAL_API_USER", LOG_DEBUG); + dol_syslog("PAYPAL_API_PASSWORD: $PAYPAL_API_PASSWORD", LOG_DEBUG); + dol_syslog("PAYPAL_API_SIGNATURE: $PAYPAL_API_SIGNATURE", LOG_DEBUG); + dol_syslog("PAYPAL_API_DEVISE: $PAYPAL_API_DEVISE", 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_SANDBOX: $PAYPAL_API_SANDBOX", LOG_DEBUG); header("Content-type: text/html; charset=".$conf->file->character_set_client); @@ -162,62 +123,26 @@ function print_paypal_redirect($PRICE,$CURRENCY,$EMAIL,$urlok,$urlko,$TAG) print ''."\n"; print "\n"; + $_SESSION["Payment_Amount"]=$PRICE; + + // A redirect is added if API call successfull + require_once(DOL_DOCUMENT_ROOT."/paypal/expresscheckout.php"); + // Formulaire pour module Paybox - print '
'."\n"; +// print ''."\n"; +//print " +// +// +//
"; +// print ''."\n"; - // For Paybox V1 (IBS_xxx) - /* - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - */ - - // For Paybox V2 (PBX_xxx) - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - - print ''."\n"; - - // Formulaire pour module Paybox v2 (PBX_xxx) +// print "\n"; +// print ''."\n"; +// print "\n"; - print "\n"; - print ''."\n"; - print "\n"; print ''."\n"; print "\n"; diff --git a/htdocs/paypal/paypalfunctions.php b/htdocs/paypal/paypalfunctions.php new file mode 100644 index 00000000000..47871c16dfb --- /dev/null +++ b/htdocs/paypal/paypalfunctions.php @@ -0,0 +1,414 @@ + with your API Username + //' Replace with your API Password + //' Replace with your Signature + //'------------------------------------ + $API_UserName=$PAYPAL_API_USER; + $API_Password=$PAYPAL_API_PASSWORD; + $API_Signature=$PAYPAL_API_SIGNATURE; + + // BN Code is only applicable for partners + $sBNCode = "PP-ECWizard"; + + + /* + ' Define the PayPal Redirect URLs. + ' This is the URL that the buyer is first sent to do authorize payment with their paypal account + ' change the URL depending if you are testing on the sandbox or the live PayPal site + ' + ' For the sandbox, the URL is https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token= + ' For the live site, the URL is https://www.paypal.com/webscr&cmd=_express-checkout&token= + */ + + if ($SandboxFlag == true) + { + $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp"; + $PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token="; + } + else + { + $API_Endpoint = "https://api-3t.paypal.com/nvp"; + $PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token="; + } + + $USE_PROXY = false; + $version="2.3"; + + if (session_id() == "") + session_start(); + + /* An express checkout transaction starts with a token, that + identifies to PayPal your transaction + In this example, when the script sees a token, the script + knows that the buyer has already authorized payment through + paypal. If no token was found, the action is to send the buyer + to PayPal to first authorize payment + */ + + /* + '------------------------------------------------------------------------------------------------------------------------------------------- + ' Purpose: Prepares the parameters for the SetExpressCheckout API Call. + ' Inputs: + ' paymentAmount: Total value of the shopping cart + ' currencyCodeType: Currency code value the PayPal API + ' paymentType: paymentType has to be one of the following values: Sale or Order or Authorization + ' returnURL: the page where buyers return to after they are done with the payment review on PayPal + ' cancelURL: the page where buyers return to when they cancel the payment review on PayPal + '-------------------------------------------------------------------------------------------------------------------------------------------- + */ + function CallShortcutExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL) + { + //------------------------------------------------------------------------------------------------------------------------------------ + // Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation + + $nvpstr="&Amt=". $paymentAmount; + $nvpstr = $nvpstr . "&PAYMENTACTION=" . $paymentType; + $nvpstr = $nvpstr . "&ReturnUrl=" . $returnURL; + $nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL; + $nvpstr = $nvpstr . "&CURRENCYCODE=" . $currencyCodeType; + + $_SESSION["currencyCodeType"] = $currencyCodeType; + $_SESSION["PaymentType"] = $paymentType; + + //'--------------------------------------------------------------------------------------------------------------- + //' Make the API call to PayPal + //' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment. + //' If an error occured, show the resulting errors + //'--------------------------------------------------------------------------------------------------------------- + $resArray=hash_call("SetExpressCheckout", $nvpstr); + $ack = strtoupper($resArray["ACK"]); + if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING") + { + $token = urldecode($resArray["TOKEN"]); + $_SESSION['TOKEN']=$token; + } + + return $resArray; + } + + /* + '------------------------------------------------------------------------------------------------------------------------------------------- + ' Purpose: Prepares the parameters for the SetExpressCheckout API Call. + ' Inputs: + ' paymentAmount: Total value of the shopping cart + ' currencyCodeType: Currency code value the PayPal API + ' paymentType: paymentType has to be one of the following values: Sale or Order or Authorization + ' returnURL: the page where buyers return to after they are done with the payment review on PayPal + ' cancelURL: the page where buyers return to when they cancel the payment review on PayPal + ' shipToName: the Ship to name entered on the merchant's site + ' shipToStreet: the Ship to Street entered on the merchant's site + ' shipToCity: the Ship to City entered on the merchant's site + ' shipToState: the Ship to State entered on the merchant's site + ' shipToCountryCode: the Code for Ship to Country entered on the merchant's site + ' shipToZip: the Ship to ZipCode entered on the merchant's site + ' shipToStreet2: the Ship to Street2 entered on the merchant's site + ' phoneNum: the phoneNum entered on the merchant's site + '-------------------------------------------------------------------------------------------------------------------------------------------- + */ + function CallMarkExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, + $cancelURL, $shipToName, $shipToStreet, $shipToCity, $shipToState, + $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum + ) + { + //------------------------------------------------------------------------------------------------------------------------------------ + // Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation + + $nvpstr="&Amt=". $paymentAmount; + $nvpstr = $nvpstr . "&PAYMENTACTION=" . $paymentType; + $nvpstr = $nvpstr . "&ReturnUrl=" . $returnURL; + $nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL; + $nvpstr = $nvpstr . "&CURRENCYCODE=" . $currencyCodeType; + $nvpstr = $nvpstr . "&ADDROVERRIDE=1"; + $nvpstr = $nvpstr . "&SHIPTONAME=" . $shipToName; + $nvpstr = $nvpstr . "&SHIPTOSTREET=" . $shipToStreet; + $nvpstr = $nvpstr . "&SHIPTOSTREET2=" . $shipToStreet2; + $nvpstr = $nvpstr . "&SHIPTOCITY=" . $shipToCity; + $nvpstr = $nvpstr . "&SHIPTOSTATE=" . $shipToState; + $nvpstr = $nvpstr . "&SHIPTOCOUNTRYCODE=" . $shipToCountryCode; + $nvpstr = $nvpstr . "&SHIPTOZIP=" . $shipToZip; + $nvpstr = $nvpstr . "&PHONENUM=" . $phoneNum; + + $_SESSION["currencyCodeType"] = $currencyCodeType; + $_SESSION["PaymentType"] = $paymentType; + + //'--------------------------------------------------------------------------------------------------------------- + //' Make the API call to PayPal + //' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment. + //' If an error occured, show the resulting errors + //'--------------------------------------------------------------------------------------------------------------- + $resArray=hash_call("SetExpressCheckout", $nvpstr); + $ack = strtoupper($resArray["ACK"]); + if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING") + { + $token = urldecode($resArray["TOKEN"]); + $_SESSION['TOKEN']=$token; + } + + return $resArray; + } + + /* + '------------------------------------------------------------------------------------------- + ' Purpose: Prepares the parameters for the GetExpressCheckoutDetails API Call. + ' + ' Inputs: + ' None + ' Returns: + ' The NVP Collection object of the GetExpressCheckoutDetails Call Response. + '------------------------------------------------------------------------------------------- + */ + function GetShippingDetails( $token ) + { + //'-------------------------------------------------------------- + //' At this point, the buyer has completed authorizing the payment + //' at PayPal. The function will call PayPal to obtain the details + //' of the authorization, incuding any shipping information of the + //' buyer. Remember, the authorization is not a completed transaction + //' at this state - the buyer still needs an additional step to finalize + //' the transaction + //'-------------------------------------------------------------- + + //'--------------------------------------------------------------------------- + //' Build a second API request to PayPal, using the token as the + //' ID to get the details on the payment authorization + //'--------------------------------------------------------------------------- + $nvpstr="&TOKEN=" . $token; + + //'--------------------------------------------------------------------------- + //' Make the API call and store the results in an array. + //' If the call was a success, show the authorization details, and provide + //' an action to complete the payment. + //' If failed, show the error + //'--------------------------------------------------------------------------- + $resArray=hash_call("GetExpressCheckoutDetails",$nvpstr); + $ack = strtoupper($resArray["ACK"]); + if($ack == "SUCCESS" || $ack=="SUCCESSWITHWARNING") + { + $_SESSION['payer_id'] = $resArray['PAYERID']; + } + return $resArray; + } + + /* + '------------------------------------------------------------------------------------------------------------------------------------------- + ' Purpose: Prepares the parameters for the GetExpressCheckoutDetails API Call. + ' + ' Inputs: + ' sBNCode: The BN code used by PayPal to track the transactions from a given shopping cart. + ' Returns: + ' The NVP Collection object of the GetExpressCheckoutDetails Call Response. + '-------------------------------------------------------------------------------------------------------------------------------------------- + */ + function ConfirmPayment( $FinalPaymentAmt ) + { + /* Gather the information to make the final call to + finalize the PayPal payment. The variable nvpstr + holds the name value pairs + */ + + + //Format the other parameters that were stored in the session from the previous calls + $token = urlencode($_SESSION['TOKEN']); + $paymentType = urlencode($_SESSION['PaymentType']); + $currencyCodeType = urlencode($_SESSION['currencyCodeType']); + $payerID = urlencode($_SESSION['payer_id']); + + $serverName = urlencode($_SERVER['SERVER_NAME']); + + $nvpstr = '&TOKEN=' . $token . '&PAYERID=' . $payerID . '&PAYMENTACTION=' . $paymentType . '&AMT=' . $FinalPaymentAmt; + $nvpstr .= '&CURRENCYCODE=' . $currencyCodeType . '&IPADDRESS=' . $serverName; + + /* Make the call to PayPal to finalize payment + If an error occured, show the resulting errors + */ + $resArray=hash_call("DoExpressCheckoutPayment",$nvpstr); + + /* Display the API response back to the browser. + If the response from PayPal was a success, display the response parameters' + If the response was an error, display the errors received using APIError.php. + */ + $ack = strtoupper($resArray["ACK"]); + + return $resArray; + } + + /* + '------------------------------------------------------------------------------------------------------------------------------------------- + ' Purpose: This function makes a DoDirectPayment API call + ' + ' Inputs: + ' paymentType: paymentType has to be one of the following values: Sale or Order or Authorization + ' paymentAmount: total value of the shopping cart + ' currencyCode: currency code value the PayPal API + ' firstName: first name as it appears on credit card + ' lastName: last name as it appears on credit card + ' street: buyer's street address line as it appears on credit card + ' city: buyer's city + ' state: buyer's state + ' countryCode: buyer's country code + ' zip: buyer's zip + ' creditCardType: buyer's credit card type (i.e. Visa, MasterCard ... ) + ' creditCardNumber: buyers credit card number without any spaces, dashes or any other characters + ' expDate: credit card expiration date + ' cvv2: Card Verification Value + ' + '------------------------------------------------------------------------------------------- + ' + ' Returns: + ' The NVP Collection object of the DoDirectPayment Call Response. + '-------------------------------------------------------------------------------------------------------------------------------------------- + */ + + + function DirectPayment( $paymentType, $paymentAmount, $creditCardType, $creditCardNumber, + $expDate, $cvv2, $firstName, $lastName, $street, $city, $state, $zip, + $countryCode, $currencyCode ) + { + //Construct the parameter string that describes DoDirectPayment + $nvpstr = "&AMT=" . $paymentAmount; + $nvpstr = $nvpstr . "&CURRENCYCODE=" . $currencyCode; + $nvpstr = $nvpstr . "&PAYMENTACTION=" . $paymentType; + $nvpstr = $nvpstr . "&CREDITCARDTYPE=" . $creditCardType; + $nvpstr = $nvpstr . "&ACCT=" . $creditCardNumber; + $nvpstr = $nvpstr . "&EXPDATE=" . $expDate; + $nvpstr = $nvpstr . "&CVV2=" . $cvv2; + $nvpstr = $nvpstr . "&FIRSTNAME=" . $firstName; + $nvpstr = $nvpstr . "&LASTNAME=" . $lastName; + $nvpstr = $nvpstr . "&STREET=" . $street; + $nvpstr = $nvpstr . "&CITY=" . $city; + $nvpstr = $nvpstr . "&STATE=" . $state; + $nvpstr = $nvpstr . "&COUNTRYCODE=" . $countryCode; + $nvpstr = $nvpstr . "&IPADDRESS=" . $_SERVER['REMOTE_ADDR']; + + $resArray=hash_call("DoDirectPayment", $nvpstr); + + return $resArray; + } + + + /** + '------------------------------------------------------------------------------------------------------------------------------------------- + * hash_call: Function to perform the API call to PayPal using API signature + * @methodName is name of API method. + * @nvpStr is nvp string. + * returns an associtive array containing the response from the server. + '------------------------------------------------------------------------------------------------------------------------------------------- + */ + function hash_call($methodName,$nvpStr) + { + //declaring of global variables + global $API_Endpoint, $version, $API_UserName, $API_Password, $API_Signature; + global $USE_PROXY, $PROXY_HOST, $PROXY_PORT; + global $gv_ApiErrorURL; + global $sBNCode; + + //setting the curl parameters. + $ch = curl_init(); + /*print $API_Endpoint."-".$version."-".$API_UserName."-".$API_Password."-".$API_Signature."
"; + print $USE_PROXY."-".$gv_ApiErrorURL."-".$sBNCode."
"; + print $nvpStr; + exit;*/ + curl_setopt($ch, CURLOPT_URL,$API_Endpoint); + curl_setopt($ch, CURLOPT_VERBOSE, 1); + + //turning off the server and peer verification(TrustManager Concept). + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); + + curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); + curl_setopt($ch, CURLOPT_POST, 1); + + //if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled. + //Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php + if($USE_PROXY) + curl_setopt ($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT); + + //NVPRequest for submitting to server + $nvpreq="METHOD=" . urlencode($methodName) . "&VERSION=" . urlencode($version) . "&PWD=" . urlencode($API_Password) . "&USER=" . urlencode($API_UserName) . "&SIGNATURE=" . urlencode($API_Signature) . $nvpStr . "&BUTTONSOURCE=" . urlencode($sBNCode); + + //setting the nvpreq as POST FIELD to curl + curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq); + + //getting response from server + $response = curl_exec($ch); + + //convrting NVPResponse to an Associative Array + $nvpResArray=deformatNVP($response); + $nvpReqArray=deformatNVP($nvpreq); + $_SESSION['nvpReqArray']=$nvpReqArray; + + if (curl_errno($ch)) + { + // moving to display page to display curl errors + $_SESSION['curl_error_no']=curl_errno($ch) ; + $_SESSION['curl_error_msg']=curl_error($ch); + + //Execute the Error handling module to display errors. + } + else + { + //closing the curl + curl_close($ch); + } + + return $nvpResArray; + } + + /*'---------------------------------------------------------------------------------- + Purpose: Redirects to PayPal.com site. + Inputs: NVP string. + Returns: + ---------------------------------------------------------------------------------- + */ + function RedirectToPayPal ( $token ) + { + global $PAYPAL_URL; + + // Redirect to paypal.com here + $payPalURL = $PAYPAL_URL . $token; + header("Location: ".$payPalURL); + } + + + /*'---------------------------------------------------------------------------------- + * This function will take NVPString and convert it to an Associative Array and it will decode the response. + * It is usefull to search for a particular key and displaying arrays. + * @nvpstr is NVPString. + * @nvpArray is Associative Array. + ---------------------------------------------------------------------------------- + */ + function deformatNVP($nvpstr) + { + $intial=0; + $nvpArray = array(); + + while(strlen($nvpstr)) + { + //postion of Key + $keypos= strpos($nvpstr,'='); + //position of value + $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr); + + /*getting the Key and Value values and storing in a Associative Array*/ + $keyval=substr($nvpstr,$intial,$keypos); + $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1); + //decoding the respose + $nvpArray[urldecode($keyval)] =urldecode( $valval); + $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr)); + } + return $nvpArray; + } + +?> \ No newline at end of file diff --git a/htdocs/public/paybox/newpayment.php b/htdocs/public/paybox/newpayment.php index 6e56d368f3b..3d90b755558 100644 --- a/htdocs/public/paybox/newpayment.php +++ b/htdocs/public/paybox/newpayment.php @@ -70,20 +70,20 @@ $langs->load("errors"); if (empty($_REQUEST["currency"])) $currency=$conf->global->MAIN_MONNAIE; else $currency=$_REQUEST["currency"]; -if (empty($_REQUEST["amount"])) +if (empty($_REQUEST["amount"]) && empty($_REQUEST["source"])) { dol_print_error('','ErrorBadParameters'); session_destroy(); exit; } $amount=$_REQUEST["amount"]; -if (is_numeric($amount) && empty($_REQUEST["tag"])) +if (is_numeric($amount) && empty($_REQUEST["tag"]) && empty($_REQUEST["source"])) { dol_print_error('','ErrorBadParameters'); session_destroy(); exit; } -if (! is_numeric($amount) && empty($_REQUEST["ref"])) +if (! empty($REQUEST["source"]) && empty($_REQUEST["ref"])) { dol_print_error('','ErrorBadParameters'); session_destroy(); @@ -98,10 +98,12 @@ $suffix=$_REQUEST["suffix"]; */ if ($_REQUEST["action"] == 'dopayment') { + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',$dolibarr_main_url_root); + $PRICE=$_REQUEST["newamount"]; $EMAIL=$_REQUEST["EMAIL"]; - $urlok=''; - $urlko=''; + $urlok=$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/paymentok.php'; + $urlko=$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/paymentko.php'; $TAG=$_REQUEST["newtag"]; $ID=$_REQUEST["id"]; @@ -190,7 +192,7 @@ $var=false; // Free payment -if (is_numeric($_REQUEST["amount"])) +if (empty($_REQUEST["source"])) { $found=true; $tag=$_REQUEST["tag"]; @@ -211,8 +213,9 @@ if (is_numeric($_REQUEST["amount"])) print ''.price($amount).''; print ''; } - print ' '.$langs->trans("Currency".$conf->monnaie).''; - print ''; + // Currency + print ' '.$langs->trans("Currency".$currency).''; + print ''; print ''."\n"; // Tag @@ -232,7 +235,7 @@ if (is_numeric($_REQUEST["amount"])) // Payment on customer order -if ($_REQUEST["amount"] == 'order') +if ($_REQUEST["source"] == 'order') { $found=true; $langs->load("orders"); @@ -252,6 +255,7 @@ if ($_REQUEST["amount"] == 'order') } $amount=$order->total_ttc; + if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"]; $newtag='IR='.$order->ref.'.TPID='.$order->client->id.'.TP='.strtr($order->client->nom,"-"," "); if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; } @@ -285,8 +289,9 @@ if ($_REQUEST["amount"] == 'order') print ''.price($amount).''; print ''; } - print ' '.$langs->trans("Currency".$conf->monnaie).''; - print ''; + // Currency + print ' '.$langs->trans("Currency".$currency).''; + print ''; print ''."\n"; // Tag @@ -306,7 +311,7 @@ if ($_REQUEST["amount"] == 'order') // Payment on customer invoice -if ($_REQUEST["amount"] == 'invoice') +if ($_REQUEST["source"] == 'invoice') { $found=true; $langs->load("bills"); @@ -326,6 +331,7 @@ if ($_REQUEST["amount"] == 'invoice') } $amount=$invoice->total_ttc - $invoice->getSommePaiement(); + if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"]; $newtag='IR='.$invoice->ref.'.TPID='.$invoice->client->id.'.TP='.strtr($invoice->client->nom,"-"," "); if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; } @@ -359,8 +365,9 @@ if ($_REQUEST["amount"] == 'invoice') print ''.price($amount).''; print ''; } - print ' '.$langs->trans("Currency".$conf->monnaie).''; - print ''; + // Currency + print ' '.$langs->trans("Currency".$currency).''; + print ''; print ''."\n"; // Tag @@ -379,7 +386,7 @@ if ($_REQUEST["amount"] == 'invoice') } // Payment on contract line -if ($_REQUEST["amount"] == 'contractline') +if ($_REQUEST["source"] == 'contractline') { $found=true; $langs->load("contracts"); @@ -443,6 +450,7 @@ if ($_REQUEST["amount"] == 'contractline') exit; } } + if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"]; $newtag='CLR='.$contractline->ref.'.CR='.$contract->ref.'.TPID='.$contract->client->id.'.TP='.strtr($contract->client->nom,"-"," "); if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; } @@ -521,8 +529,9 @@ if ($_REQUEST["amount"] == 'contractline') print ''.price($amount).''; print ''; } - print ' '.$langs->trans("Currency".$conf->monnaie).''; - print ''; + // Currency + print ' '.$langs->trans("Currency".$currency).''; + print ''; print ''."\n"; // Tag @@ -542,7 +551,7 @@ if ($_REQUEST["amount"] == 'contractline') } // Payment on member subscription -if ($_REQUEST["amount"] == 'membersubscription') +if ($_REQUEST["source"] == 'membersubscription') { $found=true; $langs->load("members"); @@ -563,6 +572,7 @@ if ($_REQUEST["amount"] == 'membersubscription') } $amount=$subscription->total_ttc; + if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"]; $newtag='MID='.$member->id.'.M='.strtr($member->getFullName($langs),"-"," "); if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; } @@ -596,8 +606,9 @@ if ($_REQUEST["amount"] == 'membersubscription') print ''.price($amount).''; print ''; } - print ' '.$langs->trans("Currency".$conf->monnaie).''; - print ''; + // Currency + print ' '.$langs->trans("Currency".$currency).''; + print ''; print ''."\n"; // Tag diff --git a/htdocs/public/paypal/newpayment.php b/htdocs/public/paypal/newpayment.php index 24c6a598978..1436ace9a88 100755 --- a/htdocs/public/paypal/newpayment.php +++ b/htdocs/public/paypal/newpayment.php @@ -71,20 +71,20 @@ $langs->load("paypal"); if (empty($_REQUEST["currency"])) $currency=$conf->global->MAIN_MONNAIE; else $currency=$_REQUEST["currency"]; -if (empty($_REQUEST["amount"])) +if (empty($_REQUEST["amount"]) && empty($_REQUEST["source"])) { dol_print_error('','ErrorBadParameters'); session_destroy(); exit; } $amount=$_REQUEST["amount"]; -if (is_numeric($amount) && empty($_REQUEST["tag"])) +if (is_numeric($amount) && empty($_REQUEST["tag"]) && empty($_REQUEST["source"])) { dol_print_error('','ErrorBadParameters'); session_destroy(); exit; } -if (! is_numeric($amount) && empty($_REQUEST["ref"])) +if (! empty($REQUEST["source"]) && empty($_REQUEST["ref"])) { dol_print_error('','ErrorBadParameters'); session_destroy(); @@ -99,23 +99,113 @@ $suffix=$_REQUEST["suffix"]; */ if ($_REQUEST["action"] == 'dopayment') { - $PRICE=$_REQUEST["newamount"]; + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',$dolibarr_main_url_root); + + $PAYPAL_API_PRICE=$_REQUEST["newamount"]; $EMAIL=$_REQUEST["EMAIL"]; - $urlok=''; - $urlko=''; + $urlok=$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/paymentok.php'; + $urlko=$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/paymentko.php'; $TAG=$_REQUEST["newtag"]; $ID=$_REQUEST["id"]; $mesg=''; - if (empty($PRICE)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount")); + if (empty($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 (empty($TAG)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentCode")); if (empty($mesg)) { - print_paypal_redirect($PRICE, $conf->monnaie, $EMAIL, $urlok, $urlko, $TAG, $ID); - session_destroy(); + //print_paypal_redirect($PAYPAL_API_PRICE, $conf->monnaie, $EMAIL, $urlok, $urlko, $TAG, $ID); + + /*global $conf, $langs, $db; + global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE; + global $PAYPAL_API_DEVISE, $PAYPAL_API_OK, $PAYPAL_API_KO; + global $PAYPAL_API_SANDBOX; + */ + + dol_syslog("newpayment.php call paypal api and do redirect", LOG_DEBUG); + + // Clean parameters + $PAYPAL_API_USER=""; + if ($conf->global->PAYPAL_API_USER) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER; + $PAYPAL_API_PASSWORD=""; + if ($conf->global->PAYPAL_API_PASSWORD) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD; + $PAYPAL_API_SIGNATURE=""; + if ($conf->global->PAYPAL_API_SIGNATURE) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE; + $PAYPAL_API_SANDBOX=""; + if ($conf->global->PAYPAL_API_SANDBOX) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX; + $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; + } + + // Other + $PAYPAL_API_DEVISE="EUR"; + if ($CURRENCY == 'EUR') $PAYPAL_API_DEVISE="EUR"; + if ($CURRENCY == 'USD') $PAYPAL_API_DEVISE="USD"; + + dol_syslog("Soumission Paypal", LOG_DEBUG); + dol_syslog("PAYPAL_API_USER: $PAYPAL_API_USER", LOG_DEBUG); + dol_syslog("PAYPAL_API_PASSWORD: $PAYPAL_API_PASSWORD", LOG_DEBUG); + 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); + + header("Content-type: text/html; charset=".$conf->file->character_set_client); + + print ''."\n"; + print ''."\n"; + print "\n"; + print ''."\n"; + print ''."\n"; + print "\n"; + + $_SESSION["Payment_Amount"]=$PAYPAL_API_PRICE; + + // A redirect is added if API call successfull + require_once(DOL_DOCUMENT_ROOT."/paypal/expresscheckout.php"); + + // Formulaire pour module Paybox + // print '
'."\n"; + //print " + // + // + //
"; + // print ''."\n"; + + // print "\n"; + // print ''."\n"; + // print "\n"; + + + print ''."\n"; + print "\n"; + + + + exit; } } @@ -191,7 +281,7 @@ $var=false; // Free payment -if (is_numeric($_REQUEST["amount"])) +if (empty($_REQUEST["source"])) { $found=true; $tag=$_REQUEST["tag"]; @@ -212,8 +302,9 @@ if (is_numeric($_REQUEST["amount"])) print ''.price($amount).''; print ''; } - print ' '.$langs->trans("Currency".$conf->monnaie).''; - print ''; + // Currency + print ' '.$langs->trans("Currency".$currency).''; + print ''; print ''."\n"; // Tag @@ -233,7 +324,7 @@ if (is_numeric($_REQUEST["amount"])) // Payment on customer order -if ($_REQUEST["amount"] == 'order') +if ($_REQUEST["source"] == 'order') { $found=true; $langs->load("orders"); @@ -253,6 +344,7 @@ if ($_REQUEST["amount"] == 'order') } $amount=$order->total_ttc; + if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"]; $newtag='IR='.$order->ref.'.TPID='.$order->client->id.'.TP='.strtr($order->client->nom,"-"," "); if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; } @@ -286,8 +378,9 @@ if ($_REQUEST["amount"] == 'order') print ''.price($amount).''; print ''; } - print ' '.$langs->trans("Currency".$conf->monnaie).''; - print ''; + // Currency + print ' '.$langs->trans("Currency".$currency).''; + print ''; print ''."\n"; // Tag @@ -307,7 +400,7 @@ if ($_REQUEST["amount"] == 'order') // Payment on customer invoice -if ($_REQUEST["amount"] == 'invoice') +if ($_REQUEST["source"] == 'invoice') { $found=true; $langs->load("bills"); @@ -327,6 +420,7 @@ if ($_REQUEST["amount"] == 'invoice') } $amount=$invoice->total_ttc - $invoice->getSommePaiement(); + if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"]; $newtag='IR='.$invoice->ref.'.TPID='.$invoice->client->id.'.TP='.strtr($invoice->client->nom,"-"," "); if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; } @@ -360,8 +454,9 @@ if ($_REQUEST["amount"] == 'invoice') print ''.price($amount).''; print ''; } - print ' '.$langs->trans("Currency".$conf->monnaie).''; - print ''; + // Currency + print ' '.$langs->trans("Currency".$currency).''; + print ''; print ''."\n"; // Tag @@ -380,7 +475,7 @@ if ($_REQUEST["amount"] == 'invoice') } // Payment on contract line -if ($_REQUEST["amount"] == 'contractline') +if ($_REQUEST["source"] == 'contractline') { $found=true; $langs->load("contracts"); @@ -444,6 +539,7 @@ if ($_REQUEST["amount"] == 'contractline') exit; } } + if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"]; $newtag='CLR='.$contractline->ref.'.CR='.$contract->ref.'.TPID='.$contract->client->id.'.TP='.strtr($contract->client->nom,"-"," "); if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; } @@ -522,8 +618,9 @@ if ($_REQUEST["amount"] == 'contractline') print ''.price($amount).''; print ''; } - print ' '.$langs->trans("Currency".$conf->monnaie).''; - print ''; + // Currency + print ' '.$langs->trans("Currency".$currency).''; + print ''; print ''."\n"; // Tag @@ -543,7 +640,7 @@ if ($_REQUEST["amount"] == 'contractline') } // Payment on member subscription -if ($_REQUEST["amount"] == 'membersubscription') +if ($_REQUEST["source"] == 'membersubscription') { $found=true; $langs->load("members"); @@ -564,6 +661,7 @@ if ($_REQUEST["amount"] == 'membersubscription') } $amount=$subscription->total_ttc; + if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"]; $newtag='MID='.$member->id.'.M='.strtr($member->getFullName($langs),"-"," "); if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; } @@ -597,8 +695,9 @@ if ($_REQUEST["amount"] == 'membersubscription') print ''.price($amount).''; print ''; } - print ' '.$langs->trans("Currency".$conf->monnaie).''; - print ''; + // Currency + print ' '.$langs->trans("Currency".$currency).''; + print ''; print ''."\n"; // Tag @@ -627,8 +726,16 @@ print ''; if ($found && ! $error) // We are in a management option and no error { - print '
'; - //print ''.$langs->trans("YouWillBeRedirectedOnPayBox").'...'; + 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 '
'; + } } else {