瀏覽代碼

Email and Paygate Redirect

master
30117125 4 年之前
父節點
當前提交
9c532d78d6

+ 31
- 0
UnivateProperties_API/Controllers/Financial/RedirectController.cs 查看文件

@@ -0,0 +1,31 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using UnivateProperties_API.Model.Financial;
3
+
4
+namespace UnivateProperties_API.Controllers.Financial
5
+{
6
+    [Route("api/[controller]")]
7
+    [ApiController]
8
+    public class RedirectController : ControllerBase
9
+    {
10
+
11
+        // POST: api/Redirect
12
+        [HttpPost]
13
+        [Consumes("application/x-www-form-urlencoded")]
14
+        public RedirectResult PostRedirect([FromForm] ReturnToMerchant context)
15
+        {
16
+            if (context.TRANSACTION_STATUS == 1)
17
+            {
18
+                return Redirect("http://localhost:8080/#/payments/success");
19
+            }
20
+            else if (context.TRANSACTION_STATUS == 2)
21
+            {
22
+                return Redirect("http://training.provision-sa.com:121/#/paymentError");
23
+            }
24
+            else
25
+            {
26
+                return Redirect("http://localhost:8080/");
27
+            }
28
+
29
+        }
30
+    }
31
+}

+ 80
- 0
UnivateProperties_API/Helpers/Communication/EmailCodedFieldsPopulator.cs 查看文件

@@ -0,0 +1,80 @@
1
+using System.Linq;
2
+using UnivateProperties_API.Containers.Timeshare;
3
+using UnivateProperties_API.Context;
4
+using UnivateProperties_API.Model.Users;
5
+
6
+namespace UnivateProperties_API.Helpers.Communication
7
+{
8
+    public class EmailCodedFieldsPopulator
9
+    {
10
+        private readonly DataContext _dbContext;
11
+
12
+        public EmailCodedFieldsPopulator(DataContext dataContext)
13
+        {
14
+            _dbContext = dataContext;
15
+        }
16
+        public EmailCodedFieldsPopulator( )
17
+        {
18
+            
19
+        }
20
+
21
+        public string getCodedBody(string htmlBody, Person sendTo, TimeshareWeekDto sellItem)
22
+        {
23
+            var agent = _dbContext.Agents.Where(ag => ag.Id == sellItem.AgentId).FirstOrDefault();
24
+            htmlBody = htmlBody.Replace("[ReferedByAgent]", sellItem.ReferedByAgent.ToString());
25
+            htmlBody = htmlBody.Replace("[AgentId]", sellItem.AgentId.ToString());
26
+            htmlBody = htmlBody.Replace("[AgencyId]", sellItem.AgencyId.ToString());
27
+            htmlBody = htmlBody.Replace("[OwnerId]", sellItem.OwnerId.ToString());
28
+            htmlBody = htmlBody.Replace("[AgentAsRep]", sellItem.AgentAsRep.ToString());
29
+            htmlBody = htmlBody.Replace("[OtherResort]", sellItem.OtherResort.ToString());
30
+            htmlBody = htmlBody.Replace("[OtherResortName]", sellItem.OtherResortName != null ? sellItem.OtherResortName.ToString() : "");
31
+            htmlBody = htmlBody.Replace("[ResortCode]", sellItem.ResortCode.ToString());
32
+            htmlBody = htmlBody.Replace("[ResortName]", sellItem.ResortName.ToString());
33
+            htmlBody = htmlBody.Replace("[RegionId]", sellItem.RegionId.ToString());
34
+            htmlBody = htmlBody.Replace("[Season]", sellItem.Season.ToString());
35
+            htmlBody = htmlBody.Replace("[Module]", sellItem.Module.ToString());
36
+            htmlBody = htmlBody.Replace("[Bedrooms]", sellItem.Bedrooms.ToString());
37
+            htmlBody = htmlBody.Replace("[MaxSleep]", sellItem.MaxSleep.ToString());
38
+            htmlBody = htmlBody.Replace("[UnitNumber]", sellItem.UnitNumber.ToString());
39
+            htmlBody = htmlBody.Replace("[WeekNumber]", sellItem.WeekNumber != null ? sellItem.WeekNumber.ToString() : "");
40
+            htmlBody = htmlBody.Replace("[LevyAmount]", sellItem.LevyAmount.ToString());
41
+            htmlBody = htmlBody.Replace("[CurrentYearBanked]", sellItem.CurrentYearBanked.ToString());
42
+            htmlBody = htmlBody.Replace("[BankedWith]", sellItem.BankedWith != null ? sellItem.BankedWith.ToString() : "");
43
+            htmlBody = htmlBody.Replace("[Valid]", sellItem.Valid != null ? sellItem.Valid.ToString() : "");
44
+            htmlBody = htmlBody.Replace("[IsDeleted]", sellItem.IsDeleted.ToString());
45
+            htmlBody = htmlBody.Replace("[Display]", sellItem.Display.ToString());
46
+            htmlBody = htmlBody.Replace("[LeviesPaidInFull]", sellItem.LeviesPaidInFull.ToString());
47
+            htmlBody = htmlBody.Replace("[WeekPlacedForRental]", sellItem.WeekPlacedForRental.ToString());
48
+            htmlBody = htmlBody.Replace("[OriginalPurchaseDate]", sellItem.OriginalPurchaseDate.ToString());
49
+            htmlBody = htmlBody.Replace("[OriginalPurchasePrice]", sellItem.OriginalPurchasePrice.ToString());
50
+            htmlBody = htmlBody.Replace("[ArrivalDate]", sellItem.ArrivalDate.ToString());
51
+            htmlBody = htmlBody.Replace("[DepartureDate]", sellItem.DepartureDate.ToString());
52
+            htmlBody = htmlBody.Replace("[SellPrice]", sellItem.SellPrice.ToString());
53
+            htmlBody = htmlBody.Replace("[AgentCommision]", sellItem.AgentCommision.ToString());
54
+            htmlBody = htmlBody.Replace("[Mandate]", sellItem.Mandate != null ? sellItem.Mandate.ToString() : "");
55
+            htmlBody = htmlBody.Replace("[StatusId]", sellItem.StatusId.ToString());
56
+            htmlBody = htmlBody.Replace("[Status]", sellItem.Status != null ? sellItem.Status.ToString() : "");
57
+            htmlBody = htmlBody.Replace("[Region]", sellItem.Region.ToString());
58
+            
59
+            if (agent != null)
60
+            {
61
+                htmlBody = htmlBody.Replace("[Agent]", agent.FullName != null ? agent.FullName.ToString() : "");
62
+                htmlBody = htmlBody.Replace("[Agency]", agent.Agency != null ? agent.Agency.ToString() : "");
63
+            }
64
+            else
65
+            {
66
+                htmlBody = htmlBody.Replace("[Agent]", "");
67
+                htmlBody = htmlBody.Replace("[Agency]", "");
68
+                htmlBody = htmlBody.Replace("[Owner]", sendTo.FullName != null ? sendTo.FullName.ToString() : "");
69
+            }
70
+            
71
+            htmlBody = htmlBody.Replace("[BidItems]", sellItem.BidItems != null ? sellItem.BidItems.ToString() : "");
72
+            htmlBody = htmlBody.Replace("[ProcessFlows]", sellItem.ProcessFlows != null ? sellItem.ProcessFlows.ToString() : "");
73
+            htmlBody = htmlBody.Replace("[Id]", sellItem.Id.ToString());
74
+            htmlBody = htmlBody.Replace("[Created]", sellItem.Created.ToString());
75
+            htmlBody = htmlBody.Replace("[Modified]", sellItem.Modified.ToString());
76
+            htmlBody = htmlBody.Replace("[ModifiedBy]", sellItem.ModifiedBy != null ? sellItem.ModifiedBy.ToString() : "");
77
+            return htmlBody;
78
+        }
79
+    }
80
+}

+ 53
- 4
UnivateProperties_API/Model/Communication/Email.cs 查看文件

@@ -6,11 +6,15 @@ using System.Text;
6 6
 using UnivateProperties_API.Model.Users;
7 7
 using System.Collections;
8 8
 using System.Collections.Generic;
9
+using UnivateProperties_API.Helpers.Communication;
10
+using UnivateProperties_API.Containers.Timeshare;
11
+using UnivateProperties_API.Context;
9 12
 
10 13
 namespace UnivateProperties_API.Model.Communication
11 14
 {
12 15
     public class Email : BaseEntity
13 16
     {
17
+        private readonly DataContext _dbContext;
14 18
         #region Constructor
15 19
         public Email()
16 20
         {
@@ -34,7 +38,7 @@ namespace UnivateProperties_API.Model.Communication
34 38
             Subject = subject;
35 39
         }
36 40
 
37
-        public Email(Template template, Person sendTo, List<BaseEntity> args)
41
+        public Email(Template template, Person sendTo, TimeshareWeekDto sellItem, DataContext dataContext)
38 42
         {
39 43
             if(sendTo != null && MyCommon.IsValidEmail(sendTo.Email))
40 44
             {
@@ -47,14 +51,16 @@ namespace UnivateProperties_API.Model.Communication
47 51
                 ToDisplay = sendTo.FullName;
48 52
                 /*BCC = ConcatEmails(template.AgentBCC, template.IndividualBCC);*/
49 53
                 IsBodyHtml = true;
50
-                Body = template.Body;
54
+                EmailCodedFieldsPopulator emailCodedFieldsPopulator = new EmailCodedFieldsPopulator(dataContext);
55
+                Body = emailCodedFieldsPopulator.getCodedBody(template.Body, sendTo, sellItem);
51 56
                 Subject = template.Subject;
52
-                foreach(var item in template.PlaceHolders)
57
+               /* foreach (var item in template.PlaceHolders)
53 58
                 {
54 59
                     foreach(var obj in args)
55 60
                     {
56 61
                         if(obj != null)
57 62
                         {
63
+                            var something = obj.GetType();
58 64
                             if (obj.GetType() == Type.GetType(item.BoundToClass) || obj.GetType().IsSubclassOf(Type.GetType(item.BoundToClass)))
59 65
                             {
60 66
                                 string replaceValue = (string)obj[item.BoundTo];
@@ -69,10 +75,52 @@ namespace UnivateProperties_API.Model.Communication
69 75
                             }
70 76
                         }                        
71 77
                     }
72
-                }
78
+                }*/
73 79
             }
74 80
             
75 81
         }
82
+
83
+        /*public Email(Template template, Person sendTo, TimeshareWeekDto sellItem, DataContext dataContext)
84
+        {
85
+            if (sendTo != null && MyCommon.IsValidEmail(sendTo.Email))
86
+            {
87
+                if (template.SenderId != null)
88
+                {
89
+                    SenderId = template.SenderId.Value;
90
+                }
91
+                Sender = template.Sender;
92
+                To = "jplouw@provision-sa.com"; // sendTo.Email;
93
+                ToDisplay = sendTo.FullName;
94
+                *//*BCC = ConcatEmails(template.AgentBCC, template.IndividualBCC);*//*
95
+                IsBodyHtml = true;
96
+                EmailCodedFieldsPopulator emailCodedFieldsPopulator = new EmailCodedFieldsPopulator(dataContext);
97
+                Body = emailCodedFieldsPopulator.getCodedBody(template.Body, sendTo, sellItem);
98
+                Subject = template.Subject;
99
+                *//*foreach (var item in template.PlaceHolders)
100
+                {
101
+                    foreach (var obj in args)
102
+                    {
103
+                        if (obj != null)
104
+                        {
105
+                            var something = obj.GetType();
106
+                            if (obj.GetType() == Type.GetType(item.BoundToClass) || obj.GetType().IsSubclassOf(Type.GetType(item.BoundToClass)))
107
+                            {
108
+                                string replaceValue = (string)obj[item.BoundTo];
109
+                                if (Body.Contains(item.Name))
110
+                                {
111
+                                    Body = Body.Replace(item.Name, replaceValue);
112
+                                }
113
+                                if (Subject.Contains(item.Name))
114
+                                {
115
+                                    Subject = Subject.Replace(item.Name, replaceValue);
116
+                                }
117
+                            }
118
+                        }
119
+                    }
120
+                }*//*
121
+            }
122
+
123
+        }*/
76 124
         #endregion Constructor
77 125
 
78 126
         #region Properties
@@ -168,6 +216,7 @@ namespace UnivateProperties_API.Model.Communication
168 216
                 }
169 217
             }
170 218
             mail.Subject = Subject;
219
+
171 220
             mail.Body = Body;
172 221
             mail.IsBodyHtml = IsBodyHtml;
173 222
             if (IsBodyHtml)

+ 13
- 0
UnivateProperties_API/Model/Financial/ReturnToMerchant.cs 查看文件

@@ -0,0 +1,13 @@
1
+namespace UnivateProperties_API.Model.Financial
2
+{
3
+    public class ReturnToMerchant
4
+    {
5
+        public string PAY_REQUEST_ID { get; set; }
6
+
7
+        public int TRANSACTION_STATUS { get; set; }
8
+
9
+        public string RESULT_CODE { get; set; }
10
+
11
+        public string CHECKSUM { get; set; }
12
+    }
13
+}

+ 33
- 1
UnivateProperties_API/Repository/Communication/TemplateRepository.cs 查看文件

@@ -3,6 +3,7 @@ using System;
3 3
 using System.Collections.Generic;
4 4
 using System.Linq;
5 5
 using UnivateProperties_API.Containers.Communication;
6
+using UnivateProperties_API.Containers.Timeshare;
6 7
 using UnivateProperties_API.Context;
7 8
 using UnivateProperties_API.Model;
8 9
 using UnivateProperties_API.Model.Communication;
@@ -166,7 +167,38 @@ namespace UnivateProperties_API.Repository.Communication
166 167
                 {
167 168
                     try
168 169
                     {
169
-                        Email email = new Email(template, sendTo, args);
170
+                        /*Email email = new Email(template, sendTo, args);
171
+                        EmailRepository emailRepo = new EmailRepository(_dbContext);
172
+                        
173
+                        emailRepo.Insert(email);*/
174
+                    }
175
+                    catch (Exception)
176
+                    {
177
+                    }
178
+                }
179
+            }
180
+        }
181
+
182
+        public void SendEmailTemplateWeek(Template template, Person sendTo, TimeshareWeekDto sellItem)
183
+        {
184
+            if (template != null)
185
+            {
186
+                if (template.SenderId == null)
187
+                {
188
+                    var acc = _dbContext.Accounts.FirstOrDefault(x => x.Default);
189
+                    if (acc != null)
190
+                    {
191
+                        template.SenderId = acc.Id;
192
+                        template.Sender = acc;
193
+                    }
194
+                }
195
+                else template.Sender = _dbContext.Accounts.FirstOrDefault(x => x.Id == template.SenderId);
196
+                template.PlaceHolders = _dbContext.PlaceHolders.Where(x => x.TemplateId == template.Id).ToList();
197
+                if (sendTo != null)
198
+                {
199
+                    try
200
+                    {
201
+                        Email email = new Email(template, sendTo, sellItem, _dbContext);
170 202
                         EmailRepository emailRepo = new EmailRepository(_dbContext);
171 203
                         emailRepo.Insert(email);
172 204
                     }

+ 1
- 1
UnivateProperties_API/Repository/Financial/PaygateRepository.cs 查看文件

@@ -36,7 +36,7 @@ namespace UnivateProperties_API.Repository.Financial
36 36
 
37 37
             string amm = Math.Round((total * 100)).ToString();
38 38
             string currenc = "ZAR";
39
-            string retUrl = "http://localhost:57260/api/values";
39
+            string retUrl = "http://localhost:57260/api/redirect";
40 40
             string transDate = utcDate;
41 41
             string loc = "en-za";
42 42
             string count = "ZAF";

+ 5
- 5
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs 查看文件

@@ -12,6 +12,7 @@ using UnivateProperties_API.Containers.Timeshare.Detailed;
12 12
 using UnivateProperties_API.Containers.Users;
13 13
 using UnivateProperties_API.Context;
14 14
 using UnivateProperties_API.Helpers;
15
+using UnivateProperties_API.Helpers.Communication;
15 16
 using UnivateProperties_API.Model;
16 17
 using UnivateProperties_API.Model.Communication;
17 18
 using UnivateProperties_API.Model.Region;
@@ -549,21 +550,20 @@ namespace UnivateProperties_API.Repository.Timeshare
549 550
             TemplateRepository templateRepository = new TemplateRepository(_dbContext);
550 551
             
551 552
             var template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekLoaded-Owner");
553
+
552 554
             if (agent != null)
553 555
             {
554
-                sellItem.Agent = agent;
555 556
                 template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekLoaded-Agent");
556 557
                 if (template != null)
557 558
                 {
558
-                    templateRepository.SendEmailTemplate(template, agent, new List<BaseEntity>() { sellItem, sellItem.Owner });
559
+                    templateRepository.SendEmailTemplateWeek(template, agent, sellItem);
559 560
                 }
560 561
             }
561
-            else if (sellItem.Owner != null)
562
+            else 
562 563
             {
563
-                
564 564
                 if (template != null)
565 565
                 {
566
-                    templateRepository.SendEmailTemplate(template, sellItem.Owner, new List<BaseEntity>() { sellItem, sellItem.Owner });
566
+                    templateRepository.SendEmailTemplateWeek(template, owner, sellItem);
567 567
                 }
568 568
                 template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekLoaded-UV");
569 569
                 if (template != null)

Loading…
取消
儲存