<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Cart;
use Stripe\Stripe;
use Stripe\Charge;

class CheckoutController extends Controller
{
    //
    public function index(){
        return view('admin.products.checkout');
    }
    public function pay(){
        Stripe::setApiKey("sk_test_3M749AJJ6re1nfC9t1WYe8Xa");
        $token = request()->stripeToken;
        // Charge the user's card:
        $charge = Charge::create(array(
            "amount" => Cart::total() * 9.95,
            "currency" => "usd",
            "description" => "Darija-Coding ecommerce site",
            "source" => $token,
        ));
        Cart::destroy();
        return redirect('/')->with(['success','Commande payée avec succés!']);
    }
}
