繁体   English   中英

使用.NET中的PayPal沙箱,“安全标头无效”

[英]'Security header is not valid' using PayPal sandbox in .NET

我在ASP.Net C#4.0中使用PayPal沙箱。 我添加了以下Web引用:

https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl
https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl 

当我运行此代码时:

PayPalAPIHelper.PayPalSandboxWS.SetExpressCheckoutReq req = new PayPalAPIHelper.PayPalSandboxWS.SetExpressCheckoutReq()
        {
            SetExpressCheckoutRequest = new PayPalAPIHelper.PayPalSandboxWS.SetExpressCheckoutRequestType()
            {
                Version = Version,
                SetExpressCheckoutRequestDetails = reqDetails
            }
        };

        // query PayPal and get token
        PayPalAPIHelper.PayPalSandboxWS.SetExpressCheckoutResponseType resp = BuildPayPalSandboxWebservice().SetExpressCheckout(req);

在我的resp对象中,错误消息显示:

安全标头无效

有人告诉我给它正确的API凭据。 我在developer.paypal.com上注册,我假设我使用的电子邮件地址和密码是我的有效凭据。 我如何以及在何处提供我的API凭据? 谢谢

您是否检查了web.config文件中的端点地址

这些应该参考以下网址

对于API证书=> SOAP https://api.sandbox.paypal.com/2.0/

对于API签名=> SOAP https://api-3t.sandbox.paypal.com/2.0/

如果您使用的是Signature,请使用以下代码

CustomSecurityHeaderType type = new CustomSecurityHeaderType();
            type.Credentials = new UserIdPasswordType()
            {
                Username = ConfigurationManager.AppSettings["PayPalUserName"], //Not paypal login username
                Password = ConfigurationManager.AppSettings["PayPalPassword"], //not login password
                Signature = ConfigurationManager.AppSettings["PayPalSignature"]
            };

要获得Paypal签名,请点击链接

欲了解更多信息, 请点击此

更新:

请检查以下代码,它对我有用

CustomSecurityHeaderType type = new CustomSecurityHeaderType();
            type.Credentials = new UserIdPasswordType()
            {
                Username = ConfigurationManager.AppSettings["PayPalUserName"],
                Password = ConfigurationManager.AppSettings["PayPalPassword"],
                Signature = ConfigurationManager.AppSettings["PayPalSignature"]
            };


            PaymentDetailsItemType[] pdItem = new PaymentDetailsItemType[1];
            pdItem[0] = new PaymentDetailsItemType() 
            { 
                Amount = new BasicAmountType(){currencyID = CurrencyCodeType.USD,Value = ItemPrice},
                Name = ItemName,
                Number = ItemNumber,
                Description = ItemDescription, 
                ItemURL = ItemUrl
            };

            SetExpressCheckoutRequestDetailsType sdt = new SetExpressCheckoutRequestDetailsType();
            sdt.NoShipping = "1";
            PaymentDetailsType pdt = new PaymentDetailsType()
            {
                OrderDescription = OrderDesc,
                PaymentDetailsItem = pdItem,
                OrderTotal = new BasicAmountType()
                {                    
                    currencyID = CurrencyCodeType.USD,
                    Value = ItemPrice
                }
            };

            sdt.PaymentDetails = new PaymentDetailsType[] { pdt };
            sdt.CancelURL = "http://localhost:62744/PaymentGateway/PaymentFailure.aspx";
            sdt.ReturnURL = "http://localhost:62744/PaymentGateway/ExpressCheckoutSuccess.aspx";

            SetExpressCheckoutReq req = new SetExpressCheckoutReq()
            {
                SetExpressCheckoutRequest = new SetExpressCheckoutRequestType()
                {
                    SetExpressCheckoutRequestDetails = sdt,
                    Version = "92.0"
                }
            };
            var paypalAAInt = new PayPalAPIAAInterfaceClient();
            var resp = paypalAAInt.SetExpressCheckout(ref type, req);
            if (resp.Errors != null && resp.Errors.Length > 0)
            {
                // errors occured
                throw new Exception("Exception(s) occured when calling PayPal. First exception: " +
                    resp.Errors[0].LongMessage);
            }

            Response.Redirect(string.Format("{0}?cmd=_express-checkout&token={1}",
                ConfigurationManager.AppSettings["PayPalOriginalUrl"], resp.Token));

暂无
暂无

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

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