25require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
40 $head[$h][0] = DOL_URL_ROOT.
"/paypal/admin/paypal.php";
41 $head[$h][1] = $langs->trans(
"PayPal");
42 $head[$h][2] =
'paypalaccount';
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;
77 global $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum;
86 $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY =
'integral';
89 $solutionType =
'Sole';
90 $landingPage =
'Billing';
93 $solutionType =
'Mark';
94 $landingPage =
'Login';
98 $solutionType =
'Sole';
99 $landingPage =
'Billing';
103 $solutionType =
'Sole';
104 $landingPage =
'Billing';
107 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");
129 dol_syslog(
"print_paypal_redirect resArray=".var_export($resArray,
true), LOG_DEBUG);
131 $ack = strtoupper($resArray[
"ACK"]);
132 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
133 $token = $resArray[
"TOKEN"];
136 $payPalURL = $API_Url.$token;
137 dol_syslog(
"Redirect to ".$payPalURL, LOG_INFO);
138 header(
"Location: ".$payPalURL);
142 $ErrorCode = urldecode($resArray[
"L_ERRORCODE0"]);
143 $ErrorShortMsg = urldecode($resArray[
"L_SHORTMESSAGE0"]);
144 $ErrorLongMsg = urldecode($resArray[
"L_LONGMESSAGE0"]);
145 $ErrorSeverityCode = urldecode($resArray[
"L_SEVERITYCODE0"]);
147 if ($ErrorCode == 10729) {
148 $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 $mesg = $langs->trans(
'SetExpressCheckoutAPICallFailed').
"<br>\n";
151 $mesg .= $langs->trans(
'DetailedErrorMessage').
": ".$ErrorLongMsg.
"<br>\n";
152 $mesg .= $langs->trans(
'ShortErrorMessage').
": ".$ErrorShortMsg.
"<br>\n";
153 $mesg .= $langs->trans(
'ErrorCode').
": ".$ErrorCode.
"<br>\n";
154 $mesg .= $langs->trans(
'ErrorSeverityCode').
": ".$ErrorSeverityCode.
"<br>\n";
202function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum, $email =
'', $desc =
'')
208 global $conf, $langs, $mysoc;
209 global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
210 global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
214 $nvpstr = $nvpstr.
"&RETURNURL=".urlencode($returnURL);
215 $nvpstr = $nvpstr.
"&CANCELURL=".urlencode($cancelURL);
217 $nvpstr = $nvpstr.
"&ALLOWNOTE=0";
220 $nvpstr = $nvpstr.
"&NOSHIPPING=1";
222 $nvpstr = $nvpstr.
"&NOSHIPPING=0";
224 $nvpstr = $nvpstr.
"&SOLUTIONTYPE=".urlencode($solutionType);
225 $nvpstr = $nvpstr.
"&LANDINGPAGE=".urlencode($landingPage);
227 $nvpstr = $nvpstr.
"&CUSTOMERSERVICENUMBER=".urlencode(
getDolGlobalString(
'PAYPAL_CUSTOMER_SERVICE_NUMBER'));
230 $paypalprefix =
'PAYMENTREQUEST_0_';
232 if (!empty($paypalprefix) && $paymentType ==
'Sole') {
233 $paymentType =
'Sale';
236 $nvpstr = $nvpstr.
"&AMT=".urlencode((
string) ($paymentAmount));
238 $nvpstr = $nvpstr.
"&".$paypalprefix.
"INVNUM=".urlencode($tag);
239 $nvpstr = $nvpstr.
"&".$paypalprefix.
"AMT=".urlencode((
string) ($paymentAmount));
240 $nvpstr = $nvpstr.
"&".$paypalprefix.
"ITEMAMT=".urlencode((
string) ($paymentAmount));
241 $nvpstr = $nvpstr.
"&".$paypalprefix.
"PAYMENTACTION=".urlencode($paymentType);
242 $nvpstr = $nvpstr.
"&".$paypalprefix.
"CURRENCYCODE=".urlencode($currencyCodeType);
244 $nvpstr = $nvpstr.
"&".$paypalprefix.
"L_PAYMENTREQUEST_0_QTY0=1";
245 $nvpstr = $nvpstr.
"&".$paypalprefix.
"L_PAYMENTREQUEST_0_AMT0=".urlencode((
string) ($paymentAmount));
246 $nvpstr = $nvpstr.
"&".$paypalprefix.
"L_PAYMENTREQUEST_0_NAME0=".urlencode($desc);
247 $nvpstr = $nvpstr.
"&".$paypalprefix.
"L_PAYMENTREQUEST_0_NUMBER0=0";
249 $nvpstr = $nvpstr.
"&".$paypalprefix.
"SHIPTONAME=".urlencode($shipToName);
250 $nvpstr = $nvpstr.
"&".$paypalprefix.
"SHIPTOSTREET=".urlencode($shipToStreet);
251 $nvpstr = $nvpstr.
"&".$paypalprefix.
"SHIPTOSTREET2=".urlencode($shipToStreet2);
252 $nvpstr = $nvpstr.
"&".$paypalprefix.
"SHIPTOCITY=".urlencode($shipToCity);
253 $nvpstr = $nvpstr.
"&".$paypalprefix.
"SHIPTOSTATE=".urlencode($shipToState);
254 $nvpstr = $nvpstr.
"&".$paypalprefix.
"SHIPTOCOUNTRYCODE=".urlencode($shipToCountryCode);
255 $nvpstr = $nvpstr.
"&".$paypalprefix.
"SHIPTOZIP=".urlencode($shipToZip);
256 $nvpstr = $nvpstr.
"&".$paypalprefix.
"PHONENUM=".urlencode($phoneNum);
257 if (!empty($email)) {
258 $nvpstr = $nvpstr.
"&".$paypalprefix.
"EMAIL=".urlencode($email);
261 $nvpstr = $nvpstr.
"&".$paypalprefix.
"DESC=".urlencode($desc);
265 global $dolibarr_main_url_root;
268 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
269 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
272 $urllogo = $urlwithroot.
"/viewimage.php?modulepart=mycompany&file=".urlencode(
'logos/'.$mysoc->logo);
273 $nvpstr = $nvpstr.
"&LOGOIMG=".urlencode($urllogo);
279 $nvpstr = $nvpstr.
"&NOTETOBUYER=".urlencode(
getDolGlobalString(
'PAYPAL_NOTETOBUYER'));
282 $_SESSION[
"FinalPaymentAmt"] = $paymentAmount;
283 $_SESSION[
"currencyCodeType"] = $currencyCodeType;
284 $_SESSION[
"PaymentType"] = $paymentType;
292 $resArray =
hash_call(
"SetExpressCheckout", $nvpstr);
293 $ack = strtoupper($resArray[
"ACK"]);
294 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
295 $token = urldecode($resArray[
"TOKEN"]);
296 $_SESSION[
'TOKEN'] = $token;
320 global $conf, $langs;
321 global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
322 global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
328 $nvpstr =
"&TOKEN=".$token;
336 $resArray =
hash_call(
"GetExpressCheckoutDetails", $nvpstr);
337 $ack = strtoupper($resArray[
"ACK"]);
338 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
339 $_SESSION[
'payer_id'] = $resArray[
'PAYERID'];
357function confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $tag)
365 global $conf, $langs;
366 global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
367 global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
370 $nvpstr .=
'&TOKEN='.urlencode($token);
371 $nvpstr .=
'&PAYERID='.urlencode($payerID);
372 $nvpstr .=
'&PAYMENTACTION='.urlencode($paymentType);
373 $nvpstr .=
'&AMT='.urlencode($FinalPaymentAmt);
374 $nvpstr .=
'&CURRENCYCODE='.urlencode($currencyCodeType);
375 $nvpstr .=
'&IPADDRESS='.urlencode($ipaddress);
376 $nvpstr .=
'&INVNUM='.urlencode($tag);
381 $resArray =
hash_call(
"DoExpressCheckoutPayment", $nvpstr);
387 $ack = strtoupper($resArray[
"ACK"]);
454 global $conf, $langs;
455 global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT, $PROXY_USER, $PROXY_PASS;
456 global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
459 $API_version =
"98.0";
461 $API_Endpoint =
"https://api-3t.sandbox.paypal.com/nvp";
462 $API_Url =
"https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
464 $API_Endpoint =
"https://api-3t.paypal.com/nvp";
465 $API_Url =
"https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
469 $PAYPAL_API_USER =
"";
473 $PAYPAL_API_PASSWORD =
"";
477 $PAYPAL_API_SIGNATURE =
"";
481 $PAYPAL_API_SANDBOX =
"";
487 dol_syslog(
"Paypal API endpoint ".$API_Endpoint);
496 curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
497 curl_setopt($ch, CURLOPT_VERBOSE, 1);
499 curl_setopt($ch, CURLOPT_SSLVERSION, (!
getDolGlobalString(
'PAYPAL_SSLVERSION') ? 1 : $conf->global->PAYPAL_SSLVERSION));
501 $ssl_verifypeer = -1;
504 if ($ssl_verifypeer < 0) {
505 global $dolibarr_main_prod;
506 $ssl_verifypeer = ($dolibarr_main_prod ? true :
false);
513 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, ($ssl_verifypeer ?
true :
false));
514 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, ($ssl_verifypeer ?
true :
false));
516 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, !
getDolGlobalString(
'MAIN_USE_CONNECT_TIMEOUT') ? 5 : $conf->global->MAIN_USE_CONNECT_TIMEOUT);
517 curl_setopt($ch, CURLOPT_TIMEOUT, !
getDolGlobalString(
'MAIN_USE_RESPONSE_TIMEOUT') ? 30 : $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
519 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
520 curl_setopt($ch, CURLOPT_POST, 1);
524 dol_syslog(
"Paypal API hash_call set proxy to ".$PROXY_HOST.
":".$PROXY_PORT.
" - ".$PROXY_USER.
":".$PROXY_PASS);
526 curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST.
":".$PROXY_PORT);
528 curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER.
":".$PROXY_PASS);
533 $nvpreq =
"METHOD=".urlencode($methodName).
"&VERSION=".urlencode($API_version).
"&PWD=".urlencode($PAYPAL_API_PASSWORD).
"&USER=".urlencode($PAYPAL_API_USER).
"&SIGNATURE=".urlencode($PAYPAL_API_SIGNATURE).$nvpStr;
534 $nvpreq .=
"&LOCALECODE=".strtoupper($langs->getDefaultLang(1));
539 dol_syslog(
"Paypal API hash_call nvpreq=".$nvpreq);
542 curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
545 $response = curl_exec($ch);
548 $_SESSION[
'nvpReqArray'] = $nvpReqArray;
551 dol_syslog(
"Paypal API hash_call Response nvpresp=".$response);
554 if (curl_errno($ch)) {
556 $_SESSION[
'curl_error_no'] = curl_errno($ch);
557 $_SESSION[
'curl_error_msg'] = curl_error($ch);
581 while (strlen($nvpstr)) {
583 $keypos = strpos($nvpstr,
'=');
585 $valuepos = strpos($nvpstr,
'&') ? strpos($nvpstr,
'&') : strlen($nvpstr);
588 $keyval = substr($nvpstr, $initial, $keypos);
589 $valval = substr($nvpstr, $keypos + 1, $valuepos - $keypos - 1);
591 $nvpArray[urldecode($keyval)] = urldecode($valval);
592 $nvpstr = substr($nvpstr, $valuepos + 1, strlen($nvpstr));
606 $resArray = $_SESSION[
'reshash'];
608 if (isset($_SESSION[
'curl_error_no'])) {
609 $errors[] = $_SESSION[
'curl_error_no'].
'-'.$_SESSION[
'curl_error_msg'];
612 foreach ($resArray as $key => $value) {
613 $errors[] = $key.
'-'.$value;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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 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.
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.