2015-03-03 85 views
0

我在我的asp.net mvc應用程序中集成了快速結賬。一切工作正常甚至,響應是成功的,但當我嘗試調用「GetExpressCheckoutDetailsResponseDetails」我在「PayerID」中變爲空。下面的字段是「requestDetails.PayerID」貝寶快遞結帳集成付款人ID爲空

public ActionResult PayPalExpressCheckout() 
    { 

     PaymentDetailsType paymentDetail = new PaymentDetailsType(); 
     CurrencyCodeType currency = (CurrencyCodeType)EnumUtils.GetValue("GBP", typeof(CurrencyCodeType)); 

     List<PaymentDetailsItemType> paymentItems = new List<PaymentDetailsItemType>(); 


     var AppCart = GetAppCart(); 

     foreach(var item in AppCart.Items) 
     { 
      PaymentDetailsItemType paymentItem = new PaymentDetailsItemType(); 
      paymentItem.Name = item.Name; 
      paymentItem.Description = item.Description; 
      double itemAmount = Convert.ToDouble(item.Price); 
      paymentItem.Amount = new BasicAmountType(CurrencyCodeType.GBP, itemAmount.ToString());     
      paymentItem.Quantity = 1;     

      paymentItems.Add(paymentItem); 

     } 

     paymentDetail.PaymentDetailsItem = paymentItems; 

     paymentDetail.PaymentAction = (PaymentActionCodeType)EnumUtils.GetValue("Sale", typeof(PaymentActionCodeType)); 
     paymentDetail.OrderTotal = new BasicAmountType(CurrencyCodeType.GBP, (AppCart.TotalPrice).ToString()); 
     List<PaymentDetailsType> paymentDetails = new List<PaymentDetailsType>(); 
     paymentDetails.Add(paymentDetail); 

     SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType(); 
     ecDetails.ReturnURL = "http://Orchard.Club/Purchase/PayPalExpressCheckoutAuthorisedSuccess"; 
     ecDetails.CancelURL = "http://Orchard.Club/Purchase/CancelPayPalTransaction"; 
     ecDetails.PaymentDetails = paymentDetails; 

     SetExpressCheckoutRequestType request = new SetExpressCheckoutRequestType(); 
     ecDetails.FundingSourceDetails = new FundingSourceDetailsType();    
     //request.Version = "104.0";    
     ecDetails.LandingPage = LandingPageType.BILLING; 
     ecDetails.SolutionType = SolutionTypeType.SOLE;      
     ecDetails.FundingSourceDetails.UserSelectedFundingSource = UserSelectedFundingSourceType.CREDITCARD; 
     request.SetExpressCheckoutRequestDetails = ecDetails; 


     SetExpressCheckoutReq wrapper = new SetExpressCheckoutReq(); 
     wrapper.SetExpressCheckoutRequest = request; 
     Dictionary<string, string> sdkConfig = new Dictionary<string, string>(); 
     sdkConfig.Add("mode", "sandbox"); 
     sdkConfig.Add("account1.apiUsername", "mrhammad-facilitator_api1.hotmail.com"); 
     sdkConfig.Add("account1.apiPassword", "1369812511"); 
     sdkConfig.Add("account1.apiSignature", "AJxdrs7c7cXRinyNUS5p1V4s1m4uAGR.wOJ7KzgkewEYmTOOtHrPgSxR"); 
     PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(sdkConfig); 

     SetExpressCheckoutResponseType setECResponse = service.SetExpressCheckout(wrapper); 


     if (setECResponse.Ack.Equals(AckCodeType.SUCCESS)) 
     { 
      GetExpressCheckoutDetailsReq getECWrapper = new GetExpressCheckoutDetailsReq(); 
      // (Required) A timestamped token, the value of which was returned by SetExpressCheckout response. 
      // Character length and limitations: 20 single-byte characters 
      getECWrapper.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(setECResponse.Token); 
      // # API call 
      // Invoke the GetExpressCheckoutDetails method in service wrapper object 
      GetExpressCheckoutDetailsResponseType getECResponse = service.GetExpressCheckoutDetails(getECWrapper); 

      // Create request object 
      DoExpressCheckoutPaymentRequestType expressrequest = new DoExpressCheckoutPaymentRequestType(); 
      DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType(); 
      expressrequest.DoExpressCheckoutPaymentRequestDetails = requestDetails; 

      requestDetails.PaymentDetails = getECResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails; 
      // (Required) The timestamped token value that was returned in the SetExpressCheckout response and passed in the GetExpressCheckoutDetails request. 
      requestDetails.Token = setECResponse.Token; 
      // (Required) Unique PayPal buyer account identification number as returned in the GetExpressCheckoutDetails response 
      requestDetails.PayerID = requestDetails.PayerID; 
      // (Required) How you want to obtain payment. It is one of the following values: 
      // * Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture. 
      // * Order – This payment is an order authorization subject to settlement with PayPal Authorization and Capture. 
      // * Sale – This is a final sale for which you are requesting payment. 
      // Note: You cannot set this value to Sale in the SetExpressCheckout request and then change this value to Authorization in the DoExpressCheckoutPayment request. 
      requestDetails.PaymentAction = (PaymentActionCodeType) 
       Enum.Parse(typeof(PaymentActionCodeType), "SALE");     

      // Invoke the API 
      DoExpressCheckoutPaymentReq expresswrapper = new DoExpressCheckoutPaymentReq(); 
      expresswrapper.DoExpressCheckoutPaymentRequest = expressrequest; 
      // # API call 
      // Invoke the DoExpressCheckoutPayment method in service wrapper object 
      DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(expresswrapper); 
      // Check for API return status 

      if (doECResponse.Ack.Equals(AckCodeType.FAILURE) || 
       (doECResponse.Errors != null && doECResponse.Errors.Count > 0)) 
      {         
       return RedirectToAction("PostPaymentFailure"); 
      } 
      else 
      { 
       TempData["TransactionResult"] = "Transaction ID:" + doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID + Environment.NewLine + "Payment status" + doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentStatus.Value.ToString(); 
       return RedirectToAction("SaveCustomer", "SignupOrLogin"); 
      }  
     } 
     else 
     { 
      return RedirectToAction("Error", "Purchase"); 
     } 
    } 
+1

嗯...你的代碼示例顯示您以單一順序調用Set,Get和DoEC。如果是這樣,那就是你的問題。如果您沒有將用戶重定向到PayPal來識別自己,您希望在SetEC和GetEC之間提供客戶的支付信息有什麼魔力? :) – geewiz 2015-03-03 14:42:21

回答

0

正如@geewiz提到的,你錯過了客戶重定向到PayPal批准付款的步驟。

請參閱How to Create One-Time Payments Using Express Checkout關於PayPal開發人員的指南,其中概述了與快速結帳有關的步驟。

在你的代碼,你將要檢索的EC令牌從setECResponse對象使用重定向,然後使用該令牌用戶重定向到PayPal網站:

SetExpressCheckoutResponseType setECResponse = service.SetExpressCheckout(wrapper); 

// Note: Add appropriate logic for targeting live URL based on your config settings 
var redirectUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + setECResponse.Token;