Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PayFlowProPaymentProcessor : BasePlugin, IPaymentMethod
- {
- #region PayFlowPro 101
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // PayFlowPro 101
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // A sale transaction requires the following objects to be set:
- // a) UserInfo Object: Info about the merchant making the transaction.
- // b) PFProConnectionData Object: The URL of the PayPal transaction server and the location of the local certificate.
- // c) Currency Object: The amount of money and currency type for this transaction.
- // d) BillTo Object: Customer's billing information.
- // e) CreditCard Object: Includes name of cardholder, cardnumber, expiration date, and card security code
- //
- //
- // Of course, to make things confusing, some of these objects are used as parameters to other objects in an unintuitive way.
- //
- // To help you understand the relationships between thess objects, here's a basic diagram using the class names. (Not instance names.)
- //
- // SaleTransaction ---(Has A)---
- // |---UserInfo
- // |
- // |---PFProConnectionData
- // |
- // |---Invoice---(Has A)-------
- // |---Currency
- // |
- // |---BillTo
- // |
- // |---ShipTo*
- // |---CardTender---(Has A)----
- // |---CreditCard
- //
- // *ShipTo, which is a member of Invoice contains the shipping address. It is not required, but I have placed it in diagram
- // and the code below.
- //
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- #endregion
- #region Fields
- private readonly PayFlowProPaymentSettings _payFlowProPaymentSettings;
- private readonly ISettingService _settingService;
- private readonly ICurrencyService _currencyService;
- private readonly CurrencySettings _currencySettings;
- private readonly IWebHelper _webHelper;
- private readonly StoreInformationSettings _storeInformationSettings;
- private readonly ICustomerService _customerService;
- private const int PFP_SUCCESS = 0;
- private const string US_DOLLARS = "USD";
- private const string TRANSACTION_TYPE_SALE = "S";
- private const string TRANSACTION_TYPE_DELAYED_CAPTURE = "D";
- #endregion
- #region Ctor
- public PayFlowProPaymentProcessor(PayFlowProPaymentSettings payFlowProPaymentSettings,
- ISettingService settingService, ICurrencyService currencyService,
- CurrencySettings currencySettings, IWebHelper webHelper,
- StoreInformationSettings storeInformationSettings, ICustomerService customerService)
- {
- _payFlowProPaymentSettings = payFlowProPaymentSettings;
- _settingService = settingService;
- _currencyService = currencyService;
- _currencySettings = currencySettings;
- _webHelper = webHelper;
- _storeInformationSettings = storeInformationSettings;
- _customerService = customerService;
- }
- #endregion
- #region Utilities
- /// <summary>
- /// Gets PayFlowPro URL
- /// </summary>
- /// <returns></returns>
- private string GetPayFlowProUrl()
- {
- return _payFlowProPaymentSettings.UseSandbox ? "pilot-payflowpro.paypal.com" : "payflowpro.paypal.com";
- }
- protected string GetApiVersion()
- {
- return "4.3.1.0";
- }
- #endregion
- #region Methods
- /// <summary>
- /// Process a payment
- /// </summary>
- /// <param name="processPaymentRequest">Payment info required for an order processing</param>
- /// <returns>Process payment result</returns>
- public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest)
- {
- /////////////////////////////////////////////////
- // UserInfo Section
- /////////////////////////////////////////////////
- _payFlowProPaymentSettings.Unlock();
- UserInfo userInfo = new UserInfo(_payFlowProPaymentSettings.User, _payFlowProPaymentSettings.Vendor,
- _payFlowProPaymentSettings.Partner, _payFlowProPaymentSettings.Password);
- _payFlowProPaymentSettings.Lock();
- /////////////////////////////////////////////////
- // PFProConnectionData Section
- /////////////////////////////////////////////////
- PayflowConnectionData connectionData = new PayflowConnectionData(GetPayFlowProUrl());
- /////////////////////////////////////////////////
- // Invoice Section
- /////////////////////////////////////////////////
- // Refer to diagram above - to construct an Invoice object, we need to
- // create a Currency and a BillTo object to pass to the Invoice ctor.
- PayPal.Payments.DataObjects.Currency currency = new PayPal.Payments.DataObjects.Currency(processPaymentRequest.OrderTotal, PayFlowProPaymentProcessor.US_DOLLARS);
- currency.NoOfDecimalDigits = 2;
- currency.Round = true;
- // Set the billing address information
- BillTo billTo = new BillTo();
- var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId);
- billTo.Street = customer.BillingAddress.Address1;
- billTo.Zip = customer.BillingAddress.ZipPostalCode;
- // Create a new Invoice data object and set the amount of sale
- // and billing address information
- Invoice invoice = new Invoice();
- invoice.Amt = currency;
- invoice.BillTo = billTo;
- if (customer.ShippingAddress != null)
- {
- ShipTo shipTo = new ShipTo();
- Core.Domain.Common.Address shipAddr = customer.ShippingAddress;
- shipTo.ShipToFirstName = shipAddr.FirstName;
- shipTo.ShipToLastName = shipAddr.LastName;
- shipTo.ShipToStreet = shipAddr.Address1;
- shipTo.ShipToStreet2 = shipAddr.Address2;
- shipTo.ShipToCity = shipAddr.City;
- shipTo.ShipToState = shipAddr.StateProvince.Abbreviation;
- shipTo.ShipToZip = shipAddr.ZipPostalCode;
- invoice.ShipTo = shipTo;
- }
- /////////////////////////////////////////////////
- // CardTender Section
- /////////////////////////////////////////////////
- // Refer to diagram above - to construct an CardTender object, we need
- // to create a CreditCard object to pass to the CardTender ctor.
- // Note: Expiration date must be in MMYY format.
- string expDate = string.Format("{0:00}{1}", processPaymentRequest.CreditCardExpireMonth, processPaymentRequest.CreditCardExpireYear.ToString().Substring(2));
- CreditCard creditCard = new CreditCard(processPaymentRequest.CreditCardNumber, expDate);
- creditCard.Name = processPaymentRequest.CreditCardName;
- creditCard.Cvv2 = processPaymentRequest.CreditCardCvv2;
- CardTender cardTender = new CardTender(creditCard);
- /////////////////////////////////////////////////
- // SaleTransaction Section
- /////////////////////////////////////////////////
- SaleTransaction saleXAction = new SaleTransaction(userInfo, connectionData, invoice, cardTender, PayflowUtility.RequestId);
- saleXAction.Verbosity = "LOW";
- //saleXAction.TrxType = "
- /////////////////////////////////////////////////
- // Let's do what we came here to do - Submit It!
- /////////////////////////////////////////////////
- Response submitResponse = saleXAction.SubmitTransaction();
- if (submitResponse == null)
- {
- // If the Response instance is null, we have some strange problem that will prevent us from
- // continuing. We will have to abort processing.
- throw new Exception("Unknown error while processing sale transaction. Transaction aborted.");
- }
- TransactionResponse transactionResponse = submitResponse.TransactionResponse;
- if (transactionResponse == null)
- {
- // If the TransactionResponse instance is null, we will have to abort processing.
- throw new Exception("Unknown error while processing sale transaction. Transaction aborted.");
- }
- ProcessPaymentResult result = new ProcessPaymentResult();
- if (transactionResponse.Result == PayFlowProPaymentProcessor.PFP_SUCCESS)
- {
- result.CaptureTransactionId = transactionResponse.Pnref;
- result.CaptureTransactionResult = transactionResponse.RespMsg;
- result.NewPaymentStatus = PaymentStatus.Paid;
- }
- else
- {
- result.CaptureTransactionResult = transactionResponse.RespMsg;
- result.AddError(transactionResponse.RespMsg);
- }
- return result;
- }
- /// <summary>
- /// Post process payment (used by payment gateways that require redirecting to a third-party URL)
- /// </summary>
- /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param>
- public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
- {
- // Not required for PayFlowPro
- }
- /// <summary>
- /// Gets additional handling fee
- /// </summary>
- /// <returns>Additional handling fee</returns>
- public decimal GetAdditionalHandlingFee()
- {
- return 0.00m;
- }
- /// <summary>
- /// Captures payment
- /// </summary>
- /// <param name="capturePaymentRequest">Capture payment request</param>
- /// <returns>Capture payment result</returns>
- public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
- {
- var result = new CapturePaymentResult();
- result.AddError("Capture method not supported");
- return result;
- }
- /// <summary>
- /// Refunds a payment
- /// </summary>
- /// <param name="refundPaymentRequest">Request</param>
- /// <returns>Result</returns>
- public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest)
- {
- var result = new RefundPaymentResult();
- /////////////////////////////////////////////////
- // UserInfo Section
- /////////////////////////////////////////////////
- _payFlowProPaymentSettings.Unlock();
- UserInfo userInfo = new UserInfo(_payFlowProPaymentSettings.User, _payFlowProPaymentSettings.Vendor,
- _payFlowProPaymentSettings.Partner, _payFlowProPaymentSettings.Password);
- _payFlowProPaymentSettings.Lock();
- /////////////////////////////////////////////////
- // PFProConnectionData Section
- /////////////////////////////////////////////////
- PayflowConnectionData connectionData = new PayflowConnectionData(GetPayFlowProUrl());
- /////////////////////////////////////////////////
- // Invoice Section
- /////////////////////////////////////////////////
- // Refer to diagram above - to construct an Invoice object, we need to
- // create a Currency and a BillTo object to pass to the Invoice ctor.
- PayPal.Payments.DataObjects.Currency currency = new PayPal.Payments.DataObjects.Currency(refundPaymentRequest.AmountToRefund, PayFlowProPaymentProcessor.US_DOLLARS);
- currency.NoOfDecimalDigits = 2;
- currency.Round = true;
- // Set the billing address information
- BillTo billTo = new BillTo();
- var customer = refundPaymentRequest.Order.Customer;
- billTo.Street = customer.BillingAddress.Address1;
- billTo.Zip = customer.BillingAddress.ZipPostalCode;
- // Create a new Invoice data object and set the amount of sale
- // and billing address information
- Invoice invoice = new Invoice();
- invoice.Amt = currency;
- invoice.BillTo = billTo;
- if (customer.ShippingAddress != null)
- {
- ShipTo shipTo = new ShipTo();
- Core.Domain.Common.Address shipAddr = customer.ShippingAddress;
- shipTo.ShipToFirstName = shipAddr.FirstName;
- shipTo.ShipToLastName = shipAddr.LastName;
- shipTo.ShipToStreet = shipAddr.Address1;
- shipTo.ShipToStreet2 = shipAddr.Address2;
- shipTo.ShipToCity = shipAddr.City;
- shipTo.ShipToState = shipAddr.StateProvince.Abbreviation;
- shipTo.ShipToZip = shipAddr.ZipPostalCode;
- invoice.ShipTo = shipTo;
- }
- ///////////////////////////////////////////////////////////////////
- // Create a new Credit Transaction.
- // Following is an example of a independent credit type of transaction.
- CreditTransaction Trans = new CreditTransaction(refundPaymentRequest.Order.CaptureTransactionId, userInfo, PayflowUtility.RequestId);
- // Submit the Transaction
- Response Resp = Trans.SubmitTransaction();
- // Display the transaction response parameters.
- if (Resp != null)
- {
- // Get the Transaction Response parameters.
- TransactionResponse TrxnResponse = Resp.TransactionResponse;
- if (TrxnResponse != null)
- {
- Console.WriteLine("RESULT = " + TrxnResponse.Result);
- Console.WriteLine("PNREF = " + TrxnResponse.Pnref);
- Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg);
- Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode);
- Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr);
- Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip);
- Console.WriteLine("IAVS = " + TrxnResponse.IAVS);
- Console.WriteLine("CVV2MATCH = " + TrxnResponse.CVV2Match);
- // If value is true, then the Request ID has not been changed and the original response
- // of the original transction is returned.
- Console.WriteLine("DUPLICATE = " + TrxnResponse.Duplicate);
- }
- // Get the Fraud Response parameters.
- FraudResponse FraudResp = Resp.FraudResponse;
- // Display Fraud Response parameter
- if (FraudResp != null)
- {
- Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg);
- Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg);
- }
- // Display the response.
- Console.WriteLine(Environment.NewLine + PayflowUtility.GetStatus(Resp));
- // Get the Transaction Context and check for any contained SDK specific errors (optional code).
- PayPal.Payments.Common.Context TransCtx = Resp.TransactionContext;
- if (TransCtx != null && TransCtx.getErrorCount() > 0)
- {
- Console.WriteLine(Environment.NewLine + "Transaction Errors = " + TransCtx.ToString());
- }
- }
- return result;
- }
- /// <summary>
- /// Voids a payment
- /// </summary>
- /// <param name="voidPaymentRequest">Request</param>
- /// <returns>Result</returns>
- public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
- {
- var result = new VoidPaymentResult();
- _payFlowProPaymentSettings.Unlock();
- UserInfo userInfo = new UserInfo(_payFlowProPaymentSettings.User, _payFlowProPaymentSettings.Vendor,
- _payFlowProPaymentSettings.Partner, _payFlowProPaymentSettings.Password);
- _payFlowProPaymentSettings.Lock();
- /////////////////////////////////////////////////
- // PFProConnectionData Section
- /////////////////////////////////////////////////
- PayflowConnectionData connectionData = new PayflowConnectionData(GetPayFlowProUrl());
- ///////////////////////////////////////////////////////////////////
- // Create a new Void Transaction.
- // The ORIGID is the PNREF no. for a previous transaction.
- VoidTransaction Trans = new VoidTransaction(voidPaymentRequest.Order.CaptureTransactionId,
- userInfo, connectionData, PayflowUtility.RequestId);
- // Submit the Transaction
- Response Resp = Trans.SubmitTransaction();
- if (Resp == null)
- {
- // If the Response instance is null, we have some strange problem that will prevent us from
- // continuing. We will have to abort processing.
- throw new Exception("Unknown error while processing void transaction. Transaction aborted.");
- }
- TransactionResponse transactionResponse = Resp.TransactionResponse;
- if (transactionResponse == null)
- {
- // If the TransactionResponse instance is null, we will have to abort processing.
- throw new Exception("Unknown error while processing void transaction. Transaction aborted.");
- }
- if (transactionResponse.Result == PayFlowProPaymentProcessor.PFP_SUCCESS)
- {
- result.NewPaymentStatus = Core.Domain.Payments.PaymentStatus.Voided;
- }
- else
- {
- result.AddError(transactionResponse.RespMsg);
- }
- return result;
- }
- /// <summary>
- /// Process recurring payment
- /// </summary>
- /// <param name="processPaymentRequest">Payment info required for an order processing</param>
- /// <returns>Process payment result</returns>
- public ProcessPaymentResult ProcessRecurringPayment(ProcessPaymentRequest processPaymentRequest)
- {
- var result = new ProcessPaymentResult();
- /////////////////////////////////////////////////
- // UserInfo Section
- /////////////////////////////////////////////////
- _payFlowProPaymentSettings.Unlock();
- UserInfo userInfo = new UserInfo(_payFlowProPaymentSettings.User, _payFlowProPaymentSettings.Vendor,
- _payFlowProPaymentSettings.Partner, _payFlowProPaymentSettings.Password);
- _payFlowProPaymentSettings.Lock();
- /////////////////////////////////////////////////
- // PFProConnectionData Section
- /////////////////////////////////////////////////
- PayflowConnectionData connectionData = new PayflowConnectionData(GetPayFlowProUrl());
- PayPal.Payments.DataObjects.Currency currency = new PayPal.Payments.DataObjects.Currency(processPaymentRequest.OrderTotal, PayFlowProPaymentProcessor.US_DOLLARS);
- currency.NoOfDecimalDigits = 2;
- currency.Round = true;
- // Set the billing address information
- BillTo billTo = new BillTo();
- var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId);
- billTo.Street = customer.BillingAddress.Address1;
- billTo.Zip = customer.BillingAddress.ZipPostalCode;
- billTo.Email = customer.Email;
- // Create a new Invoice data object and set the amount of sale
- // and billing address information
- Invoice invoice = new Invoice();
- invoice.Amt = currency;
- invoice.BillTo = billTo;
- invoice.InvNum = processPaymentRequest.OrderGuid.ToString();
- if (customer.ShippingAddress != null)
- {
- ShipTo shipTo = new ShipTo();
- Core.Domain.Common.Address shipAddr = customer.ShippingAddress;
- shipTo.ShipToFirstName = shipAddr.FirstName;
- shipTo.ShipToLastName = shipAddr.LastName;
- shipTo.ShipToStreet = shipAddr.Address1;
- shipTo.ShipToStreet2 = shipAddr.Address2;
- shipTo.ShipToCity = shipAddr.City;
- shipTo.ShipToState = shipAddr.StateProvince.Abbreviation;
- shipTo.ShipToZip = shipAddr.ZipPostalCode;
- invoice.ShipTo = shipTo;
- }
- /////////////////////////////////////////////////
- // CardTender Section
- /////////////////////////////////////////////////
- // Refer to diagram above - to construct an CardTender object, we need
- // to create a CreditCard object to pass to the CardTender ctor.
- // Note: Expiration date must be in MMYY format.
- string expDate = string.Format("{0:00}{1}", processPaymentRequest.CreditCardExpireMonth, processPaymentRequest.CreditCardExpireYear.ToString().Substring(2));
- CreditCard creditCard = new CreditCard(processPaymentRequest.CreditCardNumber, expDate);
- creditCard.Name = processPaymentRequest.CreditCardName;
- creditCard.Cvv2 = processPaymentRequest.CreditCardCvv2;
- CardTender cardTender = new CardTender(creditCard);
- RecurringInfo RecurInfo = new RecurringInfo();
- // The date that the first payment will be processed.
- // This will be of the format mmddyyyy.
- RecurInfo.Start = DateTime.UtcNow.AddDays(1).ToString("MMddyyyy");
- RecurInfo.ProfileName = "PayPal";
- RecurInfo.OptionalTrxAmt = new PayPal.Payments.DataObjects.Currency(199, "USD");
- // Specifies how often the payment occurs. All PAYPERIOD values must use
- // capital letters and can be any of WEEK / BIWK / SMMO / FRWK / MONT /
- // QTER / SMYR / YEAR
- switch (processPaymentRequest.RecurringCyclePeriod)
- {
- case RecurringProductCyclePeriod.Days:
- RecurInfo.PayPeriod = "DAY";
- break;
- case RecurringProductCyclePeriod.Weeks:
- RecurInfo.PayPeriod = "WEEK";
- break;
- case RecurringProductCyclePeriod.Months:
- RecurInfo.PayPeriod = "MONTH";
- break;
- case RecurringProductCyclePeriod.Years:
- RecurInfo.PayPeriod = "YEAR";
- break;
- default:
- throw new NopException("Not supported cycle period");
- }
- //RecurInfo.PayPeriod = "WEEK";
- ///////////////////////////////////////////////////////////////////
- // Create a new Recurring Transaction.
- RecurringTransaction Trans = new RecurringTransaction("A", RecurInfo,
- userInfo, connectionData, invoice, cardTender, PayflowUtility.RequestId);
- // Submit the Transaction
- Response Resp = Trans.SubmitTransaction();
- //if (Resp != null)
- //{
- // // Get the Transaction Response parameters.
- // TransactionResponse TrxnResponse = Resp.TransactionResponse;
- // if (TrxnResponse != null)
- // {
- // Console.WriteLine("RESULT = " + TrxnResponse.Result);
- // Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg);
- // }
- // // Get the Recurring Response parameters.
- // RecurringResponse RecurResponse = Resp.RecurringResponse;
- // if (RecurResponse != null)
- // {
- // Console.WriteLine("RPREF = " + RecurResponse.RPRef);
- // Console.WriteLine("PROFILEID = " + RecurResponse.ProfileId);
- // }
- //}
- if (Resp == null)
- {
- // If the Response instance is null, we have some strange problem that will prevent us from
- // continuing. We will have to abort processing.
- throw new Exception("Unknown error while processing sale transaction. Transaction aborted.");
- }
- TransactionResponse transactionResponse = Resp.TransactionResponse;
- if (transactionResponse == null)
- {
- // If the TransactionResponse instance is null, we will have to abort processing.
- throw new Exception("Unknown error while processing sale transaction. Transaction aborted.");
- }
- if (transactionResponse.Result == PayFlowProPaymentProcessor.PFP_SUCCESS)
- {
- // Get the Recurring Response parameters.
- RecurringResponse RecurResponse = Resp.RecurringResponse;
- if (RecurResponse != null)
- {
- result.CaptureTransactionId = RecurResponse.RPRef;
- result.SubscriptionTransactionId = RecurResponse.ProfileId;
- result.NewPaymentStatus = PaymentStatus.Paid;
- }
- }
- else
- {
- result.CaptureTransactionResult = transactionResponse.RespMsg;
- result.AddError(transactionResponse.RespMsg);
- }
- // Display the response.
- //result.AddError(Environment.NewLine + PayflowUtility.GetStatus(Resp));
- // Get the Transaction Context and check for any contained SDK specific errors (optional code).
- PayPal.Payments.Common.Context TransCtx = Resp.TransactionContext;
- if (TransCtx != null && TransCtx.getErrorCount() > 0)
- {
- result.AddError(Environment.NewLine + "Transaction Errors = " + TransCtx.ToString());
- }
- return result;
- }
- /// <summary>
- /// Cancels a recurring payment
- /// </summary>
- /// <param name="cancelPaymentRequest">Request</param>
- /// <returns>Result</returns>
- public CancelRecurringPaymentResult CancelRecurringPayment(CancelRecurringPaymentRequest cancelPaymentRequest)
- {
- var result = new CancelRecurringPaymentResult();
- _payFlowProPaymentSettings.Unlock();
- UserInfo userInfo = new UserInfo(_payFlowProPaymentSettings.User, _payFlowProPaymentSettings.Vendor,
- _payFlowProPaymentSettings.Partner, _payFlowProPaymentSettings.Password);
- _payFlowProPaymentSettings.Lock();
- PayflowConnectionData connectionData = new PayflowConnectionData(GetPayFlowProUrl());
- RecurringInfo RecurInfo = new RecurringInfo();
- //RecurInfo.OrigProfileId = "<PROFILE_ID>"; // RT0000001350
- RecurInfo.OrigProfileId = cancelPaymentRequest.Order.SubscriptionTransactionId;
- // Create a new Recurring Cancel Transaction.
- RecurringCancelTransaction Trans = new RecurringCancelTransaction(
- userInfo, connectionData, RecurInfo, PayflowUtility.RequestId);
- // Submit the Transaction
- Response Resp = Trans.SubmitTransaction();
- // Display the transaction response parameters.
- // Display the transaction response parameters.
- if (Resp != null)
- {
- RecurringResponse RecurResponse = Resp.RecurringResponse;
- if (RecurResponse.TrxResult != "0")
- {
- result.AddError(RecurResponse.TrxResult.ToString());
- result.AddError(RecurResponse.TrxRespMsg);
- }
- //if (TrxnResponse != null)
- //{
- // Console.WriteLine("RESULT = " + TrxnResponse.Result);
- // Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg);
- //}
- // Get the Recurring Response parameters.
- //if (RecurResponse != null)
- //{
- // Console.WriteLine("RPREF = " + RecurResponse.RPRef);
- // Console.WriteLine("PROFILEID = " + RecurResponse.ProfileId);
- //}
- // Display the response.
- //Console.WriteLine(Environment.NewLine + PayflowUtility.GetStatus(Resp));
- // Get the Transaction Context and check for any contained SDK specific errors (optional code).
- PayPal.Payments.Common.Context TransCtx = Resp.TransactionContext;
- //if (TransCtx != null && TransCtx.getErrorCount() > 0)
- //{
- // Console.WriteLine(Environment.NewLine + "Transaction Errors = " + TransCtx.ToString());
- //}
- }
- return result;
- }
- /// <summary>
- /// Gets a value indicating whether customers can complete a payment after order is placed but not completed (for redirection payment methods)
- /// </summary>
- /// <param name="order">Order</param>
- /// <returns>Result</returns>
- public bool CanRePostProcessPayment(Order order)
- {
- if (order == null)
- throw new ArgumentNullException("order");
- //it's not a redirection payment method. So we always return false
- return false;
- }
- /// <summary>
- /// Gets a route for provider configuration
- /// </summary>
- /// <param name="actionName">Action name</param>
- /// <param name="controllerName">Controller name</param>
- /// <param name="routeValues">Route values</param>
- public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
- {
- actionName = "Configure";
- controllerName = "PaymentPayFlowPro";
- routeValues = new RouteValueDictionary() { { "Namespaces", "Nop.Plugin.Payments.PayFlowPro.Controllers" }, { "area", null } };
- }
- /// <summary>
- /// Gets a route for payment info
- /// </summary>
- /// <param name="actionName">Action name</param>
- /// <param name="controllerName">Controller name</param>
- /// <param name="routeValues">Route values</param>
- public void GetPaymentInfoRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
- {
- actionName = "PaymentInfo";
- controllerName = "PaymentPayFlowPro";
- routeValues = new RouteValueDictionary() { { "Namespaces", "Nop.Plugin.Payments.PayFlowPro.Controllers" }, { "area", null } };
- }
- public Type GetControllerType()
- {
- return typeof(PaymentPayFlowProController);
- }
- public override void Install()
- {
- var settings = new PayFlowProPaymentSettings()
- {
- UseSandbox = true,
- User = "User Name",
- Vendor = "Vendor Id",
- Partner = "Partner",
- Password = "Password"
- };
- settings.Lock();
- _settingService.SaveSetting(settings);
- base.Install();
- }
- /// <summary>
- /// Verifies IPN
- /// </summary>
- /// <param name="formString">Form string</param>
- /// <param name="values">Values</param>
- /// <returns>Result</returns>
- public bool VerifyIPN(string formString, out Dictionary<string, string> values)
- {
- //var req = (HttpWebRequest)WebRequest.Create(GetPaypalUrl());
- //req.Method = "POST";
- //req.ContentType = "application/x-www-form-urlencoded";
- //string formContent = string.Format("{0}&cmd=_notify-validate", formString);
- //req.ContentLength = formContent.Length;
- //using (var sw = new StreamWriter(req.GetRequestStream(), Encoding.ASCII))
- //{
- // sw.Write(formContent);
- //}
- //string response = null;
- //using (var sr = new StreamReader(req.GetResponse().GetResponseStream()))
- //{
- // response = HttpUtility.UrlDecode(sr.ReadToEnd());
- //}
- //bool success = response.Trim().Equals("VERIFIED", StringComparison.OrdinalIgnoreCase);
- bool success = true;
- values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
- foreach (string l in formString.Split('&'))
- {
- string line = l.Trim();
- int equalPox = line.IndexOf('=');
- if (equalPox >= 0)
- values.Add(line.Substring(0, equalPox), line.Substring(equalPox + 1));
- }
- return success;
- }
- /// <summary>
- /// Gets Paypal URL
- /// </summary>
- /// <returns></returns>
- private string GetPaypalUrl()
- {
- return _payFlowProPaymentSettings.UseSandbox ? "https://www.sandbox.paypal.com/us/cgi-bin/webscr" :
- "https://www.paypal.com/us/cgi-bin/webscr";
- }
- #endregion
- #region Properies
- /// <summary>
- /// Gets a value indicating whether capture is supported
- /// </summary>
- public bool SupportCapture
- {
- get
- {
- return false;
- }
- }
- /// <summary>
- /// Gets a value indicating whether partial refund is supported
- /// </summary>
- public bool SupportPartiallyRefund
- {
- get
- {
- return false;
- }
- }
- /// <summary>
- /// Gets a value indicating whether refund is supported
- /// </summary>
- public bool SupportRefund
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// Gets a value indicating whether void is supported
- /// </summary>
- public bool SupportVoid
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// Gets a recurring payment type of payment method
- /// </summary>
- public RecurringPaymentType RecurringPaymentType
- {
- get
- {
- return RecurringPaymentType.Automatic;
- }
- }
- /// <summary>
- /// Gets a payment method type
- /// </summary>
- public PaymentMethodType PaymentMethodType
- {
- get
- {
- return PaymentMethodType.Standard;
- }
- }
- #endregion
- public decimal GetAdditionalHandlingFee(System.Collections.Generic.IList<ShoppingCartItem> cart)
- {
- return 0;
- //throw new NotImplementedException();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement