27require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
42 $head[$h][0] = DOL_URL_ROOT.
"/paypal/admin/paypal.php";
43 $head[$h][1] = $langs->trans(
"PayPal");
44 $head[$h][2] =
'paypalaccount';
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;
79 global $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum;
88 $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY =
'integral';
91 $solutionType =
'Sole';
92 $landingPage =
'Billing';
95 $solutionType =
'Mark';
96 $landingPage =
'Login';
100 $solutionType =
'Sole';
101 $landingPage =
'Billing';
105 $solutionType =
'Sole';
106 $landingPage =
'Billing';
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");
131 dol_syslog(
"print_paypal_redirect resArray=".var_export($resArray,
true), LOG_DEBUG);
133 $ack = strtoupper($resArray[
"ACK"]);
134 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
135 $token = $resArray[
"TOKEN"];
138 $payPalURL = $API_Url.$token;
139 dol_syslog(
"Redirect to ".$payPalURL, LOG_INFO);
140 header(
"Location: ".$payPalURL);
144 $ErrorCode = urldecode($resArray[
"L_ERRORCODE0"]);
145 $ErrorShortMsg = urldecode($resArray[
"L_SHORTMESSAGE0"]);
146 $ErrorLongMsg = urldecode($resArray[
"L_LONGMESSAGE0"]);
147 $ErrorSeverityCode = urldecode($resArray[
"L_SEVERITYCODE0"]);
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";
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";
204function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum, $email =
'', $desc =
'')
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;
216 $nvpstr = $nvpstr.
"&RETURNURL=".urlencode($returnURL);
217 $nvpstr = $nvpstr.
"&CANCELURL=".urlencode($cancelURL);
219 $nvpstr .=
"&ALLOWNOTE=0";
222 $nvpstr .=
"&NOSHIPPING=1";
224 $nvpstr .=
"&NOSHIPPING=0";
226 $nvpstr .=
"&SOLUTIONTYPE=".urlencode($solutionType);
227 $nvpstr .=
"&LANDINGPAGE=".urlencode($landingPage);
229 $nvpstr .=
"&CUSTOMERSERVICENUMBER=".urlencode(
getDolGlobalString(
'PAYPAL_CUSTOMER_SERVICE_NUMBER'));
232 $paypalprefix =
'PAYMENTREQUEST_0_';
234 if (!empty($paypalprefix) && $paymentType ==
'Sole') {
235 $paymentType =
'Sale';
238 $nvpstr = $nvpstr.
"&AMT=".urlencode((
string) ($paymentAmount));
240 $nvpstr = $nvpstr.
"&".$paypalprefix.
"INVNUM=".urlencode($tag);
241 $nvpstr = $nvpstr.
"&".$paypalprefix.
"AMT=".urlencode((
string) ($paymentAmount));
242 $nvpstr = $nvpstr.
"&".$paypalprefix.
"ITEMAMT=".urlencode((
string) ($paymentAmount));
243 $nvpstr = $nvpstr.
"&".$paypalprefix.
"PAYMENTACTION=".urlencode($paymentType);
244 $nvpstr = $nvpstr.
"&".$paypalprefix.
"CURRENCYCODE=".urlencode($currencyCodeType);
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";
251 $nvpstr = $nvpstr.
"&".$paypalprefix.
"SHIPTONAME=".urlencode($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);
263 $nvpstr = $nvpstr.
"&".$paypalprefix.
"DESC=".urlencode($desc);
267 global $dolibarr_main_url_root;
270 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
271 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
274 $urllogo = $urlwithroot.
"/viewimage.php?modulepart=mycompany&file=".urlencode(
'logos/'.$mysoc->logo);
275 $nvpstr = $nvpstr.
"&LOGOIMG=".urlencode($urllogo);
281 $nvpstr = $nvpstr.
"&NOTETOBUYER=".urlencode(
getDolGlobalString(
'PAYPAL_NOTETOBUYER'));
284 $_SESSION[
"FinalPaymentAmt"] = $paymentAmount;
285 $_SESSION[
"currencyCodeType"] = $currencyCodeType;
286 $_SESSION[
"PaymentType"] = $paymentType;
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;
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;
330 $nvpstr =
"&TOKEN=".$token;
338 $resArray =
hash_call(
"GetExpressCheckoutDetails", $nvpstr);
339 $ack = strtoupper($resArray[
"ACK"]);
340 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
341 $_SESSION[
'payer_id'] = $resArray[
'PAYERID'];
359function confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $tag)
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;
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);
383 $resArray =
hash_call(
"DoExpressCheckoutPayment", $nvpstr);
389 $ack = strtoupper($resArray[
"ACK"]);
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;
461 $API_version =
"98.0";
463 $API_Endpoint =
"https://api-3t.sandbox.paypal.com/nvp";
464 $API_Url =
"https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
466 $API_Endpoint =
"https://api-3t.paypal.com/nvp";
467 $API_Url =
"https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
477 dol_syslog(
"Paypal API endpoint ".$API_Endpoint);
486 curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
487 curl_setopt($ch, CURLOPT_VERBOSE, 1);
489 curl_setopt($ch, CURLOPT_SSLVERSION, (!
getDolGlobalString(
'PAYPAL_SSLVERSION') ? 1 :
$conf->global->PAYPAL_SSLVERSION));
491 $ssl_verifypeer = -1;
494 if ($ssl_verifypeer < 0) {
495 global $dolibarr_main_prod;
496 $ssl_verifypeer = ($dolibarr_main_prod ? true :
false);
503 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, ($ssl_verifypeer ?
true :
false));
504 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, ($ssl_verifypeer ?
true :
false));
506 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,
getDolGlobalInt(
'MAIN_USE_CONNECT_TIMEOUT', 5));
507 curl_setopt($ch, CURLOPT_TIMEOUT,
getDolGlobalInt(
'MAIN_USE_RESPONSE_TIMEOUT', 30));
509 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
510 curl_setopt($ch, CURLOPT_POST, 1);
514 dol_syslog(
"Paypal API hash_call set proxy to ".$PROXY_HOST.
":".$PROXY_PORT.
" - ".$PROXY_USER.
":".$PROXY_PASS);
516 curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST.
":".$PROXY_PORT);
518 curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER.
":".$PROXY_PASS);
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));
529 dol_syslog(
"Paypal API hash_call nvpreq=".$nvpreq);
532 curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
535 $response = curl_exec($ch);
538 $_SESSION[
'nvpReqArray'] = $nvpReqArray;
541 dol_syslog(
"Paypal API hash_call Response nvpresp=".$response);
544 if (curl_errno($ch)) {
546 $_SESSION[
'curl_error_no'] = curl_errno($ch);
547 $_SESSION[
'curl_error_msg'] = curl_error($ch);
571 while (strlen($nvpstr)) {
573 $keypos = strpos($nvpstr,
'=');
575 $valuepos = strpos($nvpstr,
'&') ? strpos($nvpstr,
'&') : strlen($nvpstr);
578 $keyval = substr($nvpstr, $initial, $keypos);
579 $valval = substr($nvpstr, $keypos + 1, $valuepos - $keypos - 1);
581 $nvpArray[urldecode($keyval)] = urldecode($valval);
582 $nvpstr = substr($nvpstr, $valuepos + 1, strlen($nvpstr));
596 $resArray = $_SESSION[
'reshash'];
598 if (isset($_SESSION[
'curl_error_no'])) {
599 $errors[] = $_SESSION[
'curl_error_no'].
'-'.$_SESSION[
'curl_error_msg'];
602 foreach ($resArray as $key => $value) {
603 $errors[] = $key.
'-'.$value;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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...
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.