40 $head[$h][0] = DOL_URL_ROOT.
"/paypal/admin/paypal.php";
41 $head[$h][1] = $langs->trans(
"PayPal");
42 $head[$h][2] =
'paypalaccount';
45 $object =
new stdClass();
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;
85 if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) {
86 $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY =
'integral';
89 $solutionType =
'Sole';
90 $landingPage =
'Billing';
92 if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY ==
'paypalonly') {
93 $solutionType =
'Mark';
94 $landingPage =
'Login';
97 if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY ==
'integral') {
98 $solutionType =
'Sole';
99 $landingPage =
'Billing';
102 if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY ==
'cconly') {
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);
216 if (!empty($conf->global->PAYPAL_ALLOW_NOTES)) {
217 $nvpstr = $nvpstr.
"&ALLOWNOTE=0";
219 if (empty($conf->global->PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS)) {
220 $nvpstr = $nvpstr.
"&NOSHIPPING=1";
222 $nvpstr = $nvpstr.
"&NOSHIPPING=0";
224 $nvpstr = $nvpstr.
"&SOLUTIONTYPE=".urlencode($solutionType);
225 $nvpstr = $nvpstr.
"&LANDINGPAGE=".urlencode($landingPage);
226 if (!empty($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER)) {
227 $nvpstr = $nvpstr.
"&CUSTOMERSERVICENUMBER=".urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER);
230 $paypalprefix =
'PAYMENTREQUEST_0_';
232 if (!empty($paypalprefix) && $paymentType ==
'Sole') {
233 $paymentType =
'Sale';
236 $nvpstr = $nvpstr.
"&AMT=".urlencode($paymentAmount);
238 $nvpstr = $nvpstr.
"&".$paypalprefix.
"INVNUM=".urlencode($tag);
239 $nvpstr = $nvpstr.
"&".$paypalprefix.
"AMT=".urlencode($paymentAmount);
240 $nvpstr = $nvpstr.
"&".$paypalprefix.
"ITEMAMT=".urlencode($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($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);
264 if (!empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo) {
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);
275 if (!empty($conf->global->PAYPAL_BRANDNAME)) {
276 $nvpstr = $nvpstr.
"&BRANDNAME=".urlencode($conf->global->PAYPAL_BRANDNAME);
278 if (!empty($conf->global->PAYPAL_NOTETOBUYER)) {
279 $nvpstr = $nvpstr.
"&NOTETOBUYER=".urlencode($conf->global->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;
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";
460 if (!empty($conf->global->PAYPAL_API_SANDBOX) ||
GETPOST(
'forcesandbox',
'alpha')) {
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 =
"";
470 if (!empty($conf->global->PAYPAL_API_USER)) {
471 $PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
473 $PAYPAL_API_PASSWORD =
"";
474 if (!empty($conf->global->PAYPAL_API_PASSWORD)) {
475 $PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
477 $PAYPAL_API_SIGNATURE =
"";
478 if (!empty($conf->global->PAYPAL_API_SIGNATURE)) {
479 $PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
481 $PAYPAL_API_SANDBOX =
"";
482 if (!empty($conf->global->PAYPAL_API_SANDBOX)) {
483 $PAYPAL_API_SANDBOX = $conf->global->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, (empty($conf->global->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);
508 if (!empty($conf->global->MAIN_CURL_DISABLE_VERIFYPEER)) {
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, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT) ? 5 : $conf->global->MAIN_USE_CONNECT_TIMEOUT);
517 curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->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, $intial, $keypos);
589 $valval = substr($nvpstr, $keypos + 1, $valuepos - $keypos - 1);
591 $nvpArray[urldecode($keyval)] = urldecode($valval);
592 $nvpstr = substr($nvpstr, $valuepos + 1, strlen($nvpstr));
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).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum, $email='', $desc='')
print_paypal_redirect($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag)
Send redirect to paypal to browser.