using System; using System.Net; using System.IO; using System.Data; using PayPal.Payments.Common; using PayPal.Payments.Common.Utility; using PayPal.Payments.DataObjects; using PayPal.Payments.Transactions; namespace Gateways { public class PayFlowPro : GatewayBase { private const string TestURL = "pilot-payflowpro.verisign.com/transaction"; private const string LiveURL = "payflowpro.verisign.com/transaction"; public PayFlowPro() { } public override GatewayResult InternalAuthorize(int OrderID, string FirstName, string LastName, string Address1, string Address2, string City, string State, string Zip, string Country, string Phone, string CustomerID, string CustomerIP, decimal Amount, string CardNumber, string ExpDate, string CSC) { // Payflow Pro integration follows // create user info #region Create Connection - pf_Connection PayflowConnectionData pf_Connection = new PayflowConnectionData((TestMode ? TestURL : LiveURL)); #endregion #region Create UserInfo - pf_UserInfo UserInfo pf_UserInfo = new UserInfo(Configuration.Get("Gateways.PayflowPro.User"), Configuration.Get("Gateways.PayflowPro.Vendor"), Configuration.Get("Gateways.PayflowPro.Partner"), Configuration.Get("Gateways.PayflowPro.Password")); #endregion #region Create Billing Information - pf_BillTo BillTo pf_BillTo = new BillTo(); pf_BillTo.FirstName = FirstName; pf_BillTo.LastName = LastName; pf_BillTo.Street = Address1; pf_BillTo.BillToStreet2 = Address2; pf_BillTo.City = City; pf_BillTo.State = State; pf_BillTo.Zip = Zip; pf_BillTo.PhoneNum = Phone; pf_BillTo.BillToCountry = "US"; #endregion #region Create Invoice - pf_Invoice Invoice pf_Invoice = new Invoice(); pf_Invoice.InvNum = OrderID.ToString(); pf_Invoice.Amt = new Currency(Amount, "USD"); pf_Invoice.BillTo = pf_BillTo; pf_Invoice.CustRef = CustomerID; #endregion #region Create Credit Card - pf_CreditCard CreditCard pf_CreditCard = new CreditCard(CardNumber, ExpDate); pf_CreditCard.Cvv2 = CSC; #endregion #region Create Tender - pf_Tender CardTender pf_Tender = new CardTender(pf_CreditCard); #endregion #region Create Transaction - pf_Transaction AuthorizationTransaction pf_Transaction = new AuthorizationTransaction(pf_UserInfo, pf_Connection, pf_Invoice, pf_Tender, PayflowUtility.RequestId); pf_Transaction.Verbosity = "MEDIUM"; #endregion #region Submit the transaction and get a response - pf_Response Response pf_Response = pf_Transaction.SubmitTransaction(); #endregion #region Extract the transaction response - pf_TransactionResponse TransactionResponse pf_TransactionResponse = null; if (pf_Response != null) { pf_TransactionResponse = pf_Response.TransactionResponse; } #endregion #region Create GatewayResult with response data GatewayResult gwResult = new GatewayResult(); gwResult.Operation = GatewayOperation.Authorize; gwResult.ResponseCode = "NTR"; gwResult.ResponseText = "NTR"; gwResult.PaymentReferenceCode = "NTR"; gwResult.Successful = false; if (pf_TransactionResponse != null) { gwResult.ResponseCode = pf_TransactionResponse.Result.ToString(); gwResult.ResponseText = pf_TransactionResponse.RespMsg + " : " + pf_Response.ResponseString; gwResult.PaymentReferenceCode = pf_TransactionResponse.Pnref; gwResult.Successful = (pf_TransactionResponse.Result == 0); } #endregion return gwResult; } public override GatewayResult InternalCapture(string PaymentReferenceCode, decimal Amount) { #region Create Connection - pf_Connection PayflowConnectionData pf_Connection = new PayflowConnectionData((TestMode ? TestURL : LiveURL)); #endregion #region Create UserInfo - pf_UserInfo UserInfo pf_UserInfo = new UserInfo(Configuration.Get("Gateways.PayflowPro.User"), Configuration.Get("Gateways.PayflowPro.Vendor"), Configuration.Get("Gateways.PayflowPro.Partner"), Configuration.Get("Gateways.PayflowPro.Password")); #endregion #region Create Transaction - pf_Transaction CaptureTransaction pf_Transaction = new CaptureTransaction(PaymentReferenceCode, pf_UserInfo, pf_Connection, PayflowUtility.RequestId); #endregion #region Submit the transaction and get a response - pf_Response Response pf_Response = pf_Transaction.SubmitTransaction(); #endregion #region Extract the transaction response - pf_TransactionResponse TransactionResponse pf_TransactionResponse = null; if (pf_Response != null) { pf_TransactionResponse = pf_Response.TransactionResponse; } #endregion #region Create GatewayResult with response data GatewayResult gwResult = new GatewayResult(); gwResult.Operation = GatewayOperation.Capture; gwResult.ResponseCode = "NTR"; gwResult.ResponseText = "NTR"; gwResult.PaymentReferenceCode = "NTR"; gwResult.Successful = false; if (pf_TransactionResponse != null) { gwResult.ResponseCode = pf_TransactionResponse.Result.ToString(); gwResult.ResponseText = pf_TransactionResponse.RespMsg; gwResult.PaymentReferenceCode = pf_TransactionResponse.Pnref; gwResult.Successful = (pf_TransactionResponse.Result == 0); } #endregion return gwResult; } public override GatewayResult InternalVoid(string PaymentReferenceCode) { #region Create Connection - pf_Connection PayflowConnectionData pf_Connection = new PayflowConnectionData((TestMode ? TestURL : LiveURL)); #endregion #region Create UserInfo - pf_UserInfo UserInfo pf_UserInfo = new UserInfo(Configuration.Get("Gateways.PayflowPro.User"), Configuration.Get("Gateways.PayflowPro.Vendor"), Configuration.Get("Gateways.PayflowPro.Partner"), Configuration.Get("Gateways.PayflowPro.Password")); #endregion #region Create Transaction - pf_Transaction VoidTransaction pf_Transaction = new VoidTransaction(PaymentReferenceCode, pf_UserInfo, pf_Connection, PayflowUtility.RequestId); #endregion #region Submit the transaction and get a response - pf_Response Response pf_Response = pf_Transaction.SubmitTransaction(); #endregion #region Extract the transaction response - pf_TransactionResponse TransactionResponse pf_TransactionResponse = null; if (pf_Response != null) { pf_TransactionResponse = pf_Response.TransactionResponse; } #endregion #region Create GatewayResult with response data GatewayResult gwResult = new GatewayResult(); gwResult.Operation = GatewayOperation.Capture; gwResult.ResponseCode = "NTR"; gwResult.ResponseText = "NTR"; gwResult.PaymentReferenceCode = "NTR"; gwResult.Successful = false; if (pf_TransactionResponse != null) { gwResult.ResponseCode = pf_TransactionResponse.Result.ToString(); gwResult.ResponseText = pf_TransactionResponse.RespMsg; gwResult.PaymentReferenceCode = pf_TransactionResponse.Pnref; gwResult.Successful = (pf_TransactionResponse.Result == 0); } #endregion return gwResult; } public override GatewayResult InternalCredit(string PaymentReferenceCode, string LastFour, decimal Amount) { #region Create Connection - pf_Connection PayflowConnectionData pf_Connection = new PayflowConnectionData((TestMode ? TestURL : LiveURL)); #endregion #region Create UserInfo - pf_UserInfo UserInfo pf_UserInfo = new UserInfo(Configuration.Get("Gateways.PayflowPro.User"), Configuration.Get("Gateways.PayflowPro.Vendor"), Configuration.Get("Gateways.PayflowPro.Partner"), Configuration.Get("Gateways.PayflowPro.Password")); #endregion #region Create Invoice - pf_Invoice Invoice pf_Invoice = new Invoice(); //pf_Invoice.InvNum = PaymentReferenceCode; pf_Invoice.Amt = new Currency(Amount); #endregion #region Create Credit Card - pf_CreditCard CreditCard pf_CreditCard = new CreditCard("000000000000" + LastFour, "0101"); #endregion #region Create Tender - pf_Tender CardTender pf_Tender = new CardTender(pf_CreditCard); #endregion #region Create Transaction - pf_Transaction CreditTransaction pf_Transaction = new CreditTransaction(PaymentReferenceCode, pf_UserInfo, pf_Connection, pf_Invoice, PayflowUtility.RequestId); #endregion #region Submit the transaction and get a response - pf_Response Response pf_Response = pf_Transaction.SubmitTransaction(); #endregion #region Extract the transaction response - pf_TransactionResponse TransactionResponse pf_TransactionResponse = null; if (pf_Response != null) { pf_TransactionResponse = pf_Response.TransactionResponse; } #endregion #region Create GatewayResult with response data GatewayResult gwResult = new GatewayResult(); gwResult.Operation = GatewayOperation.Capture; gwResult.ResponseCode = "NTR"; gwResult.ResponseText = "NTR"; gwResult.PaymentReferenceCode = "NTR"; gwResult.Successful = false; if (pf_TransactionResponse != null) { gwResult.ResponseCode = pf_TransactionResponse.Result.ToString(); gwResult.ResponseText = pf_TransactionResponse.RespMsg; gwResult.PaymentReferenceCode = pf_TransactionResponse.Pnref; gwResult.Successful = (pf_TransactionResponse.Result == 0); } #endregion return gwResult; } } }