Ejemplo n.º 1
0
        public SetExpressCheckoutResponseType SetExpressCheckout(string paymentAmount, string returnURL, string cancelURL, PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType, String name, String countryISOCode, String street1, String street2, String city, String region, String postalCode, String phone, string invoiceId)
        {
            // Create the request object
            SetExpressCheckoutRequestType pp_request = new SetExpressCheckoutRequestType();

            // Create the request details object
            pp_request.SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
            pp_request.SetExpressCheckoutRequestDetails.PaymentAction = paymentAction;
            pp_request.SetExpressCheckoutRequestDetails.PaymentActionSpecified = true;

            pp_request.SetExpressCheckoutRequestDetails.AddressOverride = "1";
            pp_request.SetExpressCheckoutRequestDetails.InvoiceID = invoiceId;

            pp_request.SetExpressCheckoutRequestDetails.OrderTotal = new BasicAmountType();

            pp_request.SetExpressCheckoutRequestDetails.OrderTotal.currencyID = currencyCodeType;
            pp_request.SetExpressCheckoutRequestDetails.OrderTotal.Value = paymentAmount;

            pp_request.SetExpressCheckoutRequestDetails.CancelURL = cancelURL;
            pp_request.SetExpressCheckoutRequestDetails.ReturnURL = returnURL;
            
            pp_request.SetExpressCheckoutRequestDetails.Address = new AddressType();            
            pp_request.SetExpressCheckoutRequestDetails.Address.AddressStatusSpecified = false;
            pp_request.SetExpressCheckoutRequestDetails.Address.AddressOwnerSpecified = false;

            pp_request.SetExpressCheckoutRequestDetails.Address.Street1 = street1;
            pp_request.SetExpressCheckoutRequestDetails.Address.Street2 = street2;
            pp_request.SetExpressCheckoutRequestDetails.Address.CityName = city;
            pp_request.SetExpressCheckoutRequestDetails.Address.StateOrProvince = region;
            pp_request.SetExpressCheckoutRequestDetails.Address.PostalCode = postalCode;
            pp_request.SetExpressCheckoutRequestDetails.Address.CountrySpecified = true;
            pp_request.SetExpressCheckoutRequestDetails.Address.Country = GetCountryCode(countryISOCode);                        
            pp_request.SetExpressCheckoutRequestDetails.Address.Phone = phone;
            pp_request.SetExpressCheckoutRequestDetails.Address.Name = name;                        
            return (SetExpressCheckoutResponseType)caller.Call("SetExpressCheckout", pp_request);
        }
Ejemplo n.º 2
0
        public SetExpressCheckoutResponseType SetExpressCheckout(string paymentAmount, string returnURL, string cancelURL, PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType, string invoiceId)
        {
            // Create the request object
            SetExpressCheckoutRequestType pp_request = new SetExpressCheckoutRequestType();

            // Create the request details object
            pp_request.SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
            pp_request.SetExpressCheckoutRequestDetails.PaymentAction = paymentAction;
            pp_request.SetExpressCheckoutRequestDetails.PaymentActionSpecified = true;
            pp_request.SetExpressCheckoutRequestDetails.InvoiceID = invoiceId;
            pp_request.SetExpressCheckoutRequestDetails.OrderTotal = new BasicAmountType();

            pp_request.SetExpressCheckoutRequestDetails.OrderTotal.currencyID = currencyCodeType;
            pp_request.SetExpressCheckoutRequestDetails.OrderTotal.Value = paymentAmount;            

            pp_request.SetExpressCheckoutRequestDetails.CancelURL = cancelURL;
            pp_request.SetExpressCheckoutRequestDetails.ReturnURL = returnURL;

            return (SetExpressCheckoutResponseType)caller.Call("SetExpressCheckout", pp_request);
        }
Ejemplo n.º 3
0
        protected SetExpressCheckoutResponseType ECSetExpressCheckoutCode(string paymentAmount, string returnURL, string cancelURL,
            PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType)
        {
            CallerServices caller = CreateCaller();

            var pp_request = new SetExpressCheckoutRequestType()
            {
                Version = "51.0",
                SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType()
                {
                    PaymentAction = paymentAction,
                    PaymentActionSpecified = true,
                    OrderTotal = new BasicAmountType()
                    {
                        currencyID = currencyCodeType,
                        Value = paymentAmount
                    },
                    CancelURL = cancelURL,
                    ReturnURL = returnURL,
                }
            };

            return (SetExpressCheckoutResponseType)caller.Call("SetExpressCheckout", pp_request);
        }
        /// <summary>
        /// Performs the setup for an express checkout.
        /// </summary>
        /// <param name="invoice">
        /// The <see cref="IInvoice"/>.
        /// </param>
        /// <param name="payment">
        /// The <see cref="IPayment"/>
        /// </param>
        /// <param name="returnUrl">
        /// The return URL.
        /// </param>
        /// <param name="cancelUrl">
        /// The cancel URL.
        /// </param>
        /// <returns>
        /// The <see cref="ExpressCheckoutResponse"/>.
        /// </returns>
        protected virtual PayPalExpressTransactionRecord SetExpressCheckout(IInvoice invoice, IPayment payment, string returnUrl, string cancelUrl)
        {
            var record = new PayPalExpressTransactionRecord
                             {
                                 Success = true,
                                 Data = { Authorized = false, CurrencyCode = invoice.CurrencyCode }
                             };

            var factory = new PayPalPaymentDetailsTypeFactory(new PayPalFactorySettings { WebsiteUrl = _websiteUrl });
            var paymentDetailsType = factory.Build(invoice, PaymentActionCodeType.ORDER);

            // The API requires this be in a list
            var paymentDetailsList = new List<PaymentDetailsType>() { paymentDetailsType };

            // ExpressCheckout details
            //// We do not want the customer to be able to reset their shipping address at PayPal
            //// due to the fact that it could affect shipping charges and in some cases tax rates.
            //// This is the AddressOverride = "0" - NOT WORKING!
            var ecDetails = new SetExpressCheckoutRequestDetailsType()
                    {
                        ReturnURL = returnUrl,
                        CancelURL = cancelUrl,
                        PaymentDetails = paymentDetailsList,
                        AddressOverride = "0"
                    };

            // Trigger the event to allow for overriding ecDetails
            var ecdOverride = new PayPalExpressCheckoutRequestDetailsOverride(invoice, payment, ecDetails);
            SettingCheckoutRequestDetails.RaiseEvent(new ObjectEventArgs<PayPalExpressCheckoutRequestDetailsOverride>(ecdOverride), this);

            // The ExpressCheckoutRequest
            var request = new SetExpressCheckoutRequestType
                    {
                        Version = Version,
                        SetExpressCheckoutRequestDetails = ecdOverride.ExpressCheckoutDetails
                    };

            // Crete the wrapper for Express Checkout
            var wrapper = new SetExpressCheckoutReq
                              {
                                  SetExpressCheckoutRequest = request
                              };

            try
            {
                var service = GetPayPalService();
                var response = service.SetExpressCheckout(wrapper);
                record.SetExpressCheckout = _responseFactory.Build(response, response.Token);
                record.Data.Token = response.Token;
                record.SetExpressCheckout.RedirectUrl = GetRedirectUrl(response.Token);
            }
            catch (Exception ex)
            {
                record.Success = false;
                record.SetExpressCheckout = _responseFactory.Build(ex);
            }

            return record;
        }
        /// <summary>
        /// Performs the setup for an express checkout.
        /// </summary>
        /// <param name="invoice">
        /// The <see cref="IInvoice"/>.
        /// </param>
        /// <param name="payment">
        /// The <see cref="IPayment"/>
        /// </param>
        /// <param name="returnUrl">
        /// The return URL.
        /// </param>
        /// <param name="cancelUrl">
        /// The cancel URL.
        /// </param>
        /// <returns>
        /// The <see cref="ExpressCheckoutResponse"/>.
        /// </returns>
        protected virtual PayPalExpressTransactionRecord SetExpressCheckout(IInvoice invoice, IPayment payment, string returnUrl, string cancelUrl)
        {
            var record = new PayPalExpressTransactionRecord
                             {
                                 Success = true,
                                 Data = { Authorized = false, CurrencyCode = invoice.CurrencyCode }
                             };

            var factory = new PayPalPaymentDetailsTypeFactory(new PayPalFactorySettings { WebsiteUrl = _websiteUrl });
            var paymentDetailsType = factory.Build(invoice, PaymentActionCodeType.ORDER);

            // The API requires this be in a list
            var paymentDetailsList = new List<PaymentDetailsType>() { paymentDetailsType };

            // ExpressCheckout details
            var ecDetails = new SetExpressCheckoutRequestDetailsType()
                    {
                        ReturnURL = returnUrl,
                        CancelURL = cancelUrl,
                        PaymentDetails = paymentDetailsList,
                        AddressOverride = "0"
                    };

            // Trigger the event to allow for overriding ecDetails
            var ecdOverride = new PayPalExpressCheckoutRequestDetailsOverride(invoice, payment, ecDetails);
            SettingCheckoutRequestDetails.RaiseEvent(new ObjectEventArgs<PayPalExpressCheckoutRequestDetailsOverride>(ecdOverride), this);

            // The ExpressCheckoutRequest
            var request = new SetExpressCheckoutRequestType
                    {
                        Version = Version,
                        SetExpressCheckoutRequestDetails = ecdOverride.ExpressCheckoutDetails
                    };

            // Crete the wrapper for Express Checkout
            var wrapper = new SetExpressCheckoutReq
                              {
                                  SetExpressCheckoutRequest = request
                              };

            try
            {
                var service = GetPayPalService();
                var response = service.SetExpressCheckout(wrapper);

                record.SetExpressCheckout = _responseFactory.Build(response, response.Token);
                if (record.SetExpressCheckout.Success())
                {
                    record.Data.Token = response.Token;
                    record.SetExpressCheckout.RedirectUrl = GetRedirectUrl(response.Token);
                }
                else
                {
                    foreach (var et in record.SetExpressCheckout.ErrorTypes)
                    {
                        var code = et.ErrorCode;
                        var sm = et.ShortMessage;
                        var lm = et.LongMessage;
                        MultiLogHelper.Warn<PayPalExpressCheckoutService>(string.Format("{0} {1} {2}", code, lm, sm));
                    }

                    record.Success = false;
                }
            }
            catch (Exception ex)
            {
                record.Success = false;
                record.SetExpressCheckout = _responseFactory.Build(ex);
            }

            return record;
        }