使用 C# .NET 调用 Paypal 自适应支付 API?最好使用 Web 服务

发布于 2024-09-02 06:58:38 字数 385 浏览 2 评论 0原文

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

我们的“网上商店”提供两种功能,购买特定产品并将其卖回给我们。后端处理用户是否可以出售。

我决定为此使用 Paypal 的自适应支付,因为这似乎是进行此类交易的最佳方式。我从来没有建立过任何类型的商店,所以我对这个商店完全不感兴趣。我最近才学习ASP.NET,在转向此类开发之前主要开发过游戏。 HTTP 对我来说仍然有一定程度的魔力,呵呵。

我可能会感到困惑,但我认为 paypal 提供了一个带有自适应支付 API 的网络服务。我的谦卑请求:一位善良的人想要分享一个使用 C# .NET 实现自适应支付 API 调用的示例。如果他们不将其作为网络服务提供,我可能会发现它是自定义的 .dll 或其他东西。

非常感谢任何提示和示例! 感谢您的阅读

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.

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..

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.

Any tips and examples are highly appreciated!
Thanks for reading

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挖鼻大婶 2024-09-09 06:58:38

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

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

这是他们的 xml api。我还没有让他们的网络服务使用 vs.net 中自动生成的代理来工作。另请记住,您必须为 api 信息、买家、卖家等声明常量或变量。

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

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

and

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

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();
靑春怀旧 2024-09-09 06:58:38

我认为该页面将帮助您找到所需的内容。
这是一个实现 PayPal 界面的代码,但没有创建立即付款按钮。
请参阅此页面 PayPal C#

I think that page would help you find what you need.
It's a code implementing PayPal interface without create the pay now button.
See on this page PayPal C#

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文