-
Notifications
You must be signed in to change notification settings - Fork 33
/
NewPayment.cs
72 lines (62 loc) · 2.37 KB
/
NewPayment.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
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Net;
using System.Net.Mail;
using System.Text.RegularExpressions;
using System.Web.Helpers;
using Gourl.Models.GoUrl;
//* ##########################################
//* ### PLEASE MODIFY THIS FILE
//* ###
//* ### Add additional actions after a payment has been received -
//* ### update database records, send email to user, etc
//* ##########################################
namespace Gourl.GoUrlCore
{
public static class NewPayment
{
public static void Main(int paymentId, IPNModel callback, string box_status)
{
//PLACE YOUR CODE HERE
//Mail(paymentId, callback, box_status);
}
private static void Mail(int paymentId, IPNModel callback, string box_status)
{
const string host = "";
const string fromEmail = "";
const string fromPassword = "";
const string toEmail = "";
if (host == "" || fromEmail == "" || fromPassword == "" || toEmail == "")
{
throw new ArgumentException("Please initialise smtp server for email.");
}
var fromAddress = new MailAddress(fromEmail, "From Test Payment Server");
var toAddress = new MailAddress(toEmail, "To You");
if (callback.err == null)
callback.err = "";
string details = Json.Encode(callback);
Regex reg = new Regex(@"\\/Date\(\d+\)\\/");
details = reg.Replace(details, callback.date.ToString("dd MMMM yyyy"), 1);
details = reg.Replace(details, callback.datetime.ToString("yyyy-MM-dd HH:mm:ss"));
const string subject = "Subject";
string body = "Payment - " + paymentId + " - " + box_status + "\nDetails:\n" + details;
var smtp = new SmtpClient
{
Host = host,
Port = 25,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
Timeout = 10000
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
}
}
}