Bläddra i källkod

feat: ✨ modified db payment table

IceToast 3 år sedan
förälder
incheckning
34a8d566a7

+ 9 - 13
app/Http/Controllers/Admin/PaymentController.php

@@ -177,7 +177,7 @@ class PaymentController extends Controller
                 $payment = Payment::create([
                     'user_id' => $user->id,
                     'payment_id' => $response->result->id,
-                    'payer_id' => $laravelRequest->input('PayerID'),
+                    'payment_method' => 'paypal',
                     'type' => 'Credits',
                     'status' => $response->result->status,
                     'amount' => $creditProduct->quantity,
@@ -186,7 +186,6 @@ class PaymentController extends Controller
                     'tax_percent' => $creditProduct->getTaxPercent(),
                     'total_price' => $creditProduct->getTotalPrice(),
                     'currency_code' => $creditProduct->currency_code,
-                    'payer' => json_encode($response->result->payer),
                 ]);
 
                 //payment notification
@@ -236,7 +235,7 @@ class PaymentController extends Controller
 
         $stripeClient = $this->getStripeClient();
 
-        $request = $stripeClient->sessions->create([
+        $request = $stripeClient->checkout->sessions->create([
             'line_items' => [
                 [
                 'price_data' => [
@@ -280,7 +279,6 @@ class PaymentController extends Controller
      */
     public function StripeSuccess(Request $request)
     {
-        echo $request->input('product');
         /** @var CreditProduct $creditProduct */
         $creditProduct = CreditProduct::findOrFail($request->input('product'));
 
@@ -289,12 +287,11 @@ class PaymentController extends Controller
 
         $stripeClient = $this->getStripeClient();
 
-
         try{
-        $paymentSession = $stripeClient->sessions->retrieve($request->input('session_id'));
-        $capturedPaymentIntent = $stripeClient->paymentIntents->capture($paymentSession.payment_intent);
+        $paymentSession = $stripeClient->checkout->sessions->retrieve($request->input('session_id'));
+        $capturedPaymentIntent = $stripeClient->paymentIntents->capture($paymentSession->payment_intent);
 
-        if ($response->payment_status == "paid") {
+        if ($capturedPaymentIntent->status == "succeeded") {
 
             //update credits
             $user->increment('credits', $creditProduct->quantity);
@@ -314,17 +311,16 @@ class PaymentController extends Controller
             //store payment
             $payment = Payment::create([
                 'user_id' => $user->id,
-                'payment_id' => $response->result->id,
-                'payer_id' => $request->input('PayerID'),
+                'payment_id' => $capturedPaymentIntent->id,
+                'payment_method' => 'stripe',
                 'type' => 'Credits',
-                'status' => $response->payment_status,
+                'status' => $capturedPaymentIntent->status,
                 'amount' => $creditProduct->quantity,
                 'price' => $creditProduct->price,
                 'tax_value' => $creditProduct->getTaxValue(),
-                'tax_percent' => $creditProduct->getTaxPercent(),
                 'total_price' => $creditProduct->getTotalPrice(),
+                'tax_percent' => $creditProduct->getTaxPercent(),
                 'currency_code' => $creditProduct->currency_code,
-                'payer' => json_encode($response->result->payer),
             ]);
 
             //payment notification

+ 2 - 3
app/Models/Payment.php

@@ -23,8 +23,7 @@ class Payment extends Model
         'id',
         'user_id',
         'payment_id',
-        'payer_id',
-        'payer',
+        'payment_method',
         'status',
         'type',
         'amount',
@@ -57,7 +56,7 @@ class Payment extends Model
     /**
      * @param mixed $value
      * @param string $locale
-     * 
+     *
      * @return float
      */
     public function formatToCurrency($value,$locale = 'en_US')

+ 1 - 2
database/migrations/2021_02_16_162655_create_payments_table.php

@@ -17,12 +17,11 @@ class CreatePaymentsTable extends Migration
             $table->uuid('id');
             $table->foreignId('user_id')->references('id')->on('users');
             $table->string('payment_id')->nullable();
-            $table->string('payer_id')->nullable();;
+            $table->string('payment_method')->nullable();
             $table->string('type')->nullable();;
             $table->string('status')->nullable();;
             $table->string('amount')->nullable();;
             $table->string('price')->nullable();;
-            $table->text('payer')->nullable();;
             $table->timestamps();
         });
     }

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 17 - 1
public/css/app.css


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 1
public/js/app.js


Vissa filer visades inte eftersom för många filer har ändrats