Ejemplo n.º 1
0
        public static void GetPaypalRequirements(out PayPalAPISoapBinding IPayPalRefund, out PayPalAPIAASoapBinding IPayPal)
        {
            IPayPal       = new PayPalAPIAASoapBinding();
            IPayPalRefund = new PayPalAPISoapBinding();

            if (AppLogic.AppConfigBool("UseLiveTransactions"))
            {
                IPayPal.Url = AppLogic.AppConfig("PayPal.API.LiveURL");
            }
            else
            {
                IPayPal.Url = AppLogic.AppConfig("PayPal.API.TestURL");
            }
            IPayPalRefund.Url = IPayPal.Url;

            IPayPal.UserAgent       = HttpContext.Current.Request.UserAgent;
            IPayPalRefund.UserAgent = IPayPal.UserAgent;

            UserIdPasswordType PayPalUser = new UserIdPasswordType();

            if (PayPalController.GetAppropriateExpressType() == ExpressAPIType.PayPalAcceleratedBording)
            {
                PayPalUser.Subject = AppLogic.AppConfig("PayPal.API.AcceleratedBoardingEmailAddress");
            }
            else
            {
                PayPalUser.Username  = AppLogic.AppConfig("PayPal.API.Username");
                PayPalUser.Password  = AppLogic.AppConfig("PayPal.API.Password");
                PayPalUser.Signature = AppLogic.AppConfig("PayPal.API.Signature");

                //Subject should be the Sellers e-mail address (if you are using 3-part API calls) with the correct account permissions. You also have
                //set up permissions for this e-mail address for the "type" of transaction you want to allow.
                //This access changes are made in the Sandbox.
                //The name of the entity on behalf of which this profile is issuing calls
                //This is for Third-Party access
                // You have to set up Virtual Terminals and complete the Billing Agreement in the Sandbox before you can make Direct Payments
                PayPalUser.Subject = AppLogic.AppConfig("PayPal.API.MerchantEMailAddress");
            }



            CustomSecurityHeaderType CSecHeaderType = new CustomSecurityHeaderType();

            CSecHeaderType.Credentials    = PayPalUser;
            CSecHeaderType.MustUnderstand = true;

            IPayPal.RequesterCredentials       = CSecHeaderType;
            IPayPalRefund.RequesterCredentials = CSecHeaderType;
        }
Ejemplo n.º 2
0
        public static CustomSecurityHeaderType GetPayPalCredentials()
        {
            UserIdPasswordType credentials = new UserIdPasswordType()
            {
                Username  = ConfigurationManager.AppSettings["PayPalAPIUsername"],
                Password  = ConfigurationManager.AppSettings["PayPalAPIPassword"],
                Signature = ConfigurationManager.AppSettings["PayPalAPISignature"],
            };

            CustomSecurityHeaderType header = new CustomSecurityHeaderType()
            {
                Credentials = credentials
            };

            return(header);
        }
        public PayPalManager()
        {
            UserIdPasswordType user = new UserIdPasswordType();

            //set api credentials
            user.Username = ConfigurationManager.AppSettings["PayPalAPIUsername"];              //set this to your API username
            user.Password = ConfigurationManager.AppSettings["PayPalAPIPassword"];              //set this to your API password

            //set this to the path of your .p12 file (api certificate) on the filesystem
            //String certlocation = @"C:\VS2005 Web Projects\LittleItalyVineyards\Class Libraries\LittleItalyVineyard.Operational\Certs\LittleItalyVineyards.p12";

            PPInterface.Url = ConfigurationManager.AppSettings["PayPalAPIURL"];

            PPInterface.RequesterCredentials             = new CustomSecurityHeaderType();
            PPInterface.RequesterCredentials.Credentials = new UserIdPasswordType();
            PPInterface.RequesterCredentials.Credentials = user;

            //service.Url = ConfigurationManager.AppSettings["PayPalAPIURL"];

            //service.RequesterCredentials = new CustomSecurityHeaderType();
            //service.RequesterCredentials.Credentials = new UserIdPasswordType();
            //service.RequesterCredentials.Credentials = user;


            //this is .NET 2.0 specific portion of the code that
            //allows us to have the .p12 on the filesystem and
            //not have to register it with WinHttpCertCfg
            //uses X509Certificate2 class.
            FileStream fstream = File.Open(CertPath, FileMode.Open, FileAccess.Read);

            byte[] buffer = new byte[fstream.Length];

            int count = fstream.Read(buffer, 0, buffer.Length);

            fstream.Close();

            //use .NET 2.0  X509Certificate2 class to read .p12 from filesystem
            // where "12345678" is the private key password

            X509Certificate2 cert = new X509Certificate2(buffer, CertPassword);

            PPInterface.ClientCertificates.Add(cert);
        }
Ejemplo n.º 4
0
        public static PayPalAPIAASoapBinding BuildPayPalWebservice()
        {
            // more details on https://www.paypal.com/en_US/ebook/PP_APIReference/architecture.html
            UserIdPasswordType credentials = new UserIdPasswordType()
            {
                Username  = ConfigurationManager.AppSettings["APIUsername"],
                Password  = ConfigurationManager.AppSettings["APIPassword"],
                Signature = ConfigurationManager.AppSettings["APISignature"],
            };

            PayPalAPIAASoapBinding paypal = new PayPalAPIAASoapBinding();

            paypal.RequesterCredentials = new CustomSecurityHeaderType()
            {
                Credentials = credentials
            };

            return(paypal);
        }
Ejemplo n.º 5
0
        public TransactionResult SubmitPaymentTransaction(CheckoutDetails details)
        {
            //init result structure
            TransactionResult ret = new TransactionResult();

            //set up Request
            //instantiate DoDirectPaymentRequestType and RequestDetails objects
            DoDirectPaymentRequestType request = new DoDirectPaymentRequestType();

            request.Version = PROCESSOR_VERSION;
            DoDirectPaymentRequestDetailsType requestDetails = new DoDirectPaymentRequestDetailsType();

            request.DoDirectPaymentRequestDetails = requestDetails;

            //set payment action
            requestDetails.PaymentAction = PaymentActionCodeType.Sale;

            //set IP
            //requestDetails.IPAddress = Request.UserHostAddress;
            requestDetails.IPAddress = details[CheckoutKeys.IPAddress];

            //set CreditCard info
            CreditCardDetailsType creditCardDetails = new CreditCardDetailsType();

            requestDetails.CreditCard          = creditCardDetails;
            creditCardDetails.CreditCardNumber = details[CheckoutKeys.CardNumber];
            creditCardDetails.CreditCardType   = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), details[CheckoutKeys.CardType], true);
            creditCardDetails.CVV2             = details[CheckoutKeys.VerificationCode];
            creditCardDetails.ExpMonth         = Int32.Parse(details[CheckoutKeys.ExpireMonth]);
            creditCardDetails.ExpYear          = Int32.Parse(details[CheckoutKeys.ExpireYear]);
            // Switch/Solo
            if (creditCardDetails.CreditCardType == CreditCardTypeType.Solo ||
                creditCardDetails.CreditCardType == CreditCardTypeType.Switch)
            {
                creditCardDetails.StartMonth  = Int32.Parse(details[CheckoutKeys.StartMonth]);
                creditCardDetails.StartYear   = Int32.Parse(details[CheckoutKeys.StartYear]);
                creditCardDetails.IssueNumber = details[CheckoutKeys.IssueNumber];
            }

            //set billing address
            PayerInfoType cardOwner = new PayerInfoType();

            creditCardDetails.CardOwner   = cardOwner;
            cardOwner.PayerName           = new PersonNameType();
            cardOwner.PayerName.FirstName = details[CheckoutKeys.FirstName];
            cardOwner.PayerName.LastName  = details[CheckoutKeys.LastName];

            cardOwner.Address         = new AddressType();
            cardOwner.Address.Street1 = details[CheckoutKeys.Address];
            //??? cardOwner.Address.Street2 = "";
            cardOwner.Address.CityName         = details[CheckoutKeys.City];
            cardOwner.Address.StateOrProvince  = details[CheckoutKeys.State];
            cardOwner.Address.PostalCode       = details[CheckoutKeys.Zip];
            cardOwner.Address.CountrySpecified = true;
            cardOwner.Address.Country          = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), details[CheckoutKeys.Country], true);

            //set payment Details
            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            requestDetails.PaymentDetails = paymentDetails;
            paymentDetails.OrderTotal     = new BasicAmountType();
            //TODO: Add currency support
            paymentDetails.OrderTotal.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), details[CheckoutKeys.Currency]);
            //paymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD;
            //No currency symbol. Decimal separator must be a period (.), and the thousands separator must be a comma (,)
            paymentDetails.OrderTotal.Value = details[CheckoutKeys.Amount];

            DoDirectPaymentReq paymentRequest = new DoDirectPaymentReq();

            paymentRequest.DoDirectPaymentRequest = request;

            //FINISH set up req
            //setup request Header, API credentials
            PayPalAPIAASoapBinding paypalInterface = new PayPalAPIAASoapBinding();
            UserIdPasswordType     user            = new UserIdPasswordType();

            //set api credentials - username, password, signature
            user.Username  = Username;
            user.Password  = Password;
            user.Signature = Signature;
            // setup service url
            paypalInterface.Url = ServiceUrl;
            paypalInterface.RequesterCredentials             = new CustomSecurityHeaderType();
            paypalInterface.RequesterCredentials.Credentials = user;

            //make call return response
            DoDirectPaymentResponseType paymentResponse = new DoDirectPaymentResponseType();

            paymentResponse = paypalInterface.DoDirectPayment(paymentRequest);
            //write response xml to the ret object
            ret.RawResponse = SerializeObject(paymentResponse);

            switch (paymentResponse.Ack)
            {
            case AckCodeType.Success:
            case AckCodeType.SuccessWithWarning:
                ret.Succeed           = true;
                ret.TransactionId     = paymentResponse.TransactionID;
                ret.TransactionStatus = TransactionStatus.Approved;
                break;

            default:                     // show errors if Ack is NOT Success
                ret.Succeed           = false;
                ret.TransactionStatus = TransactionStatus.Declined;
                if (paymentResponse.Errors != null &&
                    paymentResponse.Errors.Length > 0)
                {
                    ret.StatusCode = PayPalProKeys.ErrorPrefix + paymentResponse.Errors[0].ErrorCode;
                }
                break;
            }
            return(ret);
        }