Esempio n. 1
0
 /// <summary>
 /// Cancels recurring payment
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="cancelPaymentResult">Cancel payment result</param>
 public static void CancelRecurringPayment(Order order, ref CancelPaymentResult cancelPaymentResult)
 {
     var paymentMethod = PaymentMethodManager.GetPaymentMethodById(order.PaymentMethodId);
     if (paymentMethod == null)
         throw new NopException("Payment method couldn't be loaded");
     var iPaymentMethod = Activator.CreateInstance(Type.GetType(paymentMethod.ClassName)) as IPaymentMethod;
     iPaymentMethod.CancelRecurringPayment(order, ref cancelPaymentResult);
 }
        /// <summary>
        /// Voids payment
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="cancelPaymentResult">Cancel payment result</param>
        public void Void(Order order, ref CancelPaymentResult cancelPaymentResult)
        {
            var paymentMethod = GetPaymentMethodById(order.PaymentMethodId);

            if (paymentMethod == null)
            {
                throw new NopException("Payment method couldn't be loaded");
            }
            var iPaymentMethod = Activator.CreateInstance(Type.GetType(paymentMethod.ClassName)) as IPaymentMethod;

            iPaymentMethod.Void(order, ref cancelPaymentResult);
        }
        /// <summary>
        /// Cancels recurring payment
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="cancelPaymentResult">Cancel payment result</param>
        public void CancelRecurringPayment(Order order, ref CancelPaymentResult cancelPaymentResult)
        {
            if (order.OrderTotal == decimal.Zero)
            {
                return;
            }

            var paymentMethod = GetPaymentMethodById(order.PaymentMethodId);

            if (paymentMethod == null)
            {
                throw new NopException("Payment method couldn't be loaded");
            }
            var iPaymentMethod = Activator.CreateInstance(Type.GetType(paymentMethod.ClassName)) as IPaymentMethod;

            iPaymentMethod.CancelRecurringPayment(order, ref cancelPaymentResult);
        }
Esempio n. 4
0
        /// <summary>
        /// Cancels a recurring payment
        /// </summary>
        /// <param name="recurringPaymentId">Recurring payment identifier</param>
        /// <param name="throwException">A value indicating whether to throw the exception after an error has occupied.</param>
        public static RecurringPayment CancelRecurringPayment(int recurringPaymentId, 
            bool throwException)
        {
            var recurringPayment = GetRecurringPaymentById(recurringPaymentId);
            try
            {
                if (recurringPayment != null)
                {
                    //update recurring payment
                    UpdateRecurringPayment(recurringPayment.RecurringPaymentId, recurringPayment.InitialOrderId,
                        recurringPayment.CycleLength, recurringPayment.CyclePeriod,
                        recurringPayment.TotalCycles, recurringPayment.StartDate,
                        false, recurringPayment.Deleted, recurringPayment.CreatedOn);

                    var initialOrder = recurringPayment.InitialOrder;
                    if (initialOrder == null)
                        return recurringPayment;

                    //old info from placing order
                    var cancelPaymentResult = new CancelPaymentResult();
                    cancelPaymentResult.AuthorizationTransactionId = initialOrder.AuthorizationTransactionId;
                    cancelPaymentResult.CaptureTransactionId = initialOrder.CaptureTransactionId;
                    cancelPaymentResult.SubscriptionTransactionId = initialOrder.SubscriptionTransactionId;
                    cancelPaymentResult.Amount = initialOrder.OrderTotal;
                    PaymentManager.CancelRecurringPayment(initialOrder, ref cancelPaymentResult);
                    if (String.IsNullOrEmpty(cancelPaymentResult.Error))
                    {
                        InsertOrderNote(initialOrder.OrderId, string.Format("Recurring payment has been cancelled"), false, DateTime.UtcNow);
                    }
                    else
                    {
                        InsertOrderNote(initialOrder.OrderId, string.Format("Error cancelling recurring payment. Error: {0}", cancelPaymentResult.Error), false, DateTime.UtcNow);
                    }
                }
            }
            catch (Exception exc)
            {
                LogManager.InsertLog(LogTypeEnum.OrderError, "Error cancelling recurring payment", exc);
                if (throwException)
                    throw;
            }
            return recurringPayment;
        }
        /// <summary>
        /// Cancels recurring payment
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="cancelPaymentResult">Cancel payment result</param>        
        public void CancelRecurringPayment(Order order, ref CancelPaymentResult cancelPaymentResult)
        {
            InitSettings();
            MerchantAuthenticationType authentication = PopulateMerchantAuthentication();
            long subscriptionID = 0;
            long.TryParse(cancelPaymentResult.SubscriptionTransactionId, out subscriptionID);
            ARBCancelSubscriptionResponseType response = webService.ARBCancelSubscription(authentication, subscriptionID);

            if (response.resultCode == MessageTypeEnum.Ok)
            {
                //ok
            }
            else
            {
                cancelPaymentResult.Error = "Error cancelling subscription, please contact customer support. " + GetErrors(response);
                cancelPaymentResult.FullError = "Error cancelling subscription, please contact customer support. " + GetErrors(response);
            }
        }
        public void Void(Order order, ref CancelPaymentResult cancelPaymentResult)
        {
            var usaepay = new USAePayAPI.USAePay();
            usaepay.SourceKey = sourceKey;
            usaepay.Pin = pin;

            try
            {
                usaepay.Void(order.AuthorizationTransactionId);

                switch (usaepay.ResultCode)
                {
                    case "A":
                        cancelPaymentResult.PaymentStatus = PaymentStatusEnum.Voided;
                        //cancelPaymentResult.AuthorizationTransactionId = usaepay.RefNum;
                        break;
                    case "D":
                        cancelPaymentResult.Error = "Void Declined: " + usaepay.ErrorMesg;
                        cancelPaymentResult.FullError = "Void Declined : " + usaepay.ErrorMesg;
                        break;
                    default:
                        cancelPaymentResult.Error = "Error during void";
                        cancelPaymentResult.FullError = "Error during void: " + usaepay.ErrorMesg;
                        break;
                }
            }
            catch
            {
                cancelPaymentResult.Error = "Error during void";
                cancelPaymentResult.FullError = "Error during void";
            }
        }
 /// <summary>
 /// Cancels recurring payment
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="cancelPaymentResult">Cancel payment result</param>        
 public void CancelRecurringPayment(Order order, ref CancelPaymentResult cancelPaymentResult)
 {
 }
Esempio n. 8
0
        /// <summary>
        /// Voids order (from admin panel)
        /// </summary>
        /// <param name="orderId">Order identifier</param>
        /// <param name="error">Error</param>
        /// <returns>Voided order</returns>
        public Order Void(int orderId, ref string error)
        {
            var order = GetOrderById(orderId);
            if (order == null)
                return order;

            if (!CanVoid(order))
                throw new NopException("Can not do void for order.");

            var cancelPaymentResult = new CancelPaymentResult();
            try
            {
                //old info from placing order
                cancelPaymentResult.AuthorizationTransactionId = order.AuthorizationTransactionId;
                cancelPaymentResult.CaptureTransactionId = order.CaptureTransactionId;
                cancelPaymentResult.Amount = order.OrderTotal;
                cancelPaymentResult.PaymentStatus = order.PaymentStatus;

                IoC.Resolve<IPaymentService>().Void(order, ref cancelPaymentResult);

                if (String.IsNullOrEmpty(cancelPaymentResult.Error))
                {
                    order.AuthorizationTransactionId = cancelPaymentResult.AuthorizationTransactionId;
                    order.CaptureTransactionId = cancelPaymentResult.CaptureTransactionId;
                    order.PaymentStatusId = (int)cancelPaymentResult.PaymentStatus;
                    UpdateOrder(order);

                    InsertOrderNote(order.OrderId, string.Format("Order has been voided"), false, DateTime.UtcNow);
                }
                else
                {
                    InsertOrderNote(order.OrderId, string.Format("Unable to void order. Error: {0}", cancelPaymentResult.Error), false, DateTime.UtcNow);

                }
                order = CheckOrderStatus(order.OrderId);
            }
            catch (Exception exc)
            {
                cancelPaymentResult.Error = exc.Message;
                cancelPaymentResult.FullError = exc.ToString();
            }

            if (!String.IsNullOrEmpty(cancelPaymentResult.Error))
            {
                error = cancelPaymentResult.Error;
                IoC.Resolve<ILogService>().InsertLog(LogTypeEnum.OrderError, string.Format("Error voiding order. {0}", cancelPaymentResult.Error), cancelPaymentResult.FullError);
            }
            return order;
        }
 /// <summary>
 /// Voids paymen
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="cancelPaymentResult">Cancel payment result</param>
 public void Void(Order order, ref CancelPaymentResult cancelPaymentResult)
 {
     throw new NotImplementedException();
 }
        //This works only on refund to customer (refund what has already been captured...)
        private void DoRefund(Order order, ref CancelPaymentResult cancelPaymentResult, bool alreadyTriedCancel)
        {
            string merchant = SettingManager.GetSettingValue(QuickPayConstants.SETTING_MERCHANTID);
            string protocol = "3";
            string capturePostUrl = "https://secure.quickpay.dk/api";
            string msgtype = "refund";
            string amount = (cancelPaymentResult.Amount * 100).ToString("0", CultureInfo.InvariantCulture); //NOTE: Primary store should be changed to DKK, if you do not have internatinal agreement with pbs and quickpay. Otherwise you need to do currency conversion here.
            string transaction = order.AuthorizationTransactionId;
            string md5secret = SettingManager.GetSettingValue(QuickPayConstants.SETTING_MD5SECRET);
            string stringToMd5 = string.Concat(protocol, msgtype, merchant, amount, transaction, md5secret);

            string querystring = string.Empty;
            string md5check = GetMD5(stringToMd5);

            querystring += string.Format("protocol={0}&", protocol);
            querystring += string.Format("msgtype={0}&", msgtype);
            querystring += string.Format("merchant={0}&", merchant);
            querystring += string.Format("amount={0}&", amount);
            querystring += string.Format("transaction={0}&", transaction);
            querystring += string.Format("md5check={0}", md5check);

            string retval = HttpRequestsFunctions.HttpPost(capturePostUrl, querystring);

            try
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(retval);
                XmlElement xmlElement = xmlDocument.DocumentElement;

                string rep_qpstatmsg = xmlElement.SelectSingleNode("qpstatmsg").InnerText;
                string rep_qpstat = xmlElement.SelectSingleNode("qpstat").InnerText;
                string rep_transaction = xmlElement.SelectSingleNode("transaction").InnerText;

                //refund successful
                if (rep_qpstat == "000")
                {
                    cancelPaymentResult.PaymentStatus = PaymentStatusEnum.Refunded;
                }
                //not allowed in current state. This probably means that it has not been caputered yet.
                //we therefore try to just cancel, but not refund
                else if (rep_qpstat == "004" && (!alreadyTriedCancel))
                {
                    DoCancel(order, ref cancelPaymentResult, true);
                }
                else
                {
                    cancelPaymentResult.Error = "Quickpay Caputure refund did not succeed, qpstat is:" + rep_qpstat;
                    cancelPaymentResult.FullError = "Quickpay Caputure refund did not succeed, qpstat is:" + rep_qpstat;
                }

            }
            catch (Exception exception)
            {
                throw new NopException("XML response for Quickpay Capture was not successfull. Reasons could be that the host did not respond. Below is stacktrace:" + exception.Message + exception.StackTrace + exception.Source, exception.InnerException);
            }
        }
        //This only works when a payment have been authorized and not captured.
        private void DoCancel(Order order, ref CancelPaymentResult cancelPaymentResult, bool alreadyTriedRefund)
        {
            string merchant = SettingManager.GetSettingValue(QuickPayConstants.SETTING_MERCHANTID);
            string protocol = "3";
            string capturePostUrl = "https://secure.quickpay.dk/api";
            string msgtype = "cancel";
            string transaction = order.AuthorizationTransactionId;
            string md5secret = SettingManager.GetSettingValue(QuickPayConstants.SETTING_MD5SECRET);
            string stringToMd5 = string.Concat(protocol, msgtype, merchant, transaction, md5secret);

            string querystring = string.Empty;
            string md5check = GetMD5(stringToMd5);

            querystring += string.Format("protocol={0}&", protocol);
            querystring += string.Format("msgtype={0}&", msgtype);
            querystring += string.Format("merchant={0}&", merchant);
            querystring += string.Format("transaction={0}&", transaction);
            querystring += string.Format("md5check={0}", md5check);

            string retval = HttpRequestsFunctions.HttpPost(capturePostUrl, querystring);

            try
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(retval);
                XmlElement xmlElement = xmlDocument.DocumentElement;

                string rep_qpstatmsg = xmlElement.SelectSingleNode("qpstatmsg").InnerText;
                string rep_qpstat = xmlElement.SelectSingleNode("qpstat").InnerText;
                string rep_transaction = xmlElement.SelectSingleNode("transaction").InnerText;

                //refund successful
                if (rep_qpstat == "000")
                {
                    cancelPaymentResult.PaymentStatus = PaymentStatusEnum.Refunded;
                }
                else if (rep_qpstat == "004" && (!alreadyTriedRefund))
                {
                    DoRefund(order, ref cancelPaymentResult, true);
                }
                else
                {
                    cancelPaymentResult.Error = "Quickpay Cancel did not succeed, qpstat is:" + rep_qpstat;
                    cancelPaymentResult.FullError = "Quickpay Cancel did not succeed, qpstat is:" + rep_qpstat;
                }

            }
            catch (Exception exception)
            {
                throw new NopException("XML response for Quickpay Capture was not successfull. Reasons could be that the host did not respond. Below is stacktrace:" + exception.Message + exception.StackTrace + exception.Source, exception.InnerException);
            }
        }
 /// <summary>
 /// Refunds payment
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="cancelPaymentResult">Cancel payment result</param>        
 public void Refund(Order order, ref CancelPaymentResult cancelPaymentResult)
 {
     DoRefund(order, ref cancelPaymentResult, false);
 }
        /// <summary>
        /// Voids payment
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="cancelPaymentResult">Cancel payment result</param>        
        public void Void(Order order, ref CancelPaymentResult cancelPaymentResult)
        {
            InitSettings();

            string transactionID = cancelPaymentResult.AuthorizationTransactionId;
            if (String.IsNullOrEmpty(transactionID))
                transactionID = cancelPaymentResult.CaptureTransactionId;

            DoVoidReq req = new DoVoidReq();
            req.DoVoidRequest = new DoVoidRequestType();
            req.DoVoidRequest.Version = this.APIVersion;
            req.DoVoidRequest.AuthorizationID = transactionID;
            DoVoidResponseType response = service2.DoVoid(req);

            string error = string.Empty;
            bool Success = PaypalHelper.CheckSuccess(response, out error);
            if (Success)
            {
                cancelPaymentResult.PaymentStatus = PaymentStatusEnum.Voided;
                //cancelPaymentResult.VoidTransactionID = response.RefundTransactionID;
            }
            else
            {
                cancelPaymentResult.Error = error;
            }
        }
        /// <summary>
        /// Refunds payment
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="cancelPaymentResult">Cancel payment result</param>        
        public void Refund(Order order, ref CancelPaymentResult cancelPaymentResult)
        {
            InitSettings();

            string transactionID = cancelPaymentResult.CaptureTransactionId;

            RefundTransactionReq req = new RefundTransactionReq();
            req.RefundTransactionRequest = new RefundTransactionRequestType();
            //NOTE: Specify amount in partial refund
            req.RefundTransactionRequest.RefundType = RefundType.Full;
            req.RefundTransactionRequest.RefundTypeSpecified = true;
            req.RefundTransactionRequest.Version = this.APIVersion;
            req.RefundTransactionRequest.TransactionID = transactionID;
            RefundTransactionResponseType response = service1.RefundTransaction(req);

            string error = string.Empty;
            bool Success = PaypalHelper.CheckSuccess(response, out error);
            if (Success)
            {
                cancelPaymentResult.PaymentStatus = PaymentStatusEnum.Refunded;
                //cancelPaymentResult.RefundTransactionID = response.RefundTransactionID;
            }
            else
            {
                cancelPaymentResult.Error = error;
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Voids order (from admin panel)
        /// </summary>
        /// <param name="orderId">Order identifier</param>
        /// <param name="error">Error</param>
        /// <returns>Voided order</returns>
        public static Order Void(int orderId, ref string error)
        {
            var order = GetOrderById(orderId);
            if (order == null)
                return order;

            if (!CanVoid(order))
                throw new NopException("Can not do void for order.");

            var cancelPaymentResult = new CancelPaymentResult();
            try
            {
                //old info from placing order
                cancelPaymentResult.AuthorizationTransactionId = order.AuthorizationTransactionId;
                cancelPaymentResult.CaptureTransactionId = order.CaptureTransactionId;
                cancelPaymentResult.Amount = order.OrderTotal;
                cancelPaymentResult.PaymentStatus = order.PaymentStatus;

                PaymentManager.Void(order, ref cancelPaymentResult);

                if (String.IsNullOrEmpty(cancelPaymentResult.Error))
                {
                    order = UpdateOrder(order.OrderId, order.OrderGuid, order.CustomerId, order.CustomerLanguageId,
                        order.CustomerTaxDisplayType, order.CustomerIP, order.OrderSubtotalInclTax, order.OrderSubtotalExclTax, order.OrderShippingInclTax,
                        order.OrderShippingExclTax, order.PaymentMethodAdditionalFeeInclTax, order.PaymentMethodAdditionalFeeExclTax,
                        order.TaxRates, order.OrderTax, order.OrderTotal,
                        order.RefundedAmount, order.OrderDiscount,
                        order.OrderSubtotalInclTaxInCustomerCurrency, order.OrderSubtotalExclTaxInCustomerCurrency,
                        order.OrderShippingInclTaxInCustomerCurrency, order.OrderShippingExclTaxInCustomerCurrency,
                        order.PaymentMethodAdditionalFeeInclTaxInCustomerCurrency, order.PaymentMethodAdditionalFeeExclTaxInCustomerCurrency,
                        order.TaxRatesInCustomerCurrency, order.OrderTaxInCustomerCurrency,
                        order.OrderTotalInCustomerCurrency,
                        order.OrderDiscountInCustomerCurrency,
                        order.CheckoutAttributeDescription, order.CheckoutAttributesXml,
                        order.CustomerCurrencyCode, order.OrderWeight,
                        order.AffiliateId, order.OrderStatus, order.AllowStoringCreditCardNumber,
                        order.CardType, order.CardName, order.CardNumber, order.MaskedCreditCardNumber,
                        order.CardCvv2, order.CardExpirationMonth, order.CardExpirationYear,
                        order.PaymentMethodId, order.PaymentMethodName,
                        cancelPaymentResult.AuthorizationTransactionId,
                        order.AuthorizationTransactionCode,
                        order.AuthorizationTransactionResult,
                        cancelPaymentResult.CaptureTransactionId,
                        order.CaptureTransactionResult,
                        order.SubscriptionTransactionId, order.PurchaseOrderNumber,
                        cancelPaymentResult.PaymentStatus, order.PaidDate,
                        order.BillingFirstName, order.BillingLastName, order.BillingPhoneNumber,
                        order.BillingEmail, order.BillingFaxNumber, order.BillingCompany, order.BillingAddress1,
                        order.BillingAddress2, order.BillingCity,
                        order.BillingStateProvince, order.BillingStateProvinceId, order.BillingZipPostalCode,
                        order.BillingCountry, order.BillingCountryId, order.ShippingStatus,
                        order.ShippingFirstName, order.ShippingLastName, order.ShippingPhoneNumber,
                        order.ShippingEmail, order.ShippingFaxNumber, order.ShippingCompany,
                        order.ShippingAddress1, order.ShippingAddress2, order.ShippingCity,
                        order.ShippingStateProvince, order.ShippingStateProvinceId, order.ShippingZipPostalCode,
                        order.ShippingCountry, order.ShippingCountryId,
                        order.ShippingMethod, order.ShippingRateComputationMethodId,
                        order.ShippedDate, order.DeliveryDate,
                        order.TrackingNumber, order.VatNumber, order.Deleted, order.CreatedOn);

                    InsertOrderNote(order.OrderId, string.Format("Order has been voided"), false, DateTime.UtcNow);
                }
                else
                {
                    InsertOrderNote(order.OrderId, string.Format("Unable to void order. Error: {0}", cancelPaymentResult.Error), false, DateTime.UtcNow);

                }
                order = CheckOrderStatus(order.OrderId);
            }
            catch (Exception exc)
            {
                cancelPaymentResult.Error = exc.Message;
                cancelPaymentResult.FullError = exc.ToString();
            }

            if (!String.IsNullOrEmpty(cancelPaymentResult.Error))
            {
                error = cancelPaymentResult.Error;
                LogManager.InsertLog(LogTypeEnum.OrderError, string.Format("Error voiding order. {0}", cancelPaymentResult.Error), cancelPaymentResult.FullError);
            }
            return order;
        }
 /// <summary>
 /// Cancels recurring payment
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="cancelPaymentResult">Cancel payment result</param>
 public void CancelRecurringPayment(Order order, ref CancelPaymentResult cancelPaymentResult)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Refunds payment
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="cancelPaymentResult">Cancel payment result</param>
 public void Refund(Order order, ref CancelPaymentResult cancelPaymentResult)
 {
     try
     {
         using(usaepayService svc = new usaepayService())
         {
             svc.Url = EPaymentFormSettings.ServiceUrl;
             TransactionResponse rsp = svc.refundTransaction(EPaymentFormHelper.ServiceSecurityToken, cancelPaymentResult.CaptureTransactionId, (double)cancelPaymentResult.Amount);
             switch(rsp.ResultCode)
             {
                 case "A":
                     {
                         if (cancelPaymentResult.IsPartialRefund)
                             cancelPaymentResult.PaymentStatus = PaymentStatusEnum.PartiallyRefunded;
                         else
                             cancelPaymentResult.PaymentStatus = PaymentStatusEnum.Refunded;
                     }
                     break;
                 case "D":
                 case "E":
                 default:
                     cancelPaymentResult.Error = rsp.ErrorCode;
                     cancelPaymentResult.FullError = rsp.Error;
                     break;
             }
         }
     }
     catch(Exception ex)
     {
         cancelPaymentResult.Error = ex.Message;
         cancelPaymentResult.FullError = ex.Message;
     }
 }
Esempio n. 18
0
        /// <summary>
        /// Refunds an order (from admin panel)
        /// </summary>
        /// <param name="orderId">Order identifier</param>
        /// <param name="error">Error</param>
        /// <returns>Refunded order</returns>
        public Order Refund(int orderId, ref string error)
        {
            var order = GetOrderById(orderId);
            if (order == null)
                return order;

            if (!CanRefund(order))
                throw new NopException("Can not do refund for order.");

            var cancelPaymentResult = new CancelPaymentResult();
            try
            {
                //amout to refund
                decimal amountToRefund = order.OrderTotal;

                //old info from placing order
                cancelPaymentResult.AuthorizationTransactionId = order.AuthorizationTransactionId;
                cancelPaymentResult.CaptureTransactionId = order.CaptureTransactionId;
                cancelPaymentResult.SubscriptionTransactionId = order.SubscriptionTransactionId;
                cancelPaymentResult.Amount = amountToRefund;
                cancelPaymentResult.IsPartialRefund = false;
                cancelPaymentResult.PaymentStatus = order.PaymentStatus;

                IoC.Resolve<IPaymentService>().Refund(order, ref cancelPaymentResult);

                if (String.IsNullOrEmpty(cancelPaymentResult.Error))
                {
                    //total amount refunded
                    decimal totalAmountRefunded = order.RefundedAmount + amountToRefund;

                    //update order info
                    order.RefundedAmount = totalAmountRefunded;
                    order.AuthorizationTransactionId = cancelPaymentResult.AuthorizationTransactionId;
                    order.CaptureTransactionId = cancelPaymentResult.CaptureTransactionId;
                    order.PaymentStatusId = (int)cancelPaymentResult.PaymentStatus;
                    UpdateOrder(order);

                    InsertOrderNote(order.OrderId, string.Format("Order has been refunded. Amount = {0}", PriceHelper.FormatPrice(amountToRefund, true, false)), false, DateTime.UtcNow);
                }
                else
                {
                    InsertOrderNote(order.OrderId, string.Format("Unable to refund order. Error: {0}", cancelPaymentResult.Error), false, DateTime.UtcNow);
                }

                //check orer status
                order = CheckOrderStatus(order.OrderId);
            }
            catch (Exception exc)
            {
                cancelPaymentResult.Error = exc.Message;
                cancelPaymentResult.FullError = exc.ToString();
            }

            if (!String.IsNullOrEmpty(cancelPaymentResult.Error))
            {
                error = cancelPaymentResult.Error;
                IoC.Resolve<ILogService>().InsertLog(LogTypeEnum.OrderError, string.Format("Error refunding order. {0}", cancelPaymentResult.Error), cancelPaymentResult.FullError);
            }
            return order;
        }
 /// <summary>
 /// Voids paymen
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="cancelPaymentResult">Cancel payment result</param>
 public void Void(Order order, ref CancelPaymentResult cancelPaymentResult)
 {
     try
     {
         using(usaepayService svc = new usaepayService())
         {
             svc.Url = EPaymentFormSettings.ServiceUrl;
             if(svc.voidTransaction(EPaymentFormHelper.ServiceSecurityToken, cancelPaymentResult.AuthorizationTransactionId))
             {
                 cancelPaymentResult.PaymentStatus = PaymentStatusEnum.Voided;
             }
             else
             {
                 cancelPaymentResult.Error = "Failed";
                 cancelPaymentResult.FullError = "Failed";
             }
         }
     }
     catch(Exception ex)
     {
         cancelPaymentResult.Error = ex.Message;
         cancelPaymentResult.FullError = ex.Message;
     }
 }
Esempio n. 20
0
        /// <summary>
        /// Cancels a recurring payment
        /// </summary>
        /// <param name="recurringPaymentId">Recurring payment identifier</param>
        /// <param name="throwException">A value indicating whether to throw the exception after an error has occupied.</param>
        public RecurringPayment CancelRecurringPayment(int recurringPaymentId,
            bool throwException)
        {
            var recurringPayment = GetRecurringPaymentById(recurringPaymentId);

            if (recurringPayment != null)
            {
                var initialOrder = recurringPayment.InitialOrder;
                if (initialOrder == null)
                    return recurringPayment;

                try
                {
                    //old info from placing order
                    var cancelPaymentResult = new CancelPaymentResult();
                    cancelPaymentResult.AuthorizationTransactionId = initialOrder.AuthorizationTransactionId;
                    cancelPaymentResult.CaptureTransactionId = initialOrder.CaptureTransactionId;
                    cancelPaymentResult.SubscriptionTransactionId = initialOrder.SubscriptionTransactionId;
                    cancelPaymentResult.Amount = initialOrder.OrderTotal;
                    IoC.Resolve<IPaymentService>().CancelRecurringPayment(initialOrder, ref cancelPaymentResult);

                    if (String.IsNullOrEmpty(cancelPaymentResult.Error))
                    {
                        //update recurring payment
                        recurringPayment.IsActive = false;
                        UpdateRecurringPayment(recurringPayment);

                        //order note
                        InsertOrderNote(initialOrder.OrderId, string.Format("Recurring payment has been cancelled"), false, DateTime.UtcNow);
                    }
                    else
                    {
                        //order note
                        InsertOrderNote(initialOrder.OrderId, string.Format("Error cancelling recurring payment. Error: {0}", cancelPaymentResult.Error), false, DateTime.UtcNow);
                    }

                }
                catch (Exception exc)
                {
                    IoC.Resolve<ILogService>().InsertLog(LogTypeEnum.OrderError, "Error cancelling recurring payment", exc);
                    if (throwException)
                        throw;
                }
            }
            return recurringPayment;
        }
Esempio n. 21
0
        public void Refund(Order order, ref CancelPaymentResult cancelPaymentResult)
        {
            XmlTransaction sxml = new XmlTransaction(XmlPaymentSettings.TestMode ? XmlTransaction.MODE_TEST : XmlTransaction.MODE_LIVE, SecurePaySettings.MerchantId, SecurePaySettings.MerchantPassword, ID);
            bool success = false;
            string code = "";

            success = sxml.processRefund(cancelPaymentResult.Amount, order.OrderGuid.ToString(), cancelPaymentResult.CaptureTransactionId);

            code = sxml["response_code"];

            if(!success)
            {
                cancelPaymentResult.Error = String.Format("Declined ({0})", code);
                cancelPaymentResult.FullError = sxml.Error;
            }
            else
            {
                cancelPaymentResult.PaymentStatus = PaymentStatusEnum.Refunded;
            }
        }
 /// <summary>
 /// Voids payment
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="cancelPaymentResult">Cancel payment result</param>        
 public void Void(Order order, ref CancelPaymentResult cancelPaymentResult)
 {
     throw new NopException("Void method not supported");
 }
 /// <summary>
 /// Voids payment
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="cancelPaymentResult">Cancel payment result</param>        
 public void Void(Order order, ref CancelPaymentResult cancelPaymentResult)
 {
 }