dolibarr 21.0.0-beta
paypal.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2011-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
27
28
35{
36 global $langs, $conf;
37
38 $h = 0;
39 $head = array();
40
41 $head[$h][0] = DOL_URL_ROOT."/paypal/admin/paypal.php";
42 $head[$h][1] = $langs->trans("PayPal");
43 $head[$h][2] = 'paypalaccount';
44 $h++;
45
46 $object = new stdClass();
47
48 // Show more tabs from modules
49 // Entries must be declared in modules descriptor with line
50 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
51 // $this->tabs = array('entity:-tabname); to remove a tab
52 complete_head_from_modules($conf, $langs, $object, $head, $h, 'paypaladmin');
53
54 complete_head_from_modules($conf, $langs, $object, $head, $h, 'paypaladmin', 'remove');
55
56 return $head;
57}
58
59
71function print_paypal_redirect($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag)
72{
73 //declaring of global variables
74 global $conf, $langs;
75 global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
76 global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
77
78 global $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum;
79 global $email, $desc;
80
81 //'------------------------------------
82 //' Calls the SetExpressCheckout API call
83 //'
84 //'-------------------------------------------------
85
86 if (!getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY')) {
87 $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY = 'integral';
88 }
89
90 $solutionType = 'Sole';
91 $landingPage = 'Billing';
92 // For payment with Paypal only
93 if (getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY') == 'paypalonly') {
94 $solutionType = 'Mark';
95 $landingPage = 'Login';
96 }
97 // For payment with Credit card or Paypal
98 if (getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY') == 'integral') {
99 $solutionType = 'Sole';
100 $landingPage = 'Billing';
101 }
102 // For payment with Credit card
103 if (getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY') == 'cconly') {
104 $solutionType = 'Sole';
105 $landingPage = 'Billing';
106 }
107
108 dol_syslog("print_paypal_redirect expresscheckout redirect with callSetExpressCheckout $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum");
109 $resArray = callSetExpressCheckout(
110 $paymentAmount,
111 $currencyCodeType,
112 $paymentType,
113 $returnURL,
114 $cancelURL,
115 $tag,
116 $solutionType,
117 $landingPage,
118 $shipToName,
119 $shipToStreet,
120 $shipToCity,
121 $shipToState,
122 $shipToCountryCode,
123 $shipToZip,
124 $shipToStreet2,
125 $phoneNum,
126 $email,
127 $desc
128 );
129
130 dol_syslog("print_paypal_redirect resArray=".var_export($resArray, true), LOG_DEBUG);
131
132 $ack = strtoupper($resArray["ACK"]);
133 if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
134 $token = $resArray["TOKEN"];
135
136 // Redirect to paypal.com here
137 $payPalURL = $API_Url.$token;
138 dol_syslog("Redirect to ".$payPalURL, LOG_INFO);
139 header("Location: ".$payPalURL);
140 exit;
141 } else {
142 //Display a user friendly Error on the page using any of the following error information returned by PayPal
143 $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
144 $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
145 $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
146 $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
147
148 if ($ErrorCode == 10729) {
149 $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";
150 } else {
151 $mesg = $langs->trans('SetExpressCheckoutAPICallFailed')."<br>\n";
152 $mesg .= $langs->trans('DetailedErrorMessage').": ".$ErrorLongMsg."<br>\n";
153 $mesg .= $langs->trans('ShortErrorMessage').": ".$ErrorShortMsg."<br>\n";
154 $mesg .= $langs->trans('ErrorCode').": ".$ErrorCode."<br>\n";
155 $mesg .= $langs->trans('ErrorSeverityCode').": ".$ErrorSeverityCode."<br>\n";
156 }
157
158 return $mesg;
159 }
160}
161
203function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum, $email = '', $desc = '')
204{
205 //------------------------------------------------------------------------------------------------------------------------------------
206 // Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
207
208 //declaring of global variables
209 global $conf, $langs, $mysoc;
210 global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
211 global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
212
213 $nvpstr = '';
214 //$nvpstr = $nvpstr . "&VERSION=".$API_version; // Already added by hash_call
215 $nvpstr = $nvpstr."&RETURNURL=".urlencode($returnURL);
216 $nvpstr = $nvpstr."&CANCELURL=".urlencode($cancelURL);
217 if (getDolGlobalString('PAYPAL_ALLOW_NOTES')) {
218 $nvpstr .= "&ALLOWNOTE=0";
219 }
220 if (!getDolGlobalString('PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS')) {
221 $nvpstr .= "&NOSHIPPING=1"; // An empty or not complete shipping address will be accepted
222 } else {
223 $nvpstr .= "&NOSHIPPING=0"; // A valid shipping address is required (full required fields mandatory)
224 }
225 $nvpstr .= "&SOLUTIONTYPE=".urlencode($solutionType);
226 $nvpstr .= "&LANDINGPAGE=".urlencode($landingPage);
227 if (getDolGlobalString('PAYPAL_CUSTOMER_SERVICE_NUMBER')) {
228 $nvpstr .= "&CUSTOMERSERVICENUMBER=".urlencode(getDolGlobalString('PAYPAL_CUSTOMER_SERVICE_NUMBER')); // Hotline phone number
229 }
230
231 $paypalprefix = 'PAYMENTREQUEST_0_';
232 //$paypalprefix = '';
233 if (!empty($paypalprefix) && $paymentType == 'Sole') {
234 $paymentType = 'Sale';
235 }
236
237 $nvpstr = $nvpstr."&AMT=".urlencode((string) ($paymentAmount)); // Total for all elements
238
239 $nvpstr = $nvpstr."&".$paypalprefix."INVNUM=".urlencode($tag);
240 $nvpstr = $nvpstr."&".$paypalprefix."AMT=".urlencode((string) ($paymentAmount)); // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
241 $nvpstr = $nvpstr."&".$paypalprefix."ITEMAMT=".urlencode((string) ($paymentAmount)); // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
242 $nvpstr = $nvpstr."&".$paypalprefix."PAYMENTACTION=".urlencode($paymentType); // PAYMENTACTION deprecated by paypal -> PAYMENTREQUEST_n_PAYMENTACTION
243 $nvpstr = $nvpstr."&".$paypalprefix."CURRENCYCODE=".urlencode($currencyCodeType); // CURRENCYCODE deprecated by paypal -> PAYMENTREQUEST_n_CURRENCYCODE
244
245 $nvpstr = $nvpstr."&".$paypalprefix."L_PAYMENTREQUEST_0_QTY0=1";
246 $nvpstr = $nvpstr."&".$paypalprefix."L_PAYMENTREQUEST_0_AMT0=".urlencode((string) ($paymentAmount));
247 $nvpstr = $nvpstr."&".$paypalprefix."L_PAYMENTREQUEST_0_NAME0=".urlencode($desc);
248 $nvpstr = $nvpstr."&".$paypalprefix."L_PAYMENTREQUEST_0_NUMBER0=0";
249
250 $nvpstr = $nvpstr."&".$paypalprefix."SHIPTONAME=".urlencode($shipToName); // SHIPTONAME deprecated by paypal -> PAYMENTREQUEST_n_SHIPTONAME
251 $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOSTREET=".urlencode($shipToStreet); //
252 $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOSTREET2=".urlencode($shipToStreet2);
253 $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOCITY=".urlencode($shipToCity);
254 $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOSTATE=".urlencode($shipToState);
255 $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOCOUNTRYCODE=".urlencode($shipToCountryCode);
256 $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOZIP=".urlencode($shipToZip);
257 $nvpstr = $nvpstr."&".$paypalprefix."PHONENUM=".urlencode($phoneNum);
258 if (!empty($email)) {
259 $nvpstr = $nvpstr."&".$paypalprefix."EMAIL=".urlencode($email); // EMAIL deprecated by paypal -> PAYMENTREQUEST_n_EMAIL
260 }
261 if (!empty($desc)) {
262 $nvpstr = $nvpstr."&".$paypalprefix."DESC=".urlencode($desc); // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
263 }
264
265 if (getDolGlobalString('PAYPAL_LOGOIMG') && $mysoc->logo) {
266 global $dolibarr_main_url_root;
267
268 // Define $urlwithroot
269 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
270 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
271 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
272
273 $urllogo = $urlwithroot."/viewimage.php?modulepart=mycompany&file=".urlencode('logos/'.$mysoc->logo);
274 $nvpstr = $nvpstr."&LOGOIMG=".urlencode($urllogo);
275 }
276 if (getDolGlobalString('PAYPAL_BRANDNAME')) {
277 $nvpstr = $nvpstr."&BRANDNAME=".urlencode(getDolGlobalString('PAYPAL_BRANDNAME')); // BRANDNAME
278 }
279 if (getDolGlobalString('PAYPAL_NOTETOBUYER')) {
280 $nvpstr = $nvpstr."&NOTETOBUYER=".urlencode(getDolGlobalString('PAYPAL_NOTETOBUYER')); // PAYPAL_NOTETOBUYER
281 }
282
283 $_SESSION["FinalPaymentAmt"] = $paymentAmount;
284 $_SESSION["currencyCodeType"] = $currencyCodeType;
285 $_SESSION["PaymentType"] = $paymentType; // 'Mark', 'Sole'
286 $_SESSION['ipaddress'] = getUserRemoteIP(); // Payer ip
287
288 //'---------------------------------------------------------------------------------------------------------------
289 //' Make the API call to PayPal
290 //' If the API call succeeded, then redirect the buyer to PayPal to begin to authorize payment.
291 //' If an error occurred, show the resulting errors
292 //'---------------------------------------------------------------------------------------------------------------
293 $resArray = hash_call("SetExpressCheckout", $nvpstr);
294 $ack = strtoupper($resArray["ACK"]);
295 if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
296 $token = urldecode($resArray["TOKEN"]);
297 $_SESSION['TOKEN'] = $token;
298 }
299
300 return $resArray;
301}
302
309function getDetails($token)
310{
311 //'--------------------------------------------------------------
312 //' At this point, the buyer has completed authorizing the payment
313 //' at PayPal. The function will call PayPal to obtain the details
314 //' of the authorization, including any shipping information of the
315 //' buyer. Remember, the authorization is not a completed transaction
316 //' at this state - the buyer still needs an additional step to finalize
317 //' the transaction
318 //'--------------------------------------------------------------
319
320 //declaring of global variables
321 global $conf, $langs;
322 global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
323 global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
324
325 //'---------------------------------------------------------------------------
326 //' Build a second API request to PayPal, using the token as the
327 //' ID to get the details on the payment authorization
328 //'---------------------------------------------------------------------------
329 $nvpstr = "&TOKEN=".$token;
330
331 //'---------------------------------------------------------------------------
332 //' Make the API call and store the results in an array.
333 //' If the call was a success, show the authorization details, and provide
334 //' an action to complete the payment.
335 //' If failed, show the error
336 //'---------------------------------------------------------------------------
337 $resArray = hash_call("GetExpressCheckoutDetails", $nvpstr);
338 $ack = strtoupper($resArray["ACK"]);
339 if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
340 $_SESSION['payer_id'] = $resArray['PAYERID'];
341 }
342 return $resArray;
343}
344
345
358function confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $tag)
359{
360 /* Gather the information to make the final call to
361 finalize the PayPal payment. The variable nvpstr
362 holds the name value pairs
363 */
364
365 //declaring of global variables
366 global $conf, $langs;
367 global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
368 global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
369
370 $nvpstr = '';
371 $nvpstr .= '&TOKEN='.urlencode($token);
372 $nvpstr .= '&PAYERID='.urlencode($payerID);
373 $nvpstr .= '&PAYMENTACTION='.urlencode($paymentType);
374 $nvpstr .= '&AMT='.urlencode($FinalPaymentAmt);
375 $nvpstr .= '&CURRENCYCODE='.urlencode($currencyCodeType);
376 $nvpstr .= '&IPADDRESS='.urlencode($ipaddress);
377 $nvpstr .= '&INVNUM='.urlencode($tag);
378
379 /* Make the call to PayPal to finalize payment
380 If an error occurred, show the resulting errors
381 */
382 $resArray = hash_call("DoExpressCheckoutPayment", $nvpstr);
383
384 /* Display the API response back to the browser.
385 If the response from PayPal was a success, display the response parameters'
386 If the response was an error, display the errors received using APIError.php.
387 */
388 $ack = strtoupper($resArray["ACK"]);
389
390 return $resArray;
391}
392
412/*
413function DirectPayment($paymentType, $paymentAmount, $creditCardType, $creditCardNumber, $expDate, $cvv2, $firstName, $lastName, $street, $city, $state, $zip, $countryCode, $currencyCode, $tag)
414{
415 //declaring of global variables
416 global $conf, $langs;
417 global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
418 global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
419
420 //Construct the parameter string that describes DoDirectPayment
421 $nvpstr = '';
422 $nvpstr = $nvpstr . "&AMT=" . urlencode($paymentAmount); // deprecated by paypal
423 $nvpstr = $nvpstr . "&CURRENCYCODE=" . urlencode($currencyCode);
424 $nvpstr = $nvpstr . "&PAYMENTACTION=" . urlencode($paymentType); // deprecated by paypal
425 $nvpstr = $nvpstr . "&CREDITCARDTYPE=" . urlencode($creditCardType);
426 $nvpstr = $nvpstr . "&ACCT=" . urlencode($creditCardNumber);
427 $nvpstr = $nvpstr . "&EXPDATE=" . urlencode($expDate);
428 $nvpstr = $nvpstr . "&CVV2=" . urlencode($cvv2);
429 $nvpstr = $nvpstr . "&FIRSTNAME=" . urlencode($firstName);
430 $nvpstr = $nvpstr . "&LASTNAME=" . urlencode($lastName);
431 $nvpstr = $nvpstr . "&STREET=" . urlencode($street);
432 $nvpstr = $nvpstr . "&CITY=" . urlencode($city);
433 $nvpstr = $nvpstr . "&STATE=" . urlencode($state);
434 $nvpstr = $nvpstr . "&COUNTRYCODE=" . urlencode($countryCode);
435 $nvpstr = $nvpstr . "&IPADDRESS=" . getUserRemotIP();
436 $nvpstr = $nvpstr . "&INVNUM=" . urlencode($tag);
437
438 $resArray=hash_call("DoDirectPayment", $nvpstr);
439
440 return $resArray;
441}
442*/
443
444
452function hash_call($methodName, $nvpStr)
453{
454 //declaring of global variables
455 global $conf, $langs;
456 global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT, $PROXY_USER, $PROXY_PASS;
457 global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
458
459 // TODO problem with triggers
460 $API_version = "98.0";
461 if (getDolGlobalString('PAYPAL_API_SANDBOX') || GETPOST('forcesandbox', 'alpha')) { // We can force sand box with param 'forcesandbox'
462 $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
463 $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
464 } else {
465 $API_Endpoint = "https://api-3t.paypal.com/nvp";
466 $API_Url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
467 }
468
469 // Clean parameters
470 $PAYPAL_API_USER = "";
471 if (getDolGlobalString('PAYPAL_API_USER')) {
472 $PAYPAL_API_USER = getDolGlobalString('PAYPAL_API_USER');
473 }
474 $PAYPAL_API_PASSWORD = "";
475 if (getDolGlobalString('PAYPAL_API_PASSWORD')) {
476 $PAYPAL_API_PASSWORD = getDolGlobalString('PAYPAL_API_PASSWORD');
477 }
478 $PAYPAL_API_SIGNATURE = "";
479 if (getDolGlobalString('PAYPAL_API_SIGNATURE')) {
480 $PAYPAL_API_SIGNATURE = getDolGlobalString('PAYPAL_API_SIGNATURE');
481 }
482 $PAYPAL_API_SANDBOX = "";
483 if (getDolGlobalString('PAYPAL_API_SANDBOX')) {
484 $PAYPAL_API_SANDBOX = getDolGlobalString('PAYPAL_API_SANDBOX');
485 }
486 // TODO END problem with triggers
487
488 dol_syslog("Paypal API endpoint ".$API_Endpoint);
489
490 //setting the curl parameters.
491 $ch = curl_init();
492
493 /*print $API_Endpoint."-".$API_version."-".$PAYPAL_API_USER."-".$PAYPAL_API_PASSWORD."-".$PAYPAL_API_SIGNATURE."<br>";
494 print $USE_PROXY."-".$gv_ApiErrorURL."<br>";
495 print $nvpStr;
496 exit;*/
497 curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
498 curl_setopt($ch, CURLOPT_VERBOSE, 1);
499 // TLSv1 by default or change to TLSv1.2 in module configuration
500 curl_setopt($ch, CURLOPT_SSLVERSION, (!getDolGlobalString('PAYPAL_SSLVERSION') ? 1 : $conf->global->PAYPAL_SSLVERSION));
501
502 $ssl_verifypeer = -1;
503
504 // Turning on or off the ssl target certificate
505 if ($ssl_verifypeer < 0) {
506 global $dolibarr_main_prod;
507 $ssl_verifypeer = ($dolibarr_main_prod ? true : false);
508 }
509 if (getDolGlobalString('MAIN_CURL_DISABLE_VERIFYPEER')) {
510 $ssl_verifypeer = 0;
511 }
512
513 //turning off the server and peer verification(TrustManager Concept).
514 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, ($ssl_verifypeer ? true : false));
515 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, ($ssl_verifypeer ? true : false));
516
517 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, !getDolGlobalString('MAIN_USE_CONNECT_TIMEOUT') ? 5 : $conf->global->MAIN_USE_CONNECT_TIMEOUT);
518 curl_setopt($ch, CURLOPT_TIMEOUT, !getDolGlobalString('MAIN_USE_RESPONSE_TIMEOUT') ? 30 : $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
519
520 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
521 curl_setopt($ch, CURLOPT_POST, 1);
522
523 //if USE_PROXY constant set to true in Constants.php, then only proxy will be enabled.
524 if ($USE_PROXY) {
525 dol_syslog("Paypal API hash_call set proxy to ".$PROXY_HOST.":".$PROXY_PORT." - ".$PROXY_USER.":".$PROXY_PASS);
526 //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10
527 curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST.":".$PROXY_PORT);
528 if ($PROXY_USER) {
529 curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER.":".$PROXY_PASS);
530 }
531 }
532
533 //NVPRequest for submitting to server
534 $nvpreq = "METHOD=".urlencode($methodName)."&VERSION=".urlencode($API_version)."&PWD=".urlencode($PAYPAL_API_PASSWORD)."&USER=".urlencode($PAYPAL_API_USER)."&SIGNATURE=".urlencode($PAYPAL_API_SIGNATURE).$nvpStr;
535 $nvpreq .= "&LOCALECODE=".strtoupper($langs->getDefaultLang(1));
536 //$nvpreq.="&BRANDNAME=".urlencode(); // Override merchant name
537 //$nvpreq.="&NOTIFYURL=".urlencode(); // For Instant Payment Notification url
538
539
540 dol_syslog("Paypal API hash_call nvpreq=".$nvpreq);
541
542 //setting the nvpreq as POST FIELD to curl
543 curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
544
545 //getting response from server
546 $response = curl_exec($ch);
547
548 $nvpReqArray = deformatNVP($nvpreq);
549 $_SESSION['nvpReqArray'] = $nvpReqArray;
550
551 //convrting NVPResponse to an Associative Array
552 dol_syslog("Paypal API hash_call Response nvpresp=".$response);
553 $nvpResArray = deformatNVP($response);
554
555 if (curl_errno($ch)) {
556 // moving to display page to display curl errors
557 $_SESSION['curl_error_no'] = curl_errno($ch);
558 $_SESSION['curl_error_msg'] = curl_error($ch);
559
560 //Execute the Error handling module to display errors.
561 } else {
562 //closing the curl
563 curl_close($ch);
564 }
565
566 return $nvpResArray;
567}
568
569
577function deformatNVP($nvpstr)
578{
579 $initial = 0;
580 $nvpArray = array();
581
582 while (strlen($nvpstr)) {
583 //position of Key
584 $keypos = strpos($nvpstr, '=');
585 //position of value
586 $valuepos = strpos($nvpstr, '&') ? strpos($nvpstr, '&') : strlen($nvpstr);
587
588 /*getting the Key and Value values and storing in a Associative Array*/
589 $keyval = substr($nvpstr, $initial, $keypos);
590 $valval = substr($nvpstr, $keypos + 1, $valuepos - $keypos - 1);
591 //decoding the response
592 $nvpArray[urldecode($keyval)] = urldecode($valval);
593 $nvpstr = substr($nvpstr, $valuepos + 1, strlen($nvpstr));
594 }
595 return $nvpArray;
596}
597
603function getApiError()
604{
605 $errors = array();
606
607 $resArray = $_SESSION['reshash'];
608
609 if (isset($_SESSION['curl_error_no'])) {
610 $errors[] = $_SESSION['curl_error_no'].'-'.$_SESSION['curl_error_msg'];
611 }
612
613 foreach ($resArray as $key => $value) {
614 $errors[] = $key.'-'.$value;
615 }
616
617 return $errors;
618}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
getApiError()
Get API errors.
confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $tag)
Validate payment.
deformatNVP($nvpstr)
This function will take NVPString and convert it to an Associative Array and it will decode the respo...
callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum, $email='', $desc='')
hash_call($methodName, $nvpStr)
This function makes a DoDirectPayment API call.
getDetails($token)
Prepares the parameters for the GetExpressCheckoutDetails API Call.
print_paypal_redirect($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag)
Send redirect to paypal to browser.
paypaladmin_prepare_head()
Define head array for tabs of paypal tools setup pages.