Пример #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
        protected void Submit_Click(object sender, EventArgs e)
        {
            PayPalAPIInterfaceServiceService service      = new PayPalAPIInterfaceServiceService();
            GetExpressCheckoutDetailsReq     getECWrapper = new GetExpressCheckoutDetailsReq();

            getECWrapper.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token.Value);
            GetExpressCheckoutDetailsResponseType getECResponse = service.GetExpressCheckoutDetails(getECWrapper);

            // Create request object
            DoExpressCheckoutPaymentRequestType        request        = new DoExpressCheckoutPaymentRequestType();
            DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();

            request.DoExpressCheckoutPaymentRequestDetails = requestDetails;

            requestDetails.PaymentDetails = getECResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
            requestDetails.Token          = token.Value;
            requestDetails.PayerID        = payerId.Value;
            requestDetails.PaymentAction  = (PaymentActionCodeType)
                                            Enum.Parse(typeof(PaymentActionCodeType), paymentAction.SelectedValue);

            // Invoke the API
            DoExpressCheckoutPaymentReq wrapper = new DoExpressCheckoutPaymentReq();

            wrapper.DoExpressCheckoutPaymentRequest = request;
            DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, doECResponse);
        }
Пример #3
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Create request object
            GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();

            // (Required) A timestamped token, the value of which was returned by SetExpressCheckout response.
            // Character length and limitations: 20 single-byte characters
            request.Token = token.Value;

            // Invoke the API
            GetExpressCheckoutDetailsReq wrapper = new GetExpressCheckoutDetailsReq();

            wrapper.GetExpressCheckoutDetailsRequest = request;

            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]
            Dictionary <string, string> configurationMap = Configuration.GetAcctAndConfig();

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

            // # API call
            // Invoke the GetExpressCheckoutDetails method in service wrapper object
            GetExpressCheckoutDetailsResponseType ecResponse = service.GetExpressCheckoutDetails(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, ecResponse);
        }
Пример #4
0
        public PaymentInfo GetPaymentInfo(FinancialGateway financialGateway, String token, out string errorMessage)
        {
            errorMessage = string.Empty;
            GetExpressCheckoutDetailsResponseType response = GetExpressCheckoutDetailsResponse(financialGateway, token, out errorMessage);

            if (response == null)
            {
                return(null);
            }

            var details                   = response.GetExpressCheckoutDetailsResponseDetails;
            var paymentDetails            = details.PaymentDetails.FirstOrDefault();
            PayPalPaymentInfo paymentInfo = new PayPalPaymentInfo();

            paymentInfo.Amount     = paymentDetails.OrderTotal.value.AsDecimal();
            paymentInfo.Token      = token;
            paymentInfo.PayerId    = details.PayerInfo.PayerID;
            paymentInfo.City       = details.PayerInfo.Address.CityName;
            paymentInfo.State      = details.PayerInfo.Address.StateOrProvince;
            paymentInfo.Street1    = details.PayerInfo.Address.Street1;
            paymentInfo.Street2    = details.PayerInfo.Address.Street2;
            paymentInfo.PostalCode = details.PayerInfo.Address.PostalCode;
            paymentInfo.Country    = details.PayerInfo.Address.CountryName;
            paymentInfo.Phone      = details.PayerInfo.ContactPhone;
            paymentInfo.Email      = details.PayerInfo.Payer;
            paymentInfo.FirstName  = details.PayerInfo.PayerName.FirstName;
            paymentInfo.LastName   = details.PayerInfo.PayerName.LastName;
            return(paymentInfo);
        }
Пример #5
0
        // A helper method used by APIResponse.aspx that returns select response parameters
        // of interest.
        private void setKeyResponseObjects(PayPalAPIInterfaceServiceService service, GetExpressCheckoutDetailsResponseType response)
        {
            HttpContext CurrContext = HttpContext.Current;

            CurrContext.Items.Add("Response_apiName", "GetExpressChecoutDetails");
            CurrContext.Items.Add("Response_redirectURL", null);
            CurrContext.Items.Add("Response_requestPayload", service.getLastRequest());
            CurrContext.Items.Add("Response_responsePayload", service.getLastResponse());

            Dictionary <string, string> keyResponseParameters = new Dictionary <string, string>();

            keyResponseParameters.Add("Correlation Id", response.CorrelationID);
            keyResponseParameters.Add("API Result", response.Ack.ToString());

            if (response.Ack.Equals(AckCodeType.FAILURE) ||
                (response.Errors != null && response.Errors.Count > 0))
            {
                CurrContext.Items.Add("Response_error", response.Errors);
            }
            else
            {
                CurrContext.Items.Add("Response_error", null);
            }
            CurrContext.Items.Add("Response_keyResponseObject", keyResponseParameters);
            Server.Transfer("../APIResponse.aspx");
        }
    // # GetExpressCheckout API Operation
    // The GetExpressCheckoutDetails API operation obtains information about an Express Checkout transaction
    public GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetailsAPIOperation()
    {
        // Create the GetExpressCheckoutDetailsResponseType object
        GetExpressCheckoutDetailsResponseType responseGetExpressCheckoutDetailsResponseType = new GetExpressCheckoutDetailsResponseType();

        try
        {
            // Create the GetExpressCheckoutDetailsReq object
            GetExpressCheckoutDetailsReq getExpressCheckoutDetails = new GetExpressCheckoutDetailsReq();

            // A timestamped token, the value of which was returned by `SetExpressCheckout` response
            GetExpressCheckoutDetailsRequestType getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType("EC-11U13522TP7143059");
            getExpressCheckoutDetails.GetExpressCheckoutDetailsRequest = getExpressCheckoutDetailsRequest;

            // Create the service wrapper object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();

            // # API call
            // Invoke the GetExpressCheckoutDetails method in service wrapper object
            responseGetExpressCheckoutDetailsResponseType = service.GetExpressCheckoutDetails(getExpressCheckoutDetails);

            if (responseGetExpressCheckoutDetailsResponseType != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "GetExpressCheckoutDetails API Operation - ";
                acknowledgement += responseGetExpressCheckoutDetailsResponseType.Ack.ToString();
                logger.Info(acknowledgement + "\n");
                Console.WriteLine(acknowledgement + "\n");

                // # Success values
                if (responseGetExpressCheckoutDetailsResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // Unique PayPal Customer Account identification number. This
                    // value will be null unless you authorize the payment by
                    // redirecting to PayPal after `SetExpressCheckout` call.
                    logger.Info("Payer ID : " + responseGetExpressCheckoutDetailsResponseType.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID + "\n");
                    Console.WriteLine("Payer ID : " + responseGetExpressCheckoutDetailsResponseType.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID + "\n");
                }
                // # Error Values
                else
                {
                    List <ErrorType> errorMessages = responseGetExpressCheckoutDetailsResponseType.Errors;
                    foreach (ErrorType error in errorMessages)
                    {
                        logger.Debug("API Error Message : " + error.LongMessage);
                        Console.WriteLine("API Error Message : " + error.LongMessage + "\n");
                    }
                }
            }
        }
        // # Exception log
        catch (System.Exception ex)
        {
            // Log the exception message
            logger.Debug("Error Message : " + ex.Message);
            Console.WriteLine("Error Message : " + ex.Message);
        }
        return(responseGetExpressCheckoutDetailsResponseType);
    }
Пример #7
0
        private void DisplayPaypalExpressMode(CheckoutViewModel model)
        {
            model.PayPalToken   = Request.QueryString["token"] ?? string.Empty;
            model.PayPalPayerId = Request.QueryString["payerId"] ?? string.Empty;

            if (string.IsNullOrEmpty(model.PayPalToken))
            {
                Response.Redirect("~/cart");
            }


            PayPalAPI ppAPI  = MerchantTribe.Commerce.Utilities.PaypalExpressUtilities.GetPaypalAPI(this.MTApp.CurrentStore);
            bool      failed = false;
            GetExpressCheckoutDetailsResponseType ppResponse = null;

            try
            {
                if (!GetExpressCheckoutDetails(ppAPI, ref ppResponse, model))
                {
                    failed = true;
                    EventLog.LogEvent("Paypal Express Checkout", "GetExpressCheckoutDetails call failed. Detailed Errors will follow. ", EventLogSeverity.Error);
                    foreach (ErrorType ppError in ppResponse.Errors)
                    {
                        EventLog.LogEvent("Paypal error number: " + ppError.ErrorCode, "Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage + "' " + " Values passed to GetExpressCheckoutDetails: Token: " + model.PayPalToken, EventLogSeverity.Error);
                    }
                    this.FlashFailure("An error occurred during the Paypal Express checkout. No charges have been made. Please try again.");
                    ViewBag.HideCheckout = true;
                }
            }
            finally
            {
                Order o = model.CurrentOrder;
                ViewBag.HideEditButton = false;
                if (o.CustomProperties["PaypalAddressOverride"] != null)
                {
                    if (o.CustomProperties["PaypalAddressOverride"].Value == "1")
                    {
                        ViewBag.HideEditButton = true;
                    }
                }

                o.CustomProperties.Add("bvsoftware", "PayerID", Request.QueryString["PayerID"]);
                if (!failed)
                {
                    if (ppResponse != null && ppResponse.GetExpressCheckoutDetailsResponseDetails != null && ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo != null)
                    {
                        o.UserEmail = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
                        if (string.IsNullOrEmpty(o.ShippingAddress.Phone))
                        {
                            o.ShippingAddress.Phone = ppResponse.GetExpressCheckoutDetailsResponseDetails.ContactPhone ?? string.Empty;
                        }
                    }
                }
                MTApp.OrderServices.Orders.Update(o);
                ppAPI = null;
            }
        }
Пример #8
0
    public void GetExpressCheckoutDetails()
    {
        GetExpressCheckoutDetailsSample       sample = new GetExpressCheckoutDetailsSample();
        GetExpressCheckoutDetailsResponseType responseGetExpressCheckoutDetailsResponseType = sample.GetExpressCheckoutDetailsAPIOperation();

        Assert.IsNotNull(responseGetExpressCheckoutDetailsResponseType);
        // Please change the sample inputs according to the documentation in the sample for the following assertion:
        // Assert.AreEqual(responseGetExpressCheckoutDetailsResponseType.Ack.ToString().ToUpper(), "SUCCESS");
    }
Пример #9
0
 public static PayPalConfirmResponse ToResponse(this GetExpressCheckoutDetailsResponseType instance)
 {
     return(new PayPalConfirmResponse
     {
         Token = instance.GetExpressCheckoutDetailsResponseDetails.Token,
         Errors = instance.Errors.Select(x => ErrorTypeExtensions.ToPaypalError(x)),
         Status = instance.Ack.ToString(),
         PayerId = instance.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID
     });
 }
Пример #10
0
        private void DisplayPaypalExpressMode(CheckoutViewModel model)
        {
            model.PayPalToken   = Request.QueryString["token"] ?? string.Empty;
            model.PayPalPayerId = Request.QueryString["payerId"] ?? string.Empty;

            if (string.IsNullOrEmpty(model.PayPalToken))
            {
                Redirect(Url.RouteHccUrl(HccRoute.Cart));
            }


            var ppAPI  = PaypalExpressUtilities.GetPaypalAPI(HccApp.CurrentStore);
            var failed = false;
            GetExpressCheckoutDetailsResponseType ppResponse = null;

            try
            {
                if (!GetExpressCheckoutDetails(ppAPI, ref ppResponse, model))
                {
                    failed = true;
                    EventLog.LogEvent("Paypal Express Checkout",
                                      "GetExpressCheckoutDetails call failed. Detailed Errors will follow. ", EventLogSeverity.Error);
                    foreach (var ppError in ppResponse.Errors)
                    {
                        EventLog.LogEvent("Paypal error number: " + ppError.ErrorCode,
                                          "Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage + "' " +
                                          " Values passed to GetExpressCheckoutDetails: Token: " + model.PayPalToken,
                                          EventLogSeverity.Error);
                    }
                    FlashFailure(Localization.GetString("ErrorOccured"));
                    ViewBag.HideCheckout = true;
                }
            }
            finally
            {
                var o = model.CurrentOrder;

                o.CustomProperties.Add("hcc", "PayerID", Request.QueryString["PayerID"]);
                if (!failed)
                {
                    if (ppResponse != null && ppResponse.GetExpressCheckoutDetailsResponseDetails != null &&
                        ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo != null)
                    {
                        o.UserEmail = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
                        if (string.IsNullOrEmpty(o.ShippingAddress.Phone))
                        {
                            o.ShippingAddress.Phone =
                                ppResponse.GetExpressCheckoutDetailsResponseDetails.ContactPhone ?? string.Empty;
                        }
                    }
                }
                HccApp.OrderServices.Orders.Update(o);
            }
        }
Пример #11
0
        public static PayPalConfirmPaymentModel GetPayment(string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentNullException("token");
            }

            Dictionary <string, string>      config       = PayPal.Api.ConfigManager.Instance.GetProperties();
            PayPalAPIInterfaceServiceService service      = new PayPalAPIInterfaceServiceService(config);
            GetExpressCheckoutDetailsReq     getECWrapper = new GetExpressCheckoutDetailsReq();

            getECWrapper.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token);

            GetExpressCheckoutDetailsResponseType getECResponse = service.GetExpressCheckoutDetails(getECWrapper);

            DoExpressCheckoutPaymentRequestType        request        = new DoExpressCheckoutPaymentRequestType();
            DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();

            request.DoExpressCheckoutPaymentRequestDetails = requestDetails;

            requestDetails.PaymentDetails = getECResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
            requestDetails.Token          = getECResponse.GetExpressCheckoutDetailsResponseDetails.Token;
            requestDetails.PayerID        = getECResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;

            DoExpressCheckoutPaymentReq wrapper = new DoExpressCheckoutPaymentReq();

            wrapper.DoExpressCheckoutPaymentRequest = request;
            DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(wrapper);

            if (doECResponse.Ack == AckCodeType.SUCCESS)
            {
                var paymentInfo = doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.First();

                var confirmModel = new PayPalConfirmPaymentModel
                {
                    Success          = true,
                    PaymentRequestID = paymentInfo.PaymentRequestID,
                    OrderTotal       = decimal.Parse(paymentInfo.GrossAmount.value),
                    OrderDate        = string.IsNullOrEmpty(paymentInfo.PaymentDate)
                                                ? DateTimeOffset.Parse(paymentInfo.PaymentDate)
                                                : (DateTimeOffset?)null
                };
                return(confirmModel);
            }
            return(new PayPalConfirmPaymentModel
            {
                Success = false,
                ErrorMessage = string.Join(". ", doECResponse.Errors.Select(x => x.LongMessage).ToList())
            });
        }
Пример #12
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]
            Dictionary <string, string> configurationMap = Configuration.GetAcctAndConfig();

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

            GetExpressCheckoutDetailsReq getECWrapper = new GetExpressCheckoutDetailsReq();

            // (Required) A timestamped token, the value of which was returned by SetExpressCheckout response.
            // Character length and limitations: 20 single-byte characters
            getECWrapper.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token.Value);
            // # API call
            // Invoke the GetExpressCheckoutDetails method in service wrapper object
            GetExpressCheckoutDetailsResponseType getECResponse = service.GetExpressCheckoutDetails(getECWrapper);

            // Create request object
            DoExpressCheckoutPaymentRequestType        request        = new DoExpressCheckoutPaymentRequestType();
            DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();

            request.DoExpressCheckoutPaymentRequestDetails = requestDetails;

            requestDetails.PaymentDetails = getECResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
            // (Required) The timestamped token value that was returned in the SetExpressCheckout response and passed in the GetExpressCheckoutDetails request.
            requestDetails.Token = token.Value;
            // (Required) Unique PayPal buyer account identification number as returned in the GetExpressCheckoutDetails response
            requestDetails.PayerID = payerId.Value;
            // (Required) How you want to obtain payment. It is one of the following values:
            // * Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
            // * Order – This payment is an order authorization subject to settlement with PayPal Authorization and Capture.
            // * Sale – This is a final sale for which you are requesting payment.
            // Note: You cannot set this value to Sale in the SetExpressCheckout request and then change this value to Authorization in the DoExpressCheckoutPayment request.
            requestDetails.PaymentAction = (PaymentActionCodeType)
                                           Enum.Parse(typeof(PaymentActionCodeType), paymentAction.SelectedValue);

            // Invoke the API
            DoExpressCheckoutPaymentReq wrapper = new DoExpressCheckoutPaymentReq();

            wrapper.DoExpressCheckoutPaymentRequest = request;
            // # API call
            // Invoke the DoExpressCheckoutPayment method in service wrapper object
            DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, doECResponse);
        }
Пример #13
0
        private GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetailsResponse(FinancialGateway financialGateway, String token, out string errorMessage)
        {
            errorMessage = string.Empty;


            // Create the GetExpressCheckoutDetailsResponseType object
            GetExpressCheckoutDetailsResponseType responseGetExpressCheckoutDetailsResponseType = new GetExpressCheckoutDetailsResponseType();

            try
            {
                // Create the GetExpressCheckoutDetailsReq object
                GetExpressCheckoutDetailsReq getExpressCheckoutDetails = new GetExpressCheckoutDetailsReq();

                // A timestamped token, the value of which was returned by `SetExpressCheckout` response
                GetExpressCheckoutDetailsRequestType getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token);
                getExpressCheckoutDetails.GetExpressCheckoutDetailsRequest = getExpressCheckoutDetailsRequest;

                // Create the service wrapper object to make the API call
                PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(GetCredentials(financialGateway));

                // # API call
                // Invoke the GetExpressCheckoutDetails method in service wrapper object
                responseGetExpressCheckoutDetailsResponseType = service.GetExpressCheckoutDetails(getExpressCheckoutDetails);

                if (responseGetExpressCheckoutDetailsResponseType != null)
                {
                    // # Success values
                    if (responseGetExpressCheckoutDetailsResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                    {
                        return(responseGetExpressCheckoutDetailsResponseType);
                    }
                    // # Error Values
                    else
                    {
                        List <ErrorType> errorMessages = responseGetExpressCheckoutDetailsResponseType.Errors;
                        foreach (ErrorType error in errorMessages)
                        {
                            errorMessage += "API Error Message : " + error.LongMessage + "\n";
                        }
                    }
                }
            }
            // # Exception log
            catch (System.Exception ex)
            {
                errorMessage += "Error Message : " + ex.Message;
            }
            return(null);
        }
 private DoExpressCheckoutPaymentReq GetDoExpressCheckoutPaymentRequest(GetExpressCheckoutDetailsResponseType response, string paymentId)
 {
     return(new DoExpressCheckoutPaymentReq
     {
         DoExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType
         {
             DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType
             {
                 Token = paymentId,
                 PayerID = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID,
                 PaymentDetails = response.GetExpressCheckoutDetailsResponseDetails.PaymentDetails
             }
         }
     });
 }
Пример #15
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Create request object
            GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();

            request.Token = token.Value;

            // Invoke the API
            GetExpressCheckoutDetailsReq wrapper = new GetExpressCheckoutDetailsReq();

            wrapper.GetExpressCheckoutDetailsRequest = request;
            PayPalAPIInterfaceServiceService      service    = new PayPalAPIInterfaceServiceService();
            GetExpressCheckoutDetailsResponseType ecResponse = service.GetExpressCheckoutDetails(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, ecResponse);
        }
Пример #16
0
        public GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetails(string token)
        {
            var result   = new GetExpressCheckoutDetailsResponseType();
            var settings = Services.Settings.LoadSetting <PayPalExpressPaymentSettings>(Services.StoreContext.CurrentStore.Id);

            using (var service = GetApiAaService(settings))
            {
                var req = new GetExpressCheckoutDetailsReq();
                req.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType
                {
                    Token   = token,
                    Version = ApiVersion
                };

                result = service.GetExpressCheckoutDetails(req);
            }
            return(result);
        }
Пример #17
0
        public static DoExpressCheckoutPaymentReq GetDoExpressCheckoutPaymentReq(GetExpressCheckoutDetailsResponseType response)
        {
            DoExpressCheckoutPaymentReq payReq = new DoExpressCheckoutPaymentReq()
            {
                DoExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType()
                {
                    Version = ConfigurationManager.AppSettings["PayPalAPIVersion"],
                    DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType()
                    {
                        Token          = response.GetExpressCheckoutDetailsResponseDetails.Token,
                        PaymentAction  = PaymentActionCodeType.Sale,
                        PayerID        = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID,
                        PaymentDetails = response.GetExpressCheckoutDetailsResponseDetails.PaymentDetails
                    }
                }
            };

            return(payReq);
        }
Пример #18
0
        private bool GetExpressCheckoutDetails(PayPalAPI ppAPI, ref GetExpressCheckoutDetailsResponseType ppResponse, CheckoutViewModel model)
        {
            ppResponse = ppAPI.GetExpressCheckoutDetails(Request.QueryString["token"]);
            if (ppResponse.Ack == AckCodeType.Success || ppResponse.Ack == AckCodeType.SuccessWithWarning)
            {
                model.CurrentOrder.UserEmail = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
                model.CurrentOrder.ShippingAddress.FirstName = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.FirstName ?? string.Empty;
                if (ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.MiddleName.Length > 0)
                {
                    model.CurrentOrder.ShippingAddress.MiddleInitial = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.MiddleName.Substring(0, 1);
                }
                else
                {
                    model.CurrentOrder.ShippingAddress.MiddleInitial = string.Empty;
                }
                model.CurrentOrder.ShippingAddress.LastName                = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.LastName ?? string.Empty;
                model.CurrentOrder.ShippingAddress.Company                 = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerBusiness ?? string.Empty;
                model.CurrentOrder.ShippingAddress.Line1                   = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1 ?? string.Empty;
                model.CurrentOrder.ShippingAddress.Line2                   = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2 ?? string.Empty;
                model.CurrentOrder.ShippingAddress.CountryData.Name        = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountryName ?? string.Empty;
                model.CurrentOrder.ShippingAddress.CountryData.Bvin        = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
                model.CurrentOrder.ShippingAddress.City                    = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName ?? string.Empty;
                model.CurrentOrder.ShippingAddress.RegionData.Name         = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince ?? string.Empty;
                model.CurrentOrder.ShippingAddress.RegionData.Abbreviation =
                    model.CurrentOrder.ShippingAddress.RegionData.Name ?? string.Empty;
                model.CurrentOrder.ShippingAddress.PostalCode = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode ?? string.Empty;
                model.CurrentOrder.ShippingAddress.Phone      = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.ContactPhone ?? string.Empty;

                if (ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.AddressStatus == AddressStatusCodeType.Confirmed)
                {
                    ViewBag.AddressStatus = "Confirmed";
                }
                else
                {
                    ViewBag.AddressStatus = "Unconfirmed";
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #19
0
        public GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetails(string token)
        {
            var result = new GetExpressCheckoutDetailsResponseType();

            using (var service = new PayPalAPIAASoapBinding())
            {
                var req = new GetExpressCheckoutDetailsReq();
                req.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType
                {
                    Token   = token,
                    Version = PayPalHelper.GetApiVersion()
                };

                service.Url = PayPalHelper.GetPaypalServiceUrl(Settings);
                service.RequesterCredentials = PayPalHelper.GetPaypalApiCredentials(Settings);
                result = service.GetExpressCheckoutDetails(req);
            }
            return(result);
        }
Пример #20
0
        public GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetails(string token)
        {
            var result   = new GetExpressCheckoutDetailsResponseType();
            var settings = CommonServices.Settings.LoadSetting <PayPalExpressPaymentSettings>(CommonServices.StoreContext.CurrentStore.Id);

            using (var service = new PayPalAPIAASoapBinding())
            {
                var req = new GetExpressCheckoutDetailsReq();
                req.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType
                {
                    Token   = token,
                    Version = PayPalHelper.GetApiVersion()
                };

                service.Url = PayPalHelper.GetPaypalServiceUrl(settings);
                service.RequesterCredentials = PayPalHelper.GetPaypalApiCredentials(settings);
                result = service.GetExpressCheckoutDetails(req);
            }
            return(result);
        }
        /// <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);
        }
Пример #22
0
        private bool GetExpressCheckoutDetails(PayPalAPI ppAPI, ref GetExpressCheckoutDetailsResponseType ppResponse,
                                               CheckoutViewModel model)
        {
            ppResponse = ppAPI.GetExpressCheckoutDetails(Request.QueryString["token"]);
            if (ppResponse.Ack == AckCodeType.Success || ppResponse.Ack == AckCodeType.SuccessWithWarning)
            {
                var payerInfo = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo;
                var country   = HccApp.GlobalizationServices.Countries.FindByISOCode(payerInfo.Address.Country.ToString());
                model.CurrentOrder.UserEmail = payerInfo.Payer;

                if (model.CurrentOrder.HasShippingItems)
                {
                    model.CurrentOrder.ShippingAddress.FirstName = payerInfo.PayerName.FirstName;
                    model.CurrentOrder.ShippingAddress.LastName  = payerInfo.PayerName.LastName;

                    model.CurrentOrder.ShippingAddress.Company     = payerInfo.PayerBusiness ?? string.Empty;
                    model.CurrentOrder.ShippingAddress.Line1       = payerInfo.Address.Street1 ?? string.Empty;
                    model.CurrentOrder.ShippingAddress.Line2       = payerInfo.Address.Street2 ?? string.Empty;
                    model.CurrentOrder.ShippingAddress.CountryBvin = country.Bvin ?? string.Empty;
                    model.CurrentOrder.ShippingAddress.City        = payerInfo.Address.CityName ?? string.Empty;
                    model.CurrentOrder.ShippingAddress.RegionBvin  = payerInfo.Address.StateOrProvince ?? string.Empty;
                    model.CurrentOrder.ShippingAddress.PostalCode  = payerInfo.Address.PostalCode ?? string.Empty;
                    model.CurrentOrder.ShippingAddress.Phone       = payerInfo.Address.Phone ?? string.Empty;

                    if (payerInfo.Address.AddressStatus == AddressStatusCodeType.Confirmed)
                    {
                        ViewBag.AddressStatus = Localization.GetString("Confirmed");
                    }
                    else
                    {
                        ViewBag.AddressStatus = Localization.GetString("Unconfirmed");
                    }
                }
                return(true);
            }
            return(false);
        }
Пример #23
0
        public List <GatewayAccountItem> GetSelectedAccounts(FinancialGateway financialGateway, String token, out string errorMessage)
        {
            errorMessage = string.Empty;
            GetExpressCheckoutDetailsResponseType response = GetExpressCheckoutDetailsResponse(financialGateway, token, out errorMessage);

            if (response == null)
            {
                return(null);
            }
            var details        = response.GetExpressCheckoutDetailsResponseDetails;
            var paymentDetails = details.PaymentDetails.FirstOrDefault();
            List <GatewayAccountItem> accounts = new List <GatewayAccountItem>();

            foreach (PaymentDetailsItemType item in paymentDetails.PaymentDetailsItem)
            {
                GatewayAccountItem account = new GatewayAccountItem();
                account.Id         = item.Number.AsInteger();
                account.Name       = item.Name;
                account.PublicName = item.Description;
                account.Amount     = item.Amount.value.AsDecimal();
                accounts.Add(account);
            }
            return(accounts);
        }
Пример #24
0
        //GET : PayPal/PaymentSuccess
        public async Task <ActionResult> PaymentSuccess(Guid invoiceId)
        {
            GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();

            request.Version = "104.0";
            request.Token   = Request["token"];
            GetExpressCheckoutDetailsReq wrapper = new GetExpressCheckoutDetailsReq();

            wrapper.GetExpressCheckoutDetailsRequest = request;

            //define sdk configuration
            Dictionary <string, string> sdkConfig = new Dictionary <string, string>();

            sdkConfig.Add("mode", ConfigurationManager.AppSettings["paypal.mode"]);
            sdkConfig.Add("account1.apiUsername", ConfigurationManager.AppSettings["paypal.apiUsername"]);
            sdkConfig.Add("account1.apiPassword", ConfigurationManager.AppSettings["paypal.apiPassword"]);
            sdkConfig.Add("account1.apiSignature", ConfigurationManager.AppSettings["paypal.apiSignature"]);
//            sdkConfig.Add("acct1.UserName", ConfigurationManager.AppSettings["paypal.apiUsername"]);
//            sdkConfig.Add("acct1.Password", ConfigurationManager.AppSettings["paypal.apiPassword"]);
//            sdkConfig.Add("acct1.Signature", ConfigurationManager.AppSettings["paypal.apiSignature"]);

            PayPalAPIInterfaceServiceService      s          = new PayPalAPIInterfaceServiceService(sdkConfig);
            GetExpressCheckoutDetailsResponseType ecResponse = s.GetExpressCheckoutDetails(wrapper);

            if (ecResponse.Ack.HasValue &&
                ecResponse.Ack.Value.ToString() != "FAILURE" &&
                ecResponse.Errors.Count == 0)
            {
                double paymentAmount = 0.0;
                double.TryParse(ecResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails.FirstOrDefault().OrderTotal.value, out paymentAmount);

                PaymentDetailsType paymentDetail = new PaymentDetailsType();
                paymentDetail.NotifyURL     = "http://replaceIpnUrl.com";
                paymentDetail.PaymentAction = (PaymentActionCodeType)EnumUtils.GetValue("Sale", typeof(PaymentActionCodeType));
                paymentDetail.OrderTotal    = new BasicAmountType((CurrencyCodeType)EnumUtils.GetValue("USD", typeof(CurrencyCodeType)), paymentAmount + "");
                List <PaymentDetailsType> paymentDetails = new List <PaymentDetailsType>();
                paymentDetails.Add(paymentDetail);

                DoExpressCheckoutPaymentRequestType doExpressCheckoutPaymentRequestType = new DoExpressCheckoutPaymentRequestType();
                request.Version = "104.0";
                DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
                requestDetails.PaymentDetails = paymentDetails;
                requestDetails.Token          = Request["token"];
                requestDetails.PayerID        = Request["PayerID"];
                doExpressCheckoutPaymentRequestType.DoExpressCheckoutPaymentRequestDetails = requestDetails;

                DoExpressCheckoutPaymentReq doExpressCheckoutPaymentReq = new DoExpressCheckoutPaymentReq();
                doExpressCheckoutPaymentReq.DoExpressCheckoutPaymentRequest = doExpressCheckoutPaymentRequestType;

                s = new PayPalAPIInterfaceServiceService(sdkConfig);
                DoExpressCheckoutPaymentResponseType doECResponse = s.DoExpressCheckoutPayment(doExpressCheckoutPaymentReq);

                if (doECResponse.Ack.HasValue &&
                    doECResponse.Ack.Value.ToString() != "FAILURE" &&
                    doECResponse.Errors.Count == 0)
                {
                    //create payment object for invoice
                    PaymentService       paymentService       = new PaymentService(this.db);
                    PaymentMethodService paymentMethodService = new PaymentMethodService(this.db);
                    var ccPymtMethod = paymentMethodService.GetCreditCardPaymentMethod(UserContact);

                    if (ccPymtMethod == null)
                    {
                        try
                        {
                            PaymentMethodTypeService paymentMethodTypeService = new PaymentMethodTypeService(this.db);
                            string ccTypeCode = GNPaymentMethodType.Types.CREDIT_CARD.GetCode();
                            var    ccType     = this.db.GNPaymentMethodTypes
                                                .Where(pt => pt.Name == ccTypeCode).FirstOrDefault();

                            await paymentMethodService.Insert(UserContact, new GNPaymentMethod
                            {
                                GNAccountId           = UserContact.GNOrganization.Account.Id,
                                GNPaymentMethodTypeId = ccType.Id,
                                Description           = "PAYPAL",
                                IsDefault             = true,
                                IsActive = true,
                                UsedForRecurrentPayments = false,
                                PCITokenId     = "X",
                                LastFourDigits = "X",
                                ExpirationDate = DateTime.MaxValue,
                                CreateDateTime = DateTime.Now,
                                CreatedBy      = UserContact.Id
                            });
                        }
                        catch (Exception e)
                        {
                            LogUtil.Error(logger, "Error adding PayPal Credit Card payment method!!", e);
                        }

                        ccPymtMethod = paymentMethodService.GetCreditCardPaymentMethod(UserContact);

                        if (ccPymtMethod == null)
                        {
                            throw new Exception("Credit Card Payment Method Not Found!!");
                        }
                    }

                    var ecPaymentInfo = doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.FirstOrDefault();

                    double grossAmount = 0.0;
                    double.TryParse(ecPaymentInfo.GrossAmount.value, out grossAmount);

                    if (grossAmount != 0.0)
                    {
                        try
                        {
                            var payment = new GNPayment
                            {
                                Id                = Guid.NewGuid(),
                                GNInvoiceId       = invoiceId,
                                GNPaymentMethodId = ccPymtMethod.Id,
                                PaymentDate       = DateTime.Now,
                                TotalAmount       = grossAmount,
                                Status            = ecPaymentInfo.PaymentStatus.Value.ToString(),
                                ExternalTxnId     = ecPaymentInfo.TransactionID,
                                CreateDateTime    = DateTime.Now,
                                CreatedBy         = UserContact.Id
                            };

                            this.AddInvoiceToPayment(payment);

                            await paymentService.Insert(UserContact, payment);
                        }
                        catch (Exception e)
                        {
                            LogUtil.Error(logger, "Error inserting payment!!", e);
                        }
                    }
                    else
                    {
                        throw new Exception("Payment Amount of 0.0 Not Allowed!!");
                    }
                }
            }

            return(RedirectToAction("MyBillingPayments", "Account"));
        }
Пример #25
0
        public PaymentResponse Payment(string token, string payerId)
        {
            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(_payPalConfiguration);

            GetExpressCheckoutDetailsReq getECWrapper = new GetExpressCheckoutDetailsReq();

            // (Required) A timestamped token, the value of which was returned by SetExpressCheckout response.
            // Character length and limitations: 20 single-byte characters
            getECWrapper.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token);
            // # API call
            // Invoke the GetExpressCheckoutDetails method in service wrapper object
            GetExpressCheckoutDetailsResponseType getECResponse = service.GetExpressCheckoutDetails(getECWrapper);

            // Create request object
            DoExpressCheckoutPaymentRequestType        request        = new DoExpressCheckoutPaymentRequestType();
            DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();

            request.DoExpressCheckoutPaymentRequestDetails = requestDetails;

            requestDetails.ButtonSource = "PTSH";

            requestDetails.PaymentDetails = getECResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
            // (Required) The timestamped token value that was returned in the SetExpressCheckout response and passed in the GetExpressCheckoutDetails request.
            requestDetails.Token = token;
            // (Required) Unique PayPal buyer account identification number as returned in the GetExpressCheckoutDetails response
            requestDetails.PayerID = payerId;
            // (Required) How you want to obtain payment. It is one of the following values:
            // * Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
            // * Order – This payment is an order authorization subject to settlement with PayPal Authorization and Capture.
            // * Sale – This is a final sale for which you are requesting payment.
            // Note: You cannot set this value to Sale in the SetExpressCheckout request and then change this value to Authorization in the DoExpressCheckoutPayment request.
            requestDetails.PaymentAction = PaymentActionCodeType.SALE;

            // Invoke the API
            DoExpressCheckoutPaymentReq wrapper = new DoExpressCheckoutPaymentReq();

            wrapper.DoExpressCheckoutPaymentRequest = request;
            // # API call
            // Invoke the DoExpressCheckoutPayment method in service wrapper object
            DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(wrapper);

            // Check for API return status

            if (doECResponse.Ack.Equals(AckCodeType.FAILURE) ||
                (doECResponse.Errors != null && doECResponse.Errors.Any()))
            {
                return(null);
            }
            string transactionId = doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID;

            if (doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PendingReason != null && doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PendingReason != PendingStatusCodeType.NONE)
            {
                CancelTransaction(transactionId);

                throw new Exception(
                          doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PendingReason.ToString() + transactionId);
            }
            return(new PaymentResponse
            {
                TransactionId = transactionId,
                Price = float.Parse(requestDetails.PaymentDetails[0].OrderTotal.value)
            });
        }
        private bool GetExpressCheckoutDetails(PayPalAPI ppAPI, ref GetExpressCheckoutDetailsResponseType ppResponse, CheckoutViewModel model)
        {
            ppResponse = ppAPI.GetExpressCheckoutDetails(Request.QueryString["token"]);
            if (ppResponse.Ack == AckCodeType.Success || ppResponse.Ack == AckCodeType.SuccessWithWarning)
            {
                model.CurrentOrder.UserEmail = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
                model.CurrentOrder.ShippingAddress.FirstName = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.FirstName ?? string.Empty;
                if (ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.MiddleName.Length > 0)
                {
                    model.CurrentOrder.ShippingAddress.MiddleInitial = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.MiddleName.Substring(0, 1);
                }
                else
                {
                    model.CurrentOrder.ShippingAddress.MiddleInitial = string.Empty;
                }
                model.CurrentOrder.ShippingAddress.LastName = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.LastName ?? string.Empty;
                model.CurrentOrder.ShippingAddress.Company = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerBusiness ?? string.Empty;
                model.CurrentOrder.ShippingAddress.Line1 = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1 ?? string.Empty;
                model.CurrentOrder.ShippingAddress.Line2 = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2 ?? string.Empty;
                model.CurrentOrder.ShippingAddress.CountryData.Name = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountryName ?? string.Empty;
                model.CurrentOrder.ShippingAddress.CountryData.Bvin = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
                model.CurrentOrder.ShippingAddress.City = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName ?? string.Empty;
                model.CurrentOrder.ShippingAddress.RegionData.Name = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince ?? string.Empty;
                model.CurrentOrder.ShippingAddress.RegionData.Abbreviation =
                    model.CurrentOrder.ShippingAddress.RegionData.Name ?? string.Empty;
                model.CurrentOrder.ShippingAddress.PostalCode = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode ?? string.Empty;
                model.CurrentOrder.ShippingAddress.Phone = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.ContactPhone ?? string.Empty;

                if (ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.AddressStatus == AddressStatusCodeType.Confirmed)
                {
                    ViewBag.AddressStatus = "Confirmed";
                }
                else
                {
                    ViewBag.AddressStatus = "Unconfirmed";
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        public override PostProcessPaymentResult PostProcessPayment(PostProcessPaymentEvaluationContext context)
        {
            var retVal = new PostProcessPaymentResult();

            if (context == null && context.Payment == null)
            {
                throw new ArgumentNullException("paymentEvaluationContext");
            }

            if (context.Order == null)
            {
                throw new NullReferenceException("no order with this id");
            }

            retVal.OrderId = context.Order.Id;

            if (!(context.Store != null && !string.IsNullOrEmpty(context.Store.Url)))
            {
                throw new NullReferenceException("no store with this id");
            }

            var config = GetConfigMap(context.Store);

            var service = new PayPalAPIInterfaceServiceService(config);

            GetExpressCheckoutDetailsResponseType response   = null;
            DoExpressCheckoutPaymentResponseType  doResponse = null;

            var getExpressCheckoutDetailsRequest = GetGetExpressCheckoutDetailsRequest(context.OuterId);

            try
            {
                response = service.GetExpressCheckoutDetails(getExpressCheckoutDetailsRequest);

                CheckResponse(response);

                var status = response.GetExpressCheckoutDetailsResponseDetails.CheckoutStatus;

                if (!status.Equals("PaymentActionCompleted"))
                {
                    var doExpressCheckoutPaymentRequest = GetDoExpressCheckoutPaymentRequest(response, context.OuterId);
                    doResponse = service.DoExpressCheckoutPayment(doExpressCheckoutPaymentRequest);

                    CheckResponse(doResponse);

                    response = service.GetExpressCheckoutDetails(getExpressCheckoutDetailsRequest);
                    status   = response.GetExpressCheckoutDetailsResponseDetails.CheckoutStatus;
                }
                if (status.Equals("PaymentActionCompleted"))
                {
                    retVal.IsSuccess        = true;
                    retVal.NewPaymentStatus = PaymentStatus.Paid;
                }
            }
            catch (System.Exception ex)
            {
                retVal.Error            = ex.Message;
                retVal.NewPaymentStatus = PaymentStatus.Pending;
            }

            return(retVal);
        }
Пример #28
0
        private void SavePayPalTransactionDetailsError(GetExpressCheckoutDetailsResponseType response)
        {
            string responseStr = JSONHelper.Serialize(response);
            var details = response.GetExpressCheckoutDetailsResponseDetails;

            Log.InfoFormat("Saving retrieved-with-error PayPal transaction: token={0}, response={1}", details.Token, responseStr);

            try
            {
                using (var conn = new SqlConnection(Settings.Default.PayPalDb))
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO PayPalExpressCheckoutRetrievedError (Token, Response)" +
                                      "VALUES (@token, @response)";
                    var tokenParam = cmd.Parameters.Add("@token", SqlDbType.VarChar);
                    tokenParam.Value = details.Token;

                    var responseParam = cmd.Parameters.Add("@response", SqlDbType.VarChar);
                    responseParam.Value = responseStr;

                    conn.Open();
                    int rows = cmd.ExecuteNonQuery();

                    if (rows != 1)
                        throw new ApplicationException("Inserting a transaction returned rows != 1: " + rows);
                }
            }
            catch (Exception e)
            {
                Log.Error("Saving transaction failed. ", e);
                // we don't rethrow the exception. We'll try to complete the transaction.
            }
        }
Пример #29
0
        private ActionResult ProcessingResult_PayPal(ProcessingResultModel model)
        {
            if (model == null)
            {
                throw new System.ArgumentNullException("model");
            }
            PaymentResultContext context = new PaymentResultContext();

            context.Order = model.order;
            if (model.success == true)
            {
                if (model.token == null)
                {
                    throw new System.ArgumentNullException("token");
                }
                if (model.payerID == null)
                {
                    throw new System.ArgumentNullException("payerID");
                }
                GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();
                request.Version = "104.0";
                request.Token   = model.token;
                GetExpressCheckoutDetailsReq wrapper = new GetExpressCheckoutDetailsReq();
                wrapper.GetExpressCheckoutDetailsRequest = request;
                System.Collections.Generic.Dictionary <string, string> config = PaymentController.PayPal_CreateConfig();
                PayPalAPIInterfaceServiceService      service    = new PayPalAPIInterfaceServiceService(config);
                GetExpressCheckoutDetailsResponseType ecResponse = service.GetExpressCheckoutDetails(wrapper);
                if (ecResponse == null)
                {
                    throw new System.Exception("checkout details result is null");
                }
                if (ecResponse.Errors != null && ecResponse.Errors.Count > 0)
                {
                    ecResponse.Errors.ForEach(delegate(ErrorType m)
                    {
                        context.Errors.Add(m.LongMessage);
                    });
                }
                if (ecResponse.Ack == AckCodeType.SUCCESS || ecResponse.Ack == AckCodeType.SUCCESSWITHWARNING)
                {
                    GetExpressCheckoutDetailsResponseDetailsType details = ecResponse.GetExpressCheckoutDetailsResponseDetails;
                    if (details == null)
                    {
                        throw new System.Exception("details object is null");
                    }
                    if (string.IsNullOrEmpty(details.InvoiceID))
                    {
                        throw new System.Exception("invoiceID not found");
                    }
                    if (details.PaymentDetails == null)
                    {
                        throw new System.Exception("payment details is null");
                    }
                    System.Collections.Generic.List <PaymentDetailsType> paymentDetails = new System.Collections.Generic.List <PaymentDetailsType>();
                    foreach (PaymentDetailsType payment in details.PaymentDetails)
                    {
                        paymentDetails.Add(new PaymentDetailsType
                        {
                            NotifyURL     = null,
                            PaymentAction = payment.PaymentAction,
                            OrderTotal    = payment.OrderTotal
                        });
                    }
                    DoExpressCheckoutPaymentRequestType paymentRequest = new DoExpressCheckoutPaymentRequestType();
                    paymentRequest.Version = "104.0";
                    paymentRequest.DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType
                    {
                        PaymentDetails = paymentDetails,
                        Token          = model.token,
                        PayerID        = model.payerID
                    };
                    DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(new DoExpressCheckoutPaymentReq
                    {
                        DoExpressCheckoutPaymentRequest = paymentRequest
                    });
                    if (doECResponse == null)
                    {
                        throw new System.Exception("payment result is null");
                    }
                    if (doECResponse.Errors != null && doECResponse.Errors.Count > 0)
                    {
                        doECResponse.Errors.ForEach(delegate(ErrorType m)
                        {
                            context.Errors.Add(m.LongMessage);
                        });
                    }
                    if (doECResponse.Ack == AckCodeType.SUCCESS || doECResponse.Ack == AckCodeType.SUCCESSWITHWARNING)
                    {
                        ConfirmInvoiceResult invoiceResult = BookingProvider.ConfirmInvoice(details.InvoiceID.Trim());
                        Tracing.DataTrace.TraceEvent(TraceEventType.Information, 0, "PAYPAL transaction: invoice: '{0}', invoice confirmation: '{1}'", new object[]
                        {
                            details.InvoiceID,
                            invoiceResult.IsSuccess ? "SUCCESS" : "FAILED"
                        });
                        if (!invoiceResult.IsSuccess)
                        {
                            context.Errors.Add(string.Format("invoice confirmation error: {0}", invoiceResult.ErrorMessage));
                        }
                        else
                        {
                            context.Success = true;

                            BookingProvider.AcceptInvoice(Convert.ToInt32(context.Order));
                        }
                    }
                }
            }
            else
            {
                context.Errors.Add(PaymentStrings.PaymentCancelled);
            }
            return(base.View("_ProcessingResult", context));
        }
        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);
        }
Пример #31
0
        public static string GetECDetails(string payPalToken, int customerId)
        {
            var payPalRefund  = new PayPalAPISoapBinding();
            var payPalBinding = new PayPalAPIAASoapBinding();
            var payerId       = string.Empty;
            var addressStatus = string.Empty;
            var request       = new GetExpressCheckoutDetailsReq();
            var requestType   = new GetExpressCheckoutDetailsRequestType();
            var response      = new GetExpressCheckoutDetailsResponseType();
            var responseType  = new GetExpressCheckoutDetailsResponseDetailsType();

            GetPaypalRequirements(out payPalRefund, out payPalBinding);

            request.GetExpressCheckoutDetailsRequest          = requestType;
            response.GetExpressCheckoutDetailsResponseDetails = responseType;
            requestType.Token   = payPalToken;
            requestType.Version = API_VER;

            response = payPalBinding.GetExpressCheckoutDetails(request);

            var payerInfo = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo;

            payerId = payerInfo.PayerID;
            if (string.IsNullOrEmpty(payerId))              // If we don't have a PayerID the transaction must be aborted.
            {
                return(string.Empty);
            }

            addressStatus = payerInfo.Address.AddressStatus.ToString();

            //Is address AVS Confirmed or Unconfirmed?
            var requireConfirmedAddress = AppLogic.AppConfigBool("PayPal.Express.AVSRequireConfirmedAddress");

            if (requireConfirmedAddress && !addressStatus.Equals("Confirmed", StringComparison.OrdinalIgnoreCase))
            {
                return("AVSFAILED");
            }

            var customer = new Customer(customerId, true);

            customer.UpdateCustomer(
                email: customer.IsRegistered
                                        ? null
                                        : payerInfo.Payer,
                firstName: payerInfo.PayerName.FirstName,
                lastName: payerInfo.PayerName.LastName,
                phone: payerInfo.Address.Phone != null
                                        ? payerInfo.Address.Phone
                                        : string.Empty,
                okToEmail: false
                );

            //Use the address from PayPal
            var payPalAddress = Address.FindOrCreateOffSiteAddress(
                customerId: customerId,
                city: payerInfo.Address.CityName,
                stateAbbreviation: AppLogic.GetStateAbbreviation(payerInfo.Address.StateOrProvince, payerInfo.Address.CountryName),
                postalCode: payerInfo.Address.PostalCode,
                countryName: payerInfo.Address.CountryName,
                offSiteSource: AppLogic.ro_PMPayPalExpress,
                firstName: payerInfo.PayerName.FirstName,
                lastName: payerInfo.PayerName.LastName,
                address1: payerInfo.Address.Street1,
                address2: payerInfo.Address.Street2,
                phone: payerInfo.Address.Phone != null
                                        ? payerInfo.Address.Phone
                                        : null
                );

            customer.SetPrimaryAddress(payPalAddress.AddressID, AddressTypes.Billing);
            customer.SetPrimaryAddress(payPalAddress.AddressID, AddressTypes.Shipping);

            return(payerId);
        }
Пример #32
0
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext CurrContext = HttpContext.Current;

        // Create the GetExpressCheckoutDetailsResponseType object
        GetExpressCheckoutDetailsResponseType responseGetExpressCheckoutDetailsResponseType = new GetExpressCheckoutDetailsResponseType();

        try
        {
            // Create the GetExpressCheckoutDetailsReq object
            GetExpressCheckoutDetailsReq getExpressCheckoutDetails = new GetExpressCheckoutDetailsReq();
            // A timestamped token, the value of which was returned by `SetExpressCheckout` API response
            string EcToken = (string)(Session["EcToken"]);
            GetExpressCheckoutDetailsRequestType getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(EcToken);
            getExpressCheckoutDetails.GetExpressCheckoutDetailsRequest = getExpressCheckoutDetailsRequest;
            // Create the service wrapper object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
            // # API call
            // Invoke the GetExpressCheckoutDetails method in service wrapper object
            responseGetExpressCheckoutDetailsResponseType = service.GetExpressCheckoutDetails(getExpressCheckoutDetails);
            if (responseGetExpressCheckoutDetailsResponseType != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "GetExpressCheckoutDetails API Operation - ";
                acknowledgement += responseGetExpressCheckoutDetailsResponseType.Ack.ToString();
                //logger.Info(acknowledgement + "\n");
                System.Diagnostics.Debug.WriteLine(acknowledgement + "\n");
                // # Success values
                if (responseGetExpressCheckoutDetailsResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // Unique PayPal Customer Account identification number. This
                    // value will be null unless you authorize the payment by
                    // redirecting to PayPal after `SetExpressCheckout` call.
                    string PayerId = responseGetExpressCheckoutDetailsResponseType.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
                    // Store PayerId in session to be used in DoExpressCheckout API operation
                    Session["PayerId"] = PayerId;

                    List <PaymentDetailsType> paymentDetails = responseGetExpressCheckoutDetailsResponseType.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
                    foreach (PaymentDetailsType paymentdetail in paymentDetails)
                    {
                        AddressType ShippingAddress = paymentdetail.ShipToAddress;
                        if (ShippingAddress != null)
                        {
                            Session["Address_Name"]            = ShippingAddress.Name;
                            Session["Address_Street"]          = ShippingAddress.Street1 + " " + ShippingAddress.Street2;
                            Session["Address_CityName"]        = ShippingAddress.CityName;
                            Session["Address_StateOrProvince"] = ShippingAddress.StateOrProvince;
                            Session["Address_CountryName"]     = ShippingAddress.CountryName;
                            Session["Address_PostalCode"]      = ShippingAddress.PostalCode;
                        }
                        Session["Currency_Code"]  = paymentdetail.OrderTotal.currencyID;
                        Session["Order_Total"]    = paymentdetail.OrderTotal.value;
                        Session["Shipping_Total"] = paymentdetail.ShippingTotal.value;
                        List <PaymentDetailsItemType> itemList = paymentdetail.PaymentDetailsItem;
                        foreach (PaymentDetailsItemType item in itemList)
                        {
                            Session["Product_Quantity"] = item.Quantity;
                            Session["Product_Name"]     = item.Name;
                        }
                    }
                }
                // # Error Values
                else
                {
                    List <ErrorType> errorMessages = responseGetExpressCheckoutDetailsResponseType.Errors;
                    string           errorMessage  = "";
                    foreach (ErrorType error in errorMessages)
                    {
                        //logger.Debug("API Error Message : " + error.LongMessage);
                        System.Diagnostics.Debug.WriteLine("API Error Message : " + error.LongMessage + "\n");
                        errorMessage = errorMessage + error.LongMessage;
                    }
                    //Redirect to error page in case of any API errors
                    CurrContext.Items.Add("APIErrorMessage", errorMessage);
                    Server.Transfer("~/Response.aspx");
                }
            }
            //Redirect to DoExpressCheckoutPayment.aspx page if the method chosen is MarkExpressCheckout
            //The buyer need not review the shipping address and shipping method as it's already provided
            string ecMethod = (string)(Session["ExpressCheckoutMethod"]);
            if (ecMethod.Equals("MarkExpressCheckout"))
            {
                Response.Redirect("DoExpressCheckoutPayment.aspx", false);
                Context.ApplicationInstance.CompleteRequest();
            }
        }
        // # Exception log
        catch (System.Exception ex)
        {
            // Log the exception message
            //logger.Debug("Error Message : " + ex.Message);
            System.Diagnostics.Debug.WriteLine("Error Message : " + ex.Message);
        }
    }