forked from openstore-ecommerce/OpenStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Payment.ascx.cs
153 lines (132 loc) · 6.12 KB
/
Payment.ascx.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
142
143
144
145
146
147
148
149
150
151
152
153
// --- Copyright (c) notice NevoWeb ---
// Copyright (c) 2014 SARL NevoWeb. www.nevoweb.com. The MIT License (MIT).
// Author: D.C.Lee
// ------------------------------------------------------------------------
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// ------------------------------------------------------------------------
// This copyright notice may NOT be removed, obscured or modified without written consent from the author.
// --- End copyright notice ---
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Web.UI.WebControls;
using DotNetNuke.Common;
using DotNetNuke.Entities.Portals;
using NBrightCore.common;
using NBrightCore.render;
using NBrightDNN;
using Nevoweb.DNN.NBrightBuy.Base;
using Nevoweb.DNN.NBrightBuy.Components;
using Nevoweb.DNN.NBrightBuy.Components.Interfaces;
using DataProvider = DotNetNuke.Data.DataProvider;
namespace Nevoweb.DNN.NBrightBuy
{
/// -----------------------------------------------------------------------------
/// <summary>
/// The ViewNBrightGen class displays the content
/// </summary>
/// -----------------------------------------------------------------------------
public partial class Payment : NBrightBuyFrontOfficeBase
{
#region Event Handlers
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
if (ModuleKey == "") // if we don't have module setting jump out
{
var lit = new Literal();
lit.Text = "NO MODULE SETTINGS";
phData.Controls.Add(lit);
return;
}
}
protected override void OnLoad(EventArgs e)
{
try
{
base.OnLoad(e);
if (Page.IsPostBack == false)
{
var providerkey = Utils.RequestParam(Context, "provider");
if (providerkey != "")
{
var strOut = "";
var cartInfo = new CartData(PortalSettings.Current.PortalId);
if (cartInfo != null)
{
cartInfo.SaveModelTransQty(); // move qty into trans
cartInfo.ConvertToOrder(StoreSettings.Current.DebugMode);
var orderData = new OrderData(cartInfo.PurchaseInfo.ItemID);
orderData.PaymentProviderKey = providerkey.ToLower(); // provider keys should always be lowecase
orderData.SavePurchaseData();
PaymentsInterface.Instance(orderData.PaymentProviderKey).RedirectForPayment(orderData);
}
}
else
{
PageLoad();
}
}
}
catch (Exception exc) //Module failed to load
{
//display the error on the template (don't want to log it here, prefer to deal with errors directly.)
var l = new Literal();
l.Text = exc.ToString();
Controls.Add(l);
}
}
private void PageLoad()
{
var strOut = "";
var orderid = Utils.RequestParam(Context, "orderid");
if (Utils.IsNumeric(orderid))
{
// orderid exists, so must be return from bank; Process it!!
var orderData = new OrderData(PortalId, Convert.ToInt32(orderid));
var prov = PaymentsInterface.Instance(orderData.PaymentProviderKey);
strOut = prov.ProcessPaymentReturn(Context);
if (strOut == "")
{
orderData = new OrderData(PortalId, Convert.ToInt32(orderid)); // reload the order, becuase the status and typecode may have changed by the payment provider.
var status = Utils.RequestQueryStringParam(Context, "status");
if (status == "0")
{
var rtnerr = orderData.PurchaseInfo.GetXmlProperty("genxml/paymenterror");
orderData.AddAuditMessage(rtnerr, "paymsg", "payment.ascx", "False");
orderData.Save();
if (strOut == "")
{
strOut = NBrightBuyUtils.RazorTemplRender("payment_fail.cshtml", 0, "", orderData.PurchaseInfo, ControlPath, "config", Utils.GetCurrentCulture(), StoreSettings.Current.Settings());
}
}
else
{
orderData = new OrderData(PortalId, Convert.ToInt32(orderid)); // get the updated order.
orderData.PaymentOk("050");
if (strOut == "")
{
strOut = NBrightBuyUtils.RazorTemplRender("payment_ok.cshtml", 0, "", orderData.PurchaseInfo, ControlPath, "config", Utils.GetCurrentCulture(), StoreSettings.Current.Settings());
}
}
}
}
else
{
var cartInfo = new CartData(PortalSettings.Current.PortalId);
// not returning from bank, so display list of payment providers.
strOut = NBrightBuyUtils.RazorTemplRender(RazorTemplate, 0, "", cartInfo, ControlPath, ThemeFolder, Utils.GetCurrentCulture(), StoreSettings.Current.Settings());
}
var lit = new Literal();
lit.Text = strOut;
phData.Controls.Add(lit);
}
#endregion
}
}