Advertisement
Guest User

Untitled

a guest
Jan 9th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. <?php
  2.  
  3. function NVPToArray($NVPString)
  4. {
  5. $proArray = array();
  6. while(strlen($NVPString))
  7. {
  8. // name
  9. $keypos= strpos($NVPString,'=');
  10. $keyval = substr($NVPString,0,$keypos);
  11. // value
  12. $valuepos = strpos($NVPString,'&') ? strpos($NVPString,'&'): strlen($NVPString);
  13. $valval = substr($NVPString,$keypos+1,$valuepos-$keypos-1);
  14. // decoding the respose
  15. $proArray[$keyval] = urldecode($valval);
  16. $NVPString = substr($NVPString,$valuepos+1,strlen($NVPString));
  17. }
  18. return json_encode($proArray);
  19. }
  20. // Include config file
  21. $sandbox = FALSE;
  22. // Set PayPal API version and credentials.
  23. $api_version = '56.0';
  24. $api_endpoint = 'https://api-3t.paypal.com/nvp';
  25. $api_username = 'xxxxxxxxxxxxxxxx';
  26. $api_password = 'xxxxxxxxxxxxxxxx';
  27. $api_signature = 'xxxxxxxxxxxxxxx';
  28.  
  29. // Store request params in an array
  30. $request_params = array
  31. (
  32. 'METHOD' => 'DoDirectPayment',
  33. 'USER' => $api_username,
  34. 'PWD' => $api_password,
  35. 'SIGNATURE' => $api_signature,
  36. 'VERSION' => $api_version,
  37. 'PAYMENTACTION' => 'Sale',
  38. 'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
  39. 'CREDITCARDTYPE' => 'Visa',
  40. 'ACCT' => '4444183269154444',
  41. 'EXPDATE' => '092020',
  42. 'CVV2' => '456',
  43. 'FIRSTNAME' => 'Jane',
  44. 'LASTNAME' => 'Doe',
  45. 'STREET' => '25 Pacifica',
  46. 'CITY' => 'Irvine',
  47. 'STATE' => 'CA',
  48. 'COUNTRYCODE' => 'US',
  49. 'ZIP' => '92618',
  50. 'AMT' => 0.1,
  51. 'CURRENCYCODE' => 'USD',
  52. 'DESC' => 'Testing Payments Pro'
  53. );
  54.  
  55. // Loop through $request_params array to generate the NVP string.
  56. $nvp_string = '';
  57.  
  58. foreach($request_params as $var=>$val)
  59. {
  60. $nvp_string .= '&'.$var.'='.urlencode($val);
  61. }
  62.  
  63. $curl = curl_init();
  64. curl_setopt($curl, CURLOPT_VERBOSE, 1);
  65. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  66. curl_setopt($curl, CURLOPT_TIMEOUT, 30);
  67. curl_setopt($curl, CURLOPT_URL, $api_endpoint);
  68. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  69. curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);
  70.  
  71. $result = curl_exec($curl);
  72.  
  73. $result_array = NVPToArray($result);
  74.  
  75.  
  76. print_r($result_array);exit;
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement