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