function __construct()
 {
     adminGateKeeper();
     $guid = pageArray(2);
     $product = getEntity($guid);
     \Stripe\Stripe::setApiKey(EcommercePlugin::secretKey());
     if ($product->interval != "one_time") {
         try {
             $plan = \Stripe\Plan::retrieve($guid);
             $plan->delete();
         } catch (Exception $e) {
             forward();
         }
     } else {
         if ($product->stripe_sku) {
             $sku = \Stripe\SKU::retrieve($product->stripe_sku);
             $sku->delete();
         }
         if ($product->stripe_product_id) {
             $stripe_product = \Stripe\Product::retrieve($product->stripe_product_id);
             $stripe_product->delete();
         }
     }
     $product->delete();
     new SystemMessage("Your product has been deleted.");
     forward("store");
 }
 public function init($file)
 {
     if (!loggedIn()) {
         return false;
     }
     if (!is_a($file, "SocialApparatus\\File")) {
         return false;
     }
     $product = getEntity($file->container_guid);
     if (!is_a($product, "SocialApparatus\\Product")) {
         return false;
     }
     $user = getLoggedInUser();
     if ($user->stripe_cust) {
         \Stripe\Stripe::setApiKey(EcommercePlugin::secretKey());
         $orders = \Stripe\Order::all(array("limit" => 300, "customer" => $user->stripe_cust));
         foreach ($orders['data'] as $order) {
             foreach ($order->items as $item) {
                 if ($item->description != "Taxes (included)" && $item->description != "Free shipping") {
                     $sku = $item->parent;
                     if ($sku == $product->stripe_sku) {
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
 function __construct()
 {
     \Stripe\Stripe::setApiKey(EcommercePlugin::secretKey());
     $order_items = array();
     $user = getLoggedInUser();
     $stripe_cust = $user->stripe_cust;
     $cart = Cache::get("cart", "session");
     if (!$stripe_cust) {
         try {
             $cu = \Stripe\Customer::create(array("description" => $user->email, "source" => getInput("stripeToken")));
         } catch (Exception $e) {
             new SystemMessage("There has been an error.  Please contact us.");
             forward("home");
         }
         $user->stripe_cust = $cu->id;
         $user->save();
     } else {
         $cu = \Stripe\Customer::retrieve($stripe_cust);
         try {
             $cu->source = getInput("stripeToken");
         } catch (Exception $e) {
             new SystemMessage("There has been an error.  Please contact us.");
             forward("home");
         }
         $cu->save();
     }
     foreach ($cart as $guid => $details) {
         $product = getEntity($guid);
         if ($product->interval == "one_time") {
             $order_item = array("type" => "sku", "parent" => $product->stripe_sku, "description" => $product->description . $details);
             $order_items[] = $order_item;
         } else {
             try {
                 $cu->subscriptions->create(array("plan" => $guid));
             } catch (Exception $e) {
                 new SystemMessage("There has been an error.  Please contact us.");
                 forward("home");
             }
         }
     }
     if (!empty($order_items)) {
         try {
             $order = \Stripe\Order::create(array("items" => $order_items, "currency" => "usd", "customer" => $cu->id));
             $order->pay(array("customer" => $cu->id, "email" => $user->email));
         } catch (Exception $e) {
             new SystemMessage("There has been an error.  Please contact us.");
             forward("home");
         }
     }
     $invoice = new Invoice();
     $invoice->items = $cart;
     $invoice->status = "paid";
     $invoice->owner_guid = getLoggedInUserGuid();
     $invoice->stripe_order = $order->id;
     $invoice->save();
     Cache::delete("cart", "session");
     new SystemMessage("Your purchase is complete.");
     forward("billing");
 }
 function __construct()
 {
     gateKeeper();
     $user = getLoggedInUser();
     $subscription = pageArray(2);
     if ($subscription && $user->stripe_cust) {
         \Stripe\Stripe::setApiKey(EcommercePlugin::secretKey());
         $cu = \Stripe\Customer::retrieve($user->stripe_cust);
         $cu->subscriptions->retrieve($subscription)->cancel();
         new SystemMessage("Your subscription has been canceled.");
     }
     forward();
 }
 function __construct()
 {
     adminGateKeeper();
     \Stripe\Stripe::setApiKey(EcommercePlugin::secretKey());
     $container_guid = getInput("container_guid");
     $title = getInput("title");
     $description = getInput('description');
     $interval = getInput("interval");
     $price = getInput("price");
     $product = new Product();
     $product->title = $title;
     $product->description = $description;
     $product->price = $price;
     $product->container_guid = $container_guid;
     $product->interval = $interval;
     $product->access_id = "public";
     $product->save();
     $product->createAvatar();
     if (isset($_FILES["download"]) && $_FILES["download"]["name"]) {
         $file = new File();
         $file->access_id = "product";
         $file->container_guid = $product->guid;
         $guid = $file->save();
         uploadFile("download", $guid, array("zip"));
         $product->download = $guid;
     }
     if ($interval != "one_time") {
         $stripe_plan = \Stripe\Plan::create(array("amount" => $price * 100, "interval" => $interval, "name" => $title, "currency" => "usd", "id" => $product->guid));
         $id = $stripe_plan->id;
         $product->stripe_id = $id;
         $product->save();
     } else {
         // Create product and SKU in stripe
         $stripe_product = \Stripe\Product::create(array("name" => $product->title, "description" => $product->description, "shippable" => false));
         $product->stripe_product_id = $stripe_product->id;
         // Create SKU
         $stripe_sku = \Stripe\SKU::create(array("product" => $stripe_product->id, "price" => $product->price * 100, "currency" => "usd", "inventory" => array("type" => "infinite"), "metadata" => array("guid" => $product->guid)));
         $product->stripe_sku = $stripe_sku->id;
         $product->save();
     }
     new SystemMessage("Your product has been saved.");
     forward("store");
 }
 *
 *
 * @author     Shane Barron <*****@*****.**>
 * @author     Aaustin Barron <*****@*****.**>
 * @copyright  2015 SocialApparatus
 * @license    http://opensource.org/licenses/MIT MIT
 * @version    1
 * @link       http://socialapparatus.com
 */
namespace SocialApparatus;

denyDirect();
gateKeeper();
$user = getLoggedInUser();
if ($user->stripe_cust) {
    \Stripe\Stripe::setApiKey(EcommercePlugin::secretKey());
    $subscriptions = \Stripe\Customer::retrieve($user->stripe_cust)->subscriptions->all(array('limit' => 300));
    $orders = \Stripe\Order::all(array("limit" => 300, "customer" => $user->stripe_cust));
    ?>
    <h2>Orders</h2>
    <table class='table table-striped table-hover table-bordered'>
        <tr>
            <th>Date</th>
            <th>Order ID</th>
            <th>Amount</th>
            <th>Status</th>
            <th>Details</th>
        </tr>
        <?php 
    foreach ($orders['data'] as $order) {
        $details_url = getSiteURL() . "order/" . $order->id;
 * @link       http://socialapparatus.com
 */
namespace SocialApparatus;

denyDirect();
$total = Vars("total");
$user = getLoggedInUser();
$label = Vars("label");
if (!$label) {
    $label = "Purchase";
}
?>
<script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="<?php 
echo EcommercePlugin::publishableKey();
?>
"
    data-name="<?php 
echo getSiteName();
?>
"
    data-email ="<?php 
echo $user->email;
?>
"
    data-description="Purchase from <?php 
echo getSiteName();
?>
"
    data-amount="<?php