2013-05-03 42 views
1

我想在ASP.NET C#代碼中使用SOAP 2.0 API設置PayPal快速結帳。首先,我嘗試使用沙箱,我創建了賣方/買方測試帳戶,導入的Web服務,然後我試圖讓的道理,在我的C#代碼,我有:快速PayPal結帳,無法創建SSL/TLS安全通道

 // Create the request object 
     SetExpressCheckoutRequestType pp_request = new SetExpressCheckoutRequestType(); 

     // Create the request details object 
     pp_request.SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType(); 
     pp_request.SetExpressCheckoutRequestDetails.PaymentAction = paymentAction; 
     pp_request.SetExpressCheckoutRequestDetails.PaymentActionSpecified = true; 

     pp_request.SetExpressCheckoutRequestDetails.OrderTotal = new BasicAmountType(); 

     pp_request.SetExpressCheckoutRequestDetails.OrderTotal.currencyID = currencyCodeType; 
     pp_request.SetExpressCheckoutRequestDetails.OrderTotal.Value = paymentAmount; 

     pp_request.SetExpressCheckoutRequestDetails.CancelURL = cancelURL; 
     pp_request.SetExpressCheckoutRequestDetails.ReturnURL = returnURL; 

     SetExpressCheckoutResponseType response = (SetExpressCheckoutResponseType) caller.Call("SetExpressCheckout", pp_request); 

,但該代碼的最後一行,它拋出錯誤:

請求已中止:無法創建SSL/TLS安全通道。

我做錯了嗎? 謝謝。

+0

你可以使用這個庫,而不是:https://nuget.org/packages/Moolah – 2013-05-03 16:03:50

+0

它沒有解決我的問題 – ihorko 2013-05-03 16:48:19

回答

1

您的代碼當然看起來是正確的,但PayPal API在涉及到幾件事情時可能會很挑剔。有一點需要注意的是,如果付款金額未達到小數點後兩位,它會產生例外情況 - 您是否可以確保確保這種情況?

還要確保您的配置值是正確的。除此之外,您發佈的代碼正是我以前用於SOAP API的代碼。

我停止使用SOAP API前一陣子有利於NVP API,它在我心目中是一個有點容易對付的:https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_NVPAPIOverview

我提供一個庫來完成所有的工作,爲您提供: https://github.com/davidduffett/Moolah

此處的說明顯示究竟如何使用PayPal快速結賬:https://github.com/davidduffett/Moolah#paypal-express-checkout

+0

大衛喜, 我試過你的libr ary,它給了我一個例外「請求被中止:無法創建SSL/TLS安全通道。」 你能指導我解決這個問題嗎? – 2016-01-22 17:08:44

+0

夥計,與圖書館的驚人的工作!,但尋找Sarim的評論。確實需要做一些小的修改。 @SarimShekhani:看到這裏! http://stackoverflow.com/a/34950820/1057052 – 2016-02-14 22:21:02

+0

等等!搞定了!太感謝了。記得我以前評論的鏈接?那麼,我們只需要添加ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;在使用「SetExpressCheckout」之前。在我的情況下,爲了安全起見,我在var gateway = new PayPalExpressCheckout(configuration)之前上傳它, – 2016-02-14 22:29:22