PayPal API в VB.net

Эй все, я преобразовал некоторый PayPal C# Код 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()
    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)

David

Решенный

Dim payPalAPI As New GenerateCodeNVP.GetTransactionDetails
Dim theReturn As String

theReturn = payPalAPI.GetTransactionDetailsCode("test51322")
1
задан StealthRT 7 May 2010 в 19:08
поделиться

2 ответа

Вероятно, вы получаете эту ошибку, потому что вам нужно вызвать ее следующим образом:

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

Или вы можете сделать функцию публичной общей функцией и получить к ней доступ, как если бы это был статический метод

2
ответ дан 3 September 2019 в 00:44
поделиться

Метод GetTransactionDetailsCode является экземпляром класса GetTransactionDetails, что означает, что для вызова метода необходим экземпляр класса GetTransactionDetails.

Вы можете сделать это следующим образом:

Dim instance As New GetTransactionDetails()

thereturn = instance.GetTransactionDetailsCode("test51322")

Однако ваш метод фактически не использует экземпляр класса, поэтому вместо этого следует изменить класс GetTransactionDetails на Module.

0
ответ дан 3 September 2019 в 00:44
поделиться
Другие вопросы по тегам:

Похожие вопросы: