PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wp-e-commerce/merchants/paypal_certified.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 1137 lines | 663 code | 119 blank | 355 comment | 78 complexity | 1d39710188316a8679d4d3d3cf1eb13e MD5 | raw file
  1. <?php
  2. $nzshpcrt_gateways[$num]['name'] = 'Paypal Express Checkout';
  3. $nzshpcrt_gateways[$num]['internalname'] = 'paypal_certified';
  4. $nzshpcrt_gateways[$num]['function'] = 'gateway_paypal_certified';
  5. $nzshpcrt_gateways[$num]['form'] = "form_paypal_certified";
  6. $nzshpcrt_gateways[$num]['submit_function'] = "submit_paypal_certified";
  7. $nzshpcrt_gateways[$num]['payment_type'] = "paypal";
  8. $nzshpcrt_gateways[$num]['supported_currencies']['currency_list'] = array('USD', 'CAD', 'AUD', 'EUR', 'GBP', 'JPY', 'NZD', 'CHF', 'HKD', 'SGD', 'SEK', 'HUF', 'DKK', 'PLN', 'NOK', 'CZK', 'MXN');
  9. $nzshpcrt_gateways[$num]['supported_currencies']['option_name'] = 'paypal_curcode';
  10. function gateway_paypal_certified($seperator, $sessionid)
  11. {
  12. $_SESSION['paypalExpressMessage']= ' <h4>Transaction Canceled</h4>';
  13. // ==================================
  14. // PayPal Express Checkout Module
  15. // ==================================
  16. //'------------------------------------
  17. //' The paymentAmount is the total value of
  18. //' the shopping cart, that was set
  19. //' earlier in a session variable
  20. //' by the shopping cart page
  21. //'------------------------------------
  22. //exit('<pre>'.print_r($_SESSION, true).'</pre>');
  23. $paymentAmount = wpsc_cart_total(false);
  24. $_SESSION['paypalAmount'] = $paymentAmount;
  25. $_SESSION['paypalexpresssessionid'] = $sessionid;
  26. paypal_certified_currencyconverter();
  27. //exit($_SESSION['paypalAmount']);
  28. //'------------------------------------
  29. //' The currencyCodeType and paymentType
  30. //' are set to the selections made on the Integration Assistant
  31. //'------------------------------------
  32. $currencyCodeType = get_option('paypal_curcode');
  33. $paymentType = "Sale";
  34. //'------------------------------------
  35. //' The returnURL is the location where buyers return to when a
  36. //' payment has been succesfully authorized.
  37. //'
  38. //' This is set to the value entered on the Integration Assistant
  39. //'------------------------------------
  40. //exit(get_option('transact_url'));
  41. $transact_url = get_option('transact_url');
  42. $returnURL = $transact_url.$seperator."sessionid=".$sessionid."&gateway=paypal";
  43. //'------------------------------------
  44. //' The cancelURL is the location buyers are sent to when they hit the
  45. //' cancel button during authorization of payment during the PayPal flow
  46. //'
  47. //' This is set to the value entered on the Integration Assistant
  48. //'------------------------------------
  49. $cancelURL = $transact_url;
  50. //'------------------------------------
  51. //' Calls the SetExpressCheckout API call
  52. //'
  53. //' The CallShortcutExpressCheckout function is defined in the file PayPalFunctions.php,
  54. //' it is included at the top of this file.
  55. //'-------------------------------------------------
  56. $resArray = CallShortcutExpressCheckout ($_SESSION['paypalAmount'], $currencyCodeType, $paymentType, $returnURL, $cancelURL);
  57. //exit("<pre>".print_r($resArray,true)."</pre>");
  58. $ack = strtoupper($resArray["ACK"]);
  59. if($ack=="SUCCESS") {
  60. RedirectToPayPal ( $resArray["TOKEN"] );
  61. } else {
  62. //Display a user friendly Error on the page using any of the following error information returned by PayPal
  63. $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
  64. $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
  65. $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
  66. $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
  67. echo "SetExpressCheckout API call failed. ";
  68. echo "Detailed Error Message: " . $ErrorLongMsg;
  69. echo "Short Error Message: " . $ErrorShortMsg;
  70. echo "Error Code: " . $ErrorCode;
  71. echo "Error Severity Code: " . $ErrorSeverityCode;
  72. }
  73. // header("Location: ".get_option('paypal_multiple_url')."?".$output);
  74. exit();
  75. }
  76. function paypal_certified_currencyconverter(){
  77. global $wpdb;
  78. $currency_code = $wpdb->get_results("SELECT `code` FROM `".WPSC_TABLE_CURRENCY_LIST."` WHERE `id`='".get_option('currency_type')."' LIMIT 1",ARRAY_A);
  79. $local_currency_code = $currency_code[0]['code'];
  80. $paypal_currency_code = get_option('paypal_curcode');
  81. if($paypal_currency_code == '') {
  82. $paypal_currency_code = 'US';
  83. }
  84. //exit(get_option('currency_type'). " ".$paypal_currency_code);
  85. // Stupid paypal only accepts payments in one of 5 currencies. Convert from the currency of the users shopping cart to the curency which the user has specified in their paypal preferences.
  86. $curr=new CURRENCYCONVERTER();
  87. if($paypal_currency_code != $local_currency_code) {
  88. $paypal_currency_productprice = $curr->convert($_SESSION['paypalAmount'],$paypal_currency_code,$local_currency_code);
  89. $paypal_currency_shipping = $curr->convert($local_currency_shipping,$paypal_currency_code,$local_currency_code);
  90. //exit($paypal_currency_productprice . " " . $paypal_currency_shipping.' '.$local_currency_productprice . " " . $local_currency_code);
  91. $base_shipping = $curr->convert($purchase_log['base_shipping'],$paypal_currency_code, $local_currency_code);
  92. } else {
  93. $paypal_currency_productprice = $_SESSION['paypalAmount'];
  94. $paypal_currency_shipping = $local_currency_shipping;
  95. $base_shipping = $purchase_log['base_shipping'];
  96. }
  97. switch($paypal_currency_code) {
  98. case "JPY":
  99. $decimal_places = 0;
  100. break;
  101. case "HUF":
  102. $decimal_places = 0;
  103. default:
  104. $decimal_places = 2;
  105. break;
  106. }
  107. //echo "$paypal_currency_code|$local_currency_code";
  108. $_SESSION['paypalAmount'] = number_format(sprintf("%01.2f", $paypal_currency_productprice),$decimal_places,'.','');
  109. }
  110. function processingfunctions()
  111. {
  112. global $wpdb, $wpsc_cart;
  113. $sessionid = $_SESSION['paypalexpresssessionid'];
  114. if($_REQUEST['act']=='error'){
  115. session_start();
  116. $resArray=$_SESSION['reshash'];
  117. $_SESSION['paypalExpressMessage']= '
  118. <center>
  119. <table width="700" align="left">
  120. <tr>
  121. <td colspan="2" class="header">The PayPal API has returned an error!</td>
  122. </tr>
  123. ';
  124. //it will print if any URL errors
  125. if(isset($_SESSION['curl_error_no'])) {
  126. $errorCode= $_SESSION['curl_error_no'] ;
  127. $errorMessage=$_SESSION['curl_error_msg'] ;
  128. $response = $_SESSION['response'];
  129. session_unset();
  130. $_SESSION['paypalExpressMessage'].='
  131. <tr>
  132. <td>response:</td>
  133. <td><?php echo $response; ?></td>
  134. </tr>
  135. <tr>
  136. <td>Error Number:</td>
  137. <td><?= $errorCode ?></td>
  138. </tr>
  139. <tr>
  140. <td>Error Message:</td>
  141. <td><?= $errorMessage ?></td>
  142. </tr>
  143. </center>
  144. </table>';
  145. } else {
  146. /* If there is no URL Errors, Construct the HTML page with
  147. Response Error parameters.
  148. */
  149. $_SESSION['paypalExpressMessage'] .="
  150. <td>Ack:</td>
  151. <td>".$resArray['ACK']."</td>
  152. </tr>
  153. <tr>
  154. <td>Correlation ID:</td>
  155. <td>".$resArray['CORRELATIONID']."</td>
  156. </tr>
  157. <tr>
  158. <td>Version:</td>
  159. <td>".$resArray['VERSION']."</td>
  160. </tr>";
  161. $count=0;
  162. while (isset($resArray["L_SHORTMESSAGE".$count])) {
  163. $errorCode = $resArray["L_ERRORCODE".$count];
  164. $shortMessage = $resArray["L_SHORTMESSAGE".$count];
  165. $longMessage = $resArray["L_LONGMESSAGE".$count];
  166. $count=$count+1;
  167. $_SESSION['paypalExpressMessage'] .="
  168. <tr>
  169. <td>Error Number:</td>
  170. <td> $errorCode </td>
  171. </tr>
  172. <tr>
  173. <td>Short Message:</td>
  174. <td> $shortMessage </td>
  175. </tr>
  176. <tr>
  177. <td>Long Message:</td>
  178. <td> $longMessage </td>
  179. </tr>";
  180. }//end while
  181. }// end else
  182. $_SESSION['paypalExpressMessage'] .="
  183. </center>
  184. </table>";
  185. }else if($_REQUEST['act']=='do'){
  186. session_start();
  187. /* Gather the information to make the final call to
  188. finalize the PayPal payment. The variable nvpstr
  189. holds the name value pairs
  190. */
  191. //exit(wpsc_cart_total(false));
  192. $token =urlencode($_REQUEST['token']);
  193. $paymentAmount =urlencode ($_SESSION['paypalAmount']);
  194. $paymentType = urlencode($_SESSION['paymentType']);
  195. $currCodeType = urlencode(get_option('paypal_curcode'));
  196. $payerID = urlencode($_REQUEST['PayerID']);
  197. $serverName = urlencode($_SERVER['SERVER_NAME']);
  198. $BN='Instinct_e-commerce_wp-shopping-cart_NZ';
  199. $nvpstr='&TOKEN='.$token.'&PAYERID='.$payerID.'&PAYMENTACTION=Sale&AMT='.$paymentAmount.'&CURRENCYCODE='.$currCodeType.'&IPADDRESS='.$serverName."&BUTTONSOURCE=".$BN ;
  200. // exit($nvpstr);
  201. /* Make the call to PayPal to finalize payment
  202. If an error occured, show the resulting errors
  203. */
  204. $resArray=hash_call("DoExpressCheckoutPayment",$nvpstr);
  205. /* Display the API response back to the browser.
  206. If the response from PayPal was a success, display the response parameters'
  207. If the response was an error, display the errors received using APIError.php.
  208. */
  209. $ack = strtoupper($resArray["ACK"]);
  210. //echo('<pre>'.print_r($resArray, true).'</re>');
  211. if($ack!="SUCCESS"){
  212. $_SESSION['reshash']=$resArray;
  213. $location = get_option('transact_url')."&act=error";
  214. $_SESSION['paypalExpressMessage'] = 'Completed';
  215. // header("Location: $location");
  216. }else{
  217. $transaction_id = $wpdb->escape($resArray['TRANSACTIONID']);
  218. switch($resArray['PAYMENTSTATUS']) {
  219. case 'Processed': // I think this is mostly equivalent to Completed
  220. case 'Completed':
  221. $wpdb->query("UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `processed` = '2' WHERE `sessionid` = ".$sessionid." LIMIT 1");
  222. transaction_results($sessionid, false, $transaction_id);
  223. break;
  224. case 'Pending': // need to wait for "Completed" before processing
  225. $wpdb->query("UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `transactid` = '".$transaction_id."', `date` = '".time()."' WHERE `sessionid` = ".$sessionid." LIMIT 1");
  226. break;
  227. }
  228. $_SESSION['paypalExpressMessage'] = $resArray['PAYMENTSTATUS'];
  229. $location = add_query_arg('sessionid', $sessionid, get_option('transact_url'));
  230. //echo $location;
  231. header("Location: $location");
  232. exit();
  233. }
  234. //exit('<pre>'.print_r($resArray, true).'</pre>');
  235. // $_SESSION['paypalExpressMessage'] ="
  236. // <h4>Transaction Accepted Please Keep these References Handy.</h4>
  237. // <table class='' >
  238. //
  239. // <tr>
  240. // <td >
  241. // Transaction ID:</td>
  242. // <td>".$resArray['TRANSACTIONID']."</td>
  243. // </tr>
  244. // <tr>
  245. // <td >
  246. // Amount:</td>
  247. // <td>".$currCodeType." ".$resArray['AMT']."</td>
  248. // </tr>
  249. // </table>";
  250. //unset session shopping cart
  251. @$_SESSION['nzshpcrt_serialized_cart'] = '';
  252. $_SESSION['nzshpcrt_cart'] = '';
  253. $_SESSION['nzshpcrt_cart'] = Array();
  254. //exit('HERE');
  255. $wpsc_cart->empty_cart();
  256. } else if(isset($_REQUEST['paymentType']) || isset($_REQUEST['token'])){
  257. $token = $_REQUEST['token'];
  258. if(! isset($token)) {
  259. /*
  260. The servername and serverport tells PayPal where the buyer
  261. should be directed back to after authorizing payment.
  262. In this case, its the local webserver that is running this script
  263. Using the servername and serverport, the return URL is the first
  264. portion of the URL that buyers will return to after authorizing payment
  265. */
  266. $paymentAmount=$_SESSION['paypalAmount'];
  267. $currencyCodeType=get_option('paypal_curcode');
  268. $paymentType='Sale';
  269. /* The returnURL is the location where buyers return when a
  270. payment has been succesfully authorized.
  271. The cancelURL is the location buyers are sent to when they hit the
  272. cancel button during authorization of payment during the PayPal flow
  273. */
  274. if(get_option('permalink_structure') != '')
  275. {
  276. $seperator ="?";
  277. }
  278. else
  279. {
  280. $seperator ="&";
  281. }
  282. $returnURL =urlencode(get_option('transact_url').$seperator.'currencyCodeType='.$currencyCodeType.'&paymentType='.$paymentType.'&paymentAmount='.$paymentAmount);
  283. $cancelURL =urlencode(get_option('transact_url').$seperator.'paymentType=$paymentType' );
  284. /* Construct the parameter string that describes the PayPal payment
  285. the varialbes were set in the web form, and the resulting string
  286. is stored in $nvpstr
  287. */
  288. $nvpstr="&Amt=".$paymentAmount."&PAYMENTACTION=".$paymentType."&ReturnUrl=".$returnURL."&CANCELURL=".$cancelURL ."&CURRENCYCODE=".$currencyCodeType;
  289. /* Make the call to PayPal to set the Express Checkout token
  290. If the API call succeded, then redirect the buyer to PayPal
  291. to begin to authorize payment. If an error occured, show the
  292. resulting errors
  293. */
  294. $resArray=hash_call("SetExpressCheckout",$nvpstr);
  295. $_SESSION['reshash']=$resArray;
  296. $ack = strtoupper($resArray["ACK"]);
  297. if($ack=="SUCCESS"){
  298. // Redirect to paypal.com here
  299. $token = urldecode($resArray["TOKEN"]);
  300. $payPalURL = PAYPAL_URL.$token;
  301. header("Location: ".$payPalURL);
  302. } else {
  303. //Redirecting to APIError.php to display errors.
  304. $location = get_option('transact_url')."&act=error";
  305. header("Location: $location");
  306. }
  307. exit();
  308. } else {
  309. /* At this point, the buyer has completed in authorizing payment
  310. at PayPal. The script will now call PayPal with the details
  311. of the authorization, incuding any shipping information of the
  312. buyer. Remember, the authorization is not a completed transaction
  313. at this state - the buyer still needs an additional step to finalize
  314. the transaction
  315. */
  316. $token =urlencode( $_REQUEST['token']);
  317. /* Build a second API request to PayPal, using the token as the
  318. ID to get the details on the payment authorization
  319. */
  320. $nvpstr="&TOKEN=".$token;
  321. /* Make the API call and store the results in an array. If the
  322. call was a success, show the authorization details, and provide
  323. an action to complete the payment. If failed, show the error
  324. */
  325. $resArray=hash_call("GetExpressCheckoutDetails",$nvpstr);
  326. $_SESSION['reshash']=$resArray;
  327. $ack = strtoupper($resArray["ACK"]);
  328. if($ack=="SUCCESS"){
  329. /********************************************************
  330. GetExpressCheckoutDetails.php
  331. This functionality is called after the buyer returns from
  332. PayPal and has authorized the payment.
  333. Displays the payer details returned by the
  334. GetExpressCheckoutDetails response and calls
  335. DoExpressCheckoutPayment.php to complete the payment
  336. authorization.
  337. Called by ReviewOrder.php.
  338. Calls DoExpressCheckoutPayment.php and APIError.php.
  339. ********************************************************/
  340. session_start();
  341. /* Collect the necessary information to complete the
  342. authorization for the PayPal payment
  343. */
  344. $_SESSION['token']=$_REQUEST['token'];
  345. $_SESSION['payer_id'] = $_REQUEST['PayerID'];
  346. /*
  347. $_SESSION['paymentAmount']=$_REQUEST['paymentAmount'];
  348. $_SESSION['currCodeType']=$_REQUEST['currencyCodeType'];
  349. $_SESSION['paymentType']=$_REQUEST['paymentType'];
  350. */
  351. $resArray=$_SESSION['reshash'];
  352. if(get_option('permalink_structure') != '')
  353. {
  354. $seperator ="?";
  355. }
  356. else
  357. {
  358. $seperator ="&";
  359. }
  360. /* Display the API response back to the browser .
  361. If the response from PayPal was a success, display the response parameters
  362. */
  363. if(isset($_REQUEST['token']) && !isset($_REQUEST['PayerID'])){
  364. $_SESSION['paypalExpressMessage']= '<h4>TRANSACTION CANCELED</h4>';
  365. }else{
  366. $output ="
  367. <table width='400' class='paypal_express_form'>
  368. <tr>
  369. <td align='left' class='firstcol'><b>Order Total:</b></td>
  370. <td align='left'>".$wpsc_cart->process_as_currency($_SESSION['paypalAmount']) ."</td>
  371. </tr>
  372. <tr>
  373. <td align='left'><b>Shipping Address: </b></td>
  374. </tr>
  375. <tr>
  376. <td align='left' class='firstcol'>
  377. Street 1:</td>
  378. <td align='left'>".$resArray['SHIPTOSTREET']."</td>
  379. </tr>
  380. <tr>
  381. <td align='left' class='firstcol'>
  382. Street 2:</td>
  383. <td align='left'>".$resArray['SHIPTOSTREET2']."
  384. </td>
  385. </tr>
  386. <tr>
  387. <td align='left' class='firstcol'>
  388. City:</td>
  389. <td align='left'>".$resArray['SHIPTOCITY']."</td>
  390. </tr>
  391. <tr>
  392. <td align='left' class='firstcol'>
  393. State:</td>
  394. <td align='left'>".$resArray['SHIPTOSTATE']."</td>
  395. </tr>
  396. <tr>
  397. <td align='left' class='firstcol'>
  398. Postal code:</td>
  399. <td align='left'>".$resArray['SHIPTOZIP']."</td>
  400. </tr>
  401. <tr>
  402. <td align='left' class='firstcol'>
  403. Country:</td>
  404. <td align='left'>".$resArray['SHIPTOCOUNTRYNAME']."</td>
  405. </tr>
  406. <tr>
  407. <td>";
  408. // $purchase_log = $wpdb->get_row("SELECT `id`,`billing_region` FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid`= '".$wpdb->escape($_SESSION['paypalexpresssessionid']) ."' LIMIT 1", ARRAY_A) ;
  409. // $usersql = "SELECT `".WPSC_TABLE_SUBMITED_FORM_DATA."`.value, `".WPSC_TABLE_CHECKOUT_FORMS."`.`name`, `".WPSC_TABLE_CHECKOUT_FORMS."`.`unique_name` FROM `".WPSC_TABLE_CHECKOUT_FORMS."` LEFT JOIN `".WPSC_TABLE_SUBMITED_FORM_DATA."` ON `".WPSC_TABLE_CHECKOUT_FORMS."`.id = `".WPSC_TABLE_SUBMITED_FORM_DATA."`.`form_id` WHERE `".WPSC_TABLE_SUBMITED_FORM_DATA."`.`log_id`=".$purchase_log['id']." ORDER BY `".WPSC_TABLE_CHECKOUT_FORMS."`.`order`";
  410. //
  411. // $userinfo = $wpdb->get_results($usersql, ARRAY_A);
  412. //
  413. //
  414. $output .= "<form action=".get_option('transact_url')." method='post'>\n";
  415. $output .= " <input type='hidden' name='totalAmount' value='".wpsc_cart_total(false)."' />\n";
  416. $output .= " <input type='hidden' name='shippingStreet' value='".$resArray['SHIPTOSTREET']."' />\n";
  417. $output .= " <input type='hidden' name='shippingStreet2' value='".$resArray['SHIPTOSTREET2']."' />\n";
  418. $output .= " <input type='hidden' name='shippingCity' value='".$resArray['SHIPTOCITY']."' />\n";
  419. $output .= " <input type='hidden' name='shippingState' value='".$resArray['SHIPTOSTATE']."' />\n";
  420. $output .= " <input type='hidden' name='postalCode' value='".$resArray['SHIPTOZIP']."' />\n";
  421. $output .= " <input type='hidden' name='country' value='".$resArray['SHIPTOCOUNTRYNAME']."' />\n";
  422. $output .= " <input type='hidden' name='token' value='".$_SESSION['token']."' />\n";
  423. $output .= " <input type='hidden' name='PayerID' value='".$_SESSION['payer_id']."' />\n";
  424. $output .= " <input type='hidden' name='act' value='do' />\n";
  425. $output .= " <p> <input name='usePayPal' type='submit' value='Make Payment' /></p>\n";
  426. $output .= "</form>";
  427. $output .= "<form action=".get_option('transact_url')." method='post'>\n";
  428. $output .= " <input type='hidden' name='totalAmount' value='".wpsc_cart_total(false)."' />\n";
  429. // foreach((array)$userinfo as $key => $value){
  430. // if(($value['unique_name']=='billingfirstname') && $value['value'] != ''){
  431. // $data['SHIPTONAME'] = $value['value'];
  432. // }
  433. // if(($value['unique_name']=='billinglastname') && $value['value'] != ''){
  434. // $data['SHIPTONAME'] .= " ".$value['value'];
  435. // }
  436. //
  437. // if(($value['unique_name']=='billingaddress') && $value['value'] != ''){
  438. // $data['SHIPTOSTREET'] = $value['value'];
  439. // }
  440. // if(($value['unique_name']=='billingcity') && $value['value'] != ''){
  441. // $data['SHIPTOCITY'] = $value['value'];
  442. // }
  443. // if(($value['unique_name']=='billingcountry') && $value['value'] != ''){
  444. // $data['SHIPTOCOUNTRYCODE'] = $value['value'];
  445. // $state = $wpdb->get_var("SELECT `code` FROM `".WPSC_TABLE_REGION_TAX."` WHERE `id` ='{$purchase_log['billing_region']}' LIMIT 1");
  446. // if($purchase_log['billing_region'] > 0) {
  447. // $data['SHIPTOSTATE'] = $state;
  448. // }
  449. // }
  450. // if(($value['unique_name']=='billingpostcode') && $value['value'] != ''){
  451. // $data['SHIPTOZIP'] = $value['value'];
  452. // }
  453. // }
  454. //
  455. // $output .= " <input type='text' name='shippingStreet' value='".$data['SHIPTOSTREET']."' />\n";
  456. // $output .= " <input type='text' name='shippingCity' value='".$data['SHIPTOCITY']."' />\n";
  457. // $output .= " <input type='text' name='shippingState' value='".$data['SHIPTOSTATE']."' />\n";
  458. // $output .= " <input type='text' name='postalCode' value='".$data['SHIPTOZIP']."' />\n";
  459. // $output .= " <input type='text' name='country' value='".$data['SHIPTOCOUNTRYCODE']."' />\n";
  460. // $output .= " <input type='text' name='token' value='".$_SESSION['token']."' />\n";
  461. // $output .= " <input type='text' name='PayerID' value='".$_SESSION['payer_id']."' />\n";
  462. // $output .= " <input type='hidden' name='act' value='do' />\n";
  463. // $output .= " <p> <label for='useOther'>Use Previous Shipping Information:</label> <input name='useOther' type='submit' value='Make Payment' /></p>\n";
  464. // $output .= "</form>";
  465. $output .=" </td>
  466. </tr>
  467. </table>
  468. </center>
  469. ";
  470. $_SESSION['paypalExpressMessage'] = $output;
  471. }
  472. }
  473. }
  474. }
  475. }
  476. function submit_paypal_certified()
  477. {
  478. if($_POST['paypal_certified_apiuser'] != null)
  479. {
  480. update_option('paypal_certified_apiuser', $_POST['paypal_certified_apiuser']);
  481. }
  482. if($_POST['paypal_certified_apipass'] != null)
  483. {
  484. update_option('paypal_certified_apipass', $_POST['paypal_certified_apipass']);
  485. }
  486. if($_POST['paypal_curcode'] != null)
  487. {
  488. update_option('paypal_curcode', $_POST['paypal_curcode']);
  489. }
  490. if($_POST['paypal_certified_apisign'] != null)
  491. {
  492. update_option('paypal_certified_apisign', $_POST['paypal_certified_apisign']);
  493. }
  494. if($_POST['paypal_certified_server_type'] != null) {
  495. update_option('paypal_certified_server_type', $_POST['paypal_certified_server_type']);
  496. //exit(get_option('paypal_certified_server_type').'<pre>'.print_r($_POST, true).'</pre>');
  497. }
  498. foreach((array)$_POST['paypal_form'] as $form => $value) {
  499. update_option(('paypal_form_'.$form), $value);
  500. }
  501. return true;
  502. }
  503. function form_paypal_certified()
  504. {
  505. global $wpdb, $wpsc_gateways;
  506. $select_currency[get_option('paypal_curcode')] = "selected='selected'";
  507. if (get_option('paypal_certified_server_type') == 'sandbox'){
  508. $serverType1="checked='checked'";
  509. } elseif(get_option('paypal_certified_server_type') == 'production') {
  510. $serverType2 ="checked='checked'";
  511. }
  512. $output = "
  513. <tr>
  514. <td>API Username
  515. </td>
  516. <td>
  517. <input type='text' size='40' value='".get_option('paypal_certified_apiuser')."' name='paypal_certified_apiuser' />
  518. </td>
  519. </tr>
  520. <tr>
  521. <td>API Password
  522. </td>
  523. <td>
  524. <input type='text' size='40' value='".get_option('paypal_certified_apipass')."' name='paypal_certified_apipass' />
  525. </td>
  526. </tr>
  527. <tr>
  528. <td>API Signature
  529. </td>
  530. <td>
  531. <input type='text' size='70' value='".get_option('paypal_certified_apisign')."' name='paypal_certified_apisign' />
  532. </td>
  533. </tr>
  534. <tr>
  535. <td>Server Type
  536. </td>
  537. <td>
  538. <input $serverType1 type='radio' name='paypal_certified_server_type' value='sandbox' /> Sandbox (For testing)
  539. <input $serverType2 type='radio' name='paypal_certified_server_type' value='production' /> Production
  540. </td>
  541. </tr>
  542. ";
  543. $store_currency_code = $wpdb->get_var("SELECT `code` FROM `".WPSC_TABLE_CURRENCY_LIST."` WHERE `id` IN ('".absint(get_option('currency_type'))."')");
  544. $current_currency = get_option('paypal_curcode');
  545. if($current_currency != $store_currency_code) {
  546. $output .= "
  547. <tr>
  548. <td colspan='2'><strong class='form_group'>".__('Currency Converter')."</td>
  549. </tr>
  550. <tr>
  551. <td colspan='2'>".__('If your website uses a currency not accepted by Paypal, select an accepted currency using the drop down menu bellow. Buyers on your site will still pay in your local currency however we will send the order through to Paypal using currency you choose below.')."</td>
  552. </tr>\n";
  553. $output .= " <tr>\n";
  554. $output .= " <td>Convert to </td>\n";
  555. $output .= " <td>\n";
  556. $output .= " <select name='paypal_curcode'>\n";
  557. $paypal_currency_list = $wpsc_gateways['paypal_multiple']['supported_currencies']['currency_list'];
  558. $currency_list = $wpdb->get_results("SELECT DISTINCT `code`, `currency` FROM `".WPSC_TABLE_CURRENCY_LIST."` WHERE `code` IN ('".implode("','",$paypal_currency_list)."')", ARRAY_A);
  559. foreach($currency_list as $currency_item) {
  560. $selected_currency = '';
  561. if($current_currency == $currency_item['code']) {
  562. $selected_currency = "selected='selected'";
  563. }
  564. $output .= "<option ".$selected_currency." value='{$currency_item['code']}'>{$currency_item['currency']}</option>";
  565. }
  566. $output .= " </select> \n";
  567. $output .= " </td>\n";
  568. $output .= " </tr>\n";
  569. }
  570. $output .= "
  571. <tr class='update_gateway' >
  572. <td colspan='2'>
  573. <div class='submit'>
  574. <input type='submit' value='Update &raquo;' name='updateoption'/>
  575. </div>
  576. </td>
  577. </tr>
  578. <tr style='background: none;'>
  579. <td colspan='2'>
  580. <h4>Forms Sent to Gateway</h4>
  581. </td>
  582. </tr>
  583. <tr>
  584. <td>
  585. First Name Field
  586. </td>
  587. <td>
  588. <select name='paypal_form[first_name]'>
  589. ".nzshpcrt_form_field_list(get_option('paypal_form_first_name'))."
  590. </select>
  591. </td>
  592. </tr>
  593. <tr>
  594. <td>
  595. Last Name Field
  596. </td>
  597. <td>
  598. <select name='paypal_form[last_name]'>
  599. ".nzshpcrt_form_field_list(get_option('paypal_form_last_name'))."
  600. </select>
  601. </td>
  602. </tr>
  603. <tr>
  604. <td>
  605. Address Field
  606. </td>
  607. <td>
  608. <select name='paypal_form[address]'>
  609. ".nzshpcrt_form_field_list(get_option('paypal_form_address'))."
  610. </select>
  611. </td>
  612. </tr>
  613. <tr>
  614. <td>
  615. City Field
  616. </td>
  617. <td>
  618. <select name='paypal_form[city]'>
  619. ".nzshpcrt_form_field_list(get_option('paypal_form_city'))."
  620. </select>
  621. </td>
  622. </tr>
  623. <tr>
  624. <td>
  625. State Field
  626. </td>
  627. <td>
  628. <select name='paypal_form[state]'>
  629. ".nzshpcrt_form_field_list(get_option('paypal_form_state'))."
  630. </select>
  631. </td>
  632. </tr>
  633. <tr>
  634. <td>
  635. Postal code/Zip code Field
  636. </td>
  637. <td>
  638. <select name='paypal_form[post_code]'>
  639. ".nzshpcrt_form_field_list(get_option('paypal_form_post_code'))."
  640. </select>
  641. </td>
  642. </tr>
  643. <tr>
  644. <td>
  645. Country Field
  646. </td>
  647. <td>
  648. <select name='paypal_form[country]'>
  649. ".nzshpcrt_form_field_list(get_option('paypal_form_country'))."
  650. </select>
  651. </td>
  652. </tr>
  653. ";
  654. return $output;
  655. }
  656. //paypalfunctions//
  657. /********************************************
  658. PayPal API Module
  659. Defines all the global variables and the wrapper functions
  660. ********************************************/
  661. $PROXY_HOST = '127.0.0.1';
  662. $PROXY_PORT = '808';
  663. //'------------------------------------
  664. //' PayPal API Credentials
  665. //'------------------------------------
  666. $API_UserName=get_option('paypal_certified_apiuser');
  667. $API_Password=get_option('paypal_certified_apipass');
  668. $API_Signature=get_option('paypal_certified_apisign');
  669. // BN Code is only applicable for partners
  670. $sBNCode = "PP-ECWizard";
  671. /*
  672. ' Define the PayPal Redirect URLs.
  673. ' This is the URL that the buyer is first sent to do authorize payment with their paypal account
  674. ' change the URL depending if you are testing on the sandbox or the live PayPal site
  675. '
  676. ' For the sandbox, the URL is https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=
  677. ' For the live site, the URL is https://www.paypal.com/webscr&cmd=_express-checkout&token=
  678. */
  679. //$SandboxFlag = true;
  680. //exit(get_option('paypal_certified_server_type'));
  681. if (get_option('paypal_certified_server_type') == 'sandbox'){
  682. $SandboxFlag=true;
  683. } elseif(get_option('paypal_certified_server_type') == 'production') {
  684. $SandboxFlag=false;
  685. }
  686. if ($SandboxFlag == true)
  687. {
  688. $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
  689. $PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
  690. }
  691. else
  692. {
  693. $API_Endpoint = "https://api-3t.paypal.com/nvp";
  694. $PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
  695. }
  696. $USE_PROXY = false;
  697. $version="57.0";
  698. if (session_id() == "")
  699. session_start();
  700. /* An express checkout transaction starts with a token, that
  701. identifies to PayPal your transaction
  702. In this example, when the script sees a token, the script
  703. knows that the buyer has already authorized payment through
  704. paypal. If no token was found, the action is to send the buyer
  705. to PayPal to first authorize payment
  706. */
  707. /*
  708. '-------------------------------------------------------------------------------------------------------------------------------------------
  709. ' Purpose: Prepares the parameters for the SetExpressCheckout API Call.
  710. ' Inputs:
  711. ' paymentAmount: Total value of the shopping cart
  712. ' currencyCodeType: Currency code value the PayPal API
  713. ' paymentType: paymentType has to be one of the following values: Sale or Order or Authorization
  714. ' returnURL: the page where buyers return to after they are done with the payment review on PayPal
  715. ' cancelURL: the page where buyers return to when they cancel the payment review on PayPal
  716. '--------------------------------------------------------------------------------------------------------------------------------------------
  717. */
  718. function CallShortcutExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL) {
  719. global $wpdb;
  720. //------------------------------------------------------------------------------------------------------------------------------------
  721. // Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
  722. //exit($cancelURL);
  723. $purchase_log = $wpdb->get_row("SELECT `id`,`billing_region` FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid`= '".$wpdb->escape($_SESSION['paypalexpresssessionid']) ."' LIMIT 1", ARRAY_A) ;
  724. $usersql = "SELECT `".WPSC_TABLE_SUBMITED_FORM_DATA."`.value, `".WPSC_TABLE_CHECKOUT_FORMS."`.`name`, `".WPSC_TABLE_CHECKOUT_FORMS."`.`unique_name` FROM `".WPSC_TABLE_CHECKOUT_FORMS."` LEFT JOIN `".WPSC_TABLE_SUBMITED_FORM_DATA."` ON `".WPSC_TABLE_CHECKOUT_FORMS."`.id = `".WPSC_TABLE_SUBMITED_FORM_DATA."`.`form_id` WHERE `".WPSC_TABLE_SUBMITED_FORM_DATA."`.`log_id`=".$purchase_log['id']." ORDER BY `".WPSC_TABLE_CHECKOUT_FORMS."`.`order`";
  725. //exit($usersql);
  726. $userinfo = $wpdb->get_results($usersql, ARRAY_A);
  727. // print("<pre>".print_r($usersql,true)."</pre>");
  728. // print("<pre>".print_r($userinfo,true)."</pre>");
  729. $nvpstr="&Amt=". $paymentAmount;
  730. $nvpstr = $nvpstr . "&PAYMENTACTION=" . $paymentType;
  731. $nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
  732. $nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
  733. $nvpstr = $nvpstr . "&CURRENCYCODE=" . $currencyCodeType;
  734. $data = array();
  735. foreach((array)$userinfo as $key => $value){
  736. if(($value['unique_name']=='billingfirstname') && $value['value'] != ''){
  737. $data['SHIPTONAME'] = $value['value'];
  738. }
  739. if(($value['unique_name']=='billinglastname') && $value['value'] != ''){
  740. $data['SHIPTONAME'] .= " ".$value['value'];
  741. }
  742. if(($value['unique_name']=='billingaddress') && $value['value'] != ''){
  743. $data['SHIPTOSTREET'] = $value['value'];
  744. }
  745. if(($value['unique_name']=='billingcity') && $value['value'] != ''){
  746. $data['SHIPTOCITY'] = $value['value'];
  747. }
  748. if(($value['unique_name']=='billingcountry') && $value['value'] != ''){
  749. $values = maybe_unserialize($value['value']);
  750. $data['SHIPTOCOUNTRYCODE'] = $values[0];
  751. $state = $wpdb->get_var("SELECT `code` FROM `".WPSC_TABLE_REGION_TAX."` WHERE `id` ='{$purchase_log['billing_region']}' LIMIT 1");
  752. if($purchase_log['billing_region'] > 0) {
  753. $data['SHIPTOSTATE'] = $state;
  754. }
  755. }
  756. if(($value['unique_name']=='billingpostcode') && $value['value'] != ''){
  757. $data['SHIPTOZIP'] = $value['value'];
  758. }
  759. }
  760. if(count($data) >= 4) {
  761. //$data['ADDROVERRIDE'] = 1;
  762. $temp_data = array();
  763. foreach($data as $key => $value) {
  764. $temp_data[] = $key."=".$value;
  765. }
  766. $nvpstr = $nvpstr . "&".implode("&",$temp_data);
  767. }
  768. //print("<pre>".print_r($data,true)."</pre>");
  769. //exit($nvpstr);
  770. $_SESSION["currencyCodeType"] = $currencyCodeType;
  771. $_SESSION["PaymentType"] = $paymentType;
  772. //'---------------------------------------------------------------------------------------------------------------
  773. //' Make the API call to PayPal
  774. //' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.
  775. //' If an error occured, show the resulting errors
  776. //'---------------------------------------------------------------------------------------------------------------
  777. $resArray=hash_call("SetExpressCheckout", $nvpstr);
  778. $ack = strtoupper($resArray["ACK"]);
  779. if($ack=="SUCCESS")
  780. {
  781. $token = urldecode($resArray["TOKEN"]);
  782. $_SESSION['TOKEN']=$token;
  783. }
  784. return $resArray;
  785. }
  786. /*
  787. '-------------------------------------------------------------------------------------------------------------------------------------------
  788. ' Purpose: Prepares the parameters for the SetExpressCheckout API Call.
  789. ' Inputs:
  790. ' paymentAmount: Total value of the shopping cart
  791. ' currencyCodeType: Currency code value the PayPal API
  792. ' paymentType: paymentType has to be one of the following values: Sale or Order or Authorization
  793. ' returnURL: the page where buyers return to after they are done with the payment review on PayPal
  794. ' cancelURL: the page where buyers return to when they cancel the payment review on PayPal
  795. ' shipToName: the Ship to name entered on the merchant's site
  796. ' shipToStreet: the Ship to Street entered on the merchant's site
  797. ' shipToCity: the Ship to City entered on the merchant's site
  798. ' shipToState: the Ship to State entered on the merchant's site
  799. ' shipToCountryCode: the Code for Ship to Country entered on the merchant's site
  800. ' shipToZip: the Ship to ZipCode entered on the merchant's site
  801. ' shipToStreet2: the Ship to Street2 entered on the merchant's site
  802. ' phoneNum: the phoneNum entered on the merchant's site
  803. '--------------------------------------------------------------------------------------------------------------------------------------------
  804. */
  805. function CallMarkExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL,
  806. $cancelURL, $shipToName, $shipToStreet, $shipToCity, $shipToState,
  807. $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum
  808. )
  809. {
  810. //------------------------------------------------------------------------------------------------------------------------------------
  811. // Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
  812. $nvpstr="&Amt=". $paymentAmount;
  813. $nvpstr = $nvpstr . "&PAYMENTACTION=" . $paymentType;
  814. $nvpstr = $nvpstr . "&ReturnUrl=" . $returnURL;
  815. $nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
  816. $nvpstr = $nvpstr . "&CURRENCYCODE=" . $currencyCodeType;
  817. $nvpstr = $nvpstr . "&ADDROVERRIDE=1";
  818. $nvpstr = $nvpstr . "&SHIPTONAME=" . $shipToName;
  819. $nvpstr = $nvpstr . "&SHIPTOSTREET=" . $shipToStreet;
  820. $nvpstr = $nvpstr . "&SHIPTOSTREET2=" . $shipToStreet2;
  821. $nvpstr = $nvpstr . "&SHIPTOCITY=" . $shipToCity;
  822. $nvpstr = $nvpstr . "&SHIPTOSTATE=" . $shipToState;
  823. $nvpstr = $nvpstr . "&SHIPTOCOUNTRYCODE=" . $shipToCountryCode;
  824. $nvpstr = $nvpstr . "&SHIPTOZIP=" . $shipToZip;
  825. $nvpstr = $nvpstr . "&PHONENUM=" . $phoneNum;
  826. $_SESSION["currencyCodeType"] = $currencyCodeType;
  827. $_SESSION["PaymentType"] = $paymentType;
  828. //'---------------------------------------------------------------------------------------------------------------
  829. //' Make the API call to PayPal
  830. //' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.
  831. //' If an error occured, show the resulting errors
  832. //'---------------------------------------------------------------------------------------------------------------
  833. $resArray=hash_call("SetExpressCheckout", $nvpstr);
  834. $ack = strtoupper($resArray["ACK"]);
  835. if($ack=="SUCCESS")
  836. {
  837. $token = urldecode($resArray["TOKEN"]);
  838. $_SESSION['TOKEN']=$token;
  839. }
  840. return $resArray;
  841. }
  842. /*
  843. '-------------------------------------------------------------------------------------------
  844. ' Purpose: Prepares the parameters for the GetExpressCheckoutDetails API Call.
  845. '
  846. ' Inputs:
  847. ' None
  848. ' Returns:
  849. ' The NVP Collection object of the GetExpressCheckoutDetails Call Response.
  850. '-------------------------------------------------------------------------------------------
  851. */
  852. function GetShippingDetails( $token )
  853. {
  854. //'--------------------------------------------------------------
  855. //' At this point, the buyer has completed authorizing the payment
  856. //' at PayPal. The function will call PayPal to obtain the details
  857. //' of the authorization, incuding any shipping information of the
  858. //' buyer. Remember, the authorization is not a completed transaction
  859. //' at this state - the buyer still needs an additional step to finalize
  860. //' the transaction
  861. //'--------------------------------------------------------------
  862. //'---------------------------------------------------------------------------
  863. //' Build a second API request to PayPal, using the token as the
  864. //' ID to get the details on the payment authorization
  865. //'---------------------------------------------------------------------------
  866. $nvpstr="&TOKEN=" . $token;
  867. //'---------------------------------------------------------------------------
  868. //' Make the API call and store the results in an array.
  869. //' If the call was a success, show the authorization details, and provide
  870. //' an action to complete the payment.
  871. //' If failed, show the error
  872. //'---------------------------------------------------------------------------
  873. $resArray=hash_call("GetExpressCheckoutDetails",$nvpstr);
  874. $ack = strtoupper($resArray["ACK"]);
  875. if($ack == "SUCCESS")
  876. {
  877. $_SESSION['payer_id'] = $resArray['PAYERID'];
  878. }
  879. return $resArray;
  880. }
  881. /*
  882. '-------------------------------------------------------------------------------------------------------------------------------------------
  883. ' Purpose: Prepares the parameters for the GetExpressCheckoutDetails API Call.
  884. '
  885. ' Inputs:
  886. ' sBNCode: The BN code used by PayPal to track the transactions from a given shopping cart.
  887. ' Returns:
  888. ' The NVP Collection object of the GetExpressCheckoutDetails Call Response.
  889. '--------------------------------------------------------------------------------------------------------------------------------------------
  890. */
  891. function ConfirmPayment( $FinalPaymentAmt )
  892. {
  893. /* Gather the information to make the final call to
  894. finalize the PayPal payment. The variable nvpstr
  895. holds the name value pairs
  896. */
  897. //Format the other parameters that were stored in the session from the previous calls
  898. $token = urlencode($_SESSION['token']);
  899. $paymentType = urlencode($_SESSION['paymentType']);
  900. $currencyCodeType = urlencode($_SESSION['currencyCodeType']);
  901. $payerID = urlencode($_SESSION['payer_id']);
  902. $serverName = urlencode($_SERVER['SERVER_NAME']);
  903. $nvpstr = '&TOKEN=' . $token . '&PAYERID=' . $payerID . '&PAYMENTACTION=' . $paymentType . '&AMT=' . $FinalPaymentAmt;
  904. $nvpstr .= '&CURRENCYCODE=' . $currencyCodeType . '&IPADDRESS=' . $serverName;
  905. /* Make the call to PayPal to finalize payment
  906. If an error occured, show the resulting errors
  907. */
  908. $resArray=hash_call("DoExpressCheckoutPayment",$nvpstr);
  909. /* Display the API response back to the browser.
  910. If the response from PayPal was a success, display the response parameters'
  911. If the response was an error, display the errors received using APIError.php.
  912. */
  913. $ack = strtoupper($resArray["ACK"]);
  914. return $resArray;
  915. }
  916. /**
  917. '-------------------------------------------------------------------------------------------------------------------------------------------
  918. * hash_call: Function to perform the API call to PayPal using API signature
  919. * @methodName is name of API method.
  920. * @nvpStr is nvp string.
  921. * returns an associtive array containing the response from the server.
  922. '-------------------------------------------------------------------------------------------------------------------------------------------
  923. */
  924. function hash_call($methodName,$nvpStr)
  925. {
  926. //declaring of global variables
  927. global $API_Endpoint, $version, $API_UserName, $API_Password, $API_Signature;
  928. global $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
  929. global $gv_ApiErrorURL;
  930. global $sBNCode;
  931. $version = 57;
  932. //setting the curl parameters.
  933. $ch = curl_init();
  934. curl_setopt($ch, CURLOPT_URL,$API_Endpoint);
  935. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  936. //turning off the server and peer verification(TrustManager Concept).
  937. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  938. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  939. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  940. curl_setopt($ch, CURLOPT_POST, 1);
  941. //if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled.
  942. //Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php
  943. if($USE_PROXY)
  944. curl_setopt ($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT);
  945. //NVPRequest for submitting to server
  946. $nvpreq="METHOD=" . urlencode($methodName) . "&VERSION=" . urlencode($version) . "&PWD=" . urlencode($API_Password) . "&USER=" . urlencode($API_UserName) . "&SIGNATURE=" . urlencode($API_Signature) . $nvpStr . "&BUTTONSOURCE=" . urlencode($sBNCode);
  947. //exit('<pre>'.print_r($nvpreq,true).'</true>');
  948. //setting the nvpreq as POST FIELD to curl
  949. curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
  950. //exit($nvpreq);
  951. //getting response from server
  952. $response = curl_exec($ch);
  953. //exit('<pre>'.print_r($response, true).'</pre>');
  954. //convrting NVPResponse to an Associative Array
  955. $nvpResArray=deformatNVP($response);
  956. $nvpReqArray=deformatNVP($nvpreq);
  957. $_SESSION['nvpReqArray']=$nvpReqArray;
  958. if (curl_errno($ch))
  959. {
  960. // moving to display page to display curl errors
  961. $_SESSION['curl_error_no']=curl_errno($ch) ;
  962. $_SESSION['curl_error_msg']=curl_error($ch);
  963. //Execute the Error handling module to display errors.
  964. }
  965. else
  966. {
  967. //closing the curl
  968. curl_close($ch);
  969. } return $nvpResArray;
  970. }
  971. /*'----------------------------------------------------------------------------------
  972. Purpose: Redirects to PayPal.com site.
  973. Inputs: NVP string.
  974. Returns:
  975. ----------------------------------------------------------------------------------
  976. */
  977. function RedirectToPayPal ( $token )
  978. {
  979. global $PAYPAL_URL;
  980. // Redirect to paypal.com here
  981. $payPalURL = $PAYPAL_URL . $token;
  982. header("Location: ".$payPalURL);
  983. }
  984. /*'----------------------------------------------------------------------------------
  985. * This function will take NVPString and convert it to an Associative Array and it will decode the response.
  986. * It is usefull to search for a particular key and displaying arrays.
  987. * @nvpstr is NVPString.
  988. * @nvpArray is Associative Array.
  989. ----------------------------------------------------------------------------------
  990. */
  991. function deformatNVP($nvpstr) {
  992. $intial=0;
  993. $nvpArray = array();
  994. while(strlen($nvpstr)) {
  995. //postion of Key
  996. $keypos= strpos($nvpstr,'=');
  997. //position of value
  998. $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr);
  999. /*getting the Key and Value values and storing in a Associative Array*/
  1000. $keyval=substr($nvpstr,$intial,$keypos);
  1001. $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
  1002. //decoding the respose
  1003. $nvpArray[urldecode($keyval)] =urldecode( $valval);
  1004. $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
  1005. }
  1006. return $nvpArray;
  1007. }
  1008. add_action('init', 'processingfunctions');
  1009. ?>