Browse Source

feat: ✨ added StripePay Route

IceToast 3 years ago
parent
commit
a77455c5fd

+ 73 - 1
app/Http/Controllers/Admin/PaymentController.php

@@ -24,6 +24,8 @@ use PayPalCheckoutSdk\Core\SandboxEnvironment;
 use PayPalCheckoutSdk\Orders\OrdersCaptureRequest;
 use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
 use PayPalHttp\HttpException;
+use Stripe\Stripe;
+
 
 class PaymentController extends Controller
 {
@@ -58,7 +60,7 @@ class PaymentController extends Controller
      * @param CreditProduct $creditProduct
      * @return RedirectResponse
      */
-    public function pay(Request $request, CreditProduct $creditProduct)
+    public function PaypalPay(Request $request, CreditProduct $creditProduct)
     {
         $request = new OrdersCreateRequest();
         $request->prefer('return=representation');
@@ -223,6 +225,76 @@ class PaymentController extends Controller
         return redirect()->route('store.index')->with('success', 'Payment was Canceled');
     }
 
+     /**
+     * @param Request $request
+     * @param CreditProduct $creditProduct
+     * @return RedirectResponse
+     */
+    public function StripePay(Request $request, CreditProduct $creditProduct)
+    {
+        \Stripe\Stripe::setApiKey('sk_test_51Js6U8J2KSABgZztx8QWiohacnzGyIlpOk48DfSoUWPW8mhqLzxcQ5B9a1Wiz8jCC4Xfp3QeBDTsuSU7hkXEUksW00JyN08hoU');
+
+
+
+        $request = \Stripe\Checkout\Session::create([
+            'line_items' => [
+                [
+                'price_data' => [
+                  'currency' => 'eur',
+                  'product_data' => [
+                      'name' => $creditProduct->display,
+                      'description' => $creditProduct->description,
+                  ],
+                  'unit_amount_decimal' => round($creditProduct->price*100, 2),
+                  ],
+                  'quantity' => 1,
+                ],
+                [
+                    'price_data' => [
+                        'currency' => 'eur',
+                        'product_data' => [
+                            'name' => 'Product Tax',
+                            'description' => $creditProduct->getTaxPercent() . "%",
+                        ],
+                        'unit_amount_decimal' => round($creditProduct->getTaxValue(), 2)*100,
+                        ],
+                        'quantity' => 1,
+                ]
+            ],
+            'payment_method_types' => [
+                'card',
+                'giropay',
+                'ideal',
+                'klarna',
+                'sofort',
+                'sepa_debit',
+            ],
+            'mode' => 'payment',
+              'success_url' => route('payment.PaypalCancel'),
+              'cancel_url' => route('payment.PaypalCancel'),
+          ]);
+
+
+
+          return redirect($request->url, 303);
+    }
+
+        /**
+     * @return string
+     */
+    protected function getStripeClientId()
+    {
+        return env('APP_ENV') == 'local' ? env('PAYPAL_SANDBOX_CLIENT_ID') : env('PAYPAL_CLIENT_ID');
+    }
+
+    /**
+     * @return string
+     */
+    protected function getStripeClientSecret()
+    {
+        return env('STRIPE_SECRET');
+    }
+
 
     /**
      * @return JsonResponse|mixed

+ 39 - 27
resources/views/store/checkout.blade.php

@@ -10,8 +10,9 @@
                 </div>
                 <div class="col-sm-6">
                     <ol class="breadcrumb float-sm-right">
-                        <li class="breadcrumb-item"><a class="" href="{{route('home')}}">Dashboard</a></li>
-                        <li class="breadcrumb-item"><a class="text-muted" href="{{route('store.index')}}">Store</a></li>
+                        <li class="breadcrumb-item"><a class="" href="{{ route('home') }}">Dashboard</a></li>
+                        <li class="breadcrumb-item"><a class="text-muted" href="{{ route('store.index') }}">Store</a>
+                        </li>
                     </ol>
                 </div>
             </div>
@@ -34,7 +35,8 @@
                             <div class="col-12">
                                 <h4>
                                     <i class="fas fa-globe"></i> {{ config('app.name', 'Laravel') }}
-                                    <small class="float-right">Date: {{Carbon\Carbon::now()->isoFormat('LL')}}</small>
+                                    <small class="float-right">Date:
+                                        {{ Carbon\Carbon::now()->isoFormat('LL') }}</small>
                                 </h4>
                             </div>
                             <!-- /.col -->
@@ -44,23 +46,23 @@
                             <div class="col-sm-4 invoice-col">
                                 To
                                 <address>
-                                    <strong>{{config('app.name' , 'Laravel')}}</strong><br>
-                                    Email: {{env('PAYPAL_EMAIL' , env('MAIL_FROM_NAME'))}}
+                                    <strong>{{ config('app.name', 'Laravel') }}</strong><br>
+                                    Email: {{ env('PAYPAL_EMAIL', env('MAIL_FROM_NAME')) }}
                                 </address>
                             </div>
                             <!-- /.col -->
                             <div class="col-sm-4 invoice-col">
                                 From
                                 <address>
-                                    <strong>{{Auth::user()->name}}</strong><br>
-                                    Email: {{Auth::user()->email}}
+                                    <strong>{{ Auth::user()->name }}</strong><br>
+                                    Email: {{ Auth::user()->email }}
                                 </address>
                             </div>
                             <!-- /.col -->
                             <div class="col-sm-4 invoice-col">
                                 <b>Status</b><br>
                                 <span class="badge badge-warning">Pending</span><br>
-{{--                                <b>Order ID:</b> 4F3S8J<br>--}}
+                                {{-- <b>Order ID:</b> 4F3S8J<br> --}}
                             </div>
                             <!-- /.col -->
                         </div>
@@ -71,20 +73,22 @@
                             <div class="col-12 table-responsive">
                                 <table class="table table-striped">
                                     <thead>
-                                    <tr>
-                                        <th>Quantity</th>
-                                        <th>Product</th>
-                                        <th>Description</th>
-                                        <th>Subtotal</th>
-                                    </tr>
+                                        <tr>
+                                            <th>Quantity</th>
+                                            <th>Product</th>
+                                            <th>Description</th>
+                                            <th>Subtotal</th>
+                                        </tr>
                                     </thead>
                                     <tbody>
-                                    <tr>
-                                        <td>1</td>
-                                        <td><i class="fa fa-coins mr-2"></i>{{$product->quantity}} {{strtolower($product->type) == 'credits' ? CREDITS_DISPLAY_NAME : $product->type}}</td>
-                                        <td>{{$product->description}}</td>
-                                        <td>{{$product->formatToCurrency($product->price)}}</td>
-                                    </tr>
+                                        <tr>
+                                            <td>1</td>
+                                            <td><i class="fa fa-coins mr-2"></i>{{ $product->quantity }}
+                                                {{ strtolower($product->type) == 'credits' ? CREDITS_DISPLAY_NAME : $product->type }}
+                                            </td>
+                                            <td>{{ $product->description }}</td>
+                                            <td>{{ $product->formatToCurrency($product->price) }}</td>
+                                        </tr>
                                     </tbody>
                                 </table>
                             </div>
@@ -97,7 +101,8 @@
                             <div class="col-6">
                                 <p class="lead">Payment Methods:</p>
 
-                                <img src="https://www.paypalobjects.com/digitalassets/c/website/logo/full-text/pp_fc_hl.svg" alt="Paypal">
+                                <img src="https://www.paypalobjects.com/digitalassets/c/website/logo/full-text/pp_fc_hl.svg"
+                                    alt="Paypal">
 
                                 <p class="text-muted well well-sm shadow-none" style="margin-top: 10px;">
                                     By purchasing this product you agree and accept our terms of service</a>
@@ -105,17 +110,17 @@
                             </div>
                             <!-- /.col -->
                             <div class="col-6">
-                                <p class="lead">Amount Due {{Carbon\Carbon::now()->isoFormat('LL')}}</p>
+                                <p class="lead">Amount Due {{ Carbon\Carbon::now()->isoFormat('LL') }}</p>
 
                                 <div class="table-responsive">
                                     <table class="table">
                                         <tr>
                                             <th style="width:50%">Subtotal:</th>
-                                            <td>{{$product->formatToCurrency($product->price)}}</td>
+                                            <td>{{ $product->formatToCurrency($product->price) }}</td>
                                         </tr>
                                         <tr>
-                                            <th>Tax ({{$taxpercent}}%)</th>
-                                            <td>{{$product->formatToCurrency($taxvalue)}}</td>
+                                            <th>Tax ({{ $taxpercent }}%)</th>
+                                            <td>{{ $product->formatToCurrency($taxvalue) }}</td>
                                         </tr>
                                         <tr>
                                             <th>Quantity:</th>
@@ -123,7 +128,7 @@
                                         </tr>
                                         <tr>
                                             <th>Total:</th>
-                                            <td>{{$product->formatToCurrency($total)}}</td>
+                                            <td>{{ $product->formatToCurrency($total) }}</td>
                                         </tr>
                                     </table>
                                 </div>
@@ -135,7 +140,14 @@
                         <!-- this row will not appear when printing -->
                         <div class="row no-print">
                             <div class="col-12">
-                                <a href="{{route('payment.pay' , $product->id)}}" type="button" class="btn btn-success float-right"><i class="far fa-credit-card mr-2"></i> Submit
+                                <a href="{{ route('payment.PaypalPay', $product->id) }}" type="button"
+                                    class="btn btn-success float-right"><i class="far fa-credit-card mr-2"></i> Submit
+                                    PayPal
+                                    Payment
+                                </a>
+                                <a href="{{ route('payment.StripePay', $product->id) }}" type="button"
+                                    class="btn btn-success float-right"><i class="far fa-credit-card mr-2"></i> Submit
+                                    Stripe
                                     Payment
                                 </a>
                             </div>

+ 3 - 1
routes/web.php

@@ -64,7 +64,9 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
     Route::get('checkout/{creditProduct}', [PaymentController::class, 'checkOut'])->name('checkout');
     Route::get('payment/PaypalSuccess', [PaymentController::class, 'PaypalSuccess'])->name('payment.PaypalSuccess');
     Route::get('payment/PaypalCancel', [PaymentController::class, 'PaypalCancel'])->name('payment.PaypalCancel');
-    Route::get('payment/pay/{creditProduct}', [PaymentController::class, 'pay'])->name('payment.pay');
+    Route::get('payment/PaypalPay/{creditProduct}', [PaymentController::class, 'PaypalPay'])->name('payment.PaypalPay');
+    Route::get('payment/StripePay/{creditProduct}', [PaymentController::class, 'StripePay'])->name('payment.StripePay');
+
 
     Route::get('users/logbackin', [UserController::class, 'logBackIn'])->name('users.logbackin');