public static PayerInfoType GetExpressCheckout(string token) { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; using (var client = new PayPalAPIAAInterfaceClient(new BasicHttpsBinding(), new EndpointAddress(EndpointUrl))) { var credentials = new CustomSecurityHeaderType() { Credentials = new UserIdPasswordType() { Username = APIUserName, Password = APIPassword, Signature = APISignature } }; GetExpressCheckoutDetailsReq req = new GetExpressCheckoutDetailsReq() { GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType() { Version = "121.0", Token = token } }; var resp = client.GetExpressCheckoutDetails(ref credentials, req); string errors = CheckErrors(resp); if (errors == String.Empty) { return(resp.GetExpressCheckoutDetailsResponseDetails.PayerInfo); } return(new PayerInfoType() { PayerID = errors }); } }
private PayPalAPIAAInterfaceClient CreatePaypalConnection() { PayPalAPIAAInterfaceClient api = new PayPalAPIAAInterfaceClient(); api.Endpoint.Address = new System.ServiceModel.EndpointAddress("https://api-3t.sandbox.paypal.com/nvp"); return(api); }
public async Task <AckCodeType> DoExpressCheckoutAsync(DoExpressCheckoutPaymentReq request) { PayPalAPIAAInterfaceClient client = new PayPalAPIAAInterfaceClient(); var response = await client.DoExpressCheckoutPaymentAsync(GetAuthorizationRequest(), request); return(response.DoExpressCheckoutPaymentResponse1.Ack); }
public ActionResult BuyProduct(int?productId) { if (!productId.HasValue) { return(RedirectToAction("PayPalCancel")); } Order order = PayPalHelper.CreateOrder(productId.Value); if (order == null) { return(RedirectToAction("PayPalCancel")); } string domain = PayPalHelper.GetDomainName(Request); var returnURL = domain + "/Payment/PaymentDetails"; var cancelURL = domain + "/Payment/PaypalCancel"; SetExpressCheckoutReq request = PayPalHelper.GetSetExpressCheckoutReq(order, returnURL, cancelURL); CustomSecurityHeaderType credentials = PayPalHelper.GetPayPalCredentials(); PayPalAPIAAInterfaceClient client = new PayPalAPIAAInterfaceClient(); SetExpressCheckoutResponseType response = client.SetExpressCheckout(ref credentials, request); if (response.Errors != null && response.Errors.Length > 0) { throw new Exception("Exception occured when calling PayPal: " + response.Errors[0].LongMessage); } string redirectUrl = string.Format("{0}?cmd=_express-checkout&token={1}", PayPalHelper.GetPaypalRequestUrl(), response.Token); return(Redirect(redirectUrl)); }
public ShoppingCartPayment Pay(ShoppingCartPayment orderDetails) { if (string.IsNullOrEmpty(orderDetails.authToken)) { return(orderDetails); } if (!CheckUserBuyer(orderDetails.authToken)) { return(orderDetails); } if (orderDetails.amount <= 0.01) { return(orderDetails); } PayPalAPIAAInterfaceClient pp = CreatePaypalConnection(); CustomSecurityHeaderType credentials = CreateHeaderCredentials(orderDetails.username, orderDetails.password, orderDetails.signature); SetExpressCheckoutReq request = CreateExpressCheckoutRequest(orderDetails.amount); try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; var response = pp.SetExpressCheckout(ref credentials, request); if (response.Ack == AckCodeType.Success) { orderDetails.successfulPayment = true; return(orderDetails); } } catch (Exception ex) { } orderDetails.successfulPayment = false; return(orderDetails); }
protected string GetPaypalTransactionToken(decimal price, string returnUrl, string cancelUrl) { var client = new PayPalAPIAAInterfaceClient(); var credentials = GetPaypalCredentials(); var request = new SetExpressCheckoutReq { SetExpressCheckoutRequest = new SetExpressCheckoutRequestType { Version = "89.0", SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType { PaymentAction = PaymentActionCodeType.Sale, OrderTotal = new BasicAmountType { Value = price.ToString(), currencyID = CurrencyCodeType.USD }, PaymentActionSpecified = true, ReturnURL = returnUrl, CancelURL = cancelUrl } } }; var response = client.SetExpressCheckout(ref credentials, request); if (response.Ack == AckCodeType.Failure) { throw new InvalidOperationException("Paypal returned the following error: " + response.Errors.FirstOrDefault().LongMessage); } return(response.Token); }
public ActionResult PaymentDetails(string token) { if (token.IsNullOrWhiteSpace()) { return(RedirectToAction("PayPalCancel")); } GetExpressCheckoutDetailsReq req = PayPalHelper.GetGetExpressCheckoutDetailsReq(token); CustomSecurityHeaderType credentials = PayPalHelper.GetPayPalCredentials(); PayPalAPIAAInterfaceClient client = new PayPalAPIAAInterfaceClient(); GetExpressCheckoutDetailsResponseType response = client.GetExpressCheckoutDetails(ref credentials, req); if (response.Errors != null && response.Errors.Length > 0) { throw new Exception("Exception occured when calling PayPal: " + response.Errors[0].LongMessage); } GetExpressCheckoutDetailsResponseDetailsType respDetails = response.GetExpressCheckoutDetailsResponseDetails; Order order = PayPalHelper.UpdateOrderAfterAuthentication(respDetails.Custom, respDetails.PayerInfo.PayerID); var model = new PaymentModel { Order = order, BuyerName = respDetails.PayerInfo.PayerName.FirstName + respDetails.PayerInfo.PayerName.LastName }; Session["CheckoutDetails"] = response; return(View("PaymentDetails", model)); }
public async Task <AckCodeType> CreateRecurringPaymentsProfileAsync(CreateRecurringPaymentsProfileReq request) { PayPalAPIAAInterfaceClient client = new PayPalAPIAAInterfaceClient(); var response = await client.CreateRecurringPaymentsProfileAsync(GetAuthorizationRequest(), request); return(response.CreateRecurringPaymentsProfileResponse1.Ack); }
public async Task <AckCodeType> CreateBillingAgreementAsync(CreateBillingAgreementReq request) { PayPalAPIAAInterfaceClient client = new PayPalAPIAAInterfaceClient(); var response = await client.CreateBillingAgreementAsync(GetAuthorizationRequest(), request); return(response.CreateBillingAgreementResponse1.Ack); }
PayPalAPIAAInterfaceClient GetPayPalAAInterfaceClient(IPaymentGatewaySettings settings) { PayPalAPIAAInterfaceClient result; if (settings.TestMode) result = new PayPalAPIAAInterfaceClient("PayPalAPIAASandbox"); else result = new PayPalAPIAAInterfaceClient("PayPalAPIAA"); return result; }
protected void btnPay_Click(object sender, EventArgs e) { if (radPaypal.Checked) { PayPalAPIAAInterfaceClient paypalAAInt = new PayPalAPIAAInterfaceClient(); string hosting = ConfigurationManager.AppSettings["HostingPrefix"]; CustomSecurityHeaderType type = new CustomSecurityHeaderType(); type.Credentials = new UserIdPasswordType() { Username = ConfigurationManager.AppSettings["PP_APIUsername"], Password = ConfigurationManager.AppSettings["PP_APIPassword"], Signature = ConfigurationManager.AppSettings["PP_APISignature"] }; SetExpressCheckoutRequestDetailsType sdt = new SetExpressCheckoutRequestDetailsType(); sdt.NoShipping = "1"; PaymentDetailsType pdt = new PaymentDetailsType() { OrderDescription = "Payment Details Sushant", OrderTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = "100.00" } }; sdt.PaymentDetails = new PaymentDetailsType[] { pdt }; sdt.CancelURL = hosting + "Default.aspx"; sdt.ReturnURL = hosting + "ExpressCheckoutSuccess.aspx"; SetExpressCheckoutReq req = new SetExpressCheckoutReq() { SetExpressCheckoutRequest = new SetExpressCheckoutRequestType() { SetExpressCheckoutRequestDetails = sdt, Version = "60.0" } }; var resp = paypalAAInt.SetExpressCheckout(ref type, req); if (resp.Errors != null && resp.Errors.Length > 0) { // errors occured throw new Exception("Exception(s) occured when calling PayPal. First exception: " + resp.Errors[0].LongMessage); } Response.Redirect(string.Format("{0}?cmd=_express-checkout&token={1}", ConfigurationManager.AppSettings["PayPalSubmitUrl"], resp.Token)); } }
public async Task <string> SetExpressCheckoutAsync(SetExpressCheckoutReq request, bool recordarDatos = false) { PayPalAPIAAInterfaceClient client = new PayPalAPIAAInterfaceClient(); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var response = await client.SetExpressCheckoutAsync(GetAuthorizationRequest(), request); if (response.SetExpressCheckoutResponse1.Ack == AckCodeType.Success) { return(string.Format(PAYPALURLCHECKOUT, response.SetExpressCheckoutResponse1.Token)); } throw new ResponseException("Not correct"); }
static void Main(string[] args) { SetExpressCheckoutReq req = new SetExpressCheckoutReq { SetExpressCheckoutRequest = new SetExpressCheckoutRequestType { Version = "74.0", SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType { OrderTotal = new BasicAmountType { Value = "10.00", currencyID = CurrencyCodeType.EUR }, ReturnURL = "http://www.google.com", CancelURL = "http://www.google.com" } } }; CustomSecurityHeaderType cred = new CustomSecurityHeaderType { Credentials = new UserIdPasswordType { Username = "******", Password = "******", Signature = "AFcWxV21C7fd0v3bYYYRCpSSRl31AhzL0GoBgvn-TKnJd6oSO-B8Lqz6", AppId = "APP-80W284485P519543T" } }; PayPalAPIAAInterfaceClient pp = new PayPalAPIAAInterfaceClient(); pp.Endpoint.Address = new System.ServiceModel.EndpointAddress("https://api-3t.sandbox.paypal.com/nvp"); try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; var resp = pp.SetExpressCheckout(ref cred, req); Console.Out.WriteLine(resp.CorrelationID); Console.Out.WriteLine(resp.Ack.ToString()); foreach (ErrorType msg in resp.Errors) { Console.Out.WriteLine(msg.LongMessage); } } catch (Exception ex) { Console.Out.WriteLine(ex.Message); } }
public static string SetExpressCheckout(string email, double total, string returnUrl, string cancelUrl, bool allowGuestCheckout, bool showCreditCardAndAddress) { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; using (var client = new PayPalAPIAAInterfaceClient(new BasicHttpsBinding(), new EndpointAddress(EndpointUrl))) { var credentials = new CustomSecurityHeaderType() { Credentials = new UserIdPasswordType() { Username = APIUserName, Password = APIPassword, Signature = APISignature } }; SetExpressCheckoutReq req = new SetExpressCheckoutReq() { SetExpressCheckoutRequest = new SetExpressCheckoutRequestType() { Version = "121.0", SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType() { BuyerEmail = email, OrderTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = total.ToString() }, ReturnURL = returnUrl, CancelURL = cancelUrl, SolutionType = allowGuestCheckout ? SolutionTypeType.Sole : SolutionTypeType.Mark, SolutionTypeSpecified = allowGuestCheckout, LandingPage = LandingPageType.Billing, LandingPageSpecified = showCreditCardAndAddress } } }; var resp = client.SetExpressCheckout(ref credentials, req); string errors = CheckErrors(resp); if (errors == String.Empty) { return(resp.Token); } else { return(errors); } } }
public ChargeResult DoPayment(string CCNumber, Int32 Amount, string FirstName, string LastName, string Address, string City, string Zip, string State, string Country, string Telephone, string DOB, string EmailAddress, string CardHolderName, string ExpiryMonth, string ExpiryYear, string CVC2, String Currency) { // CreditCardDetailsType cardDetails = MapCardDetails(CCNumber, FirstName, LastName, Address, City, Zip, State, Country, Telephone, DOB, EmailAddress, CardHolderName, ExpiryMonth, ExpiryYear, CVC2); DoDirectPaymentResponseType result; using (var _client = new PayPalAPIAAInterfaceClient()) { DoDirectPaymentRequestType pp_Request = new DoDirectPaymentRequestType(); pp_Request.Version = "TODO set Version"; pp_Request.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType(); pp_Request.DoDirectPaymentRequestDetails.IPAddress = "115.187.229.184"; // pp_Request.DoDirectPaymentRequestDetails.CreditCard = cardDetails; // NOTE: The only currency supported by the Direct Payment API at this time is US dollars (USD).. pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD; pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value = Amount.ToString(); var dp = new DoDirectPaymentReq { DoDirectPaymentRequest = pp_Request }; var credentials = new CustomSecurityHeaderType { Credentials = new UserIdPasswordType { Username = "******", Password = "******", Signature = "signature", AppId = "ApiId" } }; result = _client.DoDirectPayment(ref credentials, dp); } var chargeResult = new ChargeResult(); if (result != null && result.Errors.Count() > 0) { chargeResult.failure_code = result.Errors[0].ErrorCode; chargeResult.failure_message = result.Errors[0].ShortMessage; } chargeResult.Id = result.TransactionID; return(chargeResult); }
protected string ProcessPaypalTransaction(string token, string payerId, decimal total) { var client = new PayPalAPIAAInterfaceClient(); var credentials = GetPaypalCredentials(); var request = new DoExpressCheckoutPaymentReq { DoExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType { Version = "89.0", DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType { Token = token, PayerID = payerId, PaymentAction = PaymentActionCodeType.Sale, PaymentDetails = new PaymentDetailsType[] { new PaymentDetailsType { OrderTotal = new BasicAmountType { Value = total.ToString(), currencyID = CurrencyCodeType.USD } } } } } }; var response = client.DoExpressCheckoutPayment(ref credentials, request); if (response.Ack == AckCodeType.Failure) { throw new InvalidOperationException("Paypal returned the following error: " + response.Errors.FirstOrDefault().LongMessage); } if (response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.Count() == 0) { throw new InvalidOperationException("No payment transaction returned from paypal"); } if (string.IsNullOrWhiteSpace(response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.First().TransactionID)) { throw new InvalidOperationException("No payment transaction ID returned"); } return(response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.First().TransactionID); }
private CustomSecurityHeaderType PaypalSecurityHeader() { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var credentials = new CustomSecurityHeaderType(); credentials.Credentials = new UserIdPasswordType(); if (Settings.UseSandbox == "True") { _paypalService2 = new PayPalAPIAAInterfaceClient("PayPalAPISandbox"); _paypalService1 = new PayPalAPIInterfaceClient("PayPalAPIINTSandbox"); } else { _paypalService2 = new PayPalAPIAAInterfaceClient("PayPalAPIProduction"); _paypalService1 = new PayPalAPIInterfaceClient("PayPalAPIINTProduction"); } credentials.Credentials.Username = Settings.UserName; credentials.Credentials.Password = Settings.Password; credentials.Credentials.Signature = Settings.Signature; credentials.Credentials.Subject = ""; return(credentials); }
public ActionResult PaymentConfirmation(int?orderId) { if (!orderId.HasValue) { return(RedirectToAction("PayPalCancel")); } var response = Session["CheckoutDetails"] as GetExpressCheckoutDetailsResponseType; if (response == null) { return(RedirectToAction("PayPalCancel")); } DoExpressCheckoutPaymentReq payReq = PayPalHelper.GetDoExpressCheckoutPaymentReq(response); CustomSecurityHeaderType credentials = PayPalHelper.GetPayPalCredentials(); PayPalAPIAAInterfaceClient client = new PayPalAPIAAInterfaceClient(); DoExpressCheckoutPaymentResponseType doResponse = client.DoExpressCheckoutPayment(ref credentials, payReq); if (doResponse.Errors != null && doResponse.Errors.Length > 0) { throw new Exception("Exception occured when calling PayPal: " + doResponse.Errors[0].LongMessage); } PayPalHelper.UpdateOrderAfterConfirmation(orderId.Value); return(RedirectToAction("PayPalSuccess")); }
public static OrderInfo Charge(decimal total, string PayPalToken, string payerId) { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; using (var client = new PayPalAPIAAInterfaceClient(new BasicHttpsBinding(), new EndpointAddress(EndpointUrl))) { var credentials = new CustomSecurityHeaderType() { Credentials = new UserIdPasswordType() { Username = APIUserName, Password = APIPassword, Signature = APISignature } }; DoExpressCheckoutPaymentReq req = new DoExpressCheckoutPaymentReq() { DoExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType() { Version = "121.0", DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType() { PaymentAction = PaymentActionCodeType.Sale, PaymentActionSpecified = true, Token = PayPalToken, PayerID = payerId, PaymentDetails = new PaymentDetailsType[1] { new PaymentDetailsType() { OrderTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = total.ToString("F2") }, ShippingTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = "0.00" }, TaxTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = "0.00" }, ItemTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = total.ToString("F2") } } } } } }; DoExpressCheckoutPaymentResponseType resp = client.DoExpressCheckoutPayment(ref credentials, req); string errors = CheckErrors(resp); OrderInfo info = new OrderInfo(); if (errors == String.Empty) { info.Ack = resp.Ack.ToString(); info.TransactionID = resp.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID; info.ReceiptID = resp.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].ReceiptID; } else { info.Ack = errors; } return(info); } }
static public OrderInfo Charge(string firstName, string lastName, string address1, string address2, string city, string state, string zip, string country, string ccType, string ccNumber, string ccAuthCode, int ccExpireYear, int ccExpireMonth, decimal priceFinal, decimal priceTax, decimal priceShipping) { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; CreditCardTypeType cardType = CreditCardTypeType.Visa; switch (ccType) { case "Visa": case "MasterCard": case "Discover": cardType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), ccType.ToString()); break; case "AMEX": cardType = CreditCardTypeType.Amex; break; default: cardType = CreditCardTypeType.Visa; break; } CountryCodeType countryCode = CountryCodeType.US; try { countryCode = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), country); } catch { countryCode = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), Robo.Country.NameToCode(country)); } finally { countryCode = CountryCodeType.US; } using (var client = new PayPalAPIAAInterfaceClient(new BasicHttpsBinding(), new EndpointAddress(EndpointUrl))) { var credentials = new CustomSecurityHeaderType() { Credentials = new UserIdPasswordType() { Username = APIUserName, Password = APIPassword, Signature = APISignature } }; DoDirectPaymentReq req = new DoDirectPaymentReq() { DoDirectPaymentRequest = new DoDirectPaymentRequestType() { Version = "121.0", DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType() { CreditCard = new CreditCardDetailsType() { CardOwner = new PayerInfoType() { PayerName = new PersonNameType() { FirstName = firstName, LastName = lastName }, Address = new AddressType() { CityName = city, StateOrProvince = state, PostalCode = zip, Country = countryCode, Street1 = address1, Street2 = address2 } }, CreditCardNumber = ccNumber, CreditCardType = cardType, CreditCardTypeSpecified = true, CVV2 = ccAuthCode, ExpMonth = ccExpireMonth, ExpMonthSpecified = true, ExpYear = ccExpireYear, ExpYearSpecified = true }, PaymentAction = PaymentActionCodeType.Sale, PaymentDetails = new PaymentDetailsType() { OrderTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = priceFinal.ToString("F2") }, ShippingTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = priceShipping.ToString("F2") }, TaxTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = priceTax.ToString("F2") } } } } }; var response = client.DoDirectPayment(ref credentials, req); // check errors string errors = CheckErrors(response); OrderInfo info = new OrderInfo(); if (errors == String.Empty) { info.Ack = response.Ack.ToString(); info.TransactionID = response.TransactionID; info.CVV2Code = response.CVV2Code; } else { info.Ack = errors; } return(info); } }
protected void btnPPCont_Click(object sender, EventArgs e) { try { var Surcharge = Math.Round((Convert.ToDouble(amount.Value) * 3) / 100, 2); var orderAmount = (Convert.ToDouble(amount.Value) + Surcharge).ToString(); Dictionary <string, string> PPPayment = new Dictionary <string, string>(); PPPayment.Add("AccNum", accountNum.Value); // PPPayment.Add("Amount", amount.Value); PPPayment.Add("Amount", orderAmount); Session["PPPaymentDetails"] = PPPayment; CustomSecurityHeaderType _credentials = new CustomSecurityHeaderType { Credentials = new UserIdPasswordType() { Username = System.Configuration.ConfigurationManager.AppSettings["UserName"].ToString(), Password = System.Configuration.ConfigurationManager.AppSettings["Password"].ToString(), Signature = System.Configuration.ConfigurationManager.AppSettings["Signature"].ToString(), } }; var expressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType(); // expressCheckoutRequestDetails.ReturnURL = "http://payment.trumans.blendev.com/PayPalPayment.aspx"; //expressCheckoutRequestDetails.CancelURL = "http://payment.trumans.blendev.com/PayPalCancel.aspx"; expressCheckoutRequestDetails.CancelURL = System.Configuration.ConfigurationManager.AppSettings["CancelURL"].ToString(); expressCheckoutRequestDetails.ReturnURL = System.Configuration.ConfigurationManager.AppSettings["SuccessURL"].ToString(); expressCheckoutRequestDetails.NoShipping = "1"; var paymentDetailsArray = new PaymentDetailsType[1]; paymentDetailsArray[0] = new PaymentDetailsType { PaymentAction = PaymentActionCodeType.Sale, OrderTotal = new BasicAmountType { currencyID = CurrencyCodeType.AUD, Value = orderAmount.ToString(), } }; BasicAmountType OTotal = new BasicAmountType(); OTotal.Value = orderAmount.ToString(); OTotal.currencyID = CurrencyCodeType.AUD; expressCheckoutRequestDetails.OrderTotal = OTotal; var ExpressCheck = new SetExpressCheckoutRequestType { SetExpressCheckoutRequestDetails = expressCheckoutRequestDetails, Version = "98", }; SetExpressCheckoutReq obj = new SetExpressCheckoutReq(); obj.SetExpressCheckoutRequest = ExpressCheck; PayPalAPI.PayPalAPIAAInterfaceClient objPayPalAPI = new PayPalAPIAAInterfaceClient(); var setExpressCheckoutResponse = objPayPalAPI.SetExpressCheckout(ref _credentials, obj); if (setExpressCheckoutResponse.Ack == AckCodeType.Success) { Response.Redirect("https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + setExpressCheckoutResponse.Token, false); Session["Token"] = setExpressCheckoutResponse.Token; } else { StreamWriter File2 = File.AppendText(HttpContext.Current.Server.MapPath("~/Logs/file.txt")); File2.WriteLine("Error : " + setExpressCheckoutResponse.Errors[0].LongMessage); File2.Close(); string script = "<script type=\"text/javascript\">alert('Unexpected Error Occured , Please try Later!!');</script>"; ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script); } } catch (Exception ex) { StreamWriter File2 = File.AppendText(HttpContext.Current.Server.MapPath("~/Logs/file.txt")); File2.WriteLine("Error : " + ex.Message); File2.Close(); string script = "<script type=\"text/javascript\">alert('Unexpected Error Occured , Please try Later!!');</script>"; ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script); } }
protected void Page_Load(object sender, EventArgs e) { try { CustomSecurityHeaderType _credentials = new CustomSecurityHeaderType(); //{ // Credentials = new UserIdPasswordType() // { // Username = "******", // Password = "******", // Signature = "Ao--X15RhKPZUeA3L9bihv008SFUAc03629aPWDtEWfOvvTchBkLtV3A", // } //}; //GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType(); //request.Token = Request.QueryString["Token"].ToString(); //// Invoke the API //GetExpressCheckoutDetailsReq wrapper = new GetExpressCheckoutDetailsReq(); //wrapper.GetExpressCheckoutDetailsRequest = request; PayPalAPI.PayPalAPIAAInterfaceClient objPayPalAPI = new PayPalAPIAAInterfaceClient(); //var getExpRes = objPayPalAPI.GetExpressCheckoutDetails(ref _credentials,wrapper); //if(getExpRes.Ack==AckCodeType.Success && getExpRes.GetExpressCheckoutDetailsResponseDetails.PaymentInfo[0].PaymentStatus==PaymentStatusCodeType.Pending) //{ // //Show Error Message and save details in DB //} //else //{ Dictionary <string, string> PPPayment = new Dictionary <string, string>(); PPPayment = (Dictionary <string, string>)Session["PPPaymentDetails"]; var payReq = new DoExpressCheckoutPaymentReq { DoExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType { Version = "98", DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType { Token = Request.QueryString["Token"].ToString(), PayerID = Request.QueryString["PayerId"].ToString(), PaymentAction = PaymentActionCodeType.Sale, PaymentActionSpecified = true, PaymentDetails = new[] { new PaymentDetailsType { OrderTotal = new BasicAmountType { currencyID = CurrencyCodeType.AUD, Value = PPPayment["Amount"].ToString(), } } } } } }; _credentials = new CustomSecurityHeaderType { Credentials = new UserIdPasswordType() { Username = System.Configuration.ConfigurationManager.AppSettings["UserName"].ToString(), Password = System.Configuration.ConfigurationManager.AppSettings["Password"].ToString(), Signature = System.Configuration.ConfigurationManager.AppSettings["Signature"].ToString(), } }; var DoExpRes = objPayPalAPI.DoExpressCheckoutPayment(ref _credentials, payReq); //Read the connection string from Web.Config file string ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnectionsql"].ConnectionString; using (SqlConnection con = new SqlConnection(ConnectionString)) { try { //Create the SqlCommand object SqlCommand cmd = new SqlCommand("sp_InsertPayPalPaymentDetails", con); //Specify that the SqlCommand is a stored procedure cmd.CommandType = System.Data.CommandType.StoredProcedure; //Add the input parameters to the command object cmd.Parameters.AddWithValue("@AccNum", PPPayment["AccNum"]); cmd.Parameters.AddWithValue("@Amount", PPPayment["Amount"]); cmd.Parameters.AddWithValue("@Token", Request.QueryString["Token"].ToString()); cmd.Parameters.AddWithValue("@PayerId", Request.QueryString["PayerId"].ToString()); cmd.Parameters.AddWithValue("@ExpressChkResp", DoExpRes.Ack); if (DoExpRes.Errors != null) { if (DoExpRes.Errors.Count() > 0) { cmd.Parameters.AddWithValue("@PPError", DoExpRes.Errors[0].ShortMessage); } } else { cmd.Parameters.AddWithValue("@PPError", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.BillingAgreementID != null) { cmd.Parameters.AddWithValue("@BillingAgreementId", DoExpRes.DoExpressCheckoutPaymentResponseDetails.BillingAgreementID); } else { cmd.Parameters.AddWithValue("@BillingAgreementId", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.MsgSubID != null) { cmd.Parameters.AddWithValue("@MsgSubId", DoExpRes.DoExpressCheckoutPaymentResponseDetails.MsgSubID); } else { cmd.Parameters.AddWithValue("@MsgSubId", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.Note != null) { cmd.Parameters.AddWithValue("@Note", DoExpRes.DoExpressCheckoutPaymentResponseDetails.Note); } else { cmd.Parameters.AddWithValue("@Note", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].GrossAmount != null) { cmd.Parameters.AddWithValue("@GrossAmount", DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].GrossAmount.Value); } else { cmd.Parameters.AddWithValue("@GrossAmount", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentDate != null) { cmd.Parameters.AddWithValue("@PaymentDate", DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentDate); } else { cmd.Parameters.AddWithValue("@PaymentDate", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentError != null) { cmd.Parameters.AddWithValue("@PaymentError", DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentError.ShortMessage); } else { cmd.Parameters.AddWithValue("@PaymentError", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentRequestID != null) { cmd.Parameters.AddWithValue("@PaymentRequestID", DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentRequestID); } else { cmd.Parameters.AddWithValue("@PaymentRequestID", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentStatus != null) { cmd.Parameters.AddWithValue("@PaymentStatus", DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentStatus); } else { cmd.Parameters.AddWithValue("@PaymentStatus", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentType != null) { cmd.Parameters.AddWithValue("@PaymentType", DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentType.ToString()); } else { cmd.Parameters.AddWithValue("@PaymentType", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].ReceiptID != null) { cmd.Parameters.AddWithValue("@ReceiptID", DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].ReceiptID); } else { cmd.Parameters.AddWithValue("@ReceiptID", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].ReceiptReferenceNumber != null) { cmd.Parameters.AddWithValue("@ReceiptReferenceNumber", DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].ReceiptReferenceNumber); } else { cmd.Parameters.AddWithValue("@ReceiptReferenceNumber", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID != null) { cmd.Parameters.AddWithValue("@TransactionID", DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID); } else { cmd.Parameters.AddWithValue("@TransactionID", ""); } if (DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionType != null) { cmd.Parameters.AddWithValue("@TransactionType", DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionType.ToString()); } else { cmd.Parameters.AddWithValue("@TransactionType", ""); } //Open the connection and execute the query con.Open(); cmd.ExecuteScalar(); } catch (Exception ex) { StreamWriter file2 = File.AppendText(HttpContext.Current.Server.MapPath("~/Logs/file.txt")); file2.WriteLine("Saving Error : " + DateTime.Now + " " + ex.Message); file2.Close(); } } if (DoExpRes.Ack == AckCodeType.Success && DoExpRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentStatus == PaymentStatusCodeType.Completed) { Label1.Text = "PayPal Payment Successful "; } } catch (Exception ex) { StreamWriter file2 = File.AppendText(HttpContext.Current.Server.MapPath("~/Logs/file.txt")); file2.WriteLine("Exception : " + DateTime.Now + " " + ex.Message); file2.Close(); Response.Redirect("Default.aspx?PP=Error"); } //} }