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