-
Notifications
You must be signed in to change notification settings - Fork 2
/
notify.ashx.cs
113 lines (100 loc) · 4.26 KB
/
notify.ashx.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Web;
using NBrightCore.common;
using Nevoweb.DNN.NBrightBuy.Components;
namespace Nevoweb.DNN.NBrightBuyPayPal
{
/// <summary>
/// Summary description for XMLconnector
/// </summary>
public class NBrightPayPalNotify : IHttpHandler
{
private String _lang = "";
/// <summary>
/// This function needs to process and returned message from the bank.
/// This processing may vary widely between banks.
/// </summary>
/// <param name="context"></param>
public void ProcessRequest(HttpContext context)
{
var modCtrl = new NBrightBuyController();
var info = ProviderUtils.GetProviderSettings("NBrightPayPalpayment");
try
{
var ipn = new PayPalIpnParameters(context.Request);
var debugMode = info.GetXmlPropertyBool("genxml/checkbox/debug.mode");
var debugMsg = "START CALL" + DateTime.Now.ToString("s") + " </br>";
debugMsg += "returnmessage: " + context.Request.Form.Get("returnmessage") + "</br>";
if (debugMode)
{
info.SetXmlProperty("genxml/debugmsg", debugMsg);
modCtrl.Update(info);
}
debugMsg += "NBrightPayPal DEBUG: " + DateTime.Now.ToString("s") + " </br>" + context.Request.Form + "<br/>";
if (Utils.IsNumeric(ipn.item_number))
{
var validateUrl = info.GetXmlProperty("genxml/textbox/paymenturl") + "?" + ipn.PostString;
// check the record exists
debugMsg += "OrderId: " + ipn.item_number + " </br>";
var nbi = modCtrl.Get(Convert.ToInt32(ipn.item_number), "ORDER");
if (nbi != null)
{
var orderData = new OrderData(nbi.ItemID);
debugMsg += "validateUrl: " + validateUrl + " </br>";
if (ProviderUtils.VerifyPayment(ipn, validateUrl))
{
//set order status to Payed
debugMsg += "PaymentOK </br>";
orderData.PaymentOk();
}
else
{
if (ipn.IsValid)
{
debugMsg += "NOT VALIDATED BY PAYPAL </br>";
//set order status to Not verified
orderData.PaymentOk("050");
}
else
{
if (orderData.OrderStatus == "020" || orderData.OrderStatus == "010" || orderData.OrderStatus == "030")
{
debugMsg += "PAYMENT FAIL </br>";
orderData.PaymentFail();
}
else
{
debugMsg += "INVALID UPDATE ACTION</br>";
}
}
}
}
else
{
debugMsg += "ORDER does not exists";
}
if (debugMode)
{
info.SetXmlProperty("genxml/debugmsg", debugMsg);
modCtrl.Update(info);
}
}
}
catch (Exception ex)
{
if (!ex.ToString().StartsWith("System.Threading.ThreadAbortException")) // we expect a thread abort from the End response.
{
info.SetXmlProperty("genxml/debugmsg", "NBrightPayPal ERROR: " + ex.ToString());
modCtrl.Update(info);
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}