code syntax paypal paybox directory

This commit is contained in:
Frédéric FRANCE 2021-02-26 15:27:05 +01:00
parent c5ff699b3f
commit be59a70e39
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
5 changed files with 267 additions and 178 deletions

View File

@ -32,55 +32,84 @@ $servicename = 'PayBox';
// Load translation files required by the page
$langs->loadLangs(array('admin', 'other', 'paybox', 'paypal'));
if (!$user->admin)
accessforbidden();
if (!$user->admin) {
accessforbidden();
}
$action = GETPOST('action', 'aZ09');
if ($action == 'setvalue' && $user->admin)
{
if ($action == 'setvalue' && $user->admin) {
$db->begin();
//$result=dolibarr_set_const($db, "PAYBOX_IBS_DEVISE",$_POST["PAYBOX_IBS_DEVISE"],'chaine',0,'',$conf->entity);
$result = dolibarr_set_const($db, "PAYBOX_CGI_URL_V1", GETPOST('PAYBOX_CGI_URL_V1', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYBOX_CGI_URL_V2", GETPOST('PAYBOX_CGI_URL_V2', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYBOX_IBS_SITE", GETPOST('PAYBOX_IBS_SITE', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYBOX_IBS_RANG", GETPOST('PAYBOX_IBS_RANG', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYBOX_PBX_IDENTIFIANT", GETPOST('PAYBOX_PBX_IDENTIFIANT', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
// Payment token for URL
$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYBOX_HMAC_KEY", dol_encode(GETPOST('PAYBOX_HMAC_KEY', 'alpha')), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
if (!$error)
{
$db->commit();
if (!$error) {
$db->commit();
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
$db->rollback();
} else {
$db->rollback();
dol_print_error($db);
}
}
@ -91,11 +120,17 @@ if ($action == 'setvalue' && $user->admin)
*/
$IBS_SITE = "1999888"; // Site test
if (empty($conf->global->PAYBOX_IBS_SITE)) $conf->global->PAYBOX_IBS_SITE = $IBS_SITE;
if (empty($conf->global->PAYBOX_IBS_SITE)) {
$conf->global->PAYBOX_IBS_SITE = $IBS_SITE;
}
$IBS_RANG = "99"; // Rang test
if (empty($conf->global->PAYBOX_IBS_RANG)) $conf->global->PAYBOX_IBS_RANG = $IBS_RANG;
if (empty($conf->global->PAYBOX_IBS_RANG)) {
$conf->global->PAYBOX_IBS_RANG = $IBS_RANG;
}
$IBS_DEVISE = "978"; // Euro
if (empty($conf->global->PAYBOX_IBS_DEVISE)) $conf->global->PAYBOX_IBS_DEVISE = $IBS_DEVISE;
if (empty($conf->global->PAYBOX_IBS_DEVISE)) {
$conf->global->PAYBOX_IBS_DEVISE = $IBS_DEVISE;
}
llxHeader();
@ -191,8 +226,7 @@ print '<br><span class="opacitymedium">'.$langs->trans("Example").': '.$mysoc->n
print '</td></tr>';
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
print '<tr class="oddeven"><td>';
print $langs->trans("BankAccount").'</td><td>';
$form->select_comptes($conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS, 'PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
@ -237,8 +271,9 @@ print '</td></tr>';
print '<tr class="oddeven"><td>';
print $langs->trans("SecurityToken").'</td><td>';
print '<input size="48" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">';
if (!empty($conf->use_javascript_ajax))
if (!empty($conf->use_javascript_ajax)) {
print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
}
print '</td></tr>';
print '<tr class="oddeven"><td>';

View File

@ -44,36 +44,46 @@ function print_paybox_redirect($PRICE, $CURRENCY, $EMAIL, $urlok, $urlko, $TAG)
// Clean parameters
$PBX_IDENTIFIANT = "2"; // Identifiant pour v2 test
if (!empty($conf->global->PAYBOX_PBX_IDENTIFIANT)) $PBX_IDENTIFIANT = $conf->global->PAYBOX_PBX_IDENTIFIANT;
if (!empty($conf->global->PAYBOX_PBX_IDENTIFIANT)) {
$PBX_IDENTIFIANT = $conf->global->PAYBOX_PBX_IDENTIFIANT;
}
$IBS_SITE = "1999888"; // Site test
if (!empty($conf->global->PAYBOX_IBS_SITE)) $IBS_SITE = $conf->global->PAYBOX_IBS_SITE;
if (!empty($conf->global->PAYBOX_IBS_SITE)) {
$IBS_SITE = $conf->global->PAYBOX_IBS_SITE;
}
$IBS_RANG = "99"; // Rang test
if (!empty($conf->global->PAYBOX_IBS_RANG)) $IBS_RANG = $conf->global->PAYBOX_IBS_RANG;
if (!empty($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";
if ($CURRENCY == 'EUR') {
$IBS_DEVISE = "978";
}
if ($CURRENCY == 'USD') {
$IBS_DEVISE = "840";
}
$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 ($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($IBS_DEVISE)) {
dol_print_error('', "Paybox setup param PAYBOX_IBS_DEVISE not defined");
return -1;
}
if (empty($URLPAYBOX))
{
if (empty($URLPAYBOX)) {
dol_print_error('', "Paybox setup param PAYBOX_CGI_URL_V1 and PAYBOX_CGI_URL_V2 undefined");
return -1;
}
if (empty($IBS_SITE))
{
if (empty($IBS_SITE)) {
dol_print_error('', "Paybox setup param PAYBOX_IBS_SITE not defined");
return -1;
}
if (empty($IBS_RANG))
{
if (empty($IBS_RANG)) {
dol_print_error('', "Paybox setup param PAYBOX_IBS_RANG not defined");
return -1;
}
@ -93,12 +103,24 @@ function print_paybox_redirect($PRICE, $CURRENCY, $EMAIL, $urlok, $urlko, $TAG)
$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";
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';

View File

@ -35,43 +35,72 @@ $servicename = 'PayPal';
// Load translation files required by the page
$langs->loadLangs(array('admin', 'other', 'paypal', 'paybox'));
if (!$user->admin) accessforbidden();
if (!$user->admin) {
accessforbidden();
}
$action = GETPOST('action', 'aZ09');
if ($action == 'setvalue' && $user->admin)
{
if ($action == 'setvalue' && $user->admin) {
$db->begin();
$result = dolibarr_set_const($db, "PAYPAL_API_USER", GETPOST('PAYPAL_API_USER', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYPAL_API_PASSWORD", GETPOST('PAYPAL_API_PASSWORD', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYPAL_API_SIGNATURE", GETPOST('PAYPAL_API_SIGNATURE', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYPAL_SSLVERSION", GETPOST('PAYPAL_SSLVERSION', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY", GETPOST('PAYPAL_API_INTEGRAL_OR_PAYPALONLY', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL", GETPOST('PAYPAL_ADD_PAYMENT_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
// Payment token for URL
$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) $error++;
if (!$result > 0) {
$error++;
}
if (empty($conf->use_javascript_ajax)) {
$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
if (!$result > 0) {
@ -80,21 +109,21 @@ if ($action == 'setvalue' && $user->admin)
}
if (!$error) {
$db->commit();
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
$db->rollback();
$db->commit();
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
$db->rollback();
dol_print_error($db);
}
}
if ($action == "setlive")
{
if ($action == "setlive") {
$liveenable = GETPOST('value', 'int') ? 0 : 1;
$res = dolibarr_set_const($db, "PAYPAL_API_SANDBOX", $liveenable, 'yesno', 0, '', $conf->entity);
if (!($res > 0)) $error++;
if (!$error)
{
if (!($res > 0)) {
$error++;
}
if (!$error) {
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
setEventMessages($langs->trans("Error"), null, 'errors');
@ -126,8 +155,7 @@ print dol_get_fiche_head($head, 'paypalaccount', '', -1);
print '<span class="opacitymedium">'.$langs->trans("PaypalDesc")."</span><br>\n";
// Test if php curl exist
if (!function_exists('curl_version'))
{
if (!function_exists('curl_version')) {
$langs->load("errors");
setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
}
@ -147,8 +175,7 @@ print "</tr>\n";
print '<tr class="oddeven">';
print '<td>';
print $langs->trans("PaypalLiveEnabled").'</td><td>';
if (empty($conf->global->PAYPAL_API_SANDBOX))
{
if (empty($conf->global->PAYPAL_API_SANDBOX)) {
print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlive&token='.newToken().'&value=0">';
print img_picto($langs->trans("Activated"), 'switch_on');
} else {
@ -217,8 +244,7 @@ print '<input size="64" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.$con
print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': '.$mysoc->name.'</span>';
print '</td></tr>';
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
print '<tr class="oddeven"><td>';
print $langs->trans("BankAccount").'</td><td>';
print img_picto('', 'bank_account').' ';
@ -315,8 +341,9 @@ print '<br><br>';
// Help doc
print '<u>'.$langs->trans("InformationToFindParameters", "Paypal").'</u>:<br>';
if (!empty($conf->use_javascript_ajax))
if (!empty($conf->use_javascript_ajax)) {
print '<a class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
}
$realpaypalurl = 'www.paypal.com';
$sandboxpaypalurl = 'developer.paypal.com';
@ -334,8 +361,7 @@ print 'Your API authentication information can be found with following steps. We
';
print '</div>';
if (!empty($conf->use_javascript_ajax))
{
if (!empty($conf->use_javascript_ajax)) {
print "\n".'<script type="text/javascript">';
print '$(document).ready(function () {
$("#apidoc").hide();

View File

@ -82,25 +82,24 @@ function print_paypal_redirect($paymentAmount, $currencyCodeType, $paymentType,
//'
//'-------------------------------------------------
if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY = 'integral';
if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) {
$conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY = 'integral';
}
$solutionType = 'Sole';
$landingPage = 'Billing';
// For payment with Paypal only
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly')
{
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly') {
$solutionType = 'Mark';
$landingPage = 'Login';
}
// For payment with Credit card or Paypal
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral')
{
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral') {
$solutionType = 'Sole';
$landingPage = 'Billing';
}
// For payment with Credit card
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'cconly')
{
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'cconly') {
$solutionType = 'Sole';
$landingPage = 'Billing';
}
@ -130,8 +129,7 @@ function print_paypal_redirect($paymentAmount, $currencyCodeType, $paymentType,
dol_syslog("print_paypal_redirect resArray=".var_export($resArray, true), LOG_DEBUG);
$ack = strtoupper($resArray["ACK"]);
if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING")
{
if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
$token = $resArray["TOKEN"];
// Redirect to paypal.com here
@ -146,8 +144,7 @@ function print_paypal_redirect($paymentAmount, $currencyCodeType, $paymentType,
$ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
$ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
if ($ErrorCode == 10729)
{
if ($ErrorCode == 10729) {
$mesg .= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n";
} else {
$mesg = $langs->trans('SetExpressCheckoutAPICallFailed')."<br>\n";
@ -216,26 +213,25 @@ function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType,
//$nvpstr = $nvpstr . "&VERSION=".$API_version; // Already added by hash_call
$nvpstr = $nvpstr."&RETURNURL=".urlencode($returnURL);
$nvpstr = $nvpstr."&CANCELURL=".urlencode($cancelURL);
if (!empty($conf->global->PAYPAL_ALLOW_NOTES))
{
if (!empty($conf->global->PAYPAL_ALLOW_NOTES)) {
$nvpstr = $nvpstr."&ALLOWNOTE=0";
}
if (empty($conf->global->PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS))
{
if (empty($conf->global->PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS)) {
$nvpstr = $nvpstr."&NOSHIPPING=1"; // An empty or not complete shipping address will be accepted
} else {
$nvpstr = $nvpstr."&NOSHIPPING=0"; // A valid shipping address is required (full required fields mandatory)
}
$nvpstr = $nvpstr."&SOLUTIONTYPE=".urlencode($solutionType);
$nvpstr = $nvpstr."&LANDINGPAGE=".urlencode($landingPage);
if (!empty($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER))
{
if (!empty($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER)) {
$nvpstr = $nvpstr."&CUSTOMERSERVICENUMBER=".urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER); // Hotline phone number
}
$paypalprefix = 'PAYMENTREQUEST_0_';
//$paypalprefix = '';
if (!empty($paypalprefix) && $paymentType == 'Sole') $paymentType = 'Sale';
if (!empty($paypalprefix) && $paymentType == 'Sole') {
$paymentType = 'Sale';
}
$nvpstr = $nvpstr."&AMT=".urlencode($paymentAmount); // Total for all elements
@ -258,11 +254,14 @@ function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType,
$nvpstr = $nvpstr."&".$paypalprefix."SHIPTOCOUNTRYCODE=".urlencode($shipToCountryCode);
$nvpstr = $nvpstr."&".$paypalprefix."SHIPTOZIP=".urlencode($shipToZip);
$nvpstr = $nvpstr."&".$paypalprefix."PHONENUM=".urlencode($phoneNum);
if (!empty($email)) $nvpstr = $nvpstr."&".$paypalprefix."EMAIL=".urlencode($email); // EMAIL deprecated by paypal -> PAYMENTREQUEST_n_EMAIL
if (!empty($desc)) $nvpstr = $nvpstr."&".$paypalprefix."DESC=".urlencode($desc); // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
if (!empty($email)) {
$nvpstr = $nvpstr."&".$paypalprefix."EMAIL=".urlencode($email); // EMAIL deprecated by paypal -> PAYMENTREQUEST_n_EMAIL
}
if (!empty($desc)) {
$nvpstr = $nvpstr."&".$paypalprefix."DESC=".urlencode($desc); // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
}
if (!empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo)
{
if (!empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo) {
global $dolibarr_main_url_root;
// Define $urlwithroot
@ -273,12 +272,10 @@ function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType,
$urllogo = $urlwithroot."/viewimage.php?modulepart=mycompany&file=".urlencode('logos/'.$mysoc->logo);
$nvpstr = $nvpstr."&LOGOIMG=".urlencode($urllogo);
}
if (!empty($conf->global->PAYPAL_BRANDNAME))
{
if (!empty($conf->global->PAYPAL_BRANDNAME)) {
$nvpstr = $nvpstr."&BRANDNAME=".urlencode($conf->global->PAYPAL_BRANDNAME); // BRANDNAME
}
if (!empty($conf->global->PAYPAL_NOTETOBUYER))
{
if (!empty($conf->global->PAYPAL_NOTETOBUYER)) {
$nvpstr = $nvpstr."&NOTETOBUYER=".urlencode($conf->global->PAYPAL_NOTETOBUYER); // PAYPAL_NOTETOBUYER
}
@ -294,8 +291,7 @@ function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType,
//'---------------------------------------------------------------------------------------------------------------
$resArray = hash_call("SetExpressCheckout", $nvpstr);
$ack = strtoupper($resArray["ACK"]);
if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING")
{
if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
$token = urldecode($resArray["TOKEN"]);
$_SESSION['TOKEN'] = $token;
}
@ -339,8 +335,7 @@ function getDetails($token)
//'---------------------------------------------------------------------------
$resArray = hash_call("GetExpressCheckoutDetails", $nvpstr);
$ack = strtoupper($resArray["ACK"]);
if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING")
{
if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
$_SESSION['payer_id'] = $resArray['PAYERID'];
}
return $resArray;
@ -362,9 +357,9 @@ function getDetails($token)
function confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $tag)
{
/* Gather the information to make the final call to
finalize the PayPal payment. The variable nvpstr
holds the name value pairs
*/
finalize the PayPal payment. The variable nvpstr
holds the name value pairs
*/
//declaring of global variables
global $conf, $langs;
@ -381,14 +376,14 @@ function confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipad
$nvpstr .= '&INVNUM='.urlencode($tag);
/* Make the call to PayPal to finalize payment
If an error occured, show the resulting errors
*/
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.
*/
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;
@ -416,32 +411,32 @@ function confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipad
/*
function DirectPayment($paymentType, $paymentAmount, $creditCardType, $creditCardNumber, $expDate, $cvv2, $firstName, $lastName, $street, $city, $state, $zip, $countryCode, $currencyCode, $tag)
{
//declaring of global variables
global $conf, $langs;
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
//declaring of global variables
global $conf, $langs;
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
//Construct the parameter string that describes DoDirectPayment
$nvpstr = '';
$nvpstr = $nvpstr . "&AMT=" . urlencode($paymentAmount); // deprecated by paypal
$nvpstr = $nvpstr . "&CURRENCYCODE=" . urlencode($currencyCode);
$nvpstr = $nvpstr . "&PAYMENTACTION=" . urlencode($paymentType); // deprecated by paypal
$nvpstr = $nvpstr . "&CREDITCARDTYPE=" . urlencode($creditCardType);
$nvpstr = $nvpstr . "&ACCT=" . urlencode($creditCardNumber);
$nvpstr = $nvpstr . "&EXPDATE=" . urlencode($expDate);
$nvpstr = $nvpstr . "&CVV2=" . urlencode($cvv2);
$nvpstr = $nvpstr . "&FIRSTNAME=" . urlencode($firstName);
$nvpstr = $nvpstr . "&LASTNAME=" . urlencode($lastName);
$nvpstr = $nvpstr . "&STREET=" . urlencode($street);
$nvpstr = $nvpstr . "&CITY=" . urlencode($city);
$nvpstr = $nvpstr . "&STATE=" . urlencode($state);
$nvpstr = $nvpstr . "&COUNTRYCODE=" . urlencode($countryCode);
$nvpstr = $nvpstr . "&IPADDRESS=" . getUserRemotIP();
$nvpstr = $nvpstr . "&INVNUM=" . urlencode($tag);
//Construct the parameter string that describes DoDirectPayment
$nvpstr = '';
$nvpstr = $nvpstr . "&AMT=" . urlencode($paymentAmount); // deprecated by paypal
$nvpstr = $nvpstr . "&CURRENCYCODE=" . urlencode($currencyCode);
$nvpstr = $nvpstr . "&PAYMENTACTION=" . urlencode($paymentType); // deprecated by paypal
$nvpstr = $nvpstr . "&CREDITCARDTYPE=" . urlencode($creditCardType);
$nvpstr = $nvpstr . "&ACCT=" . urlencode($creditCardNumber);
$nvpstr = $nvpstr . "&EXPDATE=" . urlencode($expDate);
$nvpstr = $nvpstr . "&CVV2=" . urlencode($cvv2);
$nvpstr = $nvpstr . "&FIRSTNAME=" . urlencode($firstName);
$nvpstr = $nvpstr . "&LASTNAME=" . urlencode($lastName);
$nvpstr = $nvpstr . "&STREET=" . urlencode($street);
$nvpstr = $nvpstr . "&CITY=" . urlencode($city);
$nvpstr = $nvpstr . "&STATE=" . urlencode($state);
$nvpstr = $nvpstr . "&COUNTRYCODE=" . urlencode($countryCode);
$nvpstr = $nvpstr . "&IPADDRESS=" . getUserRemotIP();
$nvpstr = $nvpstr . "&INVNUM=" . urlencode($tag);
$resArray=hash_call("DoDirectPayment", $nvpstr);
$resArray=hash_call("DoDirectPayment", $nvpstr);
return $resArray;
return $resArray;
}
*/
@ -462,8 +457,7 @@ function hash_call($methodName, $nvpStr)
// TODO problem with triggers
$API_version = "98.0";
if (!empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox', 'alpha')) // We can force sand box with param 'forcesandbox'
{
if (!empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox', 'alpha')) { // We can force sand box with param 'forcesandbox'
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
$API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
} else {
@ -473,13 +467,21 @@ function hash_call($methodName, $nvpStr)
// Clean parameters
$PAYPAL_API_USER = "";
if (!empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
if (!empty($conf->global->PAYPAL_API_USER)) {
$PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
}
$PAYPAL_API_PASSWORD = "";
if (!empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
if (!empty($conf->global->PAYPAL_API_PASSWORD)) {
$PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
}
$PAYPAL_API_SIGNATURE = "";
if (!empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
if (!empty($conf->global->PAYPAL_API_SIGNATURE)) {
$PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
}
$PAYPAL_API_SANDBOX = "";
if (!empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
if (!empty($conf->global->PAYPAL_API_SANDBOX)) {
$PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
}
// TODO END problem with triggers
dol_syslog("Paypal API endpoint ".$API_Endpoint);
@ -488,9 +490,9 @@ function hash_call($methodName, $nvpStr)
$ch = curl_init();
/*print $API_Endpoint."-".$API_version."-".$PAYPAL_API_USER."-".$PAYPAL_API_PASSWORD."-".$PAYPAL_API_SIGNATURE."<br>";
print $USE_PROXY."-".$gv_ApiErrorURL."<br>";
print $nvpStr;
exit;*/
print $USE_PROXY."-".$gv_ApiErrorURL."<br>";
print $nvpStr;
exit;*/
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// TLSv1 by default or change to TLSv1.2 in module configuration
@ -507,12 +509,13 @@ function hash_call($methodName, $nvpStr)
curl_setopt($ch, CURLOPT_POST, 1);
//if USE_PROXY constant set to true in Constants.php, then only proxy will be enabled.
if ($USE_PROXY)
{
if ($USE_PROXY) {
dol_syslog("Paypal API hash_call set proxy to ".$PROXY_HOST.":".$PROXY_PORT." - ".$PROXY_USER.":".$PROXY_PASS);
//curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10
curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST.":".$PROXY_PORT);
if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER.":".$PROXY_PASS);
if ($PROXY_USER) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER.":".$PROXY_PASS);
}
}
//NVPRequest for submitting to server
@ -564,8 +567,7 @@ function deformatNVP($nvpstr)
$intial = 0;
$nvpArray = array();
while (strlen($nvpstr))
{
while (strlen($nvpstr)) {
//postion of Key
$keypos = strpos($nvpstr, '=');
//position of value
@ -592,13 +594,11 @@ function getApiError()
$resArray = $_SESSION['reshash'];
if (isset($_SESSION['curl_error_no']))
{
if (isset($_SESSION['curl_error_no'])) {
$errors[] = $_SESSION['curl_error_no'].'-'.$_SESSION['curl_error_msg'];
}
foreach ($resArray as $key => $value)
{
foreach ($resArray as $key => $value) {
$errors[] = $key.'-'.$value;
}

View File

@ -22,14 +22,13 @@
* \brief Page with Paypal init var.
*/
if (session_id() == "")
{
if (session_id() == "") {
session_start();
if (ini_get('register_globals')) // To solve bug in using $_SESSION
{
foreach ($_SESSION as $key=>$value)
{
if (isset($GLOBALS[$key])) unset($GLOBALS[$key]);
if (ini_get('register_globals')) { // To solve bug in using $_SESSION
foreach ($_SESSION as $key => $value) {
if (isset($GLOBALS[$key])) {
unset($GLOBALS[$key]);
}
}
}
}
@ -48,8 +47,7 @@ $API_version = "56";
' 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 (!empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox', 'alpha')) // We can force sand box with param 'forcesandbox'
{
if (!empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox', 'alpha')) { // We can force sand box with param 'forcesandbox'
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
$API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
} else {
@ -59,13 +57,21 @@ if (!empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox', 'alpha'
// Clean parameters
$PAYPAL_API_USER = "";
if (!empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
if (!empty($conf->global->PAYPAL_API_USER)) {
$PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
}
$PAYPAL_API_PASSWORD = "";
if (!empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
if (!empty($conf->global->PAYPAL_API_PASSWORD)) {
$PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
}
$PAYPAL_API_SIGNATURE = "";
if (!empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
if (!empty($conf->global->PAYPAL_API_SIGNATURE)) {
$PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
}
$PAYPAL_API_SANDBOX = "";
if (!empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
if (!empty($conf->global->PAYPAL_API_SANDBOX)) {
$PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
}
// Proxy
$PROXY_HOST = $conf->global->MAIN_PROXY_HOST;