VB.net中的贝宝API
大家好,我已经将一些C#PayPal API代码转换为VB.net。我已将该代码添加到项目中的一个类中,但我似乎无法访问它:VB.net中的贝宝API,vb.net,visual-studio-2008,Vb.net,Visual Studio 2008,大家好,我已经将一些C#PayPal API代码转换为VB.net。我已将该代码添加到项目中的一个类中,但我似乎无法访问它: 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
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
我正在使用此访问该类:
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
但它一直在告诉我:
Error 2 Name 'GetTransactionDetailsCode' is not declared.
我在VB.net中调用类方面是新手,因此任何帮助都将非常有用!:o)
大卫
解决
您的
GetTransactionDetailsCode
方法是GetTransactionDetails
类的实例方法,这意味着您需要GetTransactionDetails
类的实例才能调用该方法
您可以这样做:
Dim instance As New GetTransactionDetails()
thereturn = instance.GetTransactionDetailsCode("test51322")
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
但是,您的方法实际上并不使用类实例,因此您应该将
GetTransactionDetails
类改为模块
。您可能会遇到该错误,因为您需要这样调用它:
Dim instance As New GetTransactionDetails()
thereturn = instance.GetTransactionDetailsCode("test51322")
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
或者您可以将函数设置为一个
公共共享函数
,并像访问静态方法一样访问它,Avitus,但我必须将Dim payPalAPI作为新一代的DenVP.GetTransactionDetails。我假设它在同一个命名空间中,所以我没有将其放置。