7

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 クレデンシャルを与える方法と場所を教えてください。ありがとう

4

1 に答える 1

4

web.config ファイルでエンドポイント アドレスを確認しましたか

これらは、次の URL を参照する必要があります

API 証明書の場合 => SOAP https://api.sandbox.paypal.com/2.0/

API 署名の場合 => SOAP https://api-3t.sandbox.paypal.com/2.0/

署名を使用している場合は、次のコードを使用します

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));
于 2012-09-18T13:18:44.233 に答える