public GenericPaymentViewModel(Guid paymentMethod, T currentPage, OrderInfo orderInfo, Cart cart) : base(currentPage)
        {
            PaymentMethodDto payment = PaymentManager.GetPaymentMethod(paymentMethod);

            _paymentMethod = payment;
            _currentCart   = cart;

            DIBSPaymentGateway gw = new DIBSPaymentGateway();

            orderInfo.Merchant = gw.Merchant;

            Mediachase.Commerce.Orders.Payment[] payments;
            if (CurrentCart != null && CurrentCart.OrderForms != null && CurrentCart.OrderForms.Count > 0)
            {
                payments = CurrentCart.OrderForms[0].Payments.ToArray();
            }
            else
            {
                payments = new Mediachase.Commerce.Orders.Payment[0];
            }
            _payment = payments.FirstOrDefault(c => c.PaymentMethodId.Equals(payment.PaymentMethod.Rows[0]["PaymentMethodId"]));


            OrderID = orderInfo.OrderId;
        }
 public PaymentMethod(Mediachase.Commerce.Orders.Payment payment)
 {
     OrderGroup       = payment.Parent.Parent;
     TransactionType  = payment.TransactionType;
     Payment          = payment as PayExPayment;
     PaymentMethodDto = Mediachase.Commerce.Orders.Managers.PaymentManager.GetPaymentMethod(payment.PaymentMethodId);
 }
Ejemplo n.º 3
0
        public bool CancelTransaction(Mediachase.Commerce.Orders.Payment payment)
        {
            var message = GetTransactionMessage(payment);
            Dictionary <string, string> res = postToDIBS(Cancel, message);

            return(GetTransactionResult(res));
        }
Ejemplo n.º 4
0
        public override bool ProcessPayment(Mediachase.Commerce.Orders.Payment payment,
                                            ref string message)
        {
            var orderGroup = payment.Parent.Parent;
            var paymentProcessingResult = ProcessPayment(orderGroup, payment);

            message += paymentProcessingResult.Message;
            return(paymentProcessingResult.IsSuccessful);
        }
        public DibsPaymentViewModel(IContentRepository contentRepository, DibsPaymentPage currentPage, OrderInfo orderInfo, Cart cart) : base(new Guid(currentPage.PaymentMethod), currentPage, orderInfo, cart)
        {
            SiteConfiguration configuration = SiteConfiguration.Current();
            PaymentMethodDto  dibs          = PaymentManager.GetPaymentMethodBySystemName(DIBSSystemName, SiteContext.Current.LanguageName);

            _paymentMethod = dibs;
            _currentCart   = cart;

            DIBSPaymentGateway gw = new DIBSPaymentGateway();

            orderInfo.Merchant = gw.Merchant;

            var paymentRedirectUrl = GetViewUrl(currentPage.ContentLink);

            IsTest = orderInfo.IsTest;

            var baseUrl = GetBaseUrl();

            AcceptReturnUrl           = baseUrl + paymentRedirectUrl + "ProcessPayment";
            orderInfo.AcceptReturnUrl = AcceptReturnUrl;

            CancelReturnUrl           = baseUrl + paymentRedirectUrl + "CancelPayment";
            orderInfo.CancelReturnUrl = CancelReturnUrl;

            Mediachase.Commerce.Orders.Payment[] payments;
            if (CurrentCart != null && CurrentCart.OrderForms != null && CurrentCart.OrderForms.Count > 0)
            {
                payments = CurrentCart.OrderForms[0].Payments.ToArray();
            }
            else
            {
                payments = new Mediachase.Commerce.Orders.Payment[0];
            }
            _payment      = payments.FirstOrDefault(c => c.PaymentMethodId.Equals(dibs.PaymentMethod.Rows[0]["PaymentMethodId"]));
            ProcessingUrl = DIBSPaymentGateway.GetParameterByName(dibs, DIBSPaymentGateway.ProcessingUrl).Value;
            Key           = gw.Key;
            OrderID       = orderInfo.OrderId;

            ShaCalculator calculator = new ShaCalculator(Key);

            if (CurrentCart != null && CurrentCart.OrderForms != null && CurrentCart.OrderForms.Count > 0)
            {
                // Note, the orderinfo is changed inside this method
                Products = GenerateLineItemInformation(CurrentCart.OrderForms[0].LineItems, ref orderInfo);
            }
            else
            {
                Products = new List <string>();
            }

            MAC = calculator.GetMac(orderInfo);


            this.OrderInfo = orderInfo.ToString();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Main entry point of ECF Payment Gateway.
        /// </summary>
        /// <param name="payment">The payment to process</param>
        /// <param name="message">The message ?</param>
        /// <returns>return false and set the message will make the WorkFlow activity raise PaymentExcetion(message)</returns>
        public override bool ProcessPayment(Mediachase.Commerce.Orders.Payment payment, ref string message)
        {
            var orderGroup = payment.Parent.Parent;
            var paymentProcessingResult = ProcessPayment(orderGroup, payment);

            if (!string.IsNullOrEmpty(paymentProcessingResult.RedirectUrl))
            {
                HttpContext.Current.Response.Redirect(paymentProcessingResult.RedirectUrl);
            }
            message = paymentProcessingResult.Message;
            return(paymentProcessingResult.IsSuccessful);
        }
Ejemplo n.º 7
0
        private Dictionary <string, string> GetTransactionMessage(Mediachase.Commerce.Orders.Payment payment)
        {
            var macCalculator = new HmacCalculator(Key);
            var merchantId    = Merchant;

            //Create Dictionary<string, string> object with used values. Can be modified to contain additional parameters.
            Dictionary <string, string> message = new Dictionary <string, string>
            {
                { "amount", GetAmount(payment) },
                { "merchantId", merchantId },
                { "transactionId", payment.TransactionID }
            };

            //Calculate mac and add it
            string mac = macCalculator.GetHex(message);

            message.Add("MAC", mac);
            return(message);
        }
        public bool Credit(PaymentMethod currentPayment)
        {
            Mediachase.Commerce.Orders.Payment payment = (Mediachase.Commerce.Orders.Payment)currentPayment.Payment;
            Log.InfoFormat("Crediting payment with ID:{0} belonging to order with ID: {1}, by order lines", payment.Id, payment.OrderGroupId);

            int transactionId;

            if (!int.TryParse(payment.AuthorizationCode, out transactionId))
            {
                Log.ErrorFormat("Could not get PayEx Transaction Id from purchase order with ID: {0}", currentPayment.PurchaseOrder.Id);
                return(false);
            }
            Log.InfoFormat("PayEx transaction ID is {0} on payment with ID:{1} belonging to order with ID: {2}", transactionId, payment.Id, payment.OrderGroupId);

            CreditResult result      = null;
            string       orderNumber = OrderNumberFormatter.MakeNumeric(currentPayment.PurchaseOrder.TrackingNumber);

            foreach (OrderForm orderForm in currentPayment.PurchaseOrder.OrderForms)
            {
                foreach (LineItem lineItem in orderForm.LineItems)
                {
                    result = _paymentManager.CreditOrderLine(transactionId, lineItem.CatalogEntryId, orderNumber);
                }
            }

            bool success = false;

            if (result != null && !string.IsNullOrWhiteSpace(result.TransactionNumber))
            {
                Log.InfoFormat("Setting PayEx transaction number to {0} on payment with ID:{1} belonging to order with ID: {2} during credit", result.TransactionNumber, payment.Id, payment.OrderGroupId);
                payment.TransactionID = result.TransactionNumber;
                payment.AcceptChanges();
                success = true;
                Log.InfoFormat("Successfully credited payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId);
            }

            if (_paymentCreditor != null)
            {
                return(_paymentCreditor.Credit(currentPayment) && success);
            }
            return(success);
        }
        public bool Capture(PaymentMethod currentPayment, string additionalValues)
        {
            Mediachase.Commerce.Orders.Payment payment = (Mediachase.Commerce.Orders.Payment)currentPayment.Payment;
            Log.InfoFormat("Capturing payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId);

            int transactionId;

            if (!int.TryParse(payment.AuthorizationCode, out transactionId))
            {
                Log.ErrorFormat("Could not get PayEx transaction ID from payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId);
                return(false);
            }
            Log.InfoFormat("PayEx transaction ID is {0} on payment with ID:{1} belonging to order with ID: {2}", transactionId, payment.Id, payment.OrderGroupId);

            long          amount      = payment.Amount.RoundToLong();
            string        orderNumber = OrderNumberFormatter.MakeNumeric(currentPayment.PurchaseOrder.TrackingNumber);
            CaptureResult result      = _paymentManager.Capture(transactionId, amount, orderNumber, currentPayment.Payment.Vat, additionalValues);

            bool success = false;

            if (result.Success && !string.IsNullOrWhiteSpace(result.TransactionNumber))
            {
                Log.InfoFormat("Setting PayEx transaction number to {0} on payment with ID:{1} belonging to order with ID: {2} during capture", result.TransactionNumber, payment.Id, payment.OrderGroupId);
                payment.ValidationCode = result.TransactionNumber;
                PaymentStatusManager.ProcessPayment(payment);
                payment.AcceptChanges();
                success = true;
                Log.InfoFormat("Successfully captured payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId);
            }

            if (_paymentCapturer != null)
            {
                return(_paymentCapturer.Capture(currentPayment) && success);
            }
            return(success);
        }
Ejemplo n.º 10
0
        public override bool ProcessPayment(Mediachase.Commerce.Orders.Payment payment, ref string message)
        {
            Log.InfoFormat("Processing payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId);

            if (HttpContext.Current == null)
            {
                Log.ErrorFormat("HttpContent.Current is null");
                return(false);
            }

            PaymentMethod currentPayment = _paymentMethodFactory.Create(payment);

            if (currentPayment == null)
            {
                Log.ErrorFormat("As the PaymentMethod for payment with ID:{0} could not be resolved, it cannot be processed by the PayEx Payment Provider!", payment.Id);
                return(false);
            }
            Log.InfoFormat("Successfully resolved the PaymentMethod for payment with ID:{0}. The PaymentMethodCode is {1}", payment.Id, currentPayment.PaymentMethodCode);

            if (currentPayment.IsPurchaseOrder)
            {
                Log.InfoFormat("Payment with ID:{0} is a purchase order. It's transaction type is {1}", payment.Id, payment.TransactionType);

                // when user click complete order in commerce manager the transaction type will be Capture
                if (currentPayment.IsCapture)
                {
                    Log.InfoFormat("Begin CapturePayment for payment with ID:{0}", payment.Id);
                    return(currentPayment.Capture());
                }

                // When "Refund" shipment in Commerce Manager, this method will be invoked with the TransactionType is Credit
                if (currentPayment.IsCredit)
                {
                    Log.InfoFormat("Begin CreditPayment for payment with ID:{0}", payment.Id);
                    return(currentPayment.Credit());
                }

                Log.ErrorFormat("The transaction type for payment with ID:{0} is {1}. The PayEx Payment Provider expected a Credit or Capture transaction type!", payment.Id, payment.TransactionType);
                return(false);
            }

            // When "Complete" or "Refund" shipment in Commerce Manager, this method will be run again with the TransactionType is Capture/Credit
            // PayEx will always return true to bypass the payment process again.
            if (!currentPayment.IsAuthorization)
            {
                Log.InfoFormat("The transaction type for payment with ID:{0} is {1}, meaning the payment process has already been run once.", payment.Id, payment.TransactionType);
                return(true);
            }

            if (!currentPayment.IsCart)
            {
                Log.ErrorFormat("Payment with ID:{0} is not a cart. That should not be possible at this stage!", payment.Id);
                return(false);
            }

            Log.InfoFormat("Initializing payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId);
            PaymentInitializeResult result = currentPayment.Initialize();

            message = result.ErrorMessage ?? string.Empty;

            if (!result.Success)
            {
                Log.ErrorFormat("Could not initialize payment with ID:{0} belonging to order with ID: {1}. Message: {2}", payment.Id, payment.OrderGroupId, message);
            }
            else
            {
                Log.InfoFormat("Successfully initialized payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId);
            }

            return(result.Success);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Processes the payment. Can be used for both positive and negative transactions.
 /// </summary>
 /// <param name="payment">The payment.</param>
 /// <param name="message">The message.</param>
 /// <returns></returns>
 public abstract bool ProcessPayment(Mediachase.Commerce.Orders.Payment payment, ref string message);
Ejemplo n.º 12
0
        /// <summary>
        /// Processes the payment.
        /// </summary>
        /// <param name="payment">The payment.</param>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public override bool ProcessPayment(Mediachase.Commerce.Orders.Payment payment, ref string message)
        {
            // We need this for some of the properties on this class that loads
            // payment method parameters (like MDS keys)
            _payment = PaymentManager.GetPaymentMethod(payment.PaymentMethodId); // .GetPaymentMethodBySystemName("DIBS", SiteContext.Current.LanguageName);

            if (payment.Parent.Parent is PurchaseOrder)
            {
                if (payment.TransactionType == TransactionType.Capture.ToString())
                {
                    bool isCaptured = CaptureTransaction(payment);

                    if (!isCaptured)
                    {
                        message = "There was an error while capturing payment with DIBS";
                        return(false);
                    }
                    return(true);
                }

                if (payment.TransactionType == TransactionType.Credit.ToString())
                {
                    var transactionID = payment.TransactionID;
                    if (string.IsNullOrEmpty(transactionID) || transactionID.Equals("0"))
                    {
                        message = "TransactionID is not valid or the current payment method does not support this order type.";
                        return(false);
                    }
                    //The transact must be captured before refunding
                    bool isRefunded = RefundTransaction(payment);
                    if (!isRefunded)
                    {
                        message = "There was an error while refunding with DIBS";
                        return(false);
                    }

                    return(true);
                }
                //right now we do not support processing the order which is created by Commerce Manager
                message = "The current payment method does not support this order type.";
                return(false);
            }

            Cart cart = payment.Parent.Parent as Cart;

            if (cart != null && cart.Status == PaymentCompleted)
            {
                //return true because this shopping cart has been paid already on DIBS
                return(true);
            }

            if (HttpContext.Current != null)
            {
                var      pageRef = DataFactory.Instance.GetPage(PageReference.StartPage)["DIBSPaymentPage"] as PageReference;
                PageData page    = DataFactory.Instance.GetPage(pageRef);
                HttpContext.Current.Response.Redirect(page.LinkURL);
            }
            else
            {
                throw new NullReferenceException("Cannot redirect to payment page without Http Context");
            }

            return(true);
        }
Ejemplo n.º 13
0
        private string GetAmount(Mediachase.Commerce.Orders.Payment payment)
        {
            var amountInCents = (payment.Amount * 100).ToString("0");

            return(amountInCents);
        }