如何从Paypal调用DoDirectPayment API调用

时间:2012-08-27 18:46:51

标签: c# paypal

首先,这涉及桌面应用程序而不是ASP .Net应用程序。

我已经为我的项目添加了一个Web引用,并构建了各种数据对象,如PayerInfo,Address和CreditCard。问题是,我如何实际调用DoDirectPaymentRequest并传入对象?根据文档,我使用CallerService和ProfileFactory对象,但我没有这些可用。

我是如何从EXE调用API的?

此致

1 个答案:

答案 0 :(得分:0)

在项目中使用服务参考而不是Web参考。 您应该创建 PayPalAPIInterfaceClient PayPalAPIAAInterfaceClient 的实例。之后,您将能够调用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);
        }
相关问题