|
@@ -6,6 +6,7 @@ use App\Models\PromoCode;
|
|
|
use App\Models\StoreOrder;
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
use Illuminate\Support\Facades\View;
|
|
|
+use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
@@ -29,16 +30,31 @@ class EmailService
|
|
|
$this->stringMappingConfig = config('constants.' . $this->appInternalName);
|
|
|
}
|
|
|
|
|
|
- protected function callJava($endPoint, $data, $sessionKey)
|
|
|
+ protected function callJava($endPoint, $data, $sessionKey, $attachment = null)
|
|
|
{
|
|
|
$data['secret'] = $this->secret;
|
|
|
$url = config('app.backendUrl') . $endPoint;
|
|
|
- $response = Http::asForm()
|
|
|
+ if($attachment){
|
|
|
+ $response = Http::asMultipart()
|
|
|
+ ->attach(
|
|
|
+ $attachment['fileName'],
|
|
|
+ $attachment['contents'],
|
|
|
+ $attachment['name']
|
|
|
+ )
|
|
|
->withHeaders([
|
|
|
'sessionKey' => $sessionKey
|
|
|
])
|
|
|
->post($url, $data)
|
|
|
->body();
|
|
|
+ }else{
|
|
|
+ $response = Http::asForm()
|
|
|
+ ->withHeaders([
|
|
|
+ 'sessionKey' => $sessionKey
|
|
|
+ ])
|
|
|
+ ->post($url, $data)
|
|
|
+ ->body();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
return json_decode($response, true);
|
|
|
}
|
|
@@ -54,7 +70,7 @@ class EmailService
|
|
|
$appUrl = $this->appUrl;
|
|
|
$emailFromName = $this->emailFromName;
|
|
|
$html = (string) view('emails.templates.user-reset-password', compact('user', 'appUrl', 'emailFromName', 'appInternalName', 'stringMappingConfig'));
|
|
|
- $plainText = (string) view('emails.templates.user-reset-password-txt', compact('user', 'appUrl', 'emailFromName', 'appInternalName', 'stringMappingConfig'));
|
|
|
+ $plainText = (string) null;
|
|
|
|
|
|
$params = [
|
|
|
'fromEmailAddress' => $this->fromEmailAddress,
|
|
@@ -215,4 +231,45 @@ class EmailService
|
|
|
|
|
|
$response = $this->callJava('/api/email/send', $params, null);
|
|
|
}
|
|
|
+
|
|
|
+ public function sendEmailWithAttachment($params)
|
|
|
+ {
|
|
|
+ if (!@$params['toEmail']) return;
|
|
|
+ $appInternalName = $this->appInternalName;
|
|
|
+ $stringMappingConfig = $this->stringMappingConfig;
|
|
|
+ $appUrl = $this->appUrl;
|
|
|
+ $emailFromName = $this->emailFromName;
|
|
|
+ $html = (string) view('emails.templates.attachment', compact('params', 'appUrl', 'emailFromName', 'appInternalName', 'stringMappingConfig'));
|
|
|
+ $plainText = (string) '';
|
|
|
+
|
|
|
+ $attachment = $this->getAttachmentFromStoragePath($params['attachmentPath'], 'attachment1');
|
|
|
+
|
|
|
+
|
|
|
+ $emailParams = [
|
|
|
+ 'fromEmailAddress' => $this->fromEmailAddress,
|
|
|
+ 'fromName' => $this->emailFromName,
|
|
|
+ 'toEmailAddress' => @$params['toEmail'],
|
|
|
+ 'subject' => @$params['subject'],
|
|
|
+ 'contentHtml' => $html,
|
|
|
+ 'contentText' => $plainText,
|
|
|
+ 'entityType' => null,
|
|
|
+ 'entityUid' => null,
|
|
|
+ 'attachment1' => $attachment
|
|
|
+ ];
|
|
|
+
|
|
|
+ $response = $this->callJava('/api/email/send', $emailParams, null, $attachment);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getAttachmentFromStoragePath($path, $fileName){
|
|
|
+ if (Storage::exists($path)) {
|
|
|
+ return [
|
|
|
+ 'fileName' => $fileName,
|
|
|
+ 'name' => basename($path),
|
|
|
+ 'contents' => Storage::get($path),
|
|
|
+ 'mime' => Storage::mimeType($path),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|