-
Notifications
You must be signed in to change notification settings - Fork 1
/
notify.ashx.cs
141 lines (113 loc) · 4.97 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Web;
using Nevoweb.DNN.NBrightBuy.Components;
using NBrightDNN;
using DnnC.Mollie.Api;
using System.IO;
using DotNetNuke.Entities.Portals;
using NBrightCore.common;
namespace DnnC.Mollie
{
/// <summary>
/// Summary description for XMLconnector
/// </summary>
public class DnnCMollieNotify : IHttpHandler
{
private String _lang = "";
/// <summary>
/// This function needs to process and returned message from the bank.
/// Thsi processing may vary widely between banks.
/// </summary>
/// <param name="context"></param>
public void ProcessRequest(HttpContext context)
{
var modCtrl = new NBrightBuyController();
var info = ProviderUtils.GetProviderSettings("DnnCMolliepayment");
try
{
var debugMode = info.GetXmlPropertyBool("genxml/checkbox/debugmode");
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 = "DnnCMollie DEBUG: " + DateTime.Now.ToString("s") + " </br>";
var rtnMsg = "version=2" + Environment.NewLine + "cdr=1";
// ------------------------------------------------------------------------
// In this case the payment provider passes back data via form POST.
// Get the data we need.
//string returnmessage = "";
//int DnnCMollieStoreOrderID = 0;
//string DnnCMollieCartID = "";
//string DnnCMollieClientLang = "";
var testMode = info.GetXmlPropertyBool("genxml/checkbox/testmode");
var testApiKey = info.GetXmlProperty("genxml/textbox/testapikey");
var liveApiKey = info.GetXmlProperty("genxml/textbox/liveapikey");
var nbi = new NBrightInfo();
var paymentMethod = nbi.GetXmlProperty("genxml/textbox/paymentmethod");
var paymentBank = nbi.GetXmlProperty("genxml/textbox/paymentbank");
var apiKey = testApiKey;
if (!testMode)
{
apiKey = liveApiKey;
}
string molliePaymentId = context.Request.Form["id"];
int oId = -1;
int.TryParse(context.Request.Form["orderid"], out oId);
if (oId <= 0)
{
int.TryParse(context.Request.Form["ordid"], out oId);
}
MollieClient mollieClient = new MollieClient();
mollieClient.setApiKey(apiKey);
PaymentStatus paymentStatus = mollieClient.GetStatus(molliePaymentId);
var orderid = paymentStatus.metadata;
var nbInfo = modCtrl.Get(Convert.ToInt32(orderid), "ORDER");
if (nbi != null)
{
var orderData = new OrderData(nbInfo.ItemID);
switch (paymentStatus.status.Value)
{
case Status.paid:
orderData.PaymentOk();
break;
case Status.cancelled:
//set order status to Cancelled
orderData.PaymentOk("030");
break;
case Status.failed:
//set order status to payment failed
orderData.PaymentFail();
break;
case Status.open:
//set order status to Waiting for payment
orderData.PaymentOk("060");
break;
case Status.pending:
//set order status to Waiting for payment
orderData.PaymentOk("060");
break;
case Status.expired:
//set order status to Incomplete
orderData.PaymentOk("010");
break;
}
var rtnStr = paymentStatus.status.Value + "<br/> id = " + molliePaymentId;
rtnStr += "<br/> orderId = " + orderid;
rtnStr += "<br/> status = " + orderData.OrderStatus;
File.WriteAllText(PortalSettings.Current.HomeDirectoryMapPath + "\\debug_DnnC_IPN_return.html", rtnStr.ToString());
}
}
catch { }
} //end
public bool IsReusable
{
get
{
return false;
}
}
}
}