Google contacts v3 integration with ASP.NET VB - asp.net

I completed a google contacts integration and it worked until some time ago.
I started getting this error
The remote server returned an error: (400) Bad Request. at System.Net.HttpWebRequest.GetResponse()
at Google.GData.Client.OAuthBase.GetOAuth2AccessToken(OAuth2Parameters parameters, String requestBody) at Google.GData.Client.OAuthUtil.GetAccessToken(OAuth2Parameters parameters)
at Success.Page_Load(Object sender, EventArgs e)
and
Execution of request failed: https://www.google.com/m8/feeds/contacts/default/full at Google.GData.Client.GDataRequest.Execute()
at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
at Google.GData.Client.GDataGAuthRequest.Execute()
at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength)
at Google.GData.Client.Service.Query(FeedQuery feedQuery)
at Google.GData.Client.Feed1.get_AtomFeed()
at Google.GData.Client.Feed1.d__0.MoveNext()
at Success.PrintAllContacts(ContactsRequest cr)
Please what could be the problem.
Please find my codes below
Dim o2 As New OAuth2Parameters
o2.ClientId = ""
o2.ClientSecret = ""
o2.RedirectUri = "http://localhost:6498/Success"
o2.Scope = "https://www.googleapis.com/auth/contacts.readonly"
'o2.Scope = "https://www.google.com/m8/feeds"
o2.ApprovalPrompt = "force"
Dim iURL As String = OAuthUtil.CreateOAuth2AuthorizationUrl(o2)
Session("MailServer") = "Google"
Response.Redirect(iURL)
and on http://localhost:6498/Success
o2.AccessCode = Request.QueryString("Code") 'After the user has allowed contacts...bring to this page
OAuthUtil.GetAccessToken(o2)
Dim reqSettings As New RequestSettings("", "tobi.omitiran#gmail.com")
reqSettings.OAuth2Parameters = o2
reqSettings.
Dim contReq As New ContactsRequest(reqSettings)
Dim Contacts As Feed(Of Google.Contacts.Contact) = contReq.GetContacts()
Dim Name As String = Nothing
Dim iEmail As String = ""
Dim iPhone As String = Nothing
For Each objContact As Google.Contacts.Contact In Contacts.Entries
Dim iName As Name = objContact.Name
For Each emailId As EMail In objContact.Emails
iEmail = iEmail & emailId.Address.ToString() & ";"
Next
For Each Phone As PhoneNumber In objContact.Phonenumbers
iPhone = iPhone & Phone.Home.ToString() & "," & Phone.Work.ToString() & ","
Next
BLL.WriteLog(iName.FullName)
BLL.WriteLog(iEmail)
BLL.WriteLog(iPhone)
DL.Insert_Lead(iName.FullName, iEmail, iPhone, Session("iLeadInvite"))
Next

Related

Paypal Express Payment Execution

I'm developing in vb.net and as of right now I am not using any API's to receive transaction details I have only been using IPN and PDT variables to get my details however I began to notice that, when using Paypal Sandbox to test, after I go through the process of check out, I do receive all the variables of the details but in my test account, there are no transactions shown.
Do I need to be using the REST API in order to actually approve and execute the payment for the transaction in order to complete a transaction? I had assumed that the entire transaction had been completed successful since I was getting all of the details back but now that I noticed there aren't any transactions showing in my account I'm not so sure whats going on?
Here is the code I have been using to view transaction details
Dim authToken As String = "c37yqZU7UdVWesSoipRHFOwB3fFLv1CfOKWz10hqp0ULz6dYKrlCNuxp9d0"
Dim txToken As String = Request.QueryString("tx")
txToken = "2F816064M1280054A" '"6AX4295820157674V" '"5PD1935338742763G" ' '"70Y83841KE749971T" '"74C31896AA9005743""2RY90202U2008611C" '"0F824628H9566062P" '"5ET57654YS955312K" '
Dim strRequest As String = "cmd=_notify-synch&tx=" & txToken & "&at=" & authToken
'Dim Payerinfo As New PayerInfo
'Dim trans As New Transaction
'Dim tra As New PayPal.PayPalAPIInterfaceService.Model.GetTransactionDetailsReq
'post back to either sandbox or live
Dim strSandbox As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
Dim strLive As String = "https://www.paypal.com/cgi-bin/webscr"
Dim req As HttpWebRequest = CType(WebRequest.Create(strSandbox), HttpWebRequest)
'req.Headers = valHeader
'Set values for the request back
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = strRequest.Length
'Send the request to PayPal and get the response
Dim streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
streamOut.Write(strRequest)
streamOut.Close()
Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
Dim strResponse As String = streamIn.ReadToEnd()
streamIn.Close()
If Not String.IsNullOrEmpty(strResponse) Then
Dim results As New Dictionary(Of String, String)
Dim reader As New StringReader(strResponse)
Dim line As String = reader.ReadLine()
If line = "SUCCESS" Then
'FormView1.Visible = False
While True
Dim aLine As String
aLine = reader.ReadLine
If aLine IsNot Nothing Then
Dim strArr() As String
strArr = aLine.Split("=")
results.Add(strArr(0), strArr(1))
Else
Exit While
End If
End While
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'when code below is uncommented remove these two end if's below
Response.Write("<li> " + results("payer_id") + "</li>")
Response.Write("<li> " + results("txn_id") + "</li>")
' Displays all the keys for results, helps to see what the keys are named for writing to text file
For Each kvp As KeyValuePair(Of String, String) In results
Dim v1 As String = kvp.Key
Dim v2 As String = kvp.Value
Response.Write(v1.ToString _
+ ": " + v2 + "<br /> ")
Next
End If

Get Paypal Express cart Price right before checkout

I am using paypal express checkout and I'm trying to get the total value that is in the shopping cart when the user decides to checkout. My shipping rate is going to be based on the total price and although I have the shipping calculations filled out in my paypal account settings, the shipping cost is not showing up in the checkout screen. How would I grab the total shopping cart price right upon checkout so that I can add the shipping cost? What I have so far is only the values after the user has checked out and they are returned back to my website but at this point it is too late to add shipping.
Dim authToken As String = "sdf5414FdsfDFS5eEF52s336DFLLJUhhbuzek64"
Dim txToken As String = Request.QueryString("tx")
txToken = "4GGSES84eEWSS"
Dim strRequest As String = "cmd=_notify-synch&tx=" & txToken & "&at=" & authToken
'Dim Payerinfo As New PayerInfo
'Dim trans As New Transaction
'Dim tra As New PayPal.PayPalAPIInterfaceService.Model.GetTransactionDetailsReq
'post back to either sandbox or live
Dim strSandbox As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
Dim strLive As String = "https://www.paypal.com/cgi-bin/webscr"
Dim req As HttpWebRequest = CType(WebRequest.Create(strSandbox), HttpWebRequest)
'req.Headers = valHeader
'Set values for the request back
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = strRequest.Length
'Send the request to PayPal and get the response
Dim streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
streamOut.Write(strRequest)
streamOut.Close()
Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
Dim strResponse As String = streamIn.ReadToEnd()
streamIn.Close()
If Not String.IsNullOrEmpty(strResponse) Then
Dim results As New Dictionary(Of String, String)
Dim reader As New StringReader(strResponse)
Dim line As String = reader.ReadLine()
If line = "SUCCESS" Then
'FormView1.Visible = False
While True
Dim aLine As String
aLine = reader.ReadLine
If aLine IsNot Nothing Then
Dim strArr() As String
strArr = aLine.Split("=")
results.Add(strArr(0), strArr(1))
Else
Exit While
End If
End While
' Displays all the keys for results, helps to see what the keys are named for writing to text file
For Each kvp As KeyValuePair(Of String, String) In results
Dim v1 As String = kvp.Key
Dim v2 As String = kvp.Value
Response.Write(v1.ToString _
+ ": " + v2 + "<br /> ")
Next
End If
I have also been trying to declare a session variable and add to it every time the add to cart button is clicked but I see a problem in this because I don't know how long the items will stay in the paypal cart and if the session variable session runs out of time and is cleared, they will then receive free shipping since the shipping amount clears out. Is their any way to make this work?
Protected Sub AddToCartBtn_Click(sender As Object, e As EventArgs)
Session("CartAmount")
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)
Session("CartAmount") = (cartTotal + Session("CartAmount"))
End Sub
You can pass shopping cart values in the provided variable from the following url reference,
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/#id08A6HF080O3

Paypal confirmation when the transaction has been successfully done

I have redirected my website to Paypal on Buy Now button, but where should i place my code when the transaction has been successfully done.
Can someone help please? I need to change my status in my biding to paid.
Dim temp As String = Request.QueryString("user").ToString
Dim temp1 As Integer = Convert.ToInt32(temp)
Dim LastName As String
Dim WinningPrice As String
Dim email As String
Dim country As String
Dim Name As String
Dim FirstName As String
Using con1 As New SqlConnection(_start)
'Build your SQL String'
Dim sql1 As String = "SELECT Item.Name, BID.WinningPrice, Member.LastName, Member.FirstName,Member.Email, Member.Country FROM Item INNER JOIN Seller ON Item.SellerID = Seller.SellerID INNER JOIN Auction ON Item.ItemID = Auction.ItemID INNER JOIN BID ON Auction.AuctionID = BID.AuctionID INNER JOIN Member ON Seller.MemberID = Member.MemberID WHERE (Member.Status = 'Available') AND (Seller.SellerStatus = 'Available') AND (BID.Status = 'Won') AND (Auction.Status = 'Expired') and BID.BidID=#bidid"
'Open your connection'
con1.Open()
'Build your Command to execute'
Dim myCommand1 As New SqlCommand(sql1, con1)
'Grab your parameter'
'Add your parameter'
myCommand1.Parameters.Add("#bidid", SqlDbType.Int).Value = temp1
Dim reader As SqlDataReader = myCommand1.ExecuteReader()
If reader.HasRows Then
If reader.Read() Then
' etc
Name = reader.GetString(0)
WinningPrice = Convert.ToString(reader.GetDouble(1))
LastName = reader.GetString(2)
FirstName = reader.GetString(3)
email = reader.GetString(4)
country = reader.GetString(5)
Dim price As Object
'Converting String Money Value Into Decimal
price = Convert.ToDouble(WinningPrice)
'declaring empty String
Dim returnURL As String = ""
returnURL += "https://www.paypal.com/xclick/business=" + email
'Passing Item Name as dynamic
returnURL += Convert.ToString("&item_name=") & Name
'Assigning Name as Statically to Parameter
returnURL += Convert.ToString("&first_name") & FirstName
'Assigning Name as Statically to Parameter
returnURL += Convert.ToString("&last_name") & LastName
'Assigning City as Statically to Parameter
returnURL += Convert.ToString("&country") & country
'Passing Amount as Dynamic
returnURL += "&amount=" + price.ToString
'Passing Currency as your
returnURL += "&currency=USD"
'If transactioin has been successfully performed, redirect SuccessURL page- this page will be designed by developer
returnURL += "&return=" + ConfigurationManager.AppSettings("SuccessURL").ToString()
'retturn Url if Customer Wants To Cancel the Transaction
'If transactioin has been failed, redirect FailedURL page- this page will be designed by developer
returnURL += "&cancel_return=" + ConfigurationManager.AppSettings("FailedURL").ToString()
Response.Redirect(returnURL)
End If
End If
End Using
You are passing in a SuccessUrl parameter; when paypal completes it is going to send a notification to that page - so you should put code in the Page_Load event of your SuccessUrl to parse the query parms returned, and do whatever local processing you need to do there.

Use of Google Directions Service in VB.Net

I am using Google Maps api v3..
According to This Documentation I can able to get the Path between any 2 points as in the Example.
Not I want to get the Same using VB.Net.. I want to get the same result in the server side processing (Means want to get the Path[lat lon pair]).
I have tried with the code
Dim lat As Double = 17.38489
Dim lon As Double = 78.486939
Dim lat2 As Double = 20.296095
Dim lon2 As Double = 85.82459
'For counter As Integer = 0 To 1
Try
Dim myURL As String = "http://maps.googleapis.com/maps/api/directions/json?origin=" & lat.ToString("0.000000") & "," & lon.ToString("0.000000") & "&destination=" & lat2.ToString("0.000000") & "," & lon2.ToString("0.000000") & "&sensor=false"
Dim myRequest As HttpWebRequest = WebRequest.Create(myURL)
myRequest.Method = "GET"
' Add request headers
myRequest.KeepAlive = True
myRequest.Accept = "*/*"
myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;)"
myRequest.Headers.Add("Accept-Language: en-us")
myRequest.Referer = "http://www.google.com/mapmaker?ll=16.303005,81.05464&spn=0.021583,0.040684&z=15"
myRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-sg")
'myRequest.ContentType = "application/x-www-form-urlencoded"
Dim c As Char = "c"
Dim sb As New StringBuilder()
' Send the request and get the response
Dim myResponse As HttpWebResponse = myRequest.GetResponse
Dim reader As StreamReader = New StreamReader(myResponse.GetResponseStream())
sb.Append(reader.ReadToEnd())
reader.Close()
myResponse.Close()
Dim s As String = sb.ToString()
Dim ds As String = s
Response.Write(s)
Catch ex As Exception
End Try
Can any one Help me out..
I'm fairly sure doing this server-side is against the TOS? Plus there are limits to how many requests can be made from an IP address. What happens if you go over that limit? You need to check for error messages from Google and handle them gracefully. If you're paying for the service then there will probably be less restrictions.

ASP Net UPDATE Command not working

I have the following UPDATE command (written in VB) in my code.
Dim currentUser As String = User.Identity.Name
Dim myConnectionString As String = ConfigurationManager.ConnectionStrings("DBConnection").ConnectionString
Dim myCommand As New SqlCommand("UPDATE tblProfile SET Title= #Title, FirstName= #FirstName, LastName= #LastName, MiddleName= #MiddleName, HomePhoneNumber= #HomePhoneNumber, MobilePhoneNumber= #MobilePhoneNumber, Address= #Address, StreetName= #StreetName, StreetType= #StreetType, Suburb= #Suburb, PostCode= #PostCode, State= #State WHERE UserName = '" & currentUser & "'", New SqlConnection(myConnectionString))
myCommand.Connection.Open()
myCommand.Parameters.AddWithValue("#Title", Title.SelectedItem.Text)
myCommand.Parameters.AddWithValue("#FirstName", FirstName.Text)
myCommand.Parameters.AddWithValue("#LastName", LastName.Text)
If MiddleNames.Text = String.Empty Then
myCommand.Parameters.AddWithValue("#MiddleName", DBNull.Value)
Else
myCommand.Parameters.AddWithValue("#MiddleName", MiddleNames.Text)
End If
If HomePhoneNumber.Text = String.Empty Then
myCommand.Parameters.AddWithValue("#HomePhoneNumber", DBNull.Value)
Else
myCommand.Parameters.AddWithValue("#HomePhoneNumber", HomePhoneNumber.Text)
End If
If MobilePhoneNumber.Text = String.Empty Then
myCommand.Parameters.AddWithValue("#MobilePhoneNumber", DBNull.Value)
Else
myCommand.Parameters.AddWithValue("#MobilePhoneNumber", MobilePhoneNumber.Text)
End If
myCommand.Parameters.AddWithValue("#Address", AddressNumber.Text)
myCommand.Parameters.AddWithValue("#StreetName", StreetName.Text)
myCommand.Parameters.AddWithValue("#StreetType", StreetType.SelectedItem.Text)
myCommand.Parameters.AddWithValue("#Suburb", Suburb.Text)
myCommand.Parameters.AddWithValue("#PostCode", Postcode.Text)
myCommand.Parameters.AddWithValue("#State", State.SelectedItem.Text)
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
Dim myCommandPref As New SqlCommand("UPDATE tblPreferences SET Classical = #Classical, Comedy = #Comedy, Concerts = #Concerts, Dance = #Dance, DiningOut = #DiningOut, Exhibitions = #Exhibitions, Family = #Family, Festivals = #Festivals, Lifestyle = #Lifestyle, Musicals = #Musicals, Opera = #Opera, Rock = #Rock, Sports = #Sports, Theatre = #Theatre WHERE UserName = '" & currentUser & "'", New SqlConnection(myConnectionString))
myCommandPref.Connection.Open()
Dim boolClassical As Boolean = Preferences.Items(0).Selected
myCommandPref.Parameters.AddWithValue("#Classical", boolClassical.ToString)
Dim boolComedy As Boolean = Preferences1.Items(0).Selected
myCommandPref.Parameters.AddWithValue("#Comedy", boolComedy.ToString)
Dim boolConcerts As Boolean = Preferences.Items(1).Selected
myCommandPref.Parameters.AddWithValue("#Concerts", boolConcerts.ToString)
Dim boolDance As Boolean = Preferences1.Items(1).Selected
myCommandPref.Parameters.AddWithValue("#Dance", boolDance.ToString)
Dim boolDiningOut As Boolean = Preferences.Items(2).Selected
myCommandPref.Parameters.AddWithValue("#DiningOut", boolDiningOut.ToString)
Dim boolExhibitions As Boolean = Preferences1.Items(2).Selected
myCommandPref.Parameters.AddWithValue("#Exhibitions", boolExhibitions.ToString)
Dim boolFamily As Boolean = Preferences.Items(3).Selected
myCommandPref.Parameters.AddWithValue("#Family", boolFamily.ToString)
Dim boolFestivals As Boolean = Preferences1.Items(3).Selected
myCommandPref.Parameters.AddWithValue("#Festivals", boolFestivals.ToString)
Dim boolLifestyle As Boolean = Preferences.Items(4).Selected
myCommandPref.Parameters.AddWithValue("#Lifestyle", boolLifestyle.ToString)
Dim boolMusicals As Boolean = Preferences1.Items(4).Selected
myCommandPref.Parameters.AddWithValue("#Musicals", boolMusicals.ToString)
Dim boolOpera As Boolean = Preferences.Items(5).Selected
myCommandPref.Parameters.AddWithValue("#Opera", boolOpera.ToString)
Dim boolRock As Boolean = Preferences1.Items(5).Selected
myCommandPref.Parameters.AddWithValue("#Rock", boolRock.ToString)
Dim boolSports As Boolean = Preferences.Items(6).Selected
myCommandPref.Parameters.AddWithValue("#Sports", boolSports.ToString)
Dim boolTheatre As Boolean = Preferences1.Items(6).Selected
myCommandPref.Parameters.AddWithValue("#Theatre", boolTheatre.ToString)
myCommandPref.ExecuteNonQuery()
myCommandPref.Connection.Close()
When the user presses the button which fires that code, my page simply refreshes, but does not update the information in the database. I have looked around, and some people were saying you needed to have the primary key as the 'where' statement, so I made 'UserName' the primary key in both tables.
Could someone please help me to fix this.
I went back to my code after a few months today, and after a brief search through, found the problem... I needed to include 'if not IsPostBack then...' to my Page_Load. I was resetting my page each time the button was pressed, which reset the fields on my page, thus sending the same information back to my server - I was updating my server with the same information.
For anyone with the same problem, this helped me:
http://www.java-samples.com/showtutorial.php?tutorialid=1083

Resources