-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPayment.cs
61 lines (58 loc) · 2.08 KB
/
Payment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
namespace NopFarsi.Payment.SizPay
{
public class Payment
{
public string Verify(string transId, string api)
{
var client = new HttpClient();
var requestContent = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("api", api),
new KeyValuePair<string, string>("transId", transId),
});
HttpResponseMessage response = client.PostAsync(
"https://sizpay.ir/payment/verify",
requestContent).Result;
HttpContent responseContent = response.Content;
var jsonString = responseContent.ReadAsStringAsync().Result;
var result = JsonConvert.DeserializeObject<ApiCallBack>(jsonString);
if (result.status == 1)
{
return jsonString;
}
else
{
return jsonString;
}
}
public async Task<string> Pay(decimal amount, int id, string api, string redirect)
{
var client = new HttpClient();
var requestContent = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("api", api),
new KeyValuePair<string, string>("amount", ((long)amount).ToString("")),
new KeyValuePair<string, string>("redirect", redirect),
new KeyValuePair<string, string>("factorNumber", $"{id}"),
});
try
{
HttpResponseMessage response = await client.PostAsync(
"https://sizpay.ir/payment/send", requestContent);
HttpContent responseContent = response.Content;
return await responseContent.ReadAsStringAsync();
}
catch (Exception exception)
{
throw exception;
}
}
}
}