用C#.NET贝宝自适应支付API调用? preferably与Web服务 [英] Paypal adaptive payment API call with C# .NET? Preferably with WebServices

查看:193
本文介绍了用C#.NET贝宝自适应支付API调用? preferably与Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我可能完全偏离了轨道,但现在这里有云:

Okay I might be entirely off track now but here goes:

我们的网上商店提供了两种功能,购买特定的产品和销售回给我们。后端处理,如果用户能卖还是不。

Our "webshop" offers two functions, buying a specific product and selling it back to us. Back-end handles if the user can sell or not.

我已经决定要使用支付宝的自适应支付这一块,因为它似乎要走的路做这类交易。我从来没有实施任何样的店,所以我完全绿色的这一个。我最近才知道ASP.NET,并主要转移到这种发展之前开发的游戏。 HTTP仍是魔术一定程度上对我嘿嘿..

I've decided to use Paypal's adaptive payments for this one as it seems the way to go doing these kinds of transactions. I've never implemented any kind of shop so I'm totally green with this one. I only recently learned ASP.NET and have mainly developed games before moving to this kind of development. HTTP is still some level of magic to me hehe..

我可能会搞不清楚,但我认为,贝宝提供与他们的自适应支付API一个Web服务。我小小的要求:一个很好的灵魂谁愿意分享实施与C#.NET的自适应支付API调用的一个例子。如果他们不提供它作为一个web服务我可能会发现它是一个自定义的.dll文件什么的。

I might be confused but I think paypal offers a webservice with their adaptive payment API. My humble request: A nice soul who wants to share an example of implementing an adaptive payment API call with C# .NET. If they don't offer it as a webservice I'll probably find it as a custom .dll or something.

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

Any tips and examples are highly appreciated! Thanks for reading

推荐答案

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

<一个href="https://www.x.com/community/ppx/$c$c_samples">https://www.x.com/community/ppx/$c$c_samples

这是他们的XML API。我还没有得到他们的web服务使用自动生成的代理在vs.net工作。同时请记住,你必须声明常量或变量的API的信息,买方,卖方,等等。

This is their xml api. I have not gotten their webservices to work using the auto-generated proxies in vs.net. Also keep in mind you'll have to declare constants or variables for the api info, buyer, seller, etc.

        // 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();

这篇关于用C#.NET贝宝自适应支付API调用? preferably与Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆