예제 #1
0
        /// <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;
            }
        }
예제 #2
0
        /// <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;
            }
        }
예제 #3
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="processPaymentResult">Process payment result</param>
        public void Capture(Order order, ref ProcessPaymentResult processPaymentResult)
        {
            InitSettings();

            string       authorizationID = processPaymentResult.AuthorizationTransactionId;
            DoCaptureReq req             = new DoCaptureReq();

            req.DoCaptureRequest                   = new DoCaptureRequestType();
            req.DoCaptureRequest.Version           = this.APIVersion;
            req.DoCaptureRequest.AuthorizationID   = authorizationID;
            req.DoCaptureRequest.Amount            = new BasicAmountType();
            req.DoCaptureRequest.Amount.Value      = order.OrderTotal.ToString("N", new CultureInfo("en-us"));
            req.DoCaptureRequest.Amount.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve <ICurrencyService>().PrimaryStoreCurrency);
            req.DoCaptureRequest.CompleteType      = CompleteCodeType.Complete;
            DoCaptureResponseType response = service2.DoCapture(req);

            string error   = string.Empty;
            bool   Success = PaypalHelper.CheckSuccess(response, out error);

            if (Success)
            {
                processPaymentResult.PaymentStatus            = PaymentStatusEnum.Paid;
                processPaymentResult.CaptureTransactionId     = response.DoCaptureResponseDetails.PaymentInfo.TransactionID;
                processPaymentResult.CaptureTransactionResult = response.Ack.ToString();
            }
            else
            {
                processPaymentResult.Error = error;
            }
        }
        /// <summary>
        /// Sets paypal express checkout
        /// </summary>
        /// <param name="OrderTotal">Order total</param>
        /// <param name="ReturnURL">Return URL</param>
        /// <param name="CancelURL">Cancel URL</param>
        /// <returns>Express checkout URL</returns>
        public string SetExpressCheckout(decimal OrderTotal, string ReturnURL, string CancelURL)
        {
            InitSettings();
            TransactMode transactionMode = GetCurrentTransactionMode();

            SetExpressCheckoutReq req = new SetExpressCheckoutReq();

            req.SetExpressCheckoutRequest         = new SetExpressCheckoutRequestType();
            req.SetExpressCheckoutRequest.Version = this.APIVersion;
            SetExpressCheckoutRequestDetailsType details = new SetExpressCheckoutRequestDetailsType();

            req.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails = details;
            if (transactionMode == TransactMode.Authorize)
            {
                details.PaymentAction = PaymentActionCodeType.Authorization;
            }
            else
            {
                details.PaymentAction = PaymentActionCodeType.Sale;
            }
            details.PaymentActionSpecified = true;
            details.OrderTotal             = new BasicAmountType();
            details.OrderTotal.Value       = OrderTotal.ToString("N", new CultureInfo("en-us"));
            details.OrderTotal.currencyID  = PaypalHelper.GetPaypalCurrency(CurrencyManager.PrimaryStoreCurrency);
            details.ReturnURL = ReturnURL;
            details.CancelURL = CancelURL;
            SetExpressCheckoutResponseType response = service2.SetExpressCheckout(req);
            string error;

            if (PaypalHelper.CheckSuccess(response, out error))
            {
                return(GetPaypalUrl(response.Token));
            }
            throw new NopException(error);
        }
        /// <summary>
        /// Do paypal express checkout
        /// </summary>
        /// <param name="Token">Paypal express checkout token</param>
        /// <param name="PayerID">Paypal payer identifier</param>
        /// <param name="OrderTotal">Order total</param>
        /// <param name="processPaymentResult">Process payment result</param>
        public void DoExpressCheckout(string Token, string PayerID, decimal OrderTotal, ProcessPaymentResult processPaymentResult)
        {
            InitSettings();
            TransactMode transactionMode = GetCurrentTransactionMode();

            DoExpressCheckoutPaymentReq         req     = new DoExpressCheckoutPaymentReq();
            DoExpressCheckoutPaymentRequestType request = new DoExpressCheckoutPaymentRequestType();

            req.DoExpressCheckoutPaymentRequest = request;
            request.Version = this.APIVersion;
            DoExpressCheckoutPaymentRequestDetailsType details = new DoExpressCheckoutPaymentRequestDetailsType();

            request.DoExpressCheckoutPaymentRequestDetails = details;
            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            details.PaymentDetails = paymentDetails;
            if (transactionMode == TransactMode.Authorize)
            {
                details.PaymentAction = PaymentActionCodeType.Authorization;
            }
            else
            {
                details.PaymentAction = PaymentActionCodeType.Sale;
            }
            details.Token                        = Token;
            details.PayerID                      = PayerID;
            paymentDetails.OrderTotal            = new BasicAmountType();
            paymentDetails.OrderTotal.Value      = OrderTotal.ToString("N", new CultureInfo("en-us"));
            paymentDetails.OrderTotal.currencyID = PaypalHelper.GetPaypalCurrency(CurrencyManager.PrimaryStoreCurrency);
            paymentDetails.ButtonSource          = "nopCommerceCart";

            DoExpressCheckoutPaymentResponseType response = service2.DoExpressCheckoutPayment(req);
            string error;

            if (!PaypalHelper.CheckSuccess(response, out error))
            {
                throw new NopException(error);
            }

            processPaymentResult.AuthorizationTransactionID     = response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.TransactionID;
            processPaymentResult.AuthorizationTransactionResult = response.Ack.ToString();
            //processPaymentResult.AuthorizationDate = response.Timestamp;
            //processPaymentResult.AuthorizationDate = DateTime.Now;

            if (transactionMode == TransactMode.Authorize)
            {
                processPaymentResult.PaymentStatus = PaymentStatusEnum.Authorized;
            }
            else
            {
                processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid;
            }
        }
        /// <summary>
        /// Gets a paypal express checkout result
        /// </summary>
        /// <param name="token">paypal express checkout token</param>
        /// <returns>Paypal payer</returns>
        public PaypalPayer GetExpressCheckout(string token)
        {
            InitSettings();
            GetExpressCheckoutDetailsReq         req     = new GetExpressCheckoutDetailsReq();
            GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();

            req.GetExpressCheckoutDetailsRequest = request;

            request.Token   = token;
            request.Version = this.APIVersion;

            GetExpressCheckoutDetailsResponseType response = service2.GetExpressCheckoutDetails(req);

            string error;

            if (!PaypalHelper.CheckSuccess(response, out error))
            {
                throw new NopException(error);
            }

            PaypalPayer payer = new PaypalPayer();

            payer.PayerEmail        = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
            payer.FirstName         = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.FirstName;
            payer.LastName          = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.LastName;
            payer.CompanyName       = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerBusiness;
            payer.Address1          = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1;
            payer.Address2          = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2;
            payer.City              = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName;
            payer.State             = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince;
            payer.Zipcode           = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
            payer.Phone             = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.ContactPhone;
            payer.PaypalCountryName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountryName;
            payer.CountryCode       = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
            payer.PayerID           = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
            payer.Token             = response.GetExpressCheckoutDetailsResponseDetails.Token;
            return(payer);
        }
예제 #7
0
        /// <summary>
        /// Process recurring payment
        /// </summary>
        /// <param name="paymentInfo">Payment info required for an order processing</param>
        /// <param name="customer">Customer</param>
        /// <param name="orderGuid">Unique order identifier</param>
        /// <param name="processPaymentResult">Process payment result</param>
        public void ProcessRecurringPayment(PaymentInfo paymentInfo, Customer customer, Guid orderGuid, ref ProcessPaymentResult processPaymentResult)
        {
            InitSettings();

            CreateRecurringPaymentsProfileReq req = new CreateRecurringPaymentsProfileReq();

            req.CreateRecurringPaymentsProfileRequest         = new CreateRecurringPaymentsProfileRequestType();
            req.CreateRecurringPaymentsProfileRequest.Version = this.APIVersion;
            CreateRecurringPaymentsProfileRequestDetailsType details = new CreateRecurringPaymentsProfileRequestDetailsType();

            req.CreateRecurringPaymentsProfileRequest.CreateRecurringPaymentsProfileRequestDetails = details;

            details.CreditCard = new CreditCardDetailsType();
            details.CreditCard.CreditCardNumber  = paymentInfo.CreditCardNumber;
            details.CreditCard.CreditCardType    = GetPaypalCreditCardType(paymentInfo.CreditCardType);
            details.CreditCard.ExpMonthSpecified = true;
            details.CreditCard.ExpMonth          = paymentInfo.CreditCardExpireMonth;
            details.CreditCard.ExpYearSpecified  = true;
            details.CreditCard.ExpYear           = paymentInfo.CreditCardExpireYear;
            details.CreditCard.CVV2      = paymentInfo.CreditCardCvv2;
            details.CreditCard.CardOwner = new PayerInfoType();
            details.CreditCard.CardOwner.PayerCountry  = GetPaypalCountryCodeType(paymentInfo.BillingAddress.Country);
            details.CreditCard.CreditCardTypeSpecified = true;

            details.CreditCard.CardOwner.Address = new AddressType();
            details.CreditCard.CardOwner.Address.CountrySpecified = true;
            details.CreditCard.CardOwner.Address.Street1          = paymentInfo.BillingAddress.Address1;
            details.CreditCard.CardOwner.Address.Street2          = paymentInfo.BillingAddress.Address2;
            details.CreditCard.CardOwner.Address.CityName         = paymentInfo.BillingAddress.City;
            if (paymentInfo.BillingAddress.StateProvince != null)
            {
                details.CreditCard.CardOwner.Address.StateOrProvince = paymentInfo.BillingAddress.StateProvince.Abbreviation;
            }
            else
            {
                details.CreditCard.CardOwner.Address.StateOrProvince = "CA";
            }
            details.CreditCard.CardOwner.Address.Country    = GetPaypalCountryCodeType(paymentInfo.BillingAddress.Country);
            details.CreditCard.CardOwner.Address.PostalCode = paymentInfo.BillingAddress.ZipPostalCode;
            details.CreditCard.CardOwner.Payer               = paymentInfo.BillingAddress.Email;
            details.CreditCard.CardOwner.PayerName           = new PersonNameType();
            details.CreditCard.CardOwner.PayerName.FirstName = paymentInfo.BillingAddress.FirstName;
            details.CreditCard.CardOwner.PayerName.LastName  = paymentInfo.BillingAddress.LastName;

            //start date
            details.RecurringPaymentsProfileDetails = new RecurringPaymentsProfileDetailsType();
            details.RecurringPaymentsProfileDetails.BillingStartDate = DateTime.UtcNow;
            details.RecurringPaymentsProfileDetails.ProfileReference = orderGuid.ToString();

            //schedule
            details.ScheduleDetails                                 = new ScheduleDetailsType();
            details.ScheduleDetails.Description                     = string.Format("{0} - {1}", IoC.Resolve <ISettingManager>().StoreName, "recurring payment");
            details.ScheduleDetails.PaymentPeriod                   = new BillingPeriodDetailsType();
            details.ScheduleDetails.PaymentPeriod.Amount            = new BasicAmountType();
            details.ScheduleDetails.PaymentPeriod.Amount.Value      = paymentInfo.OrderTotal.ToString("N", new CultureInfo("en-us"));
            details.ScheduleDetails.PaymentPeriod.Amount.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve <ICurrencyService>().PrimaryStoreCurrency);
            details.ScheduleDetails.PaymentPeriod.BillingFrequency  = paymentInfo.RecurringCycleLength;
            switch (paymentInfo.RecurringCyclePeriod)
            {
            case (int)RecurringProductCyclePeriodEnum.Days:
                details.ScheduleDetails.PaymentPeriod.BillingPeriod = BillingPeriodType.Day;
                break;

            case (int)RecurringProductCyclePeriodEnum.Weeks:
                details.ScheduleDetails.PaymentPeriod.BillingPeriod = BillingPeriodType.Week;
                break;

            case (int)RecurringProductCyclePeriodEnum.Months:
                details.ScheduleDetails.PaymentPeriod.BillingPeriod = BillingPeriodType.Month;
                break;

            case (int)RecurringProductCyclePeriodEnum.Years:
                details.ScheduleDetails.PaymentPeriod.BillingPeriod = BillingPeriodType.Year;
                break;

            default:
                throw new NopException("Not supported cycle period");
            }
            details.ScheduleDetails.PaymentPeriod.TotalBillingCycles          = paymentInfo.RecurringTotalCycles;
            details.ScheduleDetails.PaymentPeriod.TotalBillingCyclesSpecified = true;

            CreateRecurringPaymentsProfileResponseType response = service2.CreateRecurringPaymentsProfile(req);

            string error   = string.Empty;
            bool   Success = PaypalHelper.CheckSuccess(response, out error);

            if (Success)
            {
                processPaymentResult.PaymentStatus = PaymentStatusEnum.Pending;
                if (response.CreateRecurringPaymentsProfileResponseDetails != null)
                {
                    processPaymentResult.SubscriptionTransactionId = response.CreateRecurringPaymentsProfileResponseDetails.ProfileID;
                }
            }
            else
            {
                processPaymentResult.Error     = error;
                processPaymentResult.FullError = error;
            }
        }
예제 #8
0
        /// <summary>
        /// Authorizes the payment
        /// </summary>
        /// <param name="paymentInfo">Payment info required for an order processing</param>
        /// <param name="customer">Customer</param>
        /// <param name="orderGuid">Unique order identifier</param>
        /// <param name="processPaymentResult">Process payment result</param>
        /// <param name="authorizeOnly">A value indicating whether to authorize only; true - authorize; false - sale</param>
        protected void AuthorizeOrSale(PaymentInfo paymentInfo, Customer customer,
                                       Guid orderGuid, ProcessPaymentResult processPaymentResult, bool authorizeOnly)
        {
            InitSettings();

            DoDirectPaymentReq req = new DoDirectPaymentReq();

            req.DoDirectPaymentRequest         = new DoDirectPaymentRequestType();
            req.DoDirectPaymentRequest.Version = this.APIVersion;
            DoDirectPaymentRequestDetailsType details = new DoDirectPaymentRequestDetailsType();

            req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = details;
            details.IPAddress = NopContext.Current.UserHostAddress;
            if (authorizeOnly)
            {
                details.PaymentAction = PaymentActionCodeType.Authorization;
            }
            else
            {
                details.PaymentAction = PaymentActionCodeType.Sale;
            }
            details.CreditCard = new CreditCardDetailsType();
            details.CreditCard.CreditCardNumber  = paymentInfo.CreditCardNumber;
            details.CreditCard.CreditCardType    = GetPaypalCreditCardType(paymentInfo.CreditCardType);
            details.CreditCard.ExpMonthSpecified = true;
            details.CreditCard.ExpMonth          = paymentInfo.CreditCardExpireMonth;
            details.CreditCard.ExpYearSpecified  = true;
            details.CreditCard.ExpYear           = paymentInfo.CreditCardExpireYear;
            details.CreditCard.CVV2      = paymentInfo.CreditCardCvv2;
            details.CreditCard.CardOwner = new PayerInfoType();
            details.CreditCard.CardOwner.PayerCountry  = GetPaypalCountryCodeType(paymentInfo.BillingAddress.Country);
            details.CreditCard.CreditCardTypeSpecified = true;

            details.CreditCard.CardOwner.Address = new AddressType();
            details.CreditCard.CardOwner.Address.CountrySpecified = true;
            details.CreditCard.CardOwner.Address.Street1          = paymentInfo.BillingAddress.Address1;
            details.CreditCard.CardOwner.Address.Street2          = paymentInfo.BillingAddress.Address2;
            details.CreditCard.CardOwner.Address.CityName         = paymentInfo.BillingAddress.City;
            if (paymentInfo.BillingAddress.StateProvince != null)
            {
                details.CreditCard.CardOwner.Address.StateOrProvince = paymentInfo.BillingAddress.StateProvince.Abbreviation;
            }
            else
            {
                details.CreditCard.CardOwner.Address.StateOrProvince = "CA";
            }
            details.CreditCard.CardOwner.Address.Country    = GetPaypalCountryCodeType(paymentInfo.BillingAddress.Country);
            details.CreditCard.CardOwner.Address.PostalCode = paymentInfo.BillingAddress.ZipPostalCode;
            details.CreditCard.CardOwner.Payer               = paymentInfo.BillingAddress.Email;
            details.CreditCard.CardOwner.PayerName           = new PersonNameType();
            details.CreditCard.CardOwner.PayerName.FirstName = paymentInfo.BillingAddress.FirstName;
            details.CreditCard.CardOwner.PayerName.LastName  = paymentInfo.BillingAddress.LastName;
            details.PaymentDetails                       = new PaymentDetailsType();
            details.PaymentDetails.OrderTotal            = new BasicAmountType();
            details.PaymentDetails.OrderTotal.Value      = paymentInfo.OrderTotal.ToString("N", new CultureInfo("en-us"));
            details.PaymentDetails.OrderTotal.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve <ICurrencyService>().PrimaryStoreCurrency);
            details.PaymentDetails.Custom                = orderGuid.ToString();
            details.PaymentDetails.ButtonSource          = "nopCommerceCart";


            //ShoppingCart cart = IoC.Resolve<IShoppingCartService>().GetShoppingCartByCustomerSessionGUID(ShoppingCartTypeEnum.ShoppingCart, NopContext.Current.Session.CustomerSessionGUID);
            //PaymentDetailsItemType[] cartItems = new PaymentDetailsItemType[cart.Count];
            //for (int i = 0; i < cart.Count; i++)
            //{
            //    ShoppingCartItem item = cart[i];
            //    cartItems[i] = new PaymentDetailsItemType()
            //    {
            //        Name = item.ProductVariant.FullProductName,
            //        Number = item.ProductVariant.ProductVariantID.ToString(),
            //        Quantity = item.Quantity.ToString(),
            //        Amount = new BasicAmountType()
            //        {
            //            currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency),
            //            Value = (item.Quantity * item.ProductVariant.Price).ToString("N", new CultureInfo("en-us"))
            //        }
            //    };
            //};
            //details.PaymentDetails.PaymentDetailsItem = cartItems;

            //shipping
            if (paymentInfo.ShippingAddress != null)
            {
                if (paymentInfo.ShippingAddress.StateProvince != null && paymentInfo.ShippingAddress.Country != null)
                {
                    AddressType shippingAddress = new AddressType();
                    shippingAddress.Name                 = paymentInfo.ShippingAddress.FirstName + " " + paymentInfo.ShippingAddress.LastName;
                    shippingAddress.Street1              = paymentInfo.ShippingAddress.Address1;
                    shippingAddress.CityName             = paymentInfo.ShippingAddress.City;
                    shippingAddress.StateOrProvince      = paymentInfo.ShippingAddress.StateProvince.Abbreviation;
                    shippingAddress.PostalCode           = paymentInfo.ShippingAddress.ZipPostalCode;
                    shippingAddress.Country              = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), paymentInfo.ShippingAddress.Country.TwoLetterIsoCode, true);
                    shippingAddress.CountrySpecified     = true;
                    details.PaymentDetails.ShipToAddress = shippingAddress;
                }
            }

            DoDirectPaymentResponseType response = service2.DoDirectPayment(req);

            string error   = string.Empty;
            bool   Success = PaypalHelper.CheckSuccess(response, out error);

            if (Success)
            {
                processPaymentResult.AVSResult = response.AVSCode;
                processPaymentResult.AuthorizationTransactionCode = response.CVV2Code;
                if (authorizeOnly)
                {
                    processPaymentResult.AuthorizationTransactionId     = response.TransactionID;
                    processPaymentResult.AuthorizationTransactionResult = response.Ack.ToString();

                    processPaymentResult.PaymentStatus = PaymentStatusEnum.Authorized;
                }
                else
                {
                    processPaymentResult.CaptureTransactionId     = response.TransactionID;
                    processPaymentResult.CaptureTransactionResult = response.Ack.ToString();

                    processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid;
                }
            }
            else
            {
                processPaymentResult.Error     = error;
                processPaymentResult.FullError = error;
            }
        }
예제 #9
0
        /// <summary>
        /// Do paypal express checkout
        /// </summary>
        /// <param name="paymentInfo">Payment info required for an order processing</param>
        /// <param name="orderGuid">Unique order identifier</param>
        /// <param name="processPaymentResult">Process payment result</param>
        public void DoExpressCheckout(PaymentInfo paymentInfo,
                                      Guid orderGuid, ProcessPaymentResult processPaymentResult)
        {
            InitSettings();
            TransactMode transactionMode = GetCurrentTransactionMode();

            DoExpressCheckoutPaymentReq         req     = new DoExpressCheckoutPaymentReq();
            DoExpressCheckoutPaymentRequestType request = new DoExpressCheckoutPaymentRequestType();

            req.DoExpressCheckoutPaymentRequest = request;
            request.Version = this.APIVersion;
            DoExpressCheckoutPaymentRequestDetailsType details = new DoExpressCheckoutPaymentRequestDetailsType();

            request.DoExpressCheckoutPaymentRequestDetails = details;
            if (transactionMode == TransactMode.Authorize)
            {
                details.PaymentAction = PaymentActionCodeType.Authorization;
            }
            else
            {
                details.PaymentAction = PaymentActionCodeType.Sale;
            }
            details.PaymentActionSpecified = true;
            details.Token   = paymentInfo.PaypalToken;
            details.PayerID = paymentInfo.PaypalPayerId;

            details.PaymentDetails = new PaymentDetailsType[1];
            PaymentDetailsType paymentDetails1 = new PaymentDetailsType();

            details.PaymentDetails[0]             = paymentDetails1;
            paymentDetails1.OrderTotal            = new BasicAmountType();
            paymentDetails1.OrderTotal.Value      = paymentInfo.OrderTotal.ToString("N", new CultureInfo("en-us"));
            paymentDetails1.OrderTotal.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve <ICurrencyService>().PrimaryStoreCurrency);
            paymentDetails1.Custom       = orderGuid.ToString();
            paymentDetails1.ButtonSource = "nopCommerceCart";

            DoExpressCheckoutPaymentResponseType response = service2.DoExpressCheckoutPayment(req);
            string error;

            if (!PaypalHelper.CheckSuccess(response, out error))
            {
                throw new NopException(error);
            }

            if (response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo != null &&
                response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0] != null)
            {
                processPaymentResult.AuthorizationTransactionId     = response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID;
                processPaymentResult.AuthorizationTransactionResult = response.Ack.ToString();

                if (transactionMode == TransactMode.Authorize)
                {
                    processPaymentResult.PaymentStatus = PaymentStatusEnum.Authorized;
                }
                else
                {
                    processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid;
                }
            }
            else
            {
                throw new NopException("response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo is null");
            }
        }
예제 #10
0
        /// <summary>
        /// Authorizes the payment
        /// </summary>
        /// <param name="paymentInfo">Payment info required for an order processing</param>
        /// <param name="customer">Customer</param>
        /// <param name="OrderGuid">Unique order identifier</param>
        /// <param name="processPaymentResult">Process payment result</param>
        /// <param name="authorizeOnly">A value indicating whether to authorize only; true - authorize; false - sale</param>
        protected void AuthorizeOrSale(PaymentInfo paymentInfo, Customer customer, Guid OrderGuid, ProcessPaymentResult processPaymentResult, bool authorizeOnly)
        {
            InitSettings();

            DoDirectPaymentReq req = new DoDirectPaymentReq();

            req.DoDirectPaymentRequest         = new DoDirectPaymentRequestType();
            req.DoDirectPaymentRequest.Version = this.APIVersion;
            DoDirectPaymentRequestDetailsType details = new DoDirectPaymentRequestDetailsType();

            req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = details;
            details.IPAddress = HttpContext.Current.Request.UserHostAddress;
            if (authorizeOnly)
            {
                details.PaymentAction = PaymentActionCodeType.Authorization;
            }
            else
            {
                details.PaymentAction = PaymentActionCodeType.Sale;
            }
            details.CreditCard = new CreditCardDetailsType();
            details.CreditCard.CreditCardNumber  = paymentInfo.CreditCardNumber;
            details.CreditCard.CreditCardType    = GetPaypalCreditCardType(paymentInfo.CreditCardType);
            details.CreditCard.ExpMonthSpecified = true;
            details.CreditCard.ExpMonth          = paymentInfo.CreditCardExpireMonth;
            details.CreditCard.ExpYearSpecified  = true;
            details.CreditCard.ExpYear           = paymentInfo.CreditCardExpireYear;
            details.CreditCard.CVV2 = paymentInfo.CreditCardCVV2;

            details.CreditCard.CardOwner = new PayerInfoType();
            details.CreditCard.CardOwner.PayerCountry = GetPaypalCountryCodeType(paymentInfo.BillingAddress.Country);

            details.CreditCard.CardOwner.Address = new AddressType();
            details.CreditCard.CardOwner.Address.CountrySpecified = true;
            details.CreditCard.CardOwner.Address.Street1          = paymentInfo.BillingAddress.Address1;
            details.CreditCard.CardOwner.Address.Street2          = paymentInfo.BillingAddress.Address2;
            details.CreditCard.CardOwner.Address.CityName         = paymentInfo.BillingAddress.City;
            if (paymentInfo.BillingAddress.StateProvince != null)
            {
                details.CreditCard.CardOwner.Address.StateOrProvince = paymentInfo.BillingAddress.StateProvince.Abbreviation;
            }
            details.CreditCard.CardOwner.Address.Country     = GetPaypalCountryCodeType(paymentInfo.BillingAddress.Country);
            details.CreditCard.CardOwner.Address.PostalCode  = paymentInfo.BillingAddress.ZipPostalCode;
            details.CreditCard.CardOwner.PayerName           = new PersonNameType();
            details.CreditCard.CardOwner.PayerName.FirstName = paymentInfo.BillingAddress.FirstName;
            details.CreditCard.CardOwner.PayerName.LastName  = paymentInfo.BillingAddress.LastName;
            details.PaymentDetails                       = new PaymentDetailsType();
            details.PaymentDetails.OrderTotal            = new BasicAmountType();
            details.PaymentDetails.OrderTotal.Value      = paymentInfo.OrderTotal.ToString("N", new CultureInfo("en-us"));
            details.PaymentDetails.OrderTotal.currencyID = PaypalHelper.GetPaypalCurrency(CurrencyManager.PrimaryStoreCurrency);
            details.PaymentDetails.Custom                = OrderGuid.ToString();
            details.PaymentDetails.ButtonSource          = "nopCommerceCart";

            DoDirectPaymentResponseType response = service2.DoDirectPayment(req);

            string error   = string.Empty;
            bool   Success = PaypalHelper.CheckSuccess(response, out error);

            if (Success)
            {
                processPaymentResult.AuthorizationTransactionID     = response.TransactionID;
                processPaymentResult.AuthorizationTransactionResult = response.Ack.ToString();

                //TODO save AVSCode and CVVCode in datatabase
                processPaymentResult.AVSResult = response.AVSCode;
                processPaymentResult.AuthorizationTransactionCode = response.CVV2Code;
                if (authorizeOnly)
                {
                    processPaymentResult.PaymentStatus = PaymentStatusEnum.Authorized;
                }
                else
                {
                    processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid;
                }
                //processPaymentResult.AuthorizationDate = response.Timestamp;
                //processPaymentResult.AuthorizationDate = DateTime.Now;
            }
            else
            {
                processPaymentResult.Error     = error;
                processPaymentResult.FullError = error;
            }
        }