26require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
41 $head[$h][0] = DOL_URL_ROOT.
"/paypal/admin/paypal.php";
42 $head[$h][1] = $langs->trans(
"PayPal");
43 $head[$h][2] =
'paypalaccount';
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;
78 global $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum;
87 $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY =
'integral';
90 $solutionType =
'Sole';
91 $landingPage =
'Billing';
94 $solutionType =
'Mark';
95 $landingPage =
'Login';
99 $solutionType =
'Sole';
100 $landingPage =
'Billing';
104 $solutionType =
'Sole';
105 $landingPage =
'Billing';
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");
130 dol_syslog(
"print_paypal_redirect resArray=".var_export($resArray,
true), LOG_DEBUG);
132 $ack = strtoupper($resArray[
"ACK"]);
133 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
134 $token = $resArray[
"TOKEN"];
137 $payPalURL = $API_Url.$token;
138 dol_syslog(
"Redirect to ".$payPalURL, LOG_INFO);
139 header(
"Location: ".$payPalURL);
143 $ErrorCode = urldecode($resArray[
"L_ERRORCODE0"]);
144 $ErrorShortMsg = urldecode($resArray[
"L_SHORTMESSAGE0"]);
145 $ErrorLongMsg = urldecode($resArray[
"L_LONGMESSAGE0"]);
146 $ErrorSeverityCode = urldecode($resArray[
"L_SEVERITYCODE0"]);
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";
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";
203function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum, $email =
'', $desc =
'')
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;
215 $nvpstr = $nvpstr.
"&RETURNURL=".urlencode($returnURL);
216 $nvpstr = $nvpstr.
"&CANCELURL=".urlencode($cancelURL);
218 $nvpstr .=
"&ALLOWNOTE=0";
221 $nvpstr .=
"&NOSHIPPING=1";
223 $nvpstr .=
"&NOSHIPPING=0";
225 $nvpstr .=
"&SOLUTIONTYPE=".urlencode($solutionType);
226 $nvpstr .=
"&LANDINGPAGE=".urlencode($landingPage);
228 $nvpstr .=
"&CUSTOMERSERVICENUMBER=".urlencode(
getDolGlobalString(
'PAYPAL_CUSTOMER_SERVICE_NUMBER'));
231 $paypalprefix =
'PAYMENTREQUEST_0_';
233 if (!empty($paypalprefix) && $paymentType ==
'Sole') {
234 $paymentType =
'Sale';
237 $nvpstr = $nvpstr.
"&AMT=".urlencode((
string) ($paymentAmount));
239 $nvpstr = $nvpstr.
"&".$paypalprefix.
"INVNUM=".urlencode($tag);
240 $nvpstr = $nvpstr.
"&".$paypalprefix.
"AMT=".urlencode((
string) ($paymentAmount));
241 $nvpstr = $nvpstr.
"&".$paypalprefix.
"ITEMAMT=".urlencode((
string) ($paymentAmount));
242 $nvpstr = $nvpstr.
"&".$paypalprefix.
"PAYMENTACTION=".urlencode($paymentType);
243 $nvpstr = $nvpstr.
"&".$paypalprefix.
"CURRENCYCODE=".urlencode($currencyCodeType);
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";
250 $nvpstr = $nvpstr.
"&".$paypalprefix.
"SHIPTONAME=".urlencode($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);
262 $nvpstr = $nvpstr.
"&".$paypalprefix.
"DESC=".urlencode($desc);
266 global $dolibarr_main_url_root;
269 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
270 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
273 $urllogo = $urlwithroot.
"/viewimage.php?modulepart=mycompany&file=".urlencode(
'logos/'.$mysoc->logo);
274 $nvpstr = $nvpstr.
"&LOGOIMG=".urlencode($urllogo);
280 $nvpstr = $nvpstr.
"&NOTETOBUYER=".urlencode(
getDolGlobalString(
'PAYPAL_NOTETOBUYER'));
283 $_SESSION[
"FinalPaymentAmt"] = $paymentAmount;
284 $_SESSION[
"currencyCodeType"] = $currencyCodeType;
285 $_SESSION[
"PaymentType"] = $paymentType;
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;
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;
329 $nvpstr =
"&TOKEN=".$token;
337 $resArray =
hash_call(
"GetExpressCheckoutDetails", $nvpstr);
338 $ack = strtoupper($resArray[
"ACK"]);
339 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
340 $_SESSION[
'payer_id'] = $resArray[
'PAYERID'];
358function confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $tag)
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;
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);
382 $resArray =
hash_call(
"DoExpressCheckoutPayment", $nvpstr);
388 $ack = strtoupper($resArray[
"ACK"]);
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;
460 $API_version =
"98.0";
462 $API_Endpoint =
"https://api-3t.sandbox.paypal.com/nvp";
463 $API_Url =
"https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
465 $API_Endpoint =
"https://api-3t.paypal.com/nvp";
466 $API_Url =
"https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
470 $PAYPAL_API_USER =
"";
474 $PAYPAL_API_PASSWORD =
"";
478 $PAYPAL_API_SIGNATURE =
"";
482 $PAYPAL_API_SANDBOX =
"";
488 dol_syslog(
"Paypal API endpoint ".$API_Endpoint);
497 curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
498 curl_setopt($ch, CURLOPT_VERBOSE, 1);
500 curl_setopt($ch, CURLOPT_SSLVERSION, (!
getDolGlobalString(
'PAYPAL_SSLVERSION') ? 1 : $conf->global->PAYPAL_SSLVERSION));
502 $ssl_verifypeer = -1;
505 if ($ssl_verifypeer < 0) {
506 global $dolibarr_main_prod;
507 $ssl_verifypeer = ($dolibarr_main_prod ? true :
false);
514 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, ($ssl_verifypeer ?
true :
false));
515 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, ($ssl_verifypeer ?
true :
false));
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);
520 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
521 curl_setopt($ch, CURLOPT_POST, 1);
525 dol_syslog(
"Paypal API hash_call set proxy to ".$PROXY_HOST.
":".$PROXY_PORT.
" - ".$PROXY_USER.
":".$PROXY_PASS);
527 curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST.
":".$PROXY_PORT);
529 curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER.
":".$PROXY_PASS);
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));
540 dol_syslog(
"Paypal API hash_call nvpreq=".$nvpreq);
543 curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
546 $response = curl_exec($ch);
549 $_SESSION[
'nvpReqArray'] = $nvpReqArray;
552 dol_syslog(
"Paypal API hash_call Response nvpresp=".$response);
555 if (curl_errno($ch)) {
557 $_SESSION[
'curl_error_no'] = curl_errno($ch);
558 $_SESSION[
'curl_error_msg'] = curl_error($ch);
582 while (strlen($nvpstr)) {
584 $keypos = strpos($nvpstr,
'=');
586 $valuepos = strpos($nvpstr,
'&') ? strpos($nvpstr,
'&') : strlen($nvpstr);
589 $keyval = substr($nvpstr, $initial, $keypos);
590 $valval = substr($nvpstr, $keypos + 1, $valuepos - $keypos - 1);
592 $nvpArray[urldecode($keyval)] = urldecode($valval);
593 $nvpstr = substr($nvpstr, $valuepos + 1, strlen($nvpstr));
607 $resArray = $_SESSION[
'reshash'];
609 if (isset($_SESSION[
'curl_error_no'])) {
610 $errors[] = $_SESSION[
'curl_error_no'].
'-'.$_SESSION[
'curl_error_msg'];
613 foreach ($resArray as $key => $value) {
614 $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 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.
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.