Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.98 KB | None | 0 0
  1. <?php
  2.   require_once('./config.php');
  3.  
  4.   $token  = $_POST['stripeToken'];
  5.   $email  = $_POST['stripeEmail'];
  6.  
  7.   $customer = \Stripe\Customer::create(array(
  8.       'email' => $email,
  9.       'source'  => $token
  10.   ));
  11.  
  12.   $charge = \Stripe\Charge::create(array(
  13.       'customer' => $customer->id,
  14.       'amount'   => 600,
  15.       'currency' => 'usd'
  16.   ));
  17.  
  18. $servername = "localhost";
  19. $username = "XXXXXXXXX";
  20. $password = "XXXXXXXXX";
  21. $dbname = "XXXXXXXXXX";
  22.  
  23. // Create connection
  24. $conn = new mysqli($servername, $username, $password, $dbname);
  25. // Check connection
  26. if ($conn->connect_error) {
  27.     die("Connection failed: " . $conn->connect_error);
  28. }
  29.  
  30. //get the diff between today's date and the day they paid on
  31. $used_days = "select datediff(CURRENT_TIMESTAMP(), paid_on) FROM users WHERE username = '".$_POST['username']."'";
  32. $conn->query($used_days); //run the query, set $used_days = result (if any)
  33.  
  34. //SQL query for inserting into table
  35. $sql = "INSERT INTO users
  36.  (username, paid_on, days_bought, plan)
  37. VALUES
  38.  ('".$_POST['username']."', CURRENT_TIMESTAMP, '31', 'Alone')
  39. ON DUPLICATE KEY UPDATE
  40. paid_on     = (CURRENT_TIMESTAMP)
  41. plan        = ('Alone')";
  42.  
  43.  
  44. //If $used_days has no result, run query
  45. if (mysql_num_rows($used_days)==0) //no result
  46. {
  47. $conn->query($sql); //run $sql to insert/update
  48. }else //there is a result
  49.     if($used_days > "31"){ //diff between today and when they paid is more than 31 days, aka old account
  50.         $conn->query($sql);
  51.     }else{
  52.         //account is still active. Add 31 days to whatever days they have
  53.         $days_left = 31 - $used_days;
  54.         $total_days = $days_left + 31;
  55.         $sql2 = "INSERT INTO users
  56.  (username, paid_on, days_bought, plan)
  57. VALUES
  58.  ('".$_POST['username']."', CURRENT_TIMESTAMP, '31', 'Alone')
  59. ON DUPLICATE KEY UPDATE
  60. paid_on     = (CURRENT_TIMESTAMP)
  61. plan        = ('Alone'),
  62. days_bought = ('".$total_days."')";
  63.        
  64.     }
  65. }
  66.  
  67.  
  68. $conn->close();
  69.  
  70.   echo '<h1>Done. Thank you. Your account '. $_POST['username'] .' has been renewed.</h1>';
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement