![](/img/trans.png)
[英]How to Use PaymentAction in paypal adaptive chained payment system in c#
[英]Paypal adaptive payment API call with C# .NET? Preferably with WebServices
好吧,我現在可能完全偏離正軌但是這里:
我們的“網上商店”提供兩種功能,購買特定產品並將其出售給我們。 如果用戶可以銷售或不銷售后端句柄。
我決定使用Paypal的自適應支付,因為這似乎是進行這類交易的方式。 我從來沒有實施任何類型的商店,所以我對這個完全是綠色的。 我最近才學習ASP.NET,並且在轉向這種開發之前主要開發了游戲。 HTTP對我來說還是有些神奇的嘿嘿......
我可能會感到困惑,但我認為paypal提供了一個帶有自適應支付API的網絡服務。 我謙虛的要求:一個好心的人想要分享一個用C#.NET實現自適應支付API調用的例子。 如果他們不提供它作為web服務我可能會發現它是一個自定義.dll或其他東西。
任何提示和示例都非常感謝! 謝謝閱讀
https://www.x.com/docs/DOC-1414
和
https://www.x.com/community/ppx/code_samples
這是他們的xml api。 我還沒有使用vs.net中自動生成的代理來使用他們的web服務。 另外請記住,您必須為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();
我認為該頁面可以幫助您找到所需內容。 這是一個實現PayPal界面的代碼,無需創建立即付款按鈕。 在此頁面上查看PayPal C#
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.