/// <summary> /// Authorizes the specified payment info. /// </summary> /// <param name="financialGateway"></param> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public override FinancialTransaction Authorize(FinancialGateway financialGateway, PaymentInfo paymentInfo, out string errorMessage) { errorMessage = string.Empty; Response ppResponse = null; var invoice = GetInvoice(paymentInfo); var tender = GetTender(paymentInfo); if (tender != null) { if (paymentInfo is ReferencePaymentInfo) { var reference = paymentInfo as ReferencePaymentInfo; var ppTransaction = new ReferenceTransaction("Authorization", reference.TransactionCode, GetUserInfo(financialGateway), GetConnection(financialGateway), invoice, tender, PayflowUtility.RequestId); ppResponse = ppTransaction.SubmitTransaction(); } else { var ppTransaction = new AuthorizationTransaction(GetUserInfo(financialGateway), GetConnection(financialGateway), invoice, tender, PayflowUtility.RequestId); ppResponse = ppTransaction.SubmitTransaction(); } } else { errorMessage = "Could not create tender from PaymentInfo"; } if (ppResponse != null) { TransactionResponse txnResponse = ppResponse.TransactionResponse; if (txnResponse != null) { if (txnResponse.Result == 0) // Success { var transaction = new FinancialTransaction(); transaction.TransactionCode = txnResponse.Pnref; return(transaction); } else { errorMessage = string.Format("[{0}] {1}", txnResponse.Result, txnResponse.RespMsg); } } else { errorMessage = "Invalid transaction response from the financial gateway"; } } else { errorMessage = "Invalid response from the financial gateway."; } return(null); }
public static void Main(string[] Args) { Console.WriteLine("------------------------------------------------------"); Console.WriteLine("Executing Sample from File: DOReference.cs"); Console.WriteLine("------------------------------------------------------"); // Create the Data Objects. // Create the User data object with the required user details. UserInfo User = new UserInfo("<user>", "<vendor>", "<partner>", "<password>"); // Create the Payflow Connection data object with the required connection details. // The PAYFLOW_HOST property is defined in the App config file. PayflowConnectionData Connection = new PayflowConnectionData(); // Create a new Invoice data object with the Amount, Billing Address etc. details. Invoice Inv = new Invoice(); // Set Amount. Currency Amt = new Currency(new decimal(25.12)); Inv.Amt = Amt; // Create a new Tender - Base Tender data object and set the Tender Type to "C". // We do not pass any payment device BaseTender Tender = new BaseTender("C", null); // To modify the expiration date, we wil also need to create a CreditCard object // without passing the credit card number. //CreditCard CC = new CreditCard(null, "1215"); //CardTender Card = new CardTender(CC); // Create a new Reference Transaction. ReferenceTransaction Trans = new ReferenceTransaction("S", "<PNREF>", User, Connection, Inv, PayflowUtility.RequestId); // If expiration date is changed too. //ReferenceTransaction Trans = new ReferenceTransaction("S", "<PNREF>", User, Connection, Inv, Card, PayflowUtility.RequestId); // You can also change the expiration date of the new reference transaction, by passing the EXPDATE via the ExtendData object. //ExtendData ExpDate = new ExtendData("EXPDATE", "1215"); //Trans.AddToExtendData(ExpDate); // 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); } // 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). Context TransCtx = Resp.TransactionContext; if (TransCtx != null && TransCtx.getErrorCount() > 0) { Console.WriteLine(Environment.NewLine + "Transaction Errors = " + TransCtx.ToString()); } } Console.WriteLine("Press Enter to Exit ..."); Console.ReadLine(); }
/// <summary> /// Charges the specified payment info. /// </summary> /// <param name="financialGateway"></param> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public override FinancialTransaction Charge(FinancialGateway financialGateway, PaymentInfo paymentInfo, out string errorMessage) { errorMessage = string.Empty; Response ppResponse = null; var invoice = GetInvoice(paymentInfo); // add in spark reference code BrowserInfo browser = new BrowserInfo(); browser.ButtonSource = "SparkDevelopmentNetwork_SP"; invoice.BrowserInfo = browser; var tender = GetTender(paymentInfo); if (tender != null) { if (paymentInfo is ReferencePaymentInfo) { var reference = paymentInfo as ReferencePaymentInfo; var ppTransaction = new ReferenceTransaction("Sale", reference.TransactionCode, GetUserInfo(financialGateway), GetConnection(financialGateway), invoice, tender, PayflowUtility.RequestId); ppResponse = ppTransaction.SubmitTransaction(); } else { var ppTransaction = new SaleTransaction(GetUserInfo(financialGateway), GetConnection(financialGateway), invoice, tender, PayflowUtility.RequestId); ppResponse = ppTransaction.SubmitTransaction(); } } else { errorMessage = "Could not create tender from PaymentInfo"; } if (ppResponse != null) { TransactionResponse txnResponse = ppResponse.TransactionResponse; if (txnResponse != null) { if (txnResponse.Result == 0) // Success { var transaction = new FinancialTransaction(); transaction.TransactionCode = txnResponse.Pnref; // Get the stored payment method that was used so we can update it // with the latest transaction code. We do this because Paypal // will only let us use the same transaction code in reference // transactions for up to 12 months. if (paymentInfo is ReferencePaymentInfo) { var reference = paymentInfo as ReferencePaymentInfo; var rockContext = new RockContext(); var savedAccount = new FinancialPersonSavedAccountService(rockContext) .Queryable() .Where(s => s.TransactionCode == reference.TransactionCode && s.FinancialGatewayId.HasValue && s.FinancialGatewayId.Value == financialGateway.Id) .FirstOrDefault(); if (savedAccount != null) { savedAccount.TransactionCode = txnResponse.Pnref; rockContext.SaveChanges(); } } return(transaction); } else { errorMessage = string.Format("[{0}] {1}", txnResponse.Result, txnResponse.RespMsg); } } else { errorMessage = "Invalid transaction response from the financial gateway"; } } else { errorMessage = "Invalid response from the financial gateway."; } return(null); }
/// <summary> /// Charges the specified payment info. /// </summary> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public override FinancialTransaction Charge( PaymentInfo paymentInfo, out string errorMessage ) { errorMessage = string.Empty; Response ppResponse = null; var invoice = GetInvoice( paymentInfo ); var tender = GetTender( paymentInfo ); if ( tender != null ) { if ( paymentInfo is ReferencePaymentInfo ) { var reference = paymentInfo as ReferencePaymentInfo; var ppTransaction = new ReferenceTransaction( "Sale", reference.TransactionCode, GetUserInfo(), GetConnection(), invoice, tender, PayflowUtility.RequestId ); ppResponse = ppTransaction.SubmitTransaction(); } else { var ppTransaction = new SaleTransaction( GetUserInfo(), GetConnection(), invoice, tender, PayflowUtility.RequestId ); ppResponse = ppTransaction.SubmitTransaction(); } } else { errorMessage = "Could not create tender from PaymentInfo"; } if ( ppResponse != null ) { TransactionResponse txnResponse = ppResponse.TransactionResponse; if ( txnResponse != null ) { if ( txnResponse.Result == 0 ) // Success { var transaction = new FinancialTransaction(); transaction.TransactionCode = txnResponse.Pnref; return transaction; } else { errorMessage = string.Format( "[{0}] {1}", txnResponse.Result, txnResponse.RespMsg ); } } else { errorMessage = "Invalid transaction response from the financial gateway"; } } else { errorMessage = "Invalid response from the financial gateway."; } return null; }