public void ShouldNotCallParseMessageToResponseWhenStatusCodeIsNotSuccess() { //Arrange //Mock Formatter var formatterMock = new Mock <IFormatter <PaymentRequest, BaseResponse, string> >(); formatterMock.Setup(f => f.ParseMessageToResponse(It.IsAny <string>())); formatterMock.Setup(f => f.ParseRequestToMessage(It.IsAny <PaymentRequest>())); //Mock Service var serviceMock = new Mock <HttpServiceBase <PaymentRequest, HttpResponseMessage> >(MockBehavior.Strict, new Credential(), "urlFake"); serviceMock.Setup(s => s.Execute(It.IsAny <PaymentRequest>())).Returns(new HttpResponseMessage() { Content = new StringContent("teste"), StatusCode = System.Net.HttpStatusCode.NotFound }); VoidTransaction voidTransaction = new VoidTransaction(formatterMock.Object, serviceMock.Object, logger); //Act voidTransaction.Execute(new PaymentRequest()); //Assert formatterMock.Verify(f => f.ParseMessageToResponse(It.IsAny <string>()), Times.Never); formatterMock.Verify(f => f.ParseRequestToMessage(It.IsAny <PaymentRequest>()), Times.Once); serviceMock.Verify(s => s.Execute(It.IsAny <PaymentRequest>()), Times.Once); }
public void doSale() { string url = "https://staging-api.payhub.com/api/v2/"; string oauth = "107d74ab-4a18-4713-88ff-69bd05710086"; Merchant merchant = new Merchant(); merchant.organization_id = 10127; merchant.terminal_id = 215; Bill bill = new Bill(); bill.Base_amount = (decimal)7.00m; bill.Shipping_amount = (decimal)2.00m; bill.Tax_amount = (decimal)1.00m; bill.note = ""; bill.invoice_number = ""; bill.po_number = ""; CardData card_data = new CardData(); card_data.card_number = "4055011111111111"; card_data.card_expiry_date = "202012"; card_data.billing_address_1 = "123 Happy St"; card_data.billing_address_2 = "On the corner"; card_data.billing_city = "San Rafael"; card_data.billing_state = "CA"; card_data.billing_zip = "12345"; card_data.cvv_data = "999"; Customer customer = new Customer(); customer.first_name = "Joe"; customer.last_name = "Tester"; customer.company_name = "Payhub Inc"; customer.job_title = "Software Engineer"; customer.email_address = "*****@*****.**"; customer.web_address = "http://payhub.com"; customer.phone_number = "844-217-1631"; customer.phone_ext = "123"; customer.phone_type = "W"; Sale sale = new Sale(merchant, bill, card_data, customer); TransactionManager transaction = new TransactionManager(url, oauth, merchant); SaleResponseInformation response = transaction.doSale(sale); Console.Write(response.rowData); if (response.errors == null) { var saleId = response.SaleResponse.SaleId; VoidTransaction voidTransaction = new VoidTransaction(merchant, saleId); VoidResponseInformation voidInfo = transaction.doVoid(voidTransaction); Console.Write(voidInfo.rowData); } else { Console.Write(response.errors); } }
public void doSale() { /* The current url, oauth_token, orgId and Terminal Id provided in this example, are only for testing purposes * For development purposes you need to contact the Payhub Integration Support team. They will provide you with * all you need. * Thanks. */ //Defining the Web Service URL string url = "https://sandbox-api.payhub.com/api/v2/"; string oauth = "2a5d6a73-d294-4fba-bfba-957a4948d4a3"; Merchant merchant = new Merchant(); merchant.organization_id = 10074; //merchant.terminal_id = 134; Bill bill = new Bill(); bill.Base_amount = (decimal)7.00m; bill.Shipping_amount = (decimal)2.00m; bill.Tax_amount = (decimal)1.00m; bill.note = ""; bill.invoice_number = ""; bill.po_number = ""; CardData card_data = new CardData(); card_data.card_number = "4055011111111111"; card_data.card_expiry_date = "202012"; card_data.billing_address_1 = "123 Happy St"; card_data.billing_address_2 = "On the corner"; card_data.billing_city = "San Rafael"; card_data.billing_state = "CA"; card_data.billing_zip = "12345"; card_data.cvv_data = "999"; Customer customer = new Customer(); customer.first_name = "Joe"; customer.last_name = "Tester"; customer.company_name = "Payhub Inc"; customer.job_title = "Software Engineer"; customer.email_address = "*****@*****.**"; customer.web_address = "http://payhub.com"; customer.phone_number = "844-217-1631"; customer.phone_ext = "123"; customer.phone_type = "W"; Sale sale = new Sale(merchant, bill, card_data, customer); TransactionManager transaction = new TransactionManager(url, oauth, merchant); SaleResponseInformation response = transaction.getSaleInformation("1923"); Console.Write(response.rowData); if (response.errors == null) { var saleId = response.SaleResponse.SaleId; VoidTransaction voidTransaction = new VoidTransaction(merchant, saleId); VoidResponseInformation voidInfo = transaction.doVoid(voidTransaction); Console.Write(voidInfo.rowData); } else { Console.Write(response.errors[0]); } }
public void ShouldReturnErrorMessageWhenPassingNullRequest() { //Arrange VoidTransaction voidTransaction = new VoidTransaction(null, null, logger); //Act BaseResponse response = voidTransaction.Execute(null); //Assert Assert.AreEqual("Ocorreu um erro na chamada da transação de cancelamento. Verifique o log de erro para mais detalhes", response.ReturnMessage); }
/// <summary> /// Perform a new VoidTransaction. /// /// <param name="voidData"> /// VoidTransaction Object /// </param> /// <returns> /// LastVoidResponseInformation object. /// </returns> /// <seealso cref="PayHubWS.com.payhub.ws.api.LastVoidResponseInformation"/> /// </summary> public VoidResponseInformation doVoid(VoidTransaction voidData) { voidData.Merchant = _merchant; voidData._url = _url; var request = setHeadersPost(voidData._url, this._oauthToken); string json = JsonConvert.SerializeObject(voidData, Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }); VoidResponseInformation response = voidData.performVoidTransaction(json, request); response.transactionManager = this; return(response); }
public async Task SetValueAsync(IDeferredItem <TItem> item, object deserializedValue, IDataTransaction dataTransaction) { IEngineRepository <TNav> navRepository = new NavigationItemRepository <TItem, TNav>(item, _navTools.NavExpression, _navTools.Setter); var itemData = new RestItemData(deserializedValue); var navLocatorCreator = new NavigationItemLocatorCreator <TNav>(_subContext); DeferredItemBase <TNav> deferredItem = await navLocatorCreator.LocateOrCreateItemAsync(navRepository, itemData, item.LoadAsync); try { IDataTransaction transaction = new VoidTransaction(); // we commit the transaction in the parent. TODO optional save-as-you-go ? var navContext = new FullEngineContext <TNav>(transaction, navRepository, _subContext); var navEngineItem = new EngineRestItem <TNav>(navContext, deferredItem); Acknowledgment acknowledgment = await navEngineItem.EditAsync(itemData); } catch (RestApiException ex) { throw new SubWriterException(ex, item); } }
public async Task SetValueAsync(IDeferredItem <TItem> item, object deserializedValue, IDataTransaction dataTransaction) { IEngineRepository <TNav> navRepository = new NavigationCollectionRepository <TItem, TCollection, TNav>(item, _navTools.NavExpression, _navTools.Setter); IDataTransaction transaction = new VoidTransaction(); // we commit the transaction in the parent. TODO optional save-as-you-go ? var navContext = new FullEngineContext <TNav>(transaction, navRepository, _subContext); var navLocatorCreator = new NavigationItemLocatorCreator <TNav>(_subContext); IEnumerable deserializedCollection = (IEnumerable)deserializedValue; // todo null ? foreach (object deserializedItem in deserializedCollection) { var itemData = new RestItemData(deserializedItem); DeferredItemBase <TNav> deferredItem = await navLocatorCreator.LocateOrCreateItemAsync(navRepository, itemData, item.LoadAsync); var navEngineItem = new EngineRestItem <TNav>(navContext, deferredItem); Acknowledgment acknowledgment = await navEngineItem.EditAsync(itemData); } // TODO: remove items that were not located? }
public ANetApiResponse TestVoid() { var response = (createTransactionResponse)AuthorizeCreditCard.Run(apiLoginId, transactionKey, GetAmount()); return(VoidTransaction.Run(apiLoginId, transactionKey, response.transactionResponse.transId)); }
public CodedArtistEntityContext(IRestUser user) { Transaction = new VoidTransaction(); Repository = new ArtistMemoryRepository(); AuthorizationChecker = new AllowAllAuthorizationChecker <Artist>(); }
public override void ProcessTransaction(Transaction t) { bool result = false; //'Get Configuration Settings string MerchantPartner = Settings.MerchantPartner; string MerchantLogin = Settings.MerchantLogin; string MerchantUser = Settings.MerchantUser; string MerchantPassword = Settings.MerchantPassword; string CurrencyCode = Settings.CurrencyCode; bool TestMode = Settings.TestMode; bool DebugMode = Settings.DeveloperMode; UserInfo User = new UserInfo(MerchantUser, MerchantLogin, MerchantPartner, MerchantPassword); //Set HostAddress URL string HostAddress = LiveUrl; if (TestMode) HostAddress = TestUrl; //Connection Info PayflowConnectionData Connection = new PayflowConnectionData(HostAddress, 443, 45); //', CertLocation) // *** Create a new Invoice data object *** // Set Invoice object with the Amount, Billing & Shipping Address, etc. *** Invoice Inv = new Invoice(); // Set the amount object. A valid amount is a two decimal value. An invalid amount will generate a result code Currency Amt = new Currency(Decimal.Round(t.Amount, 2), CurrencyCode); //' 840 is US ISO currency code. If no code passed, 840 is default. Inv.Amt = Amt; // Generate a unique transaction ID string strRequestID = PayflowUtility.RequestId + t.MerchantInvoiceNumber; //InvNum and CustRef are sent to the processors and could show up on a customers // or your bank statement. These fields are reportable but not searchable in PayPal Manager. Inv.InvNum = t.MerchantInvoiceNumber; Inv.CustRef = t.Customer.Email; //' Comment1 and Comment2 fields are searchable within PayPal Manager . Inv.Comment1 = "Order Number: " + Inv.InvNum; Inv.Comment2 = "Customer Email: " + t.Customer.Email; // Create the BillTo object. BillTo Bill = new BillTo(); Bill.FirstName = t.Customer.FirstName; Bill.LastName = t.Customer.LastName; Bill.Street = t.Customer.Street; Bill.City = t.Customer.City; Bill.Zip = t.Customer.PostalCode; Bill.PhoneNum = t.Customer.Phone; Bill.Email = t.Customer.Email; Bill.State = t.Customer.Region; //' BillToCountry code is based on numeric ISO country codes. (e.g. 840 = USA) //Get Country Code string CountryCode = MerchantTribe.Web.Geography.Country.FindByName(t.Customer.Country).IsoNumeric; Bill.BillToCountry = CountryCode; // Set the BillTo object into invoice. Inv.BillTo = Bill; CustomerInfo CustInfo = new CustomerInfo(); CustInfo.CustId = t.Customer.Email; CustInfo.CustIP = t.Customer.IpAddress; // *** Create a new Payment Device - Credit Card data object. *** // Note: Expiration date is in the format MMYY string CCExpDate = t.Card.ExpirationMonthPadded + t.Card.ExpirationYearTwoDigits; CreditCard CC = new CreditCard(t.Card.CardNumber, CCExpDate); //' *** Card Security Code *** //' This is the 3 or 4 digit code on either side of the Credit Card. if (t.Card.SecurityCode.Length > 0) { CC.Cvv2 = t.Card.SecurityCode; } // Name on Credit Card is optional. CC.Name = t.Card.CardHolderName; // *** Create a new Tender - Card Tender data object. *** CardTender Card = new CardTender(CC); // *** Create a new Transaction. *** // The Request Id is the unique id necessary for each transaction. // If you pass a non-unique request id, you will receive the transaction details from the original request. //'DO TRANSACTION try { BaseTransaction Trans = null; switch(t.Action) { case ActionType.CreditCardHold: Trans = new AuthorizationTransaction(User,Connection, Inv, Card, strRequestID); break; case ActionType.CreditCardCharge: Trans = new SaleTransaction(User,Connection, Inv, Card, strRequestID); break; case ActionType.CreditCardCapture: Trans = new CaptureTransaction(t.PreviousTransactionNumber, User, Connection, Inv, strRequestID); break; case ActionType.CreditCardRefund: Trans = new CreditTransaction(t.PreviousTransactionNumber, User, Connection, Inv, strRequestID); break; case ActionType.CreditCardVoid: Trans = new VoidTransaction(t.PreviousTransactionNumber, User, Connection, strRequestID); break; } int Result = 0; System.Globalization.CultureInfo currCulture = System.Threading.Thread.CurrentThread.CurrentCulture; Response Resp = null; try { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; //' Submit the Transaction Resp = Trans.SubmitTransaction(); } finally { System.Threading.Thread.CurrentThread.CurrentCulture = currCulture; } if (Resp != null) { // Get the Transaction Response parameters. TransactionResponse TrxnResponse = Resp.TransactionResponse; // RESULT codes returns. if (TrxnResponse != null) { //Check for Approval (0 = approved, all else = Decline or Error) Result = TrxnResponse.Result; string RespMsg = TrxnResponse.RespMsg; //if success then save our reference number if (Result == 0) { t.Result.ReferenceNumber = TrxnResponse.Pnref; } t.Result.ResponseCode = TrxnResponse.AuthCode; //Custom Properties t.Result.AvsCode = AvsResponseType.Unavailable; t.Result.AvsCodeDescription = "AVSADDR: " + TrxnResponse.AVSAddr + " AVSZIP: " + TrxnResponse.AVSZip + " IAVS: " + TrxnResponse.IAVS; t.Result.ResponseCode = TrxnResponse.Result.ToString(); t.Result.CvvCode = CvnResponseType.Unavailable; t.Result.CvvCodeDescription = TrxnResponse.CVV2Match; t.Result.ResponseCodeDescription = TrxnResponse.RespMsg; } else { t.Result.Messages.Add(new Message("Payment Error: Transaction Response is Null", "BVP_PFP_1003", MessageType.Error)); } //Show Complete Response if Debug Mode if (DebugMode) { t.Result.Messages.Add(new Message("PayflowPro Request:" + Trans.Request, "REQ", MessageType.Information)); t.Result.Messages.Add(new Message("PayflowPro Request:" + Trans.Response.ResponseString, "RES", MessageType.Information)); // Get the Transaction Context Context TransCtx = Resp.TransactionContext; if ((TransCtx != null) && (TransCtx.getErrorCount() > 0)) { t.Result.Messages.Add(new Message("PayflowPro Context:" + TransCtx.ToString(), "CTX", MessageType.Information)); } } if (Result == 0) { result = true; } else { result = false; } } else { t.Result.Messages.Add(new Message("Payment Error: Response is Null", "BVP_PFP_1002", MessageType.Error)); } } catch(Exception ex) { result = false; t.Result.Messages.Add(new Message("Payment Error: " + ex.Message, "BVP_PFP_1001", MessageType.Error)); t.Result.Messages.Add(new Message("Stack Trace " + ex.StackTrace, "STACKTRACE", MessageType.Error)); } t.Result.Succeeded = result; }
/// <summary> /// Voids a payment /// </summary> /// <param name="voidPaymentRequest">Request</param> /// <returns>Result</returns> public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult(); // Check license bool isLicensed = this._licenseService.IsLicensed(HttpContext.Current.Request.Url.Host); if (!isLicensed && voidPaymentRequest.Order.OrderTotal > 5.00M) { result.AddError("The trial license can be used to submit order of $5.00 or less. Please purchase a full license at our website."); return result; } string transactionId = voidPaymentRequest.Order.AuthorizationTransactionId; if (String.IsNullOrEmpty(transactionId)) transactionId = voidPaymentRequest.Order.CaptureTransactionId; // Create the Payflow Data Objects. // Create the User data object with the required user details. UserInfo payflowUser = _payPalHelper.GetUserInfo(); // Create the Payflow Connection data object with the required connection details. PayflowConnectionData payflowConn = new PayflowConnectionData(_payPalHelper.GetPayflowProHost()); // Create a new Void Transaction. // The ORIGID is the PNREF no. for a previous transaction. VoidTransaction trans = new VoidTransaction(transactionId, payflowUser, payflowConn, PayflowUtility.RequestId); // Submit the Transaction Response resp = trans.SubmitTransaction(); // Process the Payflow response. if (resp != null) { // Get the Transaction Response parameters. TransactionResponse trxResp = resp.TransactionResponse; if (trxResp != null) { if (trxResp.Result == 0) { result.NewPaymentStatus = PaymentStatus.Voided; } else { result.AddError(string.Format("Void RESULT: {0}-{1}", trxResp.Result, trxResp.RespMsg)); } } } return result; }
/// <summary> /// Perform a new VoidTransaction. /// /// <param name="voidData"> /// VoidTransaction Object /// </param> /// <returns> /// LastVoidResponseInformation object. /// </returns> /// <seealso cref="PayHubWS.com.payhub.ws.api.LastVoidResponseInformation"/> /// </summary> public VoidResponseInformation doVoid(VoidTransaction voidData) { voidData.Merchant = _merchant; voidData._url = _url; var request = setHeadersPost(voidData._url, this._oauthToken); string json = JsonConvert.SerializeObject(voidData, Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }); VoidResponseInformation response = voidData.performVoidTransaction(json, request); response.transactionManager = this; return response; }
public static void Main(string[] Args) { Console.WriteLine("------------------------------------------------------"); Console.WriteLine("Executing Sample from File: DOVoid.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 Void Transaction. // The ORIGID is the PNREF no. for a previous transaction. VoidTransaction Trans = new VoidTransaction("<ORIGINAL_PNREF>", User, Connection, 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); } // 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(); }
private static void RunMethod(string methodName) { // These are default transaction keys. // You can create your own keys in seconds by signing up for a sandbox account here: https://developer.authorize.net/sandbox/ string apiLoginId = "5KP3u95bQpv"; string transactionKey = "4Ktq966gC55GAX7S"; string transactionAmount; string transactionId = string.Empty; switch (methodName) { case "ValidateCustomerPaymentProfile": ValidateCustomerPaymentProfile.Run(apiLoginId, transactionKey); break; case "UpdateCustomerShippingAddress": UpdateCustomerShippingAddress.Run(apiLoginId, transactionKey); break; case "UpdateCustomerProfile": UpdateCustomerProfile.Run(apiLoginId, transactionKey); break; case "UpdateCustomerPaymentProfile": UpdateCustomerPaymentProfile.Run(apiLoginId, transactionKey); break; case "GetCustomerShippingAddress": GetCustomerShippingAddress.Run(apiLoginId, transactionKey); break; case "GetCustomerProfileIds": GetCustomerProfileIds.Run(apiLoginId, transactionKey); break; case "GetCustomerProfile": GetCustomerProfile.Run(apiLoginId, transactionKey); break; case "GetCustomerPaymentProfile": GetCustomerPaymentProfile.Run(apiLoginId, transactionKey); break; case "DeleteCustomerShippingAddress": DeleteCustomerShippingAddress.Run(apiLoginId, transactionKey); break; case "DeleteCustomerProfile": DeleteCustomerProfile.Run(apiLoginId, transactionKey); break; case "DeleteCustomerPaymentProfile": DeleteCustomerPaymentProfile.Run(apiLoginId, transactionKey); break; case "CreateCustomerShippingAddress": CreateCustomerShippingAddress.Run(apiLoginId, transactionKey); break; case "CreateCustomerProfileFromTransaction": CreateCustomerProfileFromTransaction.Run(apiLoginId, transactionKey); break; case "GetTransactionDetails": GetTransactionDetails.Run(apiLoginId, transactionKey); break; case "GetTransactionList": GetTransactionList.Run(apiLoginId, transactionKey); break; //case "CreateAnApplePayTransaction": // CreateAnApplePayTransaction.Run(apiLoginId, transactionKey); // break; case "DecryptVisaCheckoutData": DecryptVisaCheckoutData.Run(apiLoginId, transactionKey); break; case "CreateVisaCheckoutTransaction": CreateVisaCheckoutTransaction.Run(apiLoginId, transactionKey); break; case "ChargeCreditCard": ChargeCreditCard.Run(apiLoginId, transactionKey); break; case "CaptureOnly": CaptureOnly.Run(apiLoginId, transactionKey); break; case "CapturePreviouslyAuthorizedAmount": Console.WriteLine("Enter An Transaction Amount"); transactionAmount = Console.ReadLine(); Console.WriteLine("Enter An Transaction ID"); transactionId = Console.ReadLine(); CapturePreviouslyAuthorizedAmount.Run(apiLoginId, transactionKey, Convert.ToDecimal(transactionAmount), transactionId); break; case "CaptureFundsAuthorizedThroughAnotherChannel": CaptureFundsAuthorizedThroughAnotherChannel.Run(apiLoginId, transactionKey); break; case "AuthorizeCreditCard": AuthorizeCreditCard.Run(apiLoginId, transactionKey); break; case "Refund": Console.WriteLine("Enter An Transaction Amount"); transactionAmount = Console.ReadLine(); Console.WriteLine("Enter An Transaction ID"); transactionId = Console.ReadLine(); RefundTransaction.Run(apiLoginId, transactionKey, Convert.ToDecimal(transactionAmount), transactionId); break; case "Void": Console.WriteLine("Enter An Transaction ID"); transactionId = Console.ReadLine(); VoidTransaction.Run(apiLoginId, transactionKey, transactionId); break; case "DebitBankAccount": DebitBankAccount.Run(apiLoginId, transactionKey); break; case "CreditBankAccount": Console.WriteLine("Enter An Transaction ID"); transactionId = Console.ReadLine(); CreditBankAccount.Run(apiLoginId, transactionKey, transactionId); break; case "ChargeCustomerProfile": ChargeCustomerProfile.Run(apiLoginId, transactionKey); break; case "ChargeTokenizedCard": ChargeTokenizedCreditCard.Run(apiLoginId, transactionKey); break; case "PayPalVoid": PayPalVoid.Run(apiLoginId, transactionKey, transactionId); break; case "PayPalAuthorizeCapture": PayPalAuthorizeCapture.Run(apiLoginId, transactionKey); break; case "PayPalAuthorizeCaptureContinue": PayPalAuthorizeCaptureContinue.Run(apiLoginId, transactionKey, transactionId); break; case "PayPalAuthorizeOnly": PayPalAuthorizeOnly.Run(apiLoginId, transactionKey); break; case "PayPalAuthorizeOnlyContinue": PayPalAuthorizeCaptureContinue.Run(apiLoginId, transactionKey, transactionId); break; case "PayPalCredit": PayPalCredit.Run(apiLoginId, transactionKey, transactionId); break; case "PayPalGetDetails": PayPalGetDetails.Run(apiLoginId, transactionKey, transactionId); break; case "PayPalPriorAuthorizationCapture": PayPalPriorAuthorizationCapture.Run(apiLoginId, transactionKey, transactionId); break; case "CancelSubscription": CancelSubscription.Run(apiLoginId, transactionKey); break; case "CreateSubscription": CreateSubscription.Run(apiLoginId, transactionKey); break; case "GetSubscriptionList": GetListSubscriptions.Run(apiLoginId, transactionKey); break; case "GetSubscriptionStatus": GetSubscriptionStatus.Run(apiLoginId, transactionKey); break; case "UpdateSubscription": UpdateSubscription.Run(apiLoginId, transactionKey); break; case "CreateCustomerProfile": CreateCustomerProfile.Run(apiLoginId, transactionKey); break; case "CreateCustomerPaymentProfile": CreateCustomerPaymentProfile.Run(apiLoginId, transactionKey); break; case "GetUnsettledTransactionList": GetUnsettledTransactionList.Run(apiLoginId, transactionKey); break; case "GetBatchStatistics": GetBatchStatistics.Run(apiLoginId, transactionKey); break; case "GetSettledBatchList": GetSettledBatchList.Run(apiLoginId, transactionKey); break; default: ShowUsage(); break; } }
public override void ProcessTransaction(Transaction t) { bool result = false; //'Get Configuration Settings string MerchantPartner = Settings.MerchantPartner; string MerchantLogin = Settings.MerchantLogin; string MerchantUser = Settings.MerchantUser; string MerchantPassword = Settings.MerchantPassword; string CurrencyCode = Settings.CurrencyCode; bool TestMode = Settings.TestMode; bool DebugMode = Settings.DeveloperMode; UserInfo User = new UserInfo(MerchantUser, MerchantLogin, MerchantPartner, MerchantPassword); //Set HostAddress URL string HostAddress = LiveUrl; if (TestMode) { HostAddress = TestUrl; } //Connection Info PayflowConnectionData Connection = new PayflowConnectionData(HostAddress, 443, 45); //', CertLocation) // *** Create a new Invoice data object *** // Set Invoice object with the Amount, Billing & Shipping Address, etc. *** Invoice Inv = new Invoice(); // Set the amount object. A valid amount is a two decimal value. An invalid amount will generate a result code Currency Amt = new Currency(Decimal.Round(t.Amount, 2), CurrencyCode); //' 840 is US ISO currency code. If no code passed, 840 is default. Inv.Amt = Amt; // Generate a unique transaction ID string strRequestID = PayflowUtility.RequestId + t.MerchantInvoiceNumber; //InvNum and CustRef are sent to the processors and could show up on a customers // or your bank statement. These fields are reportable but not searchable in PayPal Manager. Inv.InvNum = t.MerchantInvoiceNumber; Inv.CustRef = t.Customer.Email; //' Comment1 and Comment2 fields are searchable within PayPal Manager . Inv.Comment1 = "Order Number: " + Inv.InvNum; Inv.Comment2 = "Customer Email: " + t.Customer.Email; // Create the BillTo object. BillTo Bill = new BillTo(); Bill.FirstName = t.Customer.FirstName; Bill.LastName = t.Customer.LastName; Bill.Street = t.Customer.Street; Bill.City = t.Customer.City; Bill.Zip = t.Customer.PostalCode; Bill.PhoneNum = t.Customer.Phone; Bill.Email = t.Customer.Email; Bill.State = t.Customer.Region; //' BillToCountry code is based on numeric ISO country codes. (e.g. 840 = USA) //Get Country Code string CountryCode = MerchantTribe.Web.Geography.Country.FindByName(t.Customer.Country).IsoNumeric; Bill.BillToCountry = CountryCode; // Set the BillTo object into invoice. Inv.BillTo = Bill; CustomerInfo CustInfo = new CustomerInfo(); CustInfo.CustId = t.Customer.Email; CustInfo.CustIP = t.Customer.IpAddress; // *** Create a new Payment Device - Credit Card data object. *** // Note: Expiration date is in the format MMYY string CCExpDate = t.Card.ExpirationMonthPadded + t.Card.ExpirationYearTwoDigits; CreditCard CC = new CreditCard(t.Card.CardNumber, CCExpDate); //' *** Card Security Code *** //' This is the 3 or 4 digit code on either side of the Credit Card. if (t.Card.SecurityCode.Length > 0) { CC.Cvv2 = t.Card.SecurityCode; } // Name on Credit Card is optional. CC.Name = t.Card.CardHolderName; // *** Create a new Tender - Card Tender data object. *** CardTender Card = new CardTender(CC); // *** Create a new Transaction. *** // The Request Id is the unique id necessary for each transaction. // If you pass a non-unique request id, you will receive the transaction details from the original request. //'DO TRANSACTION try { BaseTransaction Trans = null; switch (t.Action) { case ActionType.CreditCardHold: Trans = new AuthorizationTransaction(User, Connection, Inv, Card, strRequestID); break; case ActionType.CreditCardCharge: Trans = new SaleTransaction(User, Connection, Inv, Card, strRequestID); break; case ActionType.CreditCardCapture: Trans = new CaptureTransaction(t.PreviousTransactionNumber, User, Connection, Inv, strRequestID); break; case ActionType.CreditCardRefund: Trans = new CreditTransaction(t.PreviousTransactionNumber, User, Connection, Inv, strRequestID); break; case ActionType.CreditCardVoid: Trans = new VoidTransaction(t.PreviousTransactionNumber, User, Connection, strRequestID); break; } int Result = 0; System.Globalization.CultureInfo currCulture = System.Threading.Thread.CurrentThread.CurrentCulture; Response Resp = null; try { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; //' Submit the Transaction Resp = Trans.SubmitTransaction(); } finally { System.Threading.Thread.CurrentThread.CurrentCulture = currCulture; } if (Resp != null) { // Get the Transaction Response parameters. TransactionResponse TrxnResponse = Resp.TransactionResponse; // RESULT codes returns. if (TrxnResponse != null) { //Check for Approval (0 = approved, all else = Decline or Error) Result = TrxnResponse.Result; string RespMsg = TrxnResponse.RespMsg; //if success then save our reference number if (Result == 0) { t.Result.ReferenceNumber = TrxnResponse.Pnref; } t.Result.ResponseCode = TrxnResponse.AuthCode; //Custom Properties t.Result.AvsCode = AvsResponseType.Unavailable; t.Result.AvsCodeDescription = "AVSADDR: " + TrxnResponse.AVSAddr + " AVSZIP: " + TrxnResponse.AVSZip + " IAVS: " + TrxnResponse.IAVS; t.Result.ResponseCode = TrxnResponse.Result.ToString(); t.Result.CvvCode = CvnResponseType.Unavailable; t.Result.CvvCodeDescription = TrxnResponse.CVV2Match; t.Result.ResponseCodeDescription = TrxnResponse.RespMsg; } else { t.Result.Messages.Add(new Message("Payment Error: Transaction Response is Null", "BVP_PFP_1003", MessageType.Error)); } //Show Complete Response if Debug Mode if (DebugMode) { t.Result.Messages.Add(new Message("PayflowPro Request:" + Trans.Request, "REQ", MessageType.Information)); t.Result.Messages.Add(new Message("PayflowPro Request:" + Trans.Response.ResponseString, "RES", MessageType.Information)); // Get the Transaction Context Context TransCtx = Resp.TransactionContext; if ((TransCtx != null) && (TransCtx.getErrorCount() > 0)) { t.Result.Messages.Add(new Message("PayflowPro Context:" + TransCtx.ToString(), "CTX", MessageType.Information)); } } if (Result == 0) { result = true; } else { result = false; } } else { t.Result.Messages.Add(new Message("Payment Error: Response is Null", "BVP_PFP_1002", MessageType.Error)); } } catch (Exception ex) { result = false; t.Result.Messages.Add(new Message("Payment Error: " + ex.Message, "BVP_PFP_1001", MessageType.Error)); t.Result.Messages.Add(new Message("Stack Trace " + ex.StackTrace, "STACKTRACE", MessageType.Error)); } t.Result.Succeeded = result; }