asp.netvb.netpaypalpaypal-sandboxreturnurl

Paypal Sandbox Return Url not working vb.net


I am in the beginning stages of working with paypal checkout in my website and I am trying to use a sandbox account to test some things out. I am able to go through and purchase the item with another sandbox account but after I purchase the item, it stays on the paypal checkout page and tells me that I have completed my payment and I will receive an email notification. I need it to return to some other website url so that I can try to get details of the transaction in my code behind. My code posted below is very basic and I do not have anything in the code itself about the return URL, I have filled it in under my sandbox account settings.

The second part of the problem is that I have not published my website yet, I am using the visual basic debugger to view and test my site in a browser and when I attempt to put my "local host" url into the return url it gives an error: "We were unable to validate the URL you have entered. Please check your entry and try again." an example of the url I am trying to put in is

http://localhost:11111/WebSite1/Parts_Catalog.aspx

As a test url just to attempt to start getting data back from the transaction I just put in google.com thinking that it would at least return to google with either an error or the returned query strings but it doesn't attempt to load any pages at all after the transaction.

How can I get the paypal sandbox return url to actually return to a URL? How can I enter my local host URL into the website preferences return url and actually get it to recognize my url as listed above?

Here is the markup code

<asp:ImageButton ID="AddToCartBtn" runat="server"
    RowIndex='<%# Container.DisplayIndex %>'
    ImageUrl="~/Pictures/ShoppingCart.png"
    OnClick="AddToCartBtn_Click" />

Here is the code I have so far for my addToCart button, I don't know if I need to add anything here or not for the return url

 Protected Sub AddToCartBtn_Click(sender As Object, e As ImageClickEventArgs)
 Dim Item As String = "Test"
    Dim price As String = cost
    Dim business As String = "test@aol.com"
    Dim itemNumber As String = str2
    Dim itemAmount As String = price
    Dim currencyCode As String = "USD"
    Dim addItem As Integer = 1

    Dim ppHref As StringBuilder = New StringBuilder()
    ppHref.Append("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_cart")
    ppHref.Append("&business=" + business)
    ppHref.Append("&item_name=" + itemName)
    ppHref.Append("&item_number=" + itemNumber)
    ppHref.Append("&amount=" + itemAmount)
    ppHref.Append("&currency_code=" + currencyCode)
    ppHref.Append("&add=" + addItem.ToString("#0"))
    Response.Redirect(ppHref.ToString(), True)
    Dim ReturnQaunity As String = itemAmount
    GetRouteUrl("/v1/payments/orders/<Order-Id>")
End Sub

I don't currently have anything in my page load event that deals with paypal.


Solution

  • Andre is right, the return URL must be accessible to PayPal.

    What you can do is use a generic URL (I guess google.com would work but it might be better to use one of your own) then edit the URL in the browser window.

    So return to something like http://www.test.com/return.html?paypalparms... Then when it displays in your browser change the URL to

    http://localhost/return.html?paypalparms...
    

    Then press enter.

    I have used a similar technique with PayPal PDT and IPN testing and it works fine.

    I would have replied to your comment but I haven't yet reached the dizzy heights of 50 reputation which allows me to comment everywhere.