简体   繁体   English

paypal express checkout integration payer id为null

[英]paypal express checkout integration payer id is null

i am integrating express checkout in my asp.net mvc application. 我正在我的asp.net mvc应用程序中集成express checkout。 everything works ok even, response is success but when i try to call "GetExpressCheckoutDetailsResponseDetails" i am getting null in "PayerID". 一切都工作正常,响应是成功,但当我尝试调用“GetExpressCheckoutDetailsResponseDetails”时,我在“PayerID”中得到null。 The field below is "requestDetails.PayerID" 下面的字段是“requestDetails.PayerID”

 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");
        }
    }

As @geewiz mentioned, you're missing the step of redirecting the customer to PayPal to approve the payment. 正如@geewiz所提到的,您错过了将客户重定向到PayPal以批准付款的步骤。

Refer to How to Create One-Time Payments Using Express Checkout guide on PayPal Developer that outlines the steps involved with Express Checkout. 请参阅如何使用 PayPal Developer上的快速结账创建一次性付款指南,其中概述了快速结账的相关步骤。

In your code, you will want to retrieve the EC token to use for the redirect from the setECResponse object and then redirect the customer to the PayPal site using that token: 在您的代码中,您将需要检索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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM