Эх сурвалжийг харах

Merge branch 'master' of https://rav.triplestart.com/tigerphp/lemon-admin

Peter Muturi 1 жил өмнө
parent
commit
06ee6c2104

+ 17 - 2
app/Http/Controllers/AdminController.php

@@ -259,15 +259,30 @@ class AdminController extends Controller
             'amount' => $request->get('amount')
         ];
 
+        $storeOrderUid = $request->get('orderUid');
+        $storeOrder = StoreOrder::where('uid', $storeOrderUid)->first();
+
         $response = $this->callJava('/api/financialTransaction/createCharge', $data, $this->sessionKey);
         if (!@$response['success']) {
-            $storeOrder = StoreOrder::where('uid', $request->get('orderUid'))->first();
             if($storeOrder){
-               $this->emailService->notifyUserOnFailedTransaction($storeOrder->user);
+               $this->emailService->notifyUserOnFailedTransaction($storeOrder->user, $storeOrder);
             }
 
             return $this->fail($response['message'] ?? 'Failed!');
         }
+
+        $message = $response['message'];
+        if ($message == 'ORDER_NOT_CHARGED') {
+            $message = 'Your order has been submitted but not charged.';
+            $this->emailService->notifyUserOnFailedTransaction($storeOrder->user, $storeOrder);
+            return $this->fail($message);
+        }
+        
+        if($storeOrder){
+            $user = $storeOrder->user;
+            $this->emailService->sendUserOrderChargeSuccessful($user, $storeOrder);
+        }
+
         return $this->pass();
     }
 

+ 3 - 0
app/Http/Controllers/EmailTestController.php

@@ -28,6 +28,9 @@ class EmailTestController extends Controller
 
     public function previewEmail($email = null)
     {
+        if(!$this->user->is_super_admin){
+            abort(403);
+        }
         $appInternalName = $this->appInternalName;
         $stringMappingConfig = $this->stringMappingConfig;
         if($email){

+ 25 - 1
app/Http/Services/EmailService.php

@@ -96,7 +96,7 @@ class EmailService
         $response = $this->callJava('/api/email/send', $params, null);
     }
 
-    public function notifyUserOnFailedTransaction(User $user)
+    public function notifyUserOnFailedTransaction(User $user, StoreOrder $storeOrder)
     {
         if(!@$user->getEmail()) return;
         $appInternalName = $this->appInternalName;
@@ -167,4 +167,28 @@ class EmailService
 
         $response = $this->callJava('/api/email/send', $params, null);
     }
+
+    public function sendUserOrderChargeSuccessful(User $user, StoreOrder $storeOrder)
+    {
+        if (!$user->getEmail()) return;
+        $appInternalName = $this->appInternalName;
+        $stringMappingConfig = $this->stringMappingConfig;
+        $appUrl = $this->appUrl;
+        $emailFromName = $this->emailFromName;
+        $html = (string) view('emails.templates.user-payment-successful', compact('storeOrder', 'user', 'appUrl', 'emailFromName', 'appInternalName', 'stringMappingConfig'));
+        $plainText = (string) '';
+
+        $params = [
+            'fromEmailAddress' => $this->fromEmailAddress,
+            'fromName' => $this->emailFromName,
+            'toEmailAddress' => $user->getEmail(),
+            'subject' => 'Order Charged successfully!',
+            'contentHtml' => $html,
+            'contentText' => $plainText,
+            'entityType' => 'USER',
+            'entityUid' => $user->uid,
+        ];
+
+        $response = $this->callJava('/api/email/send', $params, null);
+    }
 }