-
Notifications
You must be signed in to change notification settings - Fork 1
/
PaymentProvider.cs
131 lines (109 loc) · 5.07 KB
/
PaymentProvider.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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web;
using DotNetNuke.Common;
using DotNetNuke.Entities.Portals;
using NBrightCore.common;
using NBrightDNN;
using Nevoweb.DNN.NBrightBuy.Components;
using DnnC.Mollie.Api;
using System.IO;
using System.Globalization;
namespace DnnC.Mollie
{
public class DnnCMolliePaymentProvider : Nevoweb.DNN.NBrightBuy.Components.Interfaces.PaymentsInterface
{
public override string Paymentskey { get; set; }
public override string GetTemplate(NBrightInfo cartInfo)
{
var info = ProviderUtils.GetProviderSettings("DnnCMolliepayment");
var templ = ProviderUtils.GetTemplateMollieData(info.GetXmlProperty("genxml/textbox/checkouttemplate"), info);
return templ;
}
public override string RedirectForPayment(OrderData orderData)
{
var appliedtotal = orderData.PurchaseInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
var alreadypaid = orderData.PurchaseInfo.GetXmlPropertyDouble("genxml/alreadypaid");
var info = ProviderUtils.GetProviderSettings("DnnCMolliepayment");
var cartDesc = info.GetXmlProperty("genxml/textbox/cartdescription");
var testMode = info.GetXmlPropertyBool("genxml/checkbox/testmode");
var testApiKey = info.GetXmlProperty("genxml/textbox/testapikey");
var liveApiKey = info.GetXmlProperty("genxml/textbox/liveapikey");
var notifyUrl = Utils.ToAbsoluteUrl("/DesktopModules/NBright/DnnCMollie/notify.ashx");
var returnUrl = Globals.NavigateURL(StoreSettings.Current.PaymentTabId, "");
var ItemId = orderData.PurchaseInfo.ItemID.ToString("");
var nbi = new NBrightInfo();
nbi.XMLData = orderData.payselectionXml;
var paymentMethod = nbi.GetXmlProperty("genxml/textbox/paymentmethod");
var paymentBank = nbi.GetXmlProperty("genxml/textbox/paymentbank");
var apiKey = testApiKey;
if (!testMode)
{
apiKey = liveApiKey;
}
MollieClient mollieClient = new MollieClient();
mollieClient.setApiKey(apiKey);
Payment payment = new Payment()
{
amount = decimal.Parse((appliedtotal - alreadypaid).ToString("0.00", CultureInfo.InvariantCulture)), //99.99M,
description = cartDesc,
redirectUrl = returnUrl + "/orderid/" + ItemId,
method = (Method)Enum.Parse(typeof(Method), paymentMethod, true),
issuer = paymentBank,
metadata = ItemId,
webhookUrl = notifyUrl,
};
PaymentStatus paymentStatus = mollieClient.StartPayment(payment);
orderData.OrderStatus = "020";
orderData.PurchaseInfo.SetXmlProperty("genxml/paymenterror", "");
orderData.PurchaseInfo.SetXmlProperty("genxml/posturl", paymentStatus.links.paymentUrl);
orderData.PurchaseInfo.Lang = Utils.GetCurrentCulture();
orderData.SavePurchaseData();
try
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(ProviderUtils.GetBankRemotePost(orderData));
}
catch (Exception ex)
{
// rollback transaction
orderData.PurchaseInfo.SetXmlProperty("genxml/paymenterror", "<div>ERROR: Invalid payment data </div><div>" + ex + "</div>");
orderData.PaymentFail();
var param = new string[3];
param[0] = "orderid=" + orderData.PurchaseInfo.ItemID.ToString("");
param[1] = "status=0";
return Globals.NavigateURL(StoreSettings.Current.PaymentTabId, "", param);
}
try
{
HttpContext.Current.Response.End();
}
catch (Exception ex)
{
// this try/catch to avoid sending error 'ThreadAbortException'
}
return "";
}
public override string ProcessPaymentReturn(HttpContext context)
{
var orderid = Utils.RequestQueryStringParam(context, "orderid");
if (Utils.IsNumeric(orderid))
{
var status = Utils.RequestQueryStringParam(context, "status");
if (status == "0")
{
var orderData = new OrderData(Convert.ToInt32(orderid));
var rtnerr = orderData.PurchaseInfo.GetXmlProperty("genxml/paymenterror");
if (rtnerr == "") rtnerr = "fail"; // to return this so a fail is activated.
// check we have a waiting for bank status (IPN may have altered status already)
if (orderData.OrderStatus == "020") orderData.PaymentFail();
return rtnerr;
}
}
return "";
}
}
}