2015-06-24 17 views
5

Quindi, stavo lottando con la testa o la coda fuori dalla documentazione di PayPal e ho sempre pensato che qualcosa non fosse giusto con la mia richiesta Web.Problemi con l'integrazione con Paypal Express Checkout (WEBREQUEST)

Così ho spogliato tutto il codice di nuovo al base e semplicemente presentato la richiesta via HTTP e il lato positivo è che io ora ottenere una risposta dal server sandbox PayPal dove ACK=Success e TOKEN=Valid-token-value-here ci sono alcune altre variabili tornati anche, ad esempio come CORRELATIONID e TIMESTAMP.

E quindi così ho provato alcuni dei campioni di richiesta web e ho semplicemente ottenuto uno schermo vuoto invece di essere reindirizzato su Paypal per il cliente (sandbox) per completare il pagamento.

Quindi se qualcuno può pubblicare il proprio metodo WebRequest sarebbe fantastico.

Ecco il codice che ho usato per la mia richiesta web, sono sicuro che sia sbagliato ma non riesco a individuare dove sta andando male.

Inoltre, quando eseguo il codice sul mio localhost durante il debug, tutto funziona correttamente e la chiamata viene completata con SUCCESS e viene ricevuto un TOKEN.

Quando lo eseguo dal vivo, ricevo l'errore numero 5 nell'eccezione di errore e anche il testo "host remoto non è riuscito a connettersi" nella DESCRIZIONE STATUS.

questo è il codice aggiornato

Function MakeWebRequest(ByVal pUseSandbox As Boolean, ByVal pRequestMethod As String, ByVal pReturnUrl As String, ByVal pCancelUrl As String, ByRef pRtnStatus As String, ByRef pRtnStatusId As HttpStatusCode, ByRef pRtnResponseString As String) As Boolean 
' 
Dim _sxHost As String = Nothing 
Dim _sxEndpoint As String = Nothing 
Dim _sxNameValCol As System.Collections.Specialized.NameValueCollection = Nothing 
Dim _sxResponseCol As System.Collections.Specialized.NameValueCollection = Nothing 
Dim _sxCounta As Integer = Nothing 
Dim _sxParamsString As String = Nothing 
' 
'-> Init 
_sxParamsString = "" 
MakeWebRequest = False 
_sxNameValCol = New System.Collections.Specialized.NameValueCollection() 
_sxResponseCol = New System.Collections.Specialized.NameValueCollection() 
If pUseSandbox Then 
    _sxHost = "http://www.sandbox.paypal.com" 
    _sxEndpoint = "https://api-3t.sandbox.paypal.com/nvp" 
Else 
    _sxHost = "http://www.paypal.com" 
    _sxEndpoint = "https://api-3t.paypal.com/nvp" 
End If 
'-> Create Request 
Try 
    '-> Key/Value Collection Params 
    _sxNameValCol.Add("METHOD", "SetExpressCheckout") 
    _sxNameValCol.Add("USER", _UserName) 
    _sxNameValCol.Add("PWD", _Password) 
    _sxNameValCol.Add("SIGNATURE", _Signature) 
    _sxNameValCol.Add("PAYMENTREQUEST_0_AMT", Format(_Basket.BasketTotalIncDelivery/100, "0.00")) 
    _sxNameValCol.Add("PAYMENTREQUEST_0_PAYMENTACTION", "Sale") 
    _sxNameValCol.Add("PAYMENTREQUEST_0_CURRENCYCODE", "GBP") 
    _sxNameValCol.Add("RETURNURL", pReturnUrl) 
    _sxNameValCol.Add("CANCELURL", pCancelUrl) 
    _sxNameValCol.Add("REQCONFIRMSHIPPING", "0") 
    _sxNameValCol.Add("NOSHIPPING", "2") 
    _sxNameValCol.Add("LOCALECODE", "EN") 
    _sxNameValCol.Add("BUTTONSOURCE", "PP-ECWizard") 
    _sxNameValCol.Add("VERSION", "93.0") 
    '-> UrlEncode 
    For _sxCounta = 0 To _sxNameValCol.Count - 1 
    If _sxCounta = 0 Then 
     _sxParamsString = _sxParamsString & _sxNameValCol.Keys(_sxCounta) & "=" & HttpUtility.UrlEncode(_sxNameValCol(_sxCounta)) 
    Else 
     _sxParamsString = _sxParamsString & "&" & _sxNameValCol.Keys(_sxCounta) & "=" & HttpUtility.UrlEncode(_sxNameValCol(_sxCounta)) 
    End If 
    Next 
    '-> Credentials (not used) 
    '_sxRequest.Credentials = CredentialCache.DefaultCredentials 
    Try 
    Dim _sxRequest As WebRequest = DirectCast(System.Net.WebRequest.Create(_sxEndpoint), System.Net.HttpWebRequest) 
    '-> Convert request to byte-array 
    Dim _sxByteArray As Byte() = Encoding.UTF8.GetBytes(_sxParamsString) 
    _sxRequest.Method = "POST"              'Our method is post, otherwise the buffer (_sxParamsString) would be useless 
    _sxRequest.ContentType = "application/x-www-form-urlencoded"     'We use form contentType, for the postvars 
    _sxRequest.ContentLength = _sxByteArray.Length         'The length of the buffer (postvars) is used as contentlength 
    Dim _sxPostDataStream As System.IO.Stream = _sxRequest.GetRequestStream()  'We open a stream for writing the postvars 
    _sxPostDataStream.Write(_sxByteArray, 0, _sxByteArray.Length)     'Now we write, and afterwards, we close 
    _sxPostDataStream.Close()              'Closing is always important! 
    '-> Create Response 
    Dim _sxResponse As HttpWebResponse = DirectCast(_sxRequest.GetResponse(), HttpWebResponse) 
    '-> Get Response Status 
    pRtnStatus = _sxResponse.StatusDescription 
    pRtnStatusId = _sxResponse.StatusCode 
    '-> Reponse Stream 
    Dim _sxResponseStream As Stream = _sxResponse.GetResponseStream()    'Open a stream to the response 
    '-> Response Stream Reader 
    Dim _sxStreamReader As New StreamReader(_sxResponseStream)      'Open as reader for the stream 
    pRtnResponseString = _sxStreamReader.ReadToEnd()        'Read the response string 
    MakeWebRequest = True 
    '-> Tidy up 
    _sxStreamReader.Close() 
    _sxResponseStream.Close() 
    _sxResponse.Close() 
    _sxByteArray = Nothing 
    _sxPostDataStream = Nothing 
    _sxRequest = Nothing 
    _sxResponse = Nothing 
    _sxResponseStream = Nothing 
    _sxStreamReader = Nothing 
    Catch ex As Exception 
    pRtnStatusId = Err.Number 
    pRtnStatus = "response(" & ex.Message & ")" 
    Decode(pRtnResponseString, _sxResponseCol) 
    pRtnResponseString = Stringify(_sxResponseCol) 
    End Try 
Catch ex As Exception 
    pRtnStatusId = Err.Number 
    pRtnStatus = "request(" & ex.Message & ")" 
    Decode(pRtnResponseString, _sxResponseCol) 
    pRtnResponseString = Stringify(_sxResponseCol) 
End Try 
'-> Tidy Up 
_sxHost = Nothing 
_sxEndpoint = Nothing 
_sxNameValCol = Nothing 
_sxResponseCol = Nothing 
_sxCounta = Nothing 
_sxParamsString = Nothing 
' 
End Function 

enter image description here

+0

Quali erano i codici di risposta HTTP per le pagine vuote? – BoffinbraiN

+0

Ho aggiornato la mia domanda, per favore vedi sopra per le informazioni sull'errore. – Zeddy

risposta

0

OK, quindi è ormai chiaro che non stai ricevendo alcuna risposta dal server perché il server non è in grado di connettersi ai server di PayPal affatto. Quindi, non si riceve risposta dal server e il messaggio è Unable to connect to the remote server. Quando ho provato, ho ricevuto una risposta HTTP 200 con il seguente:

TIMESTAMP=2015-07-07T09:07:39Z&CORRELATIONID=7f4d2313c9696&ACK=Failure&VERSION=93.0&BUILD=17276661&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Authentication/Authorization Failed&L_LONGMESSAGE0=You do not have permissions to make this API call&L_SEVERITYCODE0=Error 

Ovviamente questo perché ho provato con un nome utente e una password vuota.

Quindi, c'è qualcosa di sbagliato nella configurazione del server che impedisce di effettuare connessioni esterne, a livello di IIS oa causa della configurazione del firewall.

Senza essere fisicamente presente al tuo computer, non c'è molto che possiamo fare per rintracciare cosa lo blocca, ma puoi provare ad aprire richieste HTTP ad altri siti pubblici come Google.com e vedere se riescono.

+0

Potete consigliarmi come aprire una richiesta HTTP per un altro sito Web pubblico, per favore? Grazie – Zeddy

+0

Probabilmente vorrai dare un'occhiata a [questo] (https://stackoverflow.com/questions/92522/http-get-in-vb-net) e assicurarti di rilevare l'eccezione per trovare la causa. – BoffinbraiN

+0

Hiya BoffinbraiN, Grazie per aver cercato di aiutarmi. Non sono mai riuscito a scoprire cosa c'era di sbagliato, dato che il tempo era urgente, ho esternalizzato l'integrazione con PayPal e pagato per risolverlo. Visto che tu eri l'unica persona che si è offerta di aiutarti, sto contrassegnando la tua risposta come la risposta corretta e assegnandoti i 50 punti reputazione. Grazie per l'aiuto. – Zeddy