15

paypal

  1. require_once 'paypal.inc';
  2. require_once 'sendhttp.php';

Loads the configuration parameters for the interface with the PayPal server and the code for the sendpost function.

  1. function paypal_amt($amt) {
  2.     return number_format($amt, 2, '.', '');
  3. }
  4.  
  5. function paypal_localecode($locale) {
  6.     $codes=array('en' => 'en_US', 'fr' => 'fr_FR');
  7.  
  8.     return isset($codes[$locale]) ? $codes[$locale] : 'en_US';
  9. }
  10.  
  11. function paypal_setexpresscheckout($params) {
  12.     return paypal_sendapi('SetExpressCheckout', $params);
  13. }
  14.  
  15. function paypal_getexpresscheckoutdetails($params) {
  16.     return paypal_sendapi('GetExpressCheckoutDetails', $params);
  17. }
  18.  
  19. function paypal_doexpresscheckoutpayment($params) {
  20.     return paypal_sendapi('DoExpressCheckoutPayment', $params);
  21. }
  22.  
  23. function paypal_gettransactiondetails($params) {
  24.     return paypal_sendapi('GetTransactionDetails', $params);
  25. }
  26.  
  27. function paypal_refundtransaction($params) {
  28.     return paypal_sendapi('RefundTransaction', $params);
  29. }
  30.  
  31. function paypal_getbalance() {
  32.     return paypal_sendapi('GetBalance');
  33. }
  34.  
  35. function paypal_sendapi($method, $params=false) {
  36.     $r = sendpaypal($method, $params);
  37.  
  38.     if (!$r) {
  39.         return false;
  40.     }
  41.  
  42.     $ack=strtoupper($r['ACK']);
  43.  
  44.     $success=($ack == 'SUCCESS' or $ack == 'SUCCESSWITHWARNING');
  45.  
  46.     if (!$success) {
  47.         return false;
  48.     }
  49.  
  50.     return $r;
  51. }
  52.  
  53. function sendpaypal($method, $params=false) {
  54.     global $paypal_api_url, $paypal_api_version;
  55.     global $paypal_username, $paypal_password, $paypal_signature;
  56.     global $paypal_log;
  57.  
  58.     $args = array(
  59.         'METHOD'        => $method,
  60.         'VERSION'       => $paypal_api_version,
  61.         'USER'          => $paypal_username,
  62.         'PWD'           => $paypal_password,
  63.         'SIGNATURE'     => $paypal_signature,
  64.     );
  65.  
  66.     if (is_array($params)) {
  67.         $args += $params;
  68.     }
  69.  
  70.     $response=sendpost($paypal_api_url, $args);
  71.  
  72.     if (!$response or $response[0] != 200) {
  73.         return false;
  74.     }
  75.  
  76.     parse_str($response[2], $r);
  77.  
  78.     if ($paypal_log) {
  79.         logpaypal($method, $r);
  80.     }
  81.  
  82.     return $r;
  83. }
  84.  
  85. function logpaypal($method, $r) {
  86.     global $paypal_log;
  87.  
  88.     require_once 'log.php';
  89.  
  90.     $ack=strtoupper($r['ACK']);
  91.  
  92.     $token = isset($r['TOKEN']) ? $r['TOKEN'] : false;
  93.  
  94.     $msg=array("METHOD=${method}", "ACK=${ack}");
  95.     if ($token) {
  96.         $msg[] = "TOKEN=${token}";
  97.     }
  98.  
  99.     $success=($ack == 'SUCCESS' or $ack == 'SUCCESSWITHWARNING');
  100.  
  101.     if (!$success) {
  102.         $n=0;
  103.         $err=array();
  104.         while (isset($r["L_ERRORCODE${n}"])) {
  105.             $e=$r["L_ERRORCODE${n}"];
  106.             if (isset($r["L_LONGMESSAGE${n}"])) {
  107.                 $e .= ':' . $r["L_LONGMESSAGE${n}"];
  108.             }
  109.             $err[]=$e;
  110.             $n++;
  111.         }
  112.  
  113.         if ($err) {
  114.             $msg[] = 'ERRORCODE=' . implode('|', $err);
  115.         }
  116.     }
  117.  
  118.     $logmsg=implode(';', $msg);
  119.  
  120.     write_log($paypal_log === true ? 'paypal.log' : $paypal_log, $logmsg);
  121. }
SEE ALSO

sendhttp, log, payline

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].