Ejemplo n.º 1
0
        if (empty($user["stripe_cust_id"])) {
            // create a new customer
            $stripe_cust_id = createStripeCustomer($token, $user);
            $user["stripe_cust_id"] = $stripe_cust_id;
        } else {
            // update an existing customer's source
            $cu = \Stripe\Customer::retrieve($user["stripe_cust_id"]);
            $cu->source = $token;
            // obtained with Stripe.js
            $cu->save();
        }
    }
    // create a new plan
    $cust = \Stripe\Customer::retrieve($user["stripe_cust_id"]);
    $subscription = $cust->subscriptions->create(array("plan" => $mem_level));
    enrollUser($user["user_id"], $mem_level, $subscription->id);
    // update users_table with member_level and plan id
    $_SESSION["new_member"] = true;
    header("Location:/user/membership/");
} else {
    ?>
<html>
<?php 
    include ROOT_PATH . "inc/head.php";
    ?>
<body>
  <?php 
    include ROOT_PATH . "inc/header.php";
    ?>
  <div class="wrapper content">
    <div class="row">
Ejemplo n.º 2
0
}
require_once "../../inc/config.php";
require_once ROOT_PATH . "inc/database.php";
$mem_levels = array("Individual", "Family", "Steward", "Business Basic", "Business Premium");
$mem_icons = array("fa-user", "fa-users", "fa-user-plus", "fa-briefcase", "fa-briefcase");
$mem_level = $_SESSION["member_level"];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $level = (int) $_POST["level"];
    $subscription_id = getSubscriptionId($_SESSION["user_id"]);
    $cust_id = getStripeCustomerId($_SESSION["user_id"]);
    $cust = \Stripe\Customer::retrieve($cust_id);
    $subscription = $cust->subscriptions->retrieve($subscription_id);
    $subscription->plan = $level;
    $subscription->save();
    $_SESSION["member_level"] = $level;
    enrollUser($_SESSION["user_id"], $level);
    $_SESSION["change_mem_level"] = true;
    header("Location:/user/membership/");
} else {
    ?>
<html>
<?php 
    include ROOT_PATH . "inc/head.php";
    ?>
<body>
  <?php 
    include ROOT_PATH . "inc/header.php";
    ?>
  <div class="wrapper content">
    <div class="row">
      <div class="col-20">
Ejemplo n.º 3
0
    header("Location:/login/");
}
require_once "../../inc/config.php";
require_once ROOT_PATH . "inc/database.php";
if ($_SESSION["member_level"] == 0) {
    header("Location:/user/membership/");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if ($_POST["action"] == "cancel") {
        $subscription_id = getSubscriptionId($_SESSION["user_id"]);
        $cust_id = getStripeCustomerId($_SESSION["user_id"]);
        $cust = \Stripe\Customer::retrieve($cust_id);
        $subscription = $cust->subscriptions->retrieve($subscription_id);
        $subscription->cancel();
        $_SESSION["member_level"] = 0;
        enrollUser($_SESSION["user_id"], 0);
        $_SESSION["cancelled"] = true;
        header("Location:/user/membership/cancel/");
    }
    if ($_POST["action"] == "redirect") {
        header("Location:/user/membership/");
    }
} else {
    ?>
<html>
<?php 
    include ROOT_PATH . "inc/head.php";
    ?>
<body>
  <?php 
    include ROOT_PATH . "inc/header.php";