c# - asp.net 中的 Paypal 快速结帐

标签 c# asp.net iis paypal

我正在使用下面的网络服务来实现快速结账

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

//Live
https://www.paypal.com/wsdl/PayPalSvc.wsdl

我从 belo 博客 URL 获得了帮助。

http://blog.effectlabs.com/post/2011/11/07/Paypal-Express-Checkout-with-C-using-Paypal-web-services.aspx

错误是 - 在响应对象中,当我在 xp-64 位(端口和 iis6 两者)、window server 2008(iis7 32 位模式)上运行相同的代码时,我得到“resp.Token is null”

但在 win-7 32 位 iis7 和端口上运行良好(没有错误, token 是 nut null 获取值(value))

我的代码在下面。

  protected void btnPaypal_Click(object sender, EventArgs e)
{

    CustomSecurityHeaderType type = new CustomSecurityHeaderType();

    type.Credentials = new UserIdPasswordType()
    {

        Username = "removed",
        Password = "removed",
        Signature = "removed"
    };

    SetExpressCheckoutRequestDetailsType sdt = new SetExpressCheckoutRequestDetailsType();
    sdt.NoShipping = "1";
    PaymentDetailsType pdt = new PaymentDetailsType()
    {
        OrderDescription = "Payment Details Sushant",
        OrderTotal = new BasicAmountType()
        {
            currencyID = CurrencyCodeType.USD,
            Value = "100.00"
        }
    };

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

    SetExpressCheckoutReq req = new SetExpressCheckoutReq()
    {
        SetExpressCheckoutRequest = new SetExpressCheckoutRequestType()
        {
            SetExpressCheckoutRequestDetails = sdt,
            Version = "60.0"
        }
    };
    PayPalAPIAAInterfaceClient 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 + resp.Errors.Length.ToString());
    }

// error is here.. that resp.Token is null on xp-64 bit port and iis6 both, but running fine on win-7 32 bit iis7 and port, and w

    Response.Redirect(string.Format("{0}?cmd=_express-checkout&token={1}",
            "https://www.paypal.com/cgi-bin/webscr", resp.Token));


}

最佳答案

在 PayPal Web Reference 的文件夹中,在文本编辑器中打开 Reference.cs 文件并搜索“System.Xml.XmlElement Any”

您会注意到如下代码:

[System.Xml.Serialization.XmlElementAttribute(Order=6)]
    public System.Xml.XmlElement Any {
        get {
            return this.anyField;
        }
        set {
            this.anyField = value;
            this.RaisePropertyChanged("Any");
        }
    }

现在替换

[System.Xml.Serialization.XmlElementAttribute(Order=6)]

[System.Xml.Serialization.XmlIgnoreAttribute()]

重新编译后运行您的应用程序。

您现在将看到 resp.Token 填充了所需的值

关于c# - asp.net 中的 Paypal 快速结帐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12952207/

相关文章:

c# - 无法使用表达式初始化 LambdaExpression

c# - 为什么我在 C# WinForms 到 MySQL 数据库的 SELECT 语句中出现此错误?

C#:DB2 首先测试可用连接

c# - 在编辑模式下动态更改 Gridview 列宽

asp.net - 一个带有 EntityDataSource 的 ASP.NET GridView 中两个相关数据库表的列

asp.net - 如何通过单击 MasterPage 上的按钮来处理用户控件中的回发

c# - 使用 MVC、C# 和 jQuery 导出为 CSV

apache - 单个主机上的多个 Web 服务器/服务...共享 ssl 证书?

asp.net - 如何赋予 Owin 用户身份?

sql-server - SQL Server 应该与 IIS 安装在同一台计算机上吗?