Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('./config.php');
- $token = $_POST['stripeToken'];
- $email = $_POST['stripeEmail'];
- $customer = \Stripe\Customer::create(array(
- 'email' => $email,
- 'source' => $token
- ));
- $charge = \Stripe\Charge::create(array(
- 'customer' => $customer->id,
- 'amount' => 600,
- 'currency' => 'usd'
- ));
- $servername = "localhost";
- $username = "XXXXXXXXX";
- $password = "XXXXXXXXX";
- $dbname = "XXXXXXXXXX";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- //get the diff between today's date and the day they paid on
- $used_days = "select datediff(CURRENT_TIMESTAMP(), paid_on) FROM users WHERE username = '".$_POST['username']."'";
- $conn->query($used_days); //run the query, set $used_days = result (if any)
- //SQL query for inserting into table
- $sql = "INSERT INTO users
- (username, paid_on, days_bought, plan)
- VALUES
- ('".$_POST['username']."', CURRENT_TIMESTAMP, '31', 'Alone')
- ON DUPLICATE KEY UPDATE
- paid_on = (CURRENT_TIMESTAMP)
- plan = ('Alone')";
- //If $used_days has no result, run query
- if (mysql_num_rows($used_days)==0) //no result
- {
- $conn->query($sql); //run $sql to insert/update
- }else //there is a result
- if($used_days > "31"){ //diff between today and when they paid is more than 31 days, aka old account
- $conn->query($sql);
- }else{
- //account is still active. Add 31 days to whatever days they have
- $days_left = 31 - $used_days;
- $total_days = $days_left + 31;
- $sql2 = "INSERT INTO users
- (username, paid_on, days_bought, plan)
- VALUES
- ('".$_POST['username']."', CURRENT_TIMESTAMP, '31', 'Alone')
- ON DUPLICATE KEY UPDATE
- paid_on = (CURRENT_TIMESTAMP)
- plan = ('Alone'),
- days_bought = ('".$total_days."')";
- }
- }
- $conn->close();
- echo '<h1>Done. Thank you. Your account '. $_POST['username'] .' has been renewed.</h1>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement