Exemplo n.º 1
0
        /// <summary>
        /// Process
        /// </summary>
        /// <param name="payment"></param>
        /// <param name="orderGroup"></param>
        /// <param name="message"></param>
        /// <param name="orderForm"></param>
        /// <returns></returns>
        public override PaymentStepResult Process(IPayment payment, IOrderForm orderForm, IOrderGroup orderGroup)
        {
            if (payment.TransactionType == TransactionType.Capture.ToString())
            {
                var amount = PaymentStepHelper.GetAmount(payment.Amount);

                try
                {
                    var result = this.Client.Capture(payment.TransactionID, amount);
                    if (result.ErrorOccurred)
                    {
                        payment.Status = PaymentStatus.Failed.ToString();
                        AddNoteAndSaveChanges(orderGroup, "Payment Captured - Error", "Payment - Captured - Error: " + result.ErrorMessage);
                        return(Fail(result.ErrorMessage));
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex.Message);
                    payment.Status = PaymentStatus.Failed.ToString();
                    AddNoteAndSaveChanges(orderGroup, "Payment Captured - Error", "Payment - Captured - Error: " + ex.Message);
                    return(Fail(ex.Message));
                }

                AddNoteAndSaveChanges(orderGroup, "Payment - Captured", "Payment - Captured");

                return(Success());
            }
            else if (Successor != null)
            {
                return(Successor.Process(payment, orderForm, orderGroup));
            }

            return(Fail(null));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create payment request
        /// </summary>
        /// <param name="paymentMethodDto"></param>
        /// <param name="payment"></param>
        /// <param name="orderForm"></param>
        /// <param name="orderGroup"></param>
        /// <returns></returns>
        private PaymentRequest CreatePaymentRequest(PaymentMethodDto paymentMethodDto, IPayment payment, IOrderForm orderForm, IOrderGroup orderGroup)
        {
            var request = new PaymentRequest();

            if (orderGroup.CustomerId != Guid.Empty)
            {
                var customerContact = CustomerContext.Current.GetContactById(orderGroup.CustomerId);
                if (customerContact != null)
                {
                    request.PanHash = customerContact[NetaxeptConstants.CustomerPanHashFieldName]?.ToString();
                }
            }

            var calculatedTotals = _orderGroupCalculator.Service.GetOrderGroupTotals(orderGroup);

            request.Amount           = PaymentStepHelper.GetAmount(payment.Amount);
            request.TaxTotal         = PaymentStepHelper.GetAmount(calculatedTotals.TaxTotal.Amount);
            request.CurrencyCode     = orderGroup.Currency.CurrencyCode;
            request.OrderDescription = "Netaxept order";
            request.OrderNumber      = CartOrderNumberHelper.GenerateOrderNumber(orderGroup);

            request.Language           = paymentMethodDto.GetParameter(NetaxeptConstants.TerminalLanguageField);
            request.EnableEasyPayments = bool.Parse(paymentMethodDto.GetParameter(NetaxeptConstants.EnableEasyPaymentField, "false"));

            request.SuccessUrl = payment.Properties.GetStringValue(NetaxeptConstants.CallbackUrl, string.Empty);

            request.CustomerNumber = (orderGroup.CustomerId != Guid.Empty ? orderGroup.CustomerId.ToString() : string.Empty);

            var billingAddress = payment.BillingAddress;

            if (billingAddress != null)
            {
                request.CustomerFirstname   = billingAddress.FirstName;
                request.CustomerLastname    = billingAddress.LastName;
                request.CustomerEmail       = billingAddress.Email;
                request.CustomerAddress1    = billingAddress.Line1;
                request.CustomerAddress2    = !string.IsNullOrEmpty(billingAddress.Line2) ? billingAddress.Line2 : billingAddress.Line1;
                request.CustomerPostcode    = billingAddress.PostalCode;
                request.CustomerTown        = billingAddress.City;
                request.CustomerCountry     = ConvertThreeLetterNameToTwoLetterName(billingAddress.CountryCode);
                request.CustomerPhoneNumber = GetValidPhonenumber(billingAddress.DaytimePhoneNumber ?? billingAddress.EveningPhoneNumber);
            }
            return(request);
        }