using System; using Encore.PayPal.Soap.API; public partial class ExpressCheckoutSOAP : System.Web.UI.Page { protected void checkoutButton_Click(object sender, EventArgs e) { 01 SetExpressCheckoutRequestType SetECReqType = new SetExpressCheckoutRequestType(); 02 SetExpressCheckoutRequestDetailsType SetECReqTypeDetails = new SetExpressCheckoutRequestDetailsType(); 03 SetExpressCheckoutResponseType SetECRes = new SetExpressCheckoutResponseType(); 04 SetExpressCheckoutReq SetECReq = new SetExpressCheckoutReq(); 05 SetECReqType.Version = Globals.Version; 06 SetECReqTypeDetails.OrderTotal = new BasicAmountType(); 07 SetECReqTypeDetails.OrderTotal.currencyID = CurrencyCodeType.USD; 08 SetECReqTypeDetails.OrderTotal.Value = (decimal.Parse(amountTextBox.Text)).ToString("f"); 09 string basePath = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, string.Empty) + Request.ApplicationPath; 10 SetECReqTypeDetails.ReturnURL = basePath + "/Sample/ExpressCheckoutSOAP.aspx"; 11 SetECReqTypeDetails.CancelURL = basePath + "/Default.aspx"; 12 SetECReqType.SetExpressCheckoutRequestDetails = SetECReqTypeDetails; 13 SetECReq.SetExpressCheckoutRequest = SetECReqType; 14 UserIdPasswordType user = new UserIdPasswordType(); 15 user.Username = Globals.UserName; 16 user.Password = Globals.Password; 17 user.Signature = Globals.Signature; 18 PayPalAPIAASoapBinding PPInterface = new PayPalAPIAASoapBinding(); 19 PPInterface.Url = Globals.ApiUrl; 20 PPInterface.RequesterCredentials = new CustomSecurityHeaderType(); 21 PPInterface.RequesterCredentials.Credentials = user; try { 22 SetECRes = PPInterface.SetExpressCheckout(SetECReq); 23 if (SetECRes.Ack == AckCodeType.Success) { 24 Session["OrderTotal"] = SetECReqTypeDetails.OrderTotal.Value; 25 String SBredirectURL = Globals.PayPalUrl + "webscr?cmd=_express-checkout&token="; 26 Response.Redirect(SBredirectURL + SetECRes.Token); } else { messageLabel.Text = SetECRes.Errors[0].LongMessage; } } catch (Exception ex) { messageLabel.Text = ex.ToString(); } } protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString.Get("token") != null) { 27 GetExpressCheckoutDetailsResponseType GetECDetailsRes = new GetExpressCheckoutDetailsResponseType(); 28 GetExpressCheckoutDetailsRequestType GetECDetailsReqType = new GetExpressCheckoutDetailsRequestType(); 29 GetExpressCheckoutDetailsReq GetECDetailsReq = new GetExpressCheckoutDetailsReq(); 30 GetECDetailsReqType.Version = Globals.Version; 31 GetECDetailsReqType.Token = Request.QueryString.Get("token"); 32 GetECDetailsReq.GetExpressCheckoutDetailsRequest = GetECDetailsReqType; 33 PayPalAPIAASoapBinding PPInterface = new PayPalAPIAASoapBinding(); 34 UserIdPasswordType user = new UserIdPasswordType(); 35 user.Username = Globals.UserName; 36 user.Password = Globals.Password; 37 user.Signature = Globals.Signature; 38 PPInterface.Url = Globals.ApiUrl; 39 PPInterface.RequesterCredentials = new CustomSecurityHeaderType(); 40 PPInterface.RequesterCredentials.Credentials = new UserIdPasswordType(); 41 PPInterface.RequesterCredentials.Credentials = user; try { 42 GetECDetailsRes = PPInterface.GetExpressCheckoutDetails(GetECDetailsReq); 43 if (GetECDetailsRes.Ack == AckCodeType.Success) { 44 DoExpressCheckoutPaymentRequestDetailsType DoECPmtReqDetails = new DoExpressCheckoutPaymentRequestDetailsType(); 45 DoExpressCheckoutPaymentRequestType DoECReqType = new DoExpressCheckoutPaymentRequestType(); 46 DoExpressCheckoutPaymentReq DoECPmtReq = new DoExpressCheckoutPaymentReq(); 47 DoExpressCheckoutPaymentResponseType DoECPmtRes = new DoExpressCheckoutPaymentResponseType(); 48 DoECReqType.Version = Globals.Version; 49 DoECPmtReqDetails.Token = GetECDetailsRes.GetExpressCheckoutDetailsResponseDetails.Token; 50 DoECPmtReqDetails.PayerID = GetECDetailsRes.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID; 51 DoECPmtReqDetails.PaymentAction = PaymentActionCodeType.Sale; 52 DoECPmtReqDetails.PaymentDetails = new PaymentDetailsType(); 53 DoECPmtReqDetails.PaymentDetails.OrderTotal = new BasicAmountType(); 54 DoECPmtReqDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD; 55 DoECPmtReqDetails.PaymentDetails.OrderTotal.Value = Session["OrderTotal"].ToString(); 56 DoECReqType.DoExpressCheckoutPaymentRequestDetails = DoECPmtReqDetails; 57 DoECPmtReq.DoExpressCheckoutPaymentRequest = DoECReqType; 58 PPInterface = new PayPalAPIAASoapBinding(); 59 PPInterface.Url = Globals.ApiUrl; 60 PPInterface.RequesterCredentials = new CustomSecurityHeaderType(); 61 PPInterface.RequesterCredentials.Credentials = new UserIdPasswordType(); 62 PPInterface.RequesterCredentials.Credentials = user; 63 DoECPmtRes = PPInterface.DoExpressCheckoutPayment(DoECPmtReq); 64 if (DoECPmtRes.Ack == AckCodeType.Success) { messageLabel.Text = "DoExpressCheckoutPayment Successful"; } else { messageLabel.Text = DoECPmtRes.Errors[0].LongMessage; } } else { messageLabel.Text = GetECDetailsRes.Errors[0].LongMessage; } } catch (Exception ex) { messageLabel.Text = ex.ToString(); } } } }
using System; using Encore.PayPal.Soap; public partial class ExpressCheckoutClass : System.Web.UI.Page { protected void checkoutButton_Click(object sender, EventArgs e) { 01 SoapSetExpressCheckout ppSet = new SoapSetExpressCheckout(); 02 ppSet.Request.OrderTotal = decimal.Parse(amountTextBox.Text); 03 ppSet.Request.ReturnPage = "Sample/ExpressCheckoutClass.aspx"; 04 ppSet.Request.CancelPage = "Default.aspx"; 05 if (ppSet.PostRequest()) { 06 Session["OrderTotal"] = ppSet.Request.OrderTotal.ToString("f"); 07 Response.Redirect(ppSet.Response.RedirectUrl); } else { messageLabel.Text = ppSet.Response.APIResponse.LongMessage; } } protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString.Get("token") != null) { 08 SoapGetExpressCheckoutDetails ppGet = new SoapGetExpressCheckoutDetails(); 09 ppGet.Request.Token = Request.QueryString.Get("token"); 10 if (ppGet.PostRequest()) { 11 SoapDoExpressCheckoutPayment ppPay = new SoapDoExpressCheckoutPayment(); 12 ppPay.Request.Token = ppGet.Response.Token; 13 ppPay.Request.PayerID = ppGet.Response.PayerInfo.PayerID; 14 ppPay.Request.PaymentDetails.OrderTotal = decimal.Parse(Session["OrderTotal"].ToString()); 15 if (ppPay.Post()) { messageLabel.Text = "DoExpressCheckoutPayment Successful"; } else { messageLabel.Text = ppPay.Response.ErrorList[0].LongMessage; } } else { messageLabel.Text = ppGet.Response.ErrorList[0].LongMessage; } } } }