.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to use paypal webservice in ASP.NET project

Posted By: seattlegirl     Posted Date: December 20, 2011    Points:5   Category :ASP.Net
Hi,

Please tell how I can consume a paypal webservice in my asp.net project.

Responses
Author: Pravin             
Posted Date: December 22, 2011     Points: 20   

Hi,

Below code is in VB.net, which sends credit card user details as request to Merchant server and get the response as string.

Imports System.Data.SqlClient
Imports System.Text
Imports System.Net
Imports System.IO
Imports System.Data

Public Class COrder
Inherits System.Web.UI.Page
Const OnlineMartServer As String = "https://www.xxxxx.com/scripts/process_transaction.asp"
'Place Your OnlinePaymnet Service provider link
Const MerchantID As Integer = 1170000184 'Live CDG ID
Const TestMerchantID As Integer = 117000000 'Testing ID
#Region "Methods"
Function SendInformationToTDMerchantServicesTest1(ByVal CardOwner As String, ByVal CreditCardNumber As String, ByVal ExpiryMonth As String, ByVal ExpiryYear As String, ByVal CardCVD As String, ByVal OrderTotal As Decimal, ByVal OrderName As String, ByVal OrderEmail As String, ByVal OrderPhone As String, ByVal OrderAddress1 As String, ByVal OrderAddress2 As String, ByVal OrderCity As String, ByVal OrderProvince As String, ByVal OrderPostalCode As String, ByVal OrderCountry As String) As String
Dim lastordernumber As Integer = dsCorder.Tables(0).Rows(0)("UserId")
Dim lastTranNumber As Integer = dsCorder.Tables(0).Rows(0)("OrderId")
Dim ordernumber As String = (lastordernumber).ToString & "-" & (lastTranNumber).ToString
CreditCardNumber = Trim(Replace(CreditCardNumber, " ", ""))
Dim BeanstreamResponse As String = ""
Dim SystemData As String = "merchant_id=" & Server.UrlEncode(MerchantID.ToString()) & "&requestType=BACKEND&TermUrl=" & Server.UrlEncode(TermURL)
Dim TransactionData As String = "&trnCardOwner=" & Server.UrlEncode(CardOwner) & "&trnCardNumber=" & CreditCardNumber & "&trnExpMonth=" & ExpiryMonth & "&trnExpYear=" & ExpiryYear & "&trnCardCvd=" & CardCVD
Dim Order As String = "&trnOrderNumber=" & ordernumber & "&trnAmount=" & Server.UrlEncode(OrderTotal.ToString)
Dim BillingDetails As String = "&ordName=" & Server.UrlEncode(OrderName) & "&ordEmailAddress=" & Server.UrlEncode(OrderEmail) & "&ordPhoneNumber=" & Server.UrlEncode(OrderPhone) & "&ordAddress1=" & Server.UrlEncode(OrderAddress1) & "&ordAddress2=" & Server.UrlEncode(OrderAddress2) & "&ordCity=" & Server.UrlEncode(OrderCity) & "&ordProvince=" & Server.UrlEncode(OrderProvince) & "&ordPostalCode=" & Server.UrlEncode(OrderPostalCode) & "&ordCountry=" & Server.UrlEncode(OrderCountry)
Dim UrlAndDataToPost As String = OnlineMartServer & "?" & SystemData & TransactionData & Order & BillingDetails
Dim req As WebRequest = WebRequest.Create(UrlAndDataToPost)
' If required by the server, set the credentials.
req.Credentials = CredentialCache.DefaultCredentials
' Get the response.
Dim res As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
' Display the status.
'Response.Write(res.StatusDescription)
' Get the stream containing content returned by the server.
Dim dataStream As Stream = res.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
' Display the content.
' Cleanup the streams and the response.
reader.Close()
dataStream.Close()
res.Close()
Return responseFromServer
End Function
#End Region

End Class





Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend