コード例 #1
0
 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");
 }
コード例 #2
0
 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");
 }