/** * Post OTO for stripe */ public function postStripeOto() { // Add third party libraries require_once app_path() . "/libraries/stripe-php-1.9.0/lib/Stripe.php"; // Add Stripe library Stripe::setApiKey(Config::get('project.stripe_secret_key')); $customer_id = Input::get('customer_id'); $product_id = Input::get('product_id'); $plan_id = Input::get('plan_id'); $buyer_id = Input::get('buyer_id'); $plan = Plan::where('id', '=', $plan_id)->first(); $buyer = Buyer::where('id', '=', $buyer_id)->first(); // Update Buyer IP Buyer::updateLastIP($buyer); try { $customer = Stripe_Customer::retrieve($customer_id); // If plan is recurring if ($plan->is_recurring) { // Add new subscription $cu->subscriptions->create(array("plan" => $plan->stripe_id)); // Add Setup Fee $customer->account_balance = $plan->setup_fee * 100; $customer->save(); } else { // Extract card token Stripe_Charge::create(array("amount" => $plan->price * 100, "currency" => "usd", "customer" => $customer_id, "description" => "Charge for {$plan->name} ({$buyer->email})", "metadata" => array("plan_id" => $plan->id))); } } catch (Exception $e) { return Response::make(json_encode(array("error" => true, "message" => "Cannot create charge"))); } return Response::make(json_encode(array("success" => true))); }