Paypal Sandbox PDT FAIL Error: 4020 - paypal

Dim authToken, txToken
Dim query
Dim objHttp
Dim sQuerystring
Dim sParts(), iParts(), aParts
Dim sResults(0, 0), sKey, sValue
Dim i, result
Dim firstName, lastName, itemName, mcGross, mcCurrency
authToken = "%Token From SandBox%"
txToken = Request.QueryString("tx")
query = "cmd=_notify-synch&tx=" & txToken & "&at=" & authToken
set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objHttp.open "POST", "https://www.sandbox.paypal.com/cgi-bin/webscr", False
objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHttp.Send query
sQuerystring = objHttp.responseText
I am getting Error "FAIL Error: 4020". Please guide me what I am missing.

It could be because:
LIVE account PDT token is used instead of Sandbox.
Incorrect token(check for white spaces,spelling)
If you still face issues, you can submit a ticket to MTS

Related

How can I get a JWT Access Token using Docusign 4.0.4.0

I have a legacy application written in VB6 (I Know!!) to which I am adding a DocuSign feature. I a using InterOp to run .NET code written is VS2019 VB.Net. The reason I am using 4.0.4.0 as this is the version I can successfully call using InterOp. I have all the code working except for requesting a JWT token. Does anyone have JWT code working under this version of the API ?
This is what I have working under later versions of DocuSign and am trying to replace
`Dim privatekey As Byte() = File.ReadAllBytes("docusign_private_key.key")
Dim result As Object = x.RequestJWTApplicationToken(gsSIGNERCLIENTID, docuSignAuthServer, privatekey, 1, scopes)
txtAccessToken.Text = result
'
' Second attempt at alternative
'
` Dim authToken As OAuth.OAuthToken = x.RequestJWTUserToken(gsSIGNERCLIENTID, gsUserIDGUID, docuSignAuthServer, privatekey, 1)
txtAccessToken.Text = authToken.access_token`
'
' Third attempt
'
Dim request = TryCast(System.Net.WebRequest.Create("https://account-d.docusign.com/oauth/token"), System.Net.HttpWebRequest)
request.Method = "POST"
request.Headers.Add("username", "user123")
request.Headers.Add("password", "123")
request.Headers.Add("auth_access_type", "read")
request.ContentLength = 0
Dim responseContent As String = ""
Using response = TryCast(request.GetResponse(), System.Net.HttpWebResponse)
Using reader = New System.IO.StreamReader(response.GetResponseStream())
responseContent = reader.ReadToEnd()
End Using
End Using
'
' Fifth attempt
'
Dim apiClient5 As New ApiClient(gsBASEPATH)
Dim authToken5 As OAuth.OAuthToken = apiClient5.RequestJWTUserToken(gsINTEGRATIONKEY, gsUserIDGUID, "https://account-d.docusign.com/oauth/token", privatekey, 1, scopes)
All results in 'Error while requesting server, received a non-successful HTPC code Error with response Body'
Your second attempt is correct:
Dim authToken As OAuth.OAuthToken = x.RequestJWTUserToken(gsSIGNERCLIENTID, gsUserIDGUID, docuSignAuthServer, privatekey, 1)
txtAccessToken.Text = authToken.access_token
AuthServer has to be "account-d.docusign.com"
The privateKey has to be the exact thing you got from DocuSign, including the new lines and all. To get it use this code:
File.ReadAllBytes(path) where path is the path on the disk to a plain text file with your private key.
gsSIGNERCLIENTID should be the GUID for the user that you use that has consent. You must make sure user gave consent by building a consent URL as explained in here:
https://developers.docusign.com/platform/auth/consent/obtaining-individual-consent/
If you did all of this correctly - it should work.

Google API v3 OAuth2 Service Account Token URL 404 Error

I'm getting a 404 error when attempting to post to this url:
https://www.googleapis.com/oauth2/v3/token
which is referenced in the Google Oauth documentaiton here:
https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatingjwt
Here's a snippet of code in case it helps:
Dim tokenRequestURL As String = "https://www.googleapis.com/oauth2/v3/token?grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9." & GetJWTclaimSet() & "." & GetJWTsignature()
Dim client As New WebClient()
Dim json = client.DownloadString(tokenRequestURL)
update copied from comment:
Dim tokenRequestURL As String "https://www.googleapis.com/oauth2/v3/token"
Dim client As New WebClient()
Dim params As New Specialized.NameValueCollection
params.Add("grant_type", "urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer")
params.Add("assertion", "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9." & GetJWTclaimSet() & "." & GetJWTsignature())
Dim responsebytes = client.UploadValues(tokenRequestURL, "POST", params)

Twitter oAuth 1.1 vb.net (401) unauthorized when posting tweet

I have spent some time on this and cannot figure out why I cannot post to twitter from my web site. I keep getting 401 unauthorized. I think that I was successfully posting to the 1.1 auth at one point but something changed in the last 6 weeks or so (not in my code, did oauth get stricter?).
Does anyone see anything that could be potentially causing the problem? Is there anything I can add to the code to get more info on why it's failing?
Private Function NewTweet(status As String) As WebResponse
Try
Dim oauth_token = "token" 'access token
Dim oauth_token_secret = "secret" 'acces token secret
Dim oauth_consumer_key = "key" 'consumer key
Dim oauth_consumer_secret = "secret" 'consumer secret
Dim oauth_version As String = "1.0"
Dim oauth_signature_method As String = "HMAC-SHA1"
Dim oauth_nonce = Convert.ToBase64String(New ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture)))
Dim timeSpan As TimeSpan = DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)
Dim oauth_timestamp As String = Convert.ToInt64(timeSpan.TotalSeconds).ToString(CultureInfo.InvariantCulture)
Dim resource_url As String = "https://api.twitter.com/1.1/statuses/update.json"
Dim baseFormat As String = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&status={6}"
Dim baseString As String = String.Format(baseFormat, oauth_consumer_key, oauth_nonce, oauth_signature_method, oauth_timestamp, oauth_token, oauth_version, Uri.EscapeDataString(status))
baseString = String.Concat("POST&", Uri.EscapeDataString(resource_url), "&", Uri.EscapeDataString(baseString))
Dim compositeKey As String = String.Concat(Uri.EscapeDataString(oauth_consumer_secret), "&", Uri.EscapeDataString(oauth_token_secret))
Dim oauth_signature As String
Using hasher As New HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey))
oauth_signature = Convert.ToBase64String(hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString)))
End Using
'-------------------------------------------------------
Dim headerFormat = "OAuth " & _
"oauth_consumer_key=""{0}"", " & _
"oauth_nonce=""{1}"", " & _
"oauth_signature=""{2}"", " & _
"oauth_signature_method=""{3}"", " & _
"oauth_timestamp=""{4}"", " & _
"oauth_token=""{5}"", " & _
"oauth_version=""{6}"""
Dim authHeader = String.Format(headerFormat, _
Uri.EscapeDataString(oauth_consumer_key), _
Uri.EscapeDataString(oauth_nonce), _
Uri.EscapeDataString(oauth_signature), _
Uri.EscapeDataString(oauth_signature_method), _
Uri.EscapeDataString(oauth_timestamp), _
Uri.EscapeDataString(oauth_token), _
Uri.EscapeDataString(oauth_version))
'-------------------------------------------------------
Dim postBody As String = "status=" & Uri.EscapeDataString(status)
ServicePointManager.Expect100Continue = False
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(resource_url), HttpWebRequest)
request.Headers.Add("Authorization", authHeader)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8"
Using stream As Stream = request.GetRequestStream()
Dim content As Byte() = ASCIIEncoding.ASCII.GetBytes(postBody)
stream.Write(content, 0, content.Length)
End Using
Dim response As WebResponse = request.GetResponse()
Return response
Catch ex As Exception
Return Nothing
End Try
End Function

Using ADO in VBA to connect to PostgreSQL

I am having trouble finding clear and reliable examples of connecting to a PostgreSQL database from Excel using VBA ADO. Admittedly, I am new to VBA and most examples and tutorials are very Access or MSSQL centered. (I work mostly in Ruby, Rails, Perl and PostgreSQL.)
I am looking for code to connect and return a simple query (SELECT * FROM customers;) to an Excel sheet. Connection parameters (server ip, user, pass, database) are located within cells in a separate worksheet.
I appreciate your help and patience.
Code:
Sub ConnectDatabaseTest()
Dim cnn As ADODB.connection
Dim cmd As ADODB.Command
Dim param As ADODB.Parameter
Dim xlSheet As Worksheet
Dim rs As ADODB.Recordset
Dim sConnString As String
Dim i As Integer
' Connection Parameters
Dim strUsername As String
Dim strPassword As String
Dim strServerAddress As String
Dim strDatabase As String
' User:
strUsername = Sheets("CONFIG").Range("B4").Value
' Password:
strPassword = Sheets("CONFIG").Range("B5").Value
' Server Address:
strServerAddress = Sheets("CONFIG").Range("B6").Value
' Database
strDatabase = Sheets("CONFIG").Range("B3").Value
Set xlSheet = Sheets("TEST")
xlSheet.Activate
Range("A3").Activate
Selection.CurrentRegion.Select
Selection.ClearContents
Range("A1").Select
Set cnn = New ADODB.connection
sConnString = "DRIVER={PostgreSQL Unicode};DATABASE=" & strDatabase & ";SERVER=" & strServerAddress & _
";UID=" & strUsername & ";PWD=" & strPassword
cnn.Open sConnString
cmd.ActiveConnection = cnn
Dim strSQL As String
strSQL = "SELECT * FROM customers"
cmd.CommandType = ADODB.CommandTypeEnum.adCmdText
cmd.ActiveConnection = cnn
cmd.CommandText = strSQL
...
It seems to break here: cmd.ActiveConnection = cnn
EDIT: added sample code.
EDIT: sConnString gets set to:
DRIVER={PostgreSQL35W};DATABASE=my_database;SERVER=1.2.3.4;UID=analyst;PWD=sekrit
UPDATE 2/7: I changed the 'DRIVER' parameter in the connection string:
sConnString = "DRIVER={PostgreSQL Unicode};DATABASE=" & strDatabase & ";SERVER=" & strServerAddress & _
";UID=" & strUsername & ";PWD=" & strPassword & ";"
...and I get a different error: 'Run-time error 91: Object variable or With block variable not set'
Hm. Ideas?
I wan't using a DSN as I am using an ODBC driver as opposed to OLE DB. By referencing a DSN, the above code works with very few changes.
See this question for how I found the answer once I began to suspect OLE DB/ODBC to the issue.
Does ADO work with ODBC drivers or only OLE DB providers?
New Code here:
Sub GetCustomers()
Dim oConn As New ADODB.connection
Dim cmd As New ADODB.Command
' Connection Parameters
Dim strUsername As String
Dim strPassword As String
Dim strServerAddress As String
Dim strDatabase As String
' User:
strUsername = Sheets("CONFIG").Range("B4").Value
' Password:
strPassword = Sheets("CONFIG").Range("B5").Value
' Server Address:
strServerAddress = Sheets("CONFIG").Range("B6").Value
' Database
strDatabase = Sheets("CONFIG").Range("B3").Value
oConn.Open "DSN=my_system_dsn;" & _
"Database=" & strDatabase & ";" & _
"Uid=" & strUsername & ";" & _
"Pwd=" & strPassword
Set xlSheet = Sheets("CUSTOMERS")
xlSheet.Activate
Range("A3").Activate
Selection.CurrentRegion.Select
Selection.ClearContents
Range("A1").Select
Dim strSQL As String
strSQL = "SELECT * FROM customers"
cmd.CommandType = ADODB.CommandTypeEnum.adCmdText
cmd.ActiveConnection = oConn
cmd.CommandText = strSQL
Set rs = New ADODB.Recordset
Set rs = cmd.Execute
For i = 1 To rs.Fields.Count
ActiveSheet.Cells(3, i).Value = rs.Fields(i - 1).Name
Next i
xlSheet.Range(xlSheet.Cells(3, 1), _
xlSheet.Cells(3, rs.Fields.Count)).Font.Bold = True
ActiveSheet.Range("A4").CopyFromRecordset rs
xlSheet.Select
Range("A3").Select
Selection.CurrentRegion.Select
Selection.Columns.AutoFit
Range("A1").Select
rs.Close
oConn.Close
Set cmd = Nothing
Set param = Nothing
Set rs = Nothing
Set cnn = Nothing
Set xlSheet = Nothing
End Sub
The System DSN is configured to use the PostgreSQL Unicode driver. I chose not to use OLE DB even though there is a provider available. If you look at PGFoundry, you will see it has many problems and has not been updated in several years.
In the original Code, "PostgreSQL35W" is a DSN name which included the default host and port. When you changed to "PostgreSQL Unicode", it is a driver and your connection string is lacking the value for the port. Remember to access PostgreSQL directly from driver, you need at least 5 parameters:
host
port
userid
password
database
If you are using DSN, some parameters may be defined as default.
Not sure about the details of the actual DB connection, but there is a simple although common mistake with your statement: you need to use 'set' when working with objects:
set cmd.ActiveConnection = cnn
Set cmd = New ADODB.Command
cmd.ActiveConnection = cnn

Crystal Report viewer- Server has not yet been opened

I Have a vb6 application using crystal report 8.5 and sql server 2005.My issue is that when I print report i get Server has not yet been opened.Here is my code in vb.:
Option Explicit
Dim ctr As Integer
Dim cn As New ADODB.Connection--Provider=SQLOLEDB.1;Password=password;Persist Security Info=True;User ID=user ID;Initial Catalog=database Name;Data Source=server Name
Dim crApp As CRAXDRT.Application
Dim crReport As CRAXDRT.Report
Dim crtable As CRAXDRT.DatabaseTable
Private Sub prin_Click()
Dim rs As New ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = MDI1.txtado
cn.Open
Set rs = New ADODB.Recordset
rs.Open "select * from temp_abs_yes", cn, adOpenKeyset, adLockOptimistic
Set crApp = New CRAXDRT.Application
Set crReport = crApp.OpenReport("C:\Users\user1.dom\Desktop\ANP\abs_yes.rpt")
crReport.Database.Tables.Item(1).SetLogOnInfo "servername", "databasename", "user", "password"
crReport.Database.Tables.Item(1).SetDataSource rs, 3
crReport.DiscardSavedData
Viewer.ReportSource = crReport
Viewer.ViewReport
rs.close
Set rs = Nothing
Set crReport = Nothing
Set crApp = Nothing
End Sub
I think doing "SetLogOnInfo" is innecesary in that case, as you are assigning the data to report
Probably is not your case, but for the help of someone else.
I got that error when I assigned the servername parameter incorrectly.
The correct parameters I used for logon (for an oracle DB):
[...]Item(1).SetLogOnInfo "[tnsnames]", "", "[db user]", "[db password]"
I resolved by updating dll
p2soledb.dll
in c:\Windows\Crystal I got the details from here