using PayPal.Api;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PayPalCS
{
public partial class PayPalCallback : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// From https://msdn.microsoft.com/en-us/library/system.web.httprequest.params(v=vs.110).aspx
// Create a string to contain the paramaters'
// information.
string paramInfo = "";
// Obtain a reference to the Request.Params
// collection.
NameValueCollection pColl = Request.Params;
string paymentId="";
string token = "";
string PayerID = "";
// Iterate through the collection and add
// each key to the string variable.
for (int i = 0; i <= pColl.Count - 1; i++)
{
paramInfo += "Key: " + pColl.GetKey(i) + "
";
// Create a string array that contains
// the values associated with each key.
string[] pValues = pColl.GetValues(i);
// Iterate through the array and add
// each value to the string variable.
for (int j = 0; j <= pValues.Length - 1; j++)
{
paramInfo += "Value:" + pValues[j] + "
";
}
if( pColl.GetKey(i) == "paymentId")
paymentId = pColl.GetValues(i)[0];
if (pColl.GetKey(i) == "token")
token = pColl.GetValues(i)[0];
if (pColl.GetKey(i) == "PayerID")
PayerID = pColl.GetValues(i)[0];
}
paramInfo = "paymentId:" + paymentId + "
" + paramInfo;
paramInfo = "token:" + token + "
" + paramInfo;
paramInfo = "PayerID:" + PayerID + "
" + paramInfo;
// Set a Label's Text property to the values
// contained in the string variable.
// This is from https://devtools-paypal.com/guide/pay_paypal
APIContext apiContext = new APIContext( Global.accessString );
Dictionary sdkConfig = new Dictionary();
sdkConfig.Add("mode", "sandbox");
apiContext.Config = sdkConfig;
Payment payment = new Payment();
payment.id = paymentId;
PaymentExecution paymentExecute = new PaymentExecution();
paymentExecute.payer_id = PayerID;
Payment p = payment.Execute(apiContext, paymentExecute);
paramInfo = "DONE!
" + paramInfo;
paramInfo = "state: " + p.state + "
" + paramInfo;
lblParams.Text = paramInfo;
}
}
}