Browse Source

Paygate

master
30117125 4 years ago
parent
commit
69b1e59acd

+ 7
- 3
UnivateProperties_API/Controllers/Financial/PaymentController.cs View File

@@ -2,6 +2,7 @@
2 2
 using System.Transactions;
3 3
 using UnivateProperties_API.Model.Financial;
4 4
 using UnivateProperties_API.Repository;
5
+using UnivateProperties_API.Repository.Financial;
5 6
 
6 7
 namespace UnivateProperties_API.Controllers.Financial
7 8
 {
@@ -10,10 +11,12 @@ namespace UnivateProperties_API.Controllers.Financial
10 11
     public class PaymentController : ControllerBase
11 12
     {
12 13
         private readonly IRepository<Payment> _Repo;
14
+        private readonly IPaygateRepository _paygateRepo;
13 15
 
14
-        public PaymentController(IRepository<Payment> _repo)
16
+        public PaymentController(IRepository<Payment> _repo, IPaygateRepository paygateRepo)
15 17
         {
16 18
             _Repo = _repo;
19
+            _paygateRepo = paygateRepo;
17 20
         }
18 21
         
19 22
         [HttpGet]
@@ -33,9 +36,10 @@ namespace UnivateProperties_API.Controllers.Financial
33 36
         {
34 37
             using (var scope = new TransactionScope())
35 38
             {
36
-                _Repo.Insert(payment);
39
+                var paymentResult = _paygateRepo.GoToPaymentGateway(payment);
40
+                //_Repo.Insert(payment);
37 41
                 scope.Complete();
38
-                return CreatedAtAction(nameof(Get), new { id = payment.Id }, payment);
42
+                return new OkObjectResult(paymentResult);
39 43
             }
40 44
         }
41 45
         

+ 85
- 0
UnivateProperties_API/Repository/Financial/PaygateRepository.cs View File

@@ -0,0 +1,85 @@
1
+using RestSharp;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using System.Security.Cryptography;
6
+using System.Text;
7
+using System.Threading.Tasks;
8
+using UnivateProperties_API.Model.Financial;
9
+
10
+namespace UnivateProperties_API.Repository.Financial
11
+{
12
+    public interface IPaygateRepository
13
+    {
14
+        string GoToPaymentGateway(Payment payment);
15
+    }
16
+
17
+    public class PaygateRepository: IPaygateRepository
18
+    {
19
+        public string GoToPaymentGateway(Payment payment)
20
+        {
21
+            string utcDate = DateTime.UtcNow.ToString("yyyy-MM-dd H:mm:ss");
22
+            var client = new RestClient("https://secure.paygate.co.za/payweb3/initiate.trans");
23
+            client.Timeout = -1;
24
+            var request = new RestRequest(Method.POST);
25
+            var total = payment.Amount;
26
+            string paygateId = "10011072130";
27
+            string reff = "";
28
+            if (payment.TimeshareWeekId != 0)
29
+            {
30
+                reff = payment.TimeshareWeekId.ToString();
31
+            }
32
+            else
33
+            {
34
+                reff = payment.PropertyId.ToString();
35
+            }
36
+
37
+            string amm = Math.Round((total * 100)).ToString();
38
+            string currenc = "ZAR";
39
+            string retUrl = "http://localhost:57260/api/values";
40
+            string transDate = utcDate;
41
+            string loc = "en-za";
42
+            string count = "ZAF";
43
+            string mail = "jlouw365@gmail.com";
44
+            request.AlwaysMultipartFormData = true;
45
+            request.AddParameter("PAYGATE_ID", paygateId);
46
+            request.AddParameter("REFERENCE", reff);
47
+            request.AddParameter("AMOUNT", amm);
48
+            request.AddParameter("CURRENCY", currenc);
49
+            request.AddParameter("RETURN_URL", retUrl);
50
+            request.AddParameter("TRANSACTION_DATE", transDate);
51
+            request.AddParameter("LOCALE", loc);
52
+            request.AddParameter("COUNTRY", count);
53
+            request.AddParameter("EMAIL", mail);
54
+            string checksum = Checksum(
55
+                paygateId +
56
+                reff +
57
+                amm +
58
+                currenc +
59
+                retUrl +
60
+                transDate +
61
+                loc +
62
+                count +
63
+                mail +
64
+                "secret");
65
+            request.AddParameter("CHECKSUM", checksum);
66
+            string gatewayReturn = client.Execute(request).Content.ToString();
67
+            List<string> vs = gatewayReturn.Split('&').ToList();
68
+            string payReqId = vs[1].Split('=')[1].ToString();
69
+            //var updatedOrder = _dbContext.Payments.OrderByDescending(x => x.Id).FirstOrDefault();
70
+            //updatedOrder.PaymentToken = payReqId;
71
+            //_dbContext.Payments.Update(updatedOrder);
72
+            //_dbContext.SaveChanges();
73
+            return client.Execute(request).Content.ToString();
74
+        }
75
+
76
+        private string Checksum(string data)
77
+        {
78
+            using (var md5 = MD5.Create())
79
+            {
80
+                return BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(data)))
81
+                    .Replace("-", string.Empty).ToLower();
82
+            }
83
+        }
84
+    }
85
+}

+ 3
- 0
UnivateProperties_API/Repository/Financial/PaymentRepository.cs View File

@@ -1,7 +1,10 @@
1 1
 using Microsoft.EntityFrameworkCore;
2
+using RestSharp;
2 3
 using System;
3 4
 using System.Collections.Generic;
4 5
 using System.Linq;
6
+using System.Security.Cryptography;
7
+using System.Text;
5 8
 using UnivateProperties_API.Context;
6 9
 using UnivateProperties_API.Model.Financial;
7 10
 

+ 3
- 0
UnivateProperties_API/Startup.cs View File

@@ -153,6 +153,9 @@ namespace UnivateProperties_API
153 153
             #region Logs 
154 154
             services.AddTransient<ISearchLogRepository, SearchLogRepository>();
155 155
             #endregion
156
+            #region Financial 
157
+            services.AddTransient<IPaygateRepository, PaygateRepository>();
158
+            #endregion
156 159
             #region Misc
157 160
             services.AddTransient<ICarouselRepository, CarouselRepository>();
158 161
             services.AddTransient<IRepository<PlaceHolderFormat>, PlaceHolderFormatRepository>();

+ 1
- 0
UnivateProperties_API/UnivateProperties_API.csproj View File

@@ -20,6 +20,7 @@
20 20
     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
21 21
     <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
22 22
     <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0" />
23
+    <PackageReference Include="RestSharp" Version="106.11.4" />
23 24
     <PackageReference Include="System.Drawing.Common" Version="4.6.0" />
24 25
   </ItemGroup>
25 26
 

+ 1
- 1
UnivateProperties_API/appsettings.json View File

@@ -9,7 +9,7 @@
9 9
   },
10 10
   "AllowedHosts": "*",
11 11
   "ConnectionStrings": {
12
-    "DefaultConnection": "Data Source=localhost;Initial Catalog=UniVateDemo;Persist Security Info=True;User Id=Provision;Password=What123!;Pooling=false;",
12
+    "DefaultConnection": "Data Source=192.168.0.219;Initial Catalog=UniVateDemo;Persist Security Info=True;User Id=Provision;Password=What123!;Pooling=false;",
13 13
     "TenderConnection": "http://www.unipoint-consoft.co.za/nph-srep.exe?cluvavail_test.sch&CLUB=LPA&RESORT=ALL&SUMMARY=N&HEAD=N"
14 14
   }
15 15
 }

Loading…
Cancel
Save