2012-08-27 120 views
1

首先,這涉及桌面應用程序而不是ASP .Net應用程序。如何從Paypal撥打DoDirectPayment API電話

我已經爲我的項目添加了一個Web引用,並構建了各種數據對象,如PayerInfo,Address和CreditCard。問題是,我如何實際調用DoDirectPaymentRequest並傳入對象?根據文檔,我使用CallerService和ProfileFactory對象,但我沒有這些對我有用。

任何想法如何從EXE調用API?

Regards

+0

我到底救助和所使用的貝寶NVP選項 –

回答

0

在項目中使用服務引用而不是Web引用。 您應該創建PayPalAPIInterfaceClientPayPalAPIAAInterfaceClient的一個實例。之後,您將可以調用DoDirectPayment。

實施例:

 DoDirectPaymentResponseType result; 
     using (_client = new PayPalAPIAAInterfaceClient()) 
     { 

      DoDirectPaymentRequestType pp_Request = new DoDirectPaymentRequestType(); 
      pp_Request.Version = _version; 
      pp_Request.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType(); 
      pp_Request.DoDirectPaymentRequestDetails.IPAddress = ipAddress; 
      pp_Request.DoDirectPaymentRequestDetails.CreditCard = new CreditCardDetailsType(); 
      pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber = CCNum; 

      // ..FILL DATA 

      // NOTE: The only currency supported by the Direct Payment API at this time is US dollars (USD). 
      pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD; 
      pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value = amountOfUSD; 

      var dp = new DoDirectPaymentReq 
      { 
       DoDirectPaymentRequest = pp_Request 
      }; 

      var credentials = new CustomSecurityHeaderType 
      { 
       Credentials = new UserIdPasswordType 
       { 
        Username = _username, 
        Password = _password, 
        Signature = _signature, 
        AppId = ApiId 
       } 
      }; 

      result = _client.DoDirectPayment(ref credentials, dp); 
     }