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("");
        }
Exemple #2
0
        /// <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