views:

98

answers:

2

Hey all, i have converted some C# PayPal API Code over to VB.net. I have added that code to a class within my project but i can not seem to access it:

Imports System
Imports com.paypal.sdk.services
Imports com.paypal.sdk.profiles
Imports com.paypal.sdk.util

Namespace GenerateCodeNVP
Public Class GetTransactionDetails
    Public Sub New()
    End Sub

    Public Function GetTransactionDetailsCode(ByVal transactionID As String) As String
        Dim caller As New NVPCallerServices()
        Dim profile As IAPIProfile = ProfileFactory.createSignatureAPIProfile()

        profile.APIUsername = "xxx"
        profile.APIPassword = "xxx"
        profile.APISignature = "xxx"
        profile.Environment = "sandbox"
        caller.APIProfile = profile

        Dim encoder As New NVPCodec()
        encoder("VERSION") = "51.0"
        encoder("METHOD") = "GetTransactionDetails"
        encoder("TRANSACTIONID") = transactionID

        Dim pStrrequestforNvp As String = encoder.Encode()
        Dim pStresponsenvp As String = caller.[Call](pStrrequestforNvp)
        Dim decoder As New NVPCodec()
        decoder.Decode(pStresponsenvp)

        Return decoder("ACK")
    End Function
End Class
End Namespace

I am using this to access that class:

Private Sub cmdGetTransDetail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetTransDetail.Click
    Dim thereturn As String

    thereturn =GetTransactionDetailsCode("test51322")
End Sub

But it keeps telling me:

Error 2 Name 'GetTransactionDetailsCode' is not declared.

I'm new at calling classes in VB.net so any help would be great! :o)

David

Solved

Dim payPalAPI As New GenerateCodeNVP.GetTransactionDetails
Dim theReturn As String

theReturn = payPalAPI.GetTransactionDetailsCode("test51322")
A: 

Your GetTransactionDetailsCode method is an instance method of the GetTransactionDetails class, which means that you need an instance of the GetTransactionDetails class in order to call the method.

You can do that like this:

Dim instance As New GetTransactionDetails()

thereturn = instance.GetTransactionDetailsCode("test51322")

However, your method doesn't actually use the class instance, so you should change your GetTransactionDetails class to a Module instead.

SLaks
+2  A: 

You're probably getting that error because you need to call it like this:

Private Sub cmdGetTransDetail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetTransDetail.Click
    Dim thereturn As String
    Dim myTransaction as new GetTransactionDetails

    thereturn = myTransaction.GetTransactionDetailsCode("test51322")
End Sub

Or you can make the function be a public shared function and access it as if it were a static method

Avitus
That was close there, Avitus, but i had to put Dim payPalAPI As New GenerateCodeNVP.GetTransactionDetails.
StealthRT
I assumed it was within the same namespace so I didn't put it.
Avitus