skrill-ipn.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. if(!isset($_POST['cart_id']) or !is_numeric($_POST['cart_id']))
  3. exit();
  4. ini_set('log_errors', true);
  5. ini_set('error_log', dirname(__FILE__).'/skrill-ipn_errors.log');
  6. chdir("../../"); /* It just makes life easier */
  7. set_include_path(get_include_path() . PATH_SEPARATOR . "includes/");
  8. /* Includes */
  9. require_once("helpers.php");
  10. require_once("config.inc.php");
  11. require_once("functions.php");
  12. require_once("lib_remote.php");
  13. require_once("lang.php");
  14. require_once("modules/config_games/server_config_parser.php");
  15. ogpLang();
  16. /* Query DB */
  17. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  18. $panel_settings = $db->getSettings();
  19. $s = ( isset($_SERVER['HTTPS']) and get_true_boolean($_SERVER['HTTPS']) ) ? "s" : "";
  20. $p = isset($_SERVER['SERVER_PORT']) & $_SERVER['SERVER_PORT'] != "80" ? ":".$_SERVER['SERVER_PORT'] : NULL ;
  21. $this_script = 'http'.$s.'://'.$_SERVER['SERVER_NAME'].$p.$_SERVER['SCRIPT_NAME'];
  22. function curPageName()
  23. {
  24. return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
  25. }
  26. $current_folder_url = str_replace( curPageName(), "", $this_script);
  27. if( empty( $panel_settings['panel_name'] ) )
  28. $panel_name = "Open Game Panel";
  29. else
  30. $panel_name = $panel_settings['panel_name'];
  31. $cart_id = $_POST['cart_id'];
  32. $cart_price_info = $db->resultQuery( "SELECT price,tax_amount,currency
  33. FROM OGP_DB_PREFIXbilling_carts AS cart
  34. JOIN
  35. OGP_DB_PREFIXbilling_orders AS orders
  36. ON
  37. orders.cart_id=cart.cart_id
  38. WHERE cart.cart_id=".$db->realEscapeSingle($cart_id));
  39. if(!$cart_price_info or empty($cart_price_info))
  40. exit();
  41. $cart_price = number_format( $cart_price_info[0]['price'] + (($cart_price_info[0]['price']/100)*$cart_price_info[0]['tax_amount']) , 2 );
  42. $cart_currency = $cart_price_info[0]['currency'];
  43. // Validate the Moneybookers signature
  44. $concatFields = $panel_settings['skrill_merchant_id'].
  45. $_POST['transaction_id'].
  46. strtoupper($panel_settings['skrill_secret_word']).
  47. $cart_price.
  48. $cart_currency.
  49. $_POST['status'];
  50. // Ensure the signature is valid, the status code == 2,
  51. // and that the money is going to you
  52. if (strtoupper(md5($concatFields)) == $_POST['md5sig']
  53. && $_POST['status'] == 2
  54. && $_POST['pay_to_email'] == $panel_settings['skrill_email'])
  55. {
  56. $body = 'Paid to email : '.$_POST['pay_to_email']."<br>".
  57. 'Currency : '.$_POST['currency']."<br>".
  58. 'Amount : '.$_POST['amount']."<br>".
  59. 'Payment type : '.$_POST['payment_type']."<br>".
  60. 'Transaction ID : '.$_POST['transaction_id']."<br>".
  61. 'Paid from email : '.$_POST['pay_from_email']."<br>".
  62. 'CART ID : '.$_POST['cart_id']."<br>";
  63. // Here you can do whatever you want with the variables, for instance inserting or updating data into your Database
  64. $user_homes = $db->resultQuery( "SELECT *
  65. FROM OGP_DB_PREFIXbilling_carts AS cart
  66. JOIN
  67. OGP_DB_PREFIXbilling_orders AS orders
  68. ON
  69. orders.cart_id=cart.cart_id
  70. WHERE cart.cart_id=".$db->realEscapeSingle($cart_id));
  71. $query = "UPDATE " . $table_prefix . "billing_carts
  72. SET paid=1
  73. WHERE cart_id=".$db->realEscapeSingle($cart_id);
  74. foreach($user_homes as $user_home)
  75. {
  76. if($user_home['home_id'] != 0)
  77. {
  78. $home_id = $user_home['home_id'];
  79. $home_info = $db->getGameHomeWithoutMods($home_id);
  80. $server_info = $db->getRemoteServerById($home_info['remote_server_id']);
  81. $remote = new OGPRemoteLibrary($server_info['agent_ip'], $server_info['agent_port'], $server_info['encryption_key'], $server_info['timeout']);
  82. if ( isset( $home_info['ftp_password'] ) AND !empty( $home_info['ftp_password'] ) )
  83. {
  84. $remote->ftp_mgr("useradd", $home_info['home_id'], $home_info['ftp_password'], $home_info['home_path']);
  85. $db->changeFtpStatus('enabled',$home_info['home_id']);
  86. }
  87. if ($user_home['end_date'] == "0")
  88. {
  89. if ($user_home['invoice_duration'] == "hour")
  90. {
  91. $add_time = time() + ($user_home['qty'] * 60 * 60);
  92. $end_date = date('YmdHi',$add_time);
  93. }
  94. elseif ($user_home['invoice_duration'] == "month")
  95. {
  96. $end_date = date('YmdHi', strtotime('+'.$user_home['qty'].' month'));
  97. }
  98. elseif ($user_home['invoice_duration'] == "year")
  99. {
  100. $end_date = date('YmdHi', strtotime('+'.$user_home['qty'].' year'));
  101. }
  102. //Set the expiration date to the new order
  103. $db->query( "UPDATE " . $table_prefix . "billing_orders
  104. SET end_date='" . $db->realEscapeSingle($end_date) . "'
  105. WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
  106. // Set payment/creation date
  107. $date = date('d/m/Y H:i');
  108. $db->query( "UPDATE OGP_DB_PREFIXbilling_carts
  109. SET date='" . $db->realEscapeSingle($date) . "'
  110. WHERE cart_id=".$cart_id);
  111. }
  112. $services = $db->resultQuery( "SELECT *
  113. FROM OGP_DB_PREFIXbilling_services
  114. WHERE service_id=".$db->realEscapeSingle($user_home['service_id']));
  115. $service = $services[0];
  116. $user_id = $user_home['user_id'];
  117. $db->assignHomeTo("user", $user_id, $home_id, $service['access_rights']);
  118. $query = "UPDATE " . $table_prefix . "billing_carts
  119. SET paid=3
  120. WHERE cart_id=".$db->realEscapeSingle($cart_id);
  121. }
  122. }
  123. $db->query($query);
  124. $subject = "Payment done.";
  125. mymail($panel_settings['skrill_email'], $subject, $body, $panel_settings);
  126. }
  127. ?>