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 += "¤cy=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.
Related
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
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("¤cy_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
I have created a website and I want to send sms to my users. The sms is sent correctly to 0zeki server message but the problem is that it is being redirecting to the server URL, while I only want the sms to be sent and that there is no response redirect to the server can someone help please
Dim con As New SqlConnection(_start)
con.Open()
Dim sql1 As String = "SELECT TOP (1) Member.PhoneNumber FROM (SELECT TOP (2) BidID, Date, BiddingPrice, Status, AuctionID, BuyerID, WinningPrice from BID ORDER BY BidID DESC) AS tabel1 INNER JOIN Buyer ON tabel1.BuyerID = Buyer.BuyerID INNER JOIN Member ON Buyer.MemberID = Member.MemberID INNER JOIN Auction ON tabel1.AuctionID = Auction.AuctionID WHERE(Auction.AuctionID = #auction) ORDER BY tabel1.BidID"
Dim auction1 As Integer = Convert.ToInt32(lblauction.Text)
Dim sqlcommand As New SqlCommand(sql1, con)
sqlcommand.Parameters.AddWithValue("#auction", auction1)
Dim phone As String = sqlcommand.ExecuteScalar
Dim sql2 As String = "SELECT Item.Name FROM Item INNER JOIN Auction ON Item.ItemID = Auction.ItemID WHERE (Auction.AuctionID = #auction)"
Dim cmd As New SqlCommand(sql2, con)
cmd.Parameters.AddWithValue("#auction", auction1)
Dim name As String = cmd.ExecuteScalar
Dim message As String = "Your bid has been overbid please, Visit the Website to bid against on auction " + name + "thanks you"
Response.Redirect("http://localhost:9333/Ozeki?login=admin&password=abc123&action=sendMessage&messagetype=SMS&recepient=" + phone + "&messageData=" + message)
Just replace Response.Redirect with
WebRequest.Create("http://localhost:9333/Ozeki?login=admin&password=abc123&action=sendMessage&messagetype=SMS&recepient=" + phone + "&messageData=" + message)
.GetResponse();
It will call the service and won't redirect the page.
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
I have a web page with following fields
name,address,post
with three textboxes.I want to provide the search facility to the user.if user enter only the name and hit search it should search only by name, if user enter the values for all the textboxes it should query the database with all 3 values.like wise how can i write the sql query for all the searching possibilities?
select *
from Table1
where
(coalesce(#Name, '') = '' or Name = #Name) and
(coalesce(#Address, '') = '' or Address = #Address) and
(coalesce(#Post, '') = '' or Post = #Post)
I prefer this option for the query. If the user enters a value in only one of the fields, then pass a null to the parameter of the other respective fields.
Create PROCEDURE [dbo].[uspGetPeople]
#name varchar(50),
#Address varchar(200),
#Post varchar(5)
AS
SET NOCOUNT ON;
Select name, address, post
from tblPeople
where (name = #Name or #Name IS NULL) and
(address = #Address or #Address IS NULL) and
(post = #Post or #Post IS NULL)
A simple VB.NET example to call the stored procedure:
Dim strName As String = NameTextBox.Value
Dim strAddress as string = AddressTextBox.Value
Dim strPost as string = PostTextBox.Value
Dim strSQL As String = "uspGetPeople"
Dim strConn As String = "My.Database.ConnectionString"
Dim cn As New SqlConnection(strConn)
Dim cmd As New SqlCommand(strSQL, cn)
cmd.CommandType = CommandType.StoredProcedure
If not string.isnullorempty(strName) then
cmd.Parameters.AddWithValue("#Name", strName)
Else
cmd.Parameters.AddWithValue("#Name", dbnull.value)
End if
If not string.isnullorempty(strPost) then
cmd.Parameters.AddWithValue("#Post", strPost)
Else
cmd.Parameters.AddWithValue("#Post", dbnull.value)
End if
If not string.isnullorempty(strAddress) then
cmd.Parameters.AddWithValue("#Address", strAddress)
Else
cmd.Parameters.AddWithValue("#Address", dbnull.value)
End if
Dim dr As SqlDataReader
Using cn
cn.Open()
dr = cmd.ExecuteReader
While dr.Read
'process records returned
'dr("name")
'dr("address")
'dr("post")
End While
cn.Close()
End Using