代码之家  ›  专栏  ›  技术社区  ›  Phil

贝宝自适应支付API调用与C#.NET?最好是网络服务

  •  3
  • Phil  · 技术社区  · 16 年前

    我们的“网店”提供两个功能,购买一个特定的产品,并把它卖给我们。后端处理,如果用户可以出售或不。

    我已经决定使用贝宝的自适应支付这一个,因为它似乎是去做这种交易的方式。我从来没有实施过任何类型的商店,所以我完全没有这个。我最近才学习ASP.NET,主要是开发游戏,然后才转向这种开发。HTTP对我来说还是有魔力的,呵呵。。

    我可能会感到困惑,但我认为贝宝提供了一个与他们的自适应支付API网络服务。我谦虚的请求:一个很好的灵魂,他想分享一个用C#.NET实现自适应支付API调用的例子。如果他们不把它作为Web服务提供,我可能会发现它是一个自定义的.dll之类的。

    任何提示和例子都非常感谢! 谢谢你的阅读

    2 回复  |  直到 16 年前
        1
  •  9
  •   fregas    16 年前

    https://www.x.com/docs/DOC-1414

    和

    https://www.x.com/community/ppx/code_samples

    这是他们的xmlapi。我还没有让他们的Web服务使用vs.net中自动生成的代理来工作。还要记住,您必须为api info、buyer、seller等声明常量或变量。

            // API endpoint for the Refund call in the Sandbox
            string sAPIEndpoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay";
    
            // Version that you are coding against
            string sVersion = "1.1.0";
    
            // Error Langugage
            string sErrorLangugage = "en_US";
    
            // Detail Level
            string sDetailLevel = "ReturnAll";
    
            // Request Data Binding
            string sRequestDataBinding = "XML";
    
            // Response Data Binding
            string sResponseDataBinding = "XML";
    
            // Application ID
            string sAppID = "APP-80W284485P519543T";
    
            // other clientDetails fields
            string sIpAddress = "255.255.255.255";
            string sPartnerName = "MyCompanyName";
            string sDeviceID = "255.255.255.255";
    
            // Currency Code
            string sCurrencyCode = "USD";
    
            // Action Type
            string sActionType = "PAY";
    
            // ReturnURL and CancelURL used for approval flow
            string sReturnURL = "https://MyReturnURL";
            string sCancelURL = "https://MyCancelURL";
    
            // who pays the fees
            string sFeesPayer = "EACHRECEIVER";
    
            // memo field
            string sMemo = "testing my first pay call";
    
            // transaction amount
            string sAmount = "5";
    
            // supply your own sandbox accounts for receiver and sender
    
    
            string sTrackingID = System.Guid.NewGuid().ToString();
    
            // construct the XML request string
            StringBuilder sRequest = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            sRequest.Append("<PayRequest xmlns:ns2=\"http://svcs.paypal.com/types/ap\">");
            // requestEnvelope fields
            sRequest.Append("<requestEnvelope><errorLanguage>");
            sRequest.Append(sErrorLangugage);
            sRequest.Append("</errorLanguage><detailLevel>");
            sRequest.Append(sDetailLevel);
            sRequest.Append("</detailLevel></requestEnvelope>");
            // clientDetails fields
            sRequest.Append("<clientDetails><applicationId>");
            sRequest.Append(sAppID);
            sRequest.Append("</applicationId><deviceId>");
            sRequest.Append(sDeviceID);
            sRequest.Append("</deviceId><ipAddress>");
            sRequest.Append(sIpAddress);
            sRequest.Append("</ipAddress><partnerName>");
            sRequest.Append(sPartnerName);
            sRequest.Append("</partnerName></clientDetails>");
            // request specific data fields
            sRequest.Append("<actionType>");
            sRequest.Append(sActionType);
            sRequest.Append("</actionType><cancelUrl>");
            sRequest.Append(sCancelURL);
            sRequest.Append("</cancelUrl><returnUrl>");
            sRequest.Append(sReturnURL);
            sRequest.Append("</returnUrl><currencyCode>");
            sRequest.Append(sCurrencyCode);
            sRequest.Append("</currencyCode><feesPayer>");
            sRequest.Append(sFeesPayer);
            sRequest.Append("</feesPayer><memo>");
            sRequest.Append(sMemo);
            sRequest.Append("</memo><receiverList><receiver><amount>");
            sRequest.Append(sAmount);
            sRequest.Append("</amount><email>");
            sRequest.Append(Receiver);
            sRequest.Append("</email></receiver></receiverList><senderEmail>");
            sRequest.Append(Sender);
            sRequest.Append("</senderEmail><trackingId>");
            sRequest.Append(sTrackingID);
            sRequest.Append("</trackingId></PayRequest>");
    
    
            // get ready to make the call
            HttpWebRequest oPayRequest = (HttpWebRequest)WebRequest.Create(sAPIEndpoint);
            oPayRequest.Method = "POST";
            byte[] array = Encoding.UTF8.GetBytes(sRequest.ToString());
            oPayRequest.ContentLength = array.Length;
            oPayRequest.ContentType = "text/xml;charset=utf-8";
            // set the HTTP Headers
            oPayRequest.Headers.Add("X-PAYPAL-SECURITY-USERID", UserID);
            oPayRequest.Headers.Add("X-PAYPAL-SECURITY-PASSWORD", Pass);
            oPayRequest.Headers.Add("X-PAYPAL-SECURITY-SIGNATURE", Signature);
            oPayRequest.Headers.Add("X-PAYPAL-SERVICE-VERSION", sVersion);
            oPayRequest.Headers.Add("X-PAYPAL-APPLICATION-ID", sAppID);
            oPayRequest.Headers.Add("X-PAYPAL-REQUEST-DATA-FORMAT", sRequestDataBinding);
            oPayRequest.Headers.Add("X-PAYPAL-RESPONSE-DATA-FORMAT", sResponseDataBinding);
            // send the request
            Stream oStream = oPayRequest.GetRequestStream();
            oStream.Write(array, 0, array.Length);
            oStream.Close();
            // get the response
            HttpWebResponse oPayResponse = (HttpWebResponse)oPayRequest.GetResponse();
            StreamReader oStreamReader = new StreamReader(oPayResponse.GetResponseStream());
            string sResponse = oStreamReader.ReadToEnd();
            oStreamReader.Close();
    
        2
  •  1
  •   bob    14 年前

    我想那页能帮你找到你需要的东西。 这是一个实现PayPal界面的代码,没有创建pay now按钮。 请参见本页的 PayPal C#