paypal.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. function exec_ogp_module()
  3. {
  4. global $db,$view;
  5. $settings = $db->getSettings();
  6. $cart_id = $_GET['cart_id'];
  7. if(!empty($cart_id))
  8. {
  9. $orders = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXbilling_orders WHERE cart_id=".$db->realEscapeSingle($cart_id));
  10. if( !empty( $orders ) )
  11. {
  12. $cart['price'] = 0;
  13. foreach($orders as $order)
  14. {
  15. if( $order['qty'] > 1 )
  16. $order['invoice_duration'] = $order['invoice_duration']."s";
  17. $cart['price'] += $order['price'];
  18. if( !isset( $cart['name'] ) )
  19. $cart['name'] = $order['home_name']."(".$order['qty'].get_lang($order['invoice_duration']).",".$order['max_players'].get_lang('slots').")";
  20. else
  21. $cart['name'] .= ' + '.$order['home_name']."(".$order['qty'].get_lang($order['invoice_duration']).",".$order['max_players'].get_lang('slots').")";
  22. }
  23. $total = $cart['price']+($settings['tax_amount']/100*$cart['price']);
  24. if ($total === 0)
  25. {
  26. $db->query("UPDATE " . $table_prefix . "billing_carts
  27. SET paid=1
  28. WHERE cart_id=".$db->realEscapeSingle($cart_id));
  29. $view->refresh("home.php?m=simple-billing&p=cart",0);
  30. }
  31. else
  32. {
  33. // Setup class
  34. require_once('paypal.class.php'); // include the class file
  35. $receiver_email = $settings['paypal_email'];
  36. $p = new paypal_class; // initiate an instance of the class
  37. //$p->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; // Paypal Sandbox URL for developers (https://developer.paypal.com)
  38. $p->paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; // PayPal url
  39. // setup a variable for this script (ie: 'http://www.micahcarrick.com/paypal.php')
  40. $s = ( isset($_SERVER['HTTPS']) and get_true_boolean($_SERVER['HTTPS']) ) ? "s" : "";
  41. $port = isset($_SERVER['SERVER_PORT']) & $_SERVER['SERVER_PORT'] != "80" ? ":".$_SERVER['SERVER_PORT'] : NULL ;
  42. $this_script = 'http'.$s.'://'.$_SERVER['SERVER_NAME'].$port.$_SERVER['SCRIPT_NAME'];
  43. function curPageName()
  44. {
  45. return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
  46. }
  47. $current_folder_url = str_replace( curPageName(), "", $this_script);
  48. $p->add_field('business', $receiver_email);
  49. $p->add_field('currency_code', $settings['currency']);
  50. $p->add_field('return', $this_script.'?m=simple-billing&p=paid');
  51. $p->add_field('cancel_return', $this_script.'?m=simple-billing&p=cart');
  52. $p->add_field('notify_url', $current_folder_url.'modules/simple-billing/paid-ipn.php');
  53. $p->add_field('item_name', $cart['name']);
  54. $p->add_field('item_number', $cart_id);
  55. $p->add_field('amount', number_format( $total , 2 ));
  56. echo "<h2>".get_lang_f('redirecting_to',get_lang('paypal'))."</h2>";
  57. echo "<img style='border:4px dotted white;background:black' src='modules/addonsmanager/loading.gif' width='180' height='180' /img>";
  58. $p->submit_paypal_post(); // submit the fields to paypal
  59. //$p->dump_fields(); // for debugging, output a table of all the fields
  60. }
  61. }
  62. }
  63. }
  64. ?>