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"); }
* @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; ?> <tr>
* * * * @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(); \Stripe\Stripe::setApiKey(EcommercePlugin::secretKey()); $order_id = pageArray(1); $order = \Stripe\Order::retrieve($order_id); echo "<table class='table table-striped table-hover table-bordered'>"; echo "<tr>"; echo "<th>Date</th>"; echo "<th>Order ID</th>"; echo "<th>Description</th>"; echo "<th>Amount</th>"; echo "<th>Download</th>"; echo "</tr>"; foreach ($order->items as $item) { if ($item->description != "Taxes (included)" && $item->description != "Free shipping") { $sku = $item->parent; $product = getEntity(array("type" => "Product", "metadata_name" => "stripe_sku", "metadata_value" => $sku)); echo "<tr>"; echo "<td>"; echo date("m/d/Y", $order->created);