1

I know this question will sound too general, but I have no idea where to look for the sloution.

I have made an application based on the Paypal Rest Api SDK, and it works on local machine (win 10, visual studio 2015, .net 4.5) but when I upload it to my server (server 2008R2 .net 4.5 ) when the application calls Paypal, there is an error on RECEIVE.

Invalid HTTP response The underlying connection was closed: An unexpected error occurred on a receive.

at PayPal.HttpConnection.Execute(String payLoad, HttpWebRequest httpRequest)

The only main difference between the two machines is that the server is under Domain Cotroller, and might refuse paypal callback, but I have more applications running on same server, and they work with paypal calls.

So I tried the original Paypal Rest Api Sample app called "Pizza App" and the result is same, the app runs all ok on my local machine, but it doesn't work on the server.

I turned on FailedRequestTracing log but it only gives a general 500 error on the page that triggers the call.

Does anyone have any idea where to start to find the problem?

My code looks like:

 protected void Page_Init(Object sender, EventArgs e)
    {
        if (HttpContext.Current.User.Identity.IsAuthenticated)
        {
            if (Request.QueryString["order[amount]"] != null && Request.QueryString["order[description]"] != null)
            {
                TextBoxOrderAmount.Text = Request.QueryString["order[amount]"];
                TextBoxOrderDescription.Text = Request.QueryString["order[description]"];
            }
            else
            {
                Response.Redirect("~/Account/SignIn.aspx");
            }
        }
        else
        {
            if (Request.QueryString["order[amount]"] != null && Request.QueryString["order[description]"] != null)
            {
                Response.Redirect("~/Account/SignIn.aspx" + Request.Url.Query);
            }
            else
            {
                Response.Redirect("~/Account/SignIn.aspx");
            }
        }
    }     

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void ButtonPlaceOrder_Click(object sender, EventArgs e)
    {
        if (HttpContext.Current.User.Identity.IsAuthenticated)
        {
            var email = HttpContext.Current.User.Identity.Name.Trim();
            var userID = GetSignedInUserID(email);

            if (DropDownPaymentMethod.SelectedIndex == 0)
            {
                
            }
            else if (DropDownPaymentMethod.SelectedIndex == 1)
            {
                DateTime createdDateTime = DateTime.Now;
                var createdAt = createdDateTime.ToString("yyyy-MM-dd hh:mm:ss.FFFFF");
                var updatedAt = createdDateTime.ToString("yyyy-MM-dd hh:mm:ss.FFFFF");
                bool isSuccess = Insert(userID, createdAt, updatedAt);
                if (isSuccess)
                {
                    int orderID = GetSignedInUserLastInsertedOrderID(userID);
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Orders/Orders.aspx?";
                    string requestUrl = Request.Url.OriginalString;
                    string returnUrl = baseURI + "Success=True&OrderID=" + orderID;
                    string cancelUrl = baseURI + "Success=False&OrderID=" + orderID;
                    var amount = TextBoxOrderAmount.Text.Trim();
                    var description = TextBoxOrderDescription.Text.Trim();
                    Payment pymnt = null;

                    pymnt = CreatePayment(email, PaymentMethod.paypal, amount, description, returnUrl, cancelUrl);
                    if (pymnt != null)
                    {
                        var pymntID = pymnt.id;
                        var state = pymnt.state;
                        var updatedAtDateTime = Convert.ToDateTime(pymnt.create_time);
                        var pymntUpdatedAt = updatedAtDateTime.ToString("yyyy-MM-dd hh:mm:ss.FFFFF");
                        bool isUpdateSuccess = Update(orderID, pymntID, state, amount, description, pymntUpdatedAt);
                        if (isUpdateSuccess)
                        {
                            string dredirectUrl = GetApprovalURL(pymnt);
                            Response.Redirect(dredirectUrl);
                        }
                    }
                    else
                    {
                        divAlertMessage.Visible = true;
                        divAlertMessage.Attributes["class"] = "alert fade in alert-error";
                        LabelAlertMessage.Text = "Order failed.";
                    }
                }

            }
            else if (DropDownPaymentMethod.SelectedIndex == 2)
            {
                Panel1.Visible = true;
            }
        }
    }
    #endregion
Community
  • 1
  • 1

0 Answers0