예제 #1
0
        public ActionResult PaymentDetails(string token)
        {
            if (token.IsNullOrWhiteSpace())
            {
                return(RedirectToAction("PayPalCancel"));
            }
            GetExpressCheckoutDetailsReq          req         = PayPalHelper.GetGetExpressCheckoutDetailsReq(token);
            CustomSecurityHeaderType              credentials = PayPalHelper.GetPayPalCredentials();
            PayPalAPIAAInterfaceClient            client      = new PayPalAPIAAInterfaceClient();
            GetExpressCheckoutDetailsResponseType response    = client.GetExpressCheckoutDetails(ref credentials, req);

            if (response.Errors != null && response.Errors.Length > 0)
            {
                throw new Exception("Exception occured when calling PayPal: " + response.Errors[0].LongMessage);
            }
            GetExpressCheckoutDetailsResponseDetailsType respDetails = response.GetExpressCheckoutDetailsResponseDetails;
            Order order = PayPalHelper.UpdateOrderAfterAuthentication(respDetails.Custom, respDetails.PayerInfo.PayerID);
            var   model = new PaymentModel
            {
                Order     = order,
                BuyerName = respDetails.PayerInfo.PayerName.FirstName + respDetails.PayerInfo.PayerName.LastName
            };

            Session["CheckoutDetails"] = response;
            return(View("PaymentDetails", model));
        }
예제 #2
0
파일: PayPal.cs 프로젝트: TheScripters/kpfw
 public static PayerInfoType GetExpressCheckout(string token)
 {
     System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
     using (var client = new PayPalAPIAAInterfaceClient(new BasicHttpsBinding(), new EndpointAddress(EndpointUrl)))
     {
         var credentials = new CustomSecurityHeaderType()
         {
             Credentials = new UserIdPasswordType()
             {
                 Username  = APIUserName,
                 Password  = APIPassword,
                 Signature = APISignature
             }
         };
         GetExpressCheckoutDetailsReq req = new GetExpressCheckoutDetailsReq()
         {
             GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType()
             {
                 Version = "121.0",
                 Token   = token
             }
         };
         var    resp   = client.GetExpressCheckoutDetails(ref credentials, req);
         string errors = CheckErrors(resp);
         if (errors == String.Empty)
         {
             return(resp.GetExpressCheckoutDetailsResponseDetails.PayerInfo);
         }
         return(new PayerInfoType()
         {
             PayerID = errors
         });
     }
 }
        private PayerInfo GetPayerInfo(string token, string payerId)
        {
            var payer   = new PayerInfo();
            var req     = new GetExpressCheckoutDetailsReq();
            var request = new GetExpressCheckoutDetailsRequestType();

            req.GetExpressCheckoutDetailsRequest = request;
            request.Token   = token;
            request.Version = Settings.Version;
            // System.Net.ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            var credentials = PaypalSecurityHeader();
            GetExpressCheckoutDetailsResponseType response = _paypalService2.GetExpressCheckoutDetails(ref credentials, req);

            if (response.Ack == AckCodeType.Success)
            {
                try
                {
                    payer.Email = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
                }
                catch (Exception)
                {
                    payer.Email = "";
                }

                payer.FirstName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.FirstName;
                payer.LastName  = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.LastName;

                if (response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerStatusSpecified == true)
                {
                    if (response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerStatus == PayPalUserStatusCodeType.verified)
                    {
                        payer.IsVerify = true;
                    }
                    payer.AccountVerifyCode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerStatus.ToString();
                }


                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.PostCode    = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
                payer.PhoneNo     = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.ContactPhone;
                payer.Country     = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountryName;
                payer.CountryCode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
                payer.PayerId     = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
                payer.Token       = response.GetExpressCheckoutDetailsResponseDetails.Token;

                //if (response.GetExpressCheckoutDetailsResponseDetails.Note > "")
                //{
                //    payer.note = payer.note + response.GetExpressCheckoutDetailsResponseDetails.Note;
                //}
                //payer.OrderTotal = response.GetExpressCheckoutDetailsResponseDetails.PaymentDetails(0).OrderTotal.Value;
                //payer.IsValid = true;
                if (response.GetExpressCheckoutDetailsResponseDetails.BillingAddress == null)
                {
                    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.PostCode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
                    payer.Country  = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountryName;

                    if (response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.AddressStatusSpecified == true)
                    {
                        if (response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.AddressStatus == AddressStatusCodeType.Confirmed)
                        {
                            payer.IsValidAddress = true;
                        }
                        payer.AddressVerifyCode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.AddressStatus.ToString();
                    }
                }
                else
                {
                    payer.Address1 = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.Street1;
                    payer.Address2 = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.Street2;
                    payer.City     = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.CityName;
                    payer.State    = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.StateOrProvince;
                    payer.PostCode = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.PostalCode;
                    payer.Country  = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.CountryName;
                    if (response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.AddressStatusSpecified == true)
                    {
                        if (response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.AddressStatus == AddressStatusCodeType.Confirmed)
                        {
                            payer.IsValidAddress = true;
                        }
                        payer.AddressVerifyCode = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.AddressStatus.ToString();
                    }
                }

                //Shipping addd-----------------------------

                if (response.GetExpressCheckoutDetailsResponseDetails.PayerInfo == null)
                {
                    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.PostCode    = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
                    payer.CountryCode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
                }
            }
            return(payer);
        }