private IEnumerable <IGatewayResponse> SendGetTransactionsRequest(AuthorizeDotNetRequest request) { var result = string.Empty; //IGatewayResponse gatewayResponse; var transactions = new List <Model.Gateway.Payment>(); var authentication = new MerchantAuthenticationType(); authentication.name = request.KeyValues[AuthorizeDotNetApi.ApiLogin]; authentication.transactionKey = request.KeyValues[AuthorizeDotNetApi.TransactionKey]; string id = request.KeyValues[AuthorizeDotNetApi.BatchId]; using (var webService = new RevStack.AuthorizeDotNet.net.authorize.api.Service()) { webService.Url = request.PostUrl; GetTransactionListRequestType listType = new GetTransactionListRequestType(); listType.batchId = id; GetTransactionListResponseType response = webService.GetTransactionList(authentication, listType, null); char del = request.KeyValues[AuthorizeDotNetApi.DelimitCharacter].ToCharArray()[0]; if (response == null) { return(transactions); } foreach (var transaction in response.transactions) { var gatewayResponse = new Model.Gateway.Payment(transaction); transactions.Add(gatewayResponse); } } return(transactions); }
private IGatewayResponse SendUnsettledTransactionsRequest(AuthorizeDotNetRequest request) { var result = string.Empty; IGatewayResponse gatewayResponse; var authentication = new MerchantAuthenticationType(); authentication.name = request.KeyValues[AuthorizeDotNetApi.ApiLogin]; authentication.transactionKey = request.KeyValues[AuthorizeDotNetApi.TransactionKey]; using (var webService = new RevStack.AuthorizeDotNet.net.authorize.api.Service()) { webService.Url = request.PostUrl; GetUnsettledTransactionListRequestType listType = new GetUnsettledTransactionListRequestType(); GetUnsettledTransactionListResponseType response = webService.GetUnsettledTransactionList(authentication, listType, null); char del = request.KeyValues[AuthorizeDotNetApi.DelimitCharacter].ToCharArray()[0]; for (int i = 0; i < response.messages.Length; i++) { result = response.messages[i].text + del; } result = result.TrimEnd(del); gatewayResponse = new GatewayResponse(result, del); } return(gatewayResponse); }
public SubscriptionResult CreateSubscription(CreditCardInfo CCInfo, CustomerInfo CustInfo, SubscriptionInfo SubInfo, OrderInfo OrderInfo) { SubscriptionResult result = new SubscriptionResult(); Console.WriteLine("\r\nCreate subscription"); MerchantAuthenticationType authentication = GetMerchantAuthentication(); ARBSubscriptionType subscription = new ARBSubscriptionType(); PopulateSubscription(subscription, CCInfo, CustInfo, SubInfo, OrderInfo, false); ARBCreateSubscriptionResponseType response; response = GetArbService().ARBCreateSubscription(authentication, subscription); if (response.resultCode == MessageTypeEnum.Ok) { result.Successful = true; result.SubscriptionId = response.subscriptionId; result.Message = string.Format("A subscription with an ID of '{0}' was successfully created.", response.subscriptionId); } else { result.Successful = false; result.Message = GetSubscriptionErrors(response); } return(result); }
private IGatewayResponse SendCancelSubscriptionRequest(AuthorizeDotNetRequest request) { var result = string.Empty; IGatewayResponse gatewayResponse; var authentication = new MerchantAuthenticationType(); authentication.name = request.KeyValues[AuthorizeDotNetApi.ApiLogin]; authentication.transactionKey = request.KeyValues[AuthorizeDotNetApi.TransactionKey]; string id = request.KeyValues[AuthorizeDotNetApi.SubscriptionID]; using (var webService = new RevStack.AuthorizeDotNet.net.authorize.api.Service()) { webService.Url = request.PostUrl; ARBCancelSubscriptionResponseType response = webService.ARBCancelSubscription(authentication, long.Parse(id), null); char del = request.KeyValues[AuthorizeDotNetApi.DelimitCharacter].ToCharArray()[0]; IList <string> list = new List <string>(); for (int i = 0; i < response.messages.Length; i++) { result = response.messages[i].text + del; list.Add(response.messages[i].text); } result = result.TrimEnd(del); gatewayResponse = new GatewayResponse(result, del); gatewayResponse.SubscriptionResponse = list; } return(gatewayResponse); }
// Populate merchant authentication (ARB Support) private MerchantAuthenticationType PopulateMerchantAuthentication() { var authentication = new MerchantAuthenticationType(); authentication.name = _authorizeNetPaymentSettings.LoginId; authentication.transactionKey = _authorizeNetPaymentSettings.TransactionKey; return(authentication); }
private MerchantAuthenticationType GetMerchantAuthentication() { MerchantAuthenticationType authentication = new MerchantAuthenticationType(); authentication.name = API_Login; authentication.transactionKey = TransactionKey; return(authentication); }
// Populate merchant authentication (ARB Support) private MerchantAuthenticationType PopulateMerchantAuthentication() { MerchantAuthenticationType authentication = new MerchantAuthenticationType(); authentication.name = loginID; authentication.transactionKey = transactionKey; return(authentication); }
public AuthorizeNetClient( MerchantAuthenticationType merchantAuthenticationType, IAuthorizeNetClientOptions options, IHttpClientFactory httpClientFactory, ILogger <AuthorizeNetClient <TRequest, TResponse> > logger) { _merchantAuthenticationType = merchantAuthenticationType ?? throw new ArgumentNullException(nameof(merchantAuthenticationType)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _httpClient = httpClientFactory.CreateClient(options.Name); }
public static MerchantAuthenticationType CreateMerchantAuthenticationType(string merchantName, string merchantTransactionKey) { MerchantAuthenticationType mat = new MerchantAuthenticationType() { name = merchantName, transactionKey = merchantTransactionKey, }; return(mat); }
public static bool CreateNewCustomerPaymentProfile(SiteDT site, CustomerDT customer, string cardNumber, string expirationDate, out long paymentProfile, out string message) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; using (ServiceSoapClient client = new ServiceSoapClient()) { paymentProfile = 0; message = string.Empty; var merchant = new MerchantAuthenticationType() { name = site.AuthorizeLoginId, transactionKey = site.AuthorizeTransactionKey }; CustomerPaymentProfileType customerPPT = new CustomerPaymentProfileType(); customerPPT.customerType = CustomerTypeEnum.individual; customerPPT.customerTypeSpecified = true; customerPPT.billTo = new CustomerAddressType() { firstName = customer.FirstName, lastName = customer.LastName, address = customer.Address, city = customer.City, country = "USA", state = customer.StateId, zip = customer.ZipCode }; CreditCardType ccT = new CreditCardType(); ccT.cardNumber = cardNumber; ccT.expirationDate = expirationDate; ccT.cardCode = string.Empty; PaymentType payment = new PaymentType(); payment.Item = ccT; customerPPT.payment = payment; var resp = client.CreateCustomerPaymentProfile(merchant, customer.AuthorizeProfileId, customerPPT, ValidationModeEnum.testMode); if (resp.resultCode == MessageTypeEnum.Ok) { paymentProfile = resp.customerPaymentProfileId; return(true); } else { message = resp.messages.Select(x => x.code + ": " + x.text).Aggregate((a, b) => a + "\n" + b); } return(false); } }
public static bool CreateCustomerProfileTransactionAuthCapture(Site site, Invoice invoice, Customer customer, CreditCard creditCard, out long transactionId, out string message, out bool cancel) { cancel = false; MerchantAuthenticationType merchantAT = new MerchantAuthenticationType(); merchantAT.name = site.AuthorizeLoginId; merchantAT.transactionKey = site.AuthorizeTransactionKey; ProfileTransactionType profileTT = new ProfileTransactionType(); ProfileTransAuthCaptureType profileTACT = new ProfileTransAuthCaptureType(); OrderExType orderET = new OrderExType(); orderET.invoiceNumber = invoice.Id.ToString(); profileTACT.amount = invoice.Amount; profileTACT.customerProfileId = customer.AuthorizeProfileId; profileTACT.customerPaymentProfileId = creditCard.AuthorizePaymentProfileId; profileTACT.order = orderET; profileTT.Item = profileTACT; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;// comparable to modern browsers ServiceSoapClient client = new ServiceSoapClient(); CreateCustomerProfileTransactionResponseType resp = client.CreateCustomerProfileTransaction(merchantAT, profileTT, String.Empty); if (resp.directResponse != null) { PaymentGatewayResponse paymentGatewayResponse = new PaymentGatewayResponse(resp.directResponse); transactionId = paymentGatewayResponse.TransactionId; message = paymentGatewayResponse.ResponseReasonText; if (!string.IsNullOrEmpty(paymentGatewayResponse.ResponseReasonText)) { cancel = paymentGatewayResponse.ResponseReasonText.ToLower().Contains("the credit card number is invalid") || paymentGatewayResponse.ResponseReasonText.ToLower().Contains("the credit card expiration date is invalid") || paymentGatewayResponse.ResponseReasonText.ToLower().Contains("the credit card has expired"); } } else { transactionId = 0; if (resp.messages.Length > 0) { message = resp.messages[0].text; } else { message = ""; } } return(resp.resultCode == MessageTypeEnum.Ok); }
public static bool CreateCustomerProfileTransactionAuthCapture(SiteDT site, InvoiceDT invoice, CustomerDT customer, CreditCardDT creditCard, out long transactionId, out string message, out string code) { MerchantAuthenticationType merchantAT = new MerchantAuthenticationType(); merchantAT.name = site.AuthorizeLoginId; merchantAT.transactionKey = site.AuthorizeTransactionKey; ProfileTransactionType profileTT = new ProfileTransactionType(); ProfileTransAuthCaptureType profileTACT = new ProfileTransAuthCaptureType(); OrderExType orderET = new OrderExType(); orderET.invoiceNumber = invoice.Id.ToString(); profileTACT.amount = invoice.Amount; profileTACT.customerProfileId = customer.AuthorizeProfileId; profileTACT.customerPaymentProfileId = creditCard.AuthorizePaymentProfileId; profileTACT.order = orderET; profileTT.Item = profileTACT; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServiceSoapClient client = new ServiceSoapClient(); CreateCustomerProfileTransactionResponseType resp = client.CreateCustomerProfileTransaction(merchantAT, profileTT, String.Empty); code = string.Empty; if (resp.directResponse != null) { PaymentGatewayResponse paymentGatewayResponse = new PaymentGatewayResponse(resp.directResponse); transactionId = paymentGatewayResponse.TransactionId; message = paymentGatewayResponse.ResponseReasonText; code = resp.messages != null && resp.messages.Count() > 0 ? resp.messages.Select(x => x.code + " - " + x.text).Aggregate((a, b) => a + "; " + b) : string.Empty; } else { transactionId = 0; if (resp.messages.Length > 0) { message = resp.messages[0].text; } else { message = ""; } } return(resp.resultCode == MessageTypeEnum.Ok); }
/// <summary> /// Cancels recurring payment /// </summary> /// <param name="order">Order</param> /// <param name="cancelPaymentResult">Cancel payment result</param> public void CancelRecurringPayment(Order order, ref CancelPaymentResult cancelPaymentResult) { InitSettings(); MerchantAuthenticationType authentication = PopulateMerchantAuthentication(); long subscriptionID = 0; long.TryParse(cancelPaymentResult.SubscriptionTransactionId, out subscriptionID); ARBCancelSubscriptionResponseType response = webService.ARBCancelSubscription(authentication, subscriptionID); if (response.resultCode == MessageTypeEnum.Ok) { //ok } else { cancelPaymentResult.Error = "Error cancelling subscription, please contact customer support. " + GetErrors(response); cancelPaymentResult.FullError = "Error cancelling subscription, please contact customer support. " + GetErrors(response); } }
public static bool UpdateCustomerPaymentProfile(SiteDT site, CustomerDT customer, CreditCardDT creditCard) { using (ServiceSoapClient client = new ServiceSoapClient()) { var merchant = new MerchantAuthenticationType() { name = site.AuthorizeLoginId, transactionKey = site.AuthorizeTransactionKey }; var paymentProfileResponse = client.GetCustomerPaymentProfile(merchant, customer.AuthorizeProfileId, creditCard.AuthorizePaymentProfileId); if (paymentProfileResponse.resultCode == MessageTypeEnum.Ok) { CreditCardType creditCardType = new CreditCardType() { cardCode = string.Empty, cardNumber = creditCard.CardNumber, expirationDate = creditCard.ExpDate }; var customerUpdate = new CustomerPaymentProfileExType() { billTo = paymentProfileResponse.paymentProfile.billTo, customerPaymentProfileId = paymentProfileResponse.paymentProfile.customerPaymentProfileId, payment = new PaymentType() { Item = creditCardType } }; var updateResponse = client.UpdateCustomerPaymentProfile(merchant, customer.AuthorizeProfileId, null, ValidationModeEnum.none); if (updateResponse.resultCode == MessageTypeEnum.Ok) { return(true); } } return(false); } }
private IGatewayResponse SendGetTransactionDetailsRequest(AuthorizeDotNetRequest request) { var result = string.Empty; IGatewayResponse gatewayResponse; var authentication = new MerchantAuthenticationType(); authentication.name = request.KeyValues[AuthorizeDotNetApi.ApiLogin]; authentication.transactionKey = request.KeyValues[AuthorizeDotNetApi.TransactionKey]; string id = request.KeyValues[AuthorizeDotNetApi.TransactionId]; using (var webService = new RevStack.AuthorizeDotNet.net.authorize.api.Service()) { webService.Url = request.PostUrl; GetTransactionDetailsResponseType response = webService.GetTransactionDetails(authentication, id, null); char del = request.KeyValues[AuthorizeDotNetApi.DelimitCharacter].ToCharArray()[0]; gatewayResponse = new Model.Gateway.Payment(response.transaction); } return(gatewayResponse); }
public ServiceProcessContext() { String liveUrl = AspDotNetStorefrontCore.AppLogic.AppConfig("AUTHORIZENET_Cim_LiveServiceURL"); String testUrl = AspDotNetStorefrontCore.AppLogic.AppConfig("AUTHORIZENET_Cim_SandboxServiceURL"); String merchantId = AspDotNetStorefrontCore.AppLogic.AppConfig("AUTHORIZENET_X_Login"); String transactionKey = AspDotNetStorefrontCore.AppLogic.AppConfig("AUTHORIZENET_X_Tran_Key"); bool sandboxEnabled = AspDotNetStorefrontCore.AppLogic.AppConfigBool("AUTHORIZENET_Cim_UseSandbox"); System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding(); binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport; string url = liveUrl; if (sandboxEnabled) { url = testUrl; } System.ServiceModel.EndpointAddress endpointAddress = new System.ServiceModel.EndpointAddress(url); Service = new ServiceSoapClient(binding, endpointAddress); MerchantAuthenticationType = ServiceTools.CreateMerchantAuthenticationType(merchantId, transactionKey); }
// Populate merchant authentication (ARB Support) private MerchantAuthenticationType PopulateMerchantAuthentication() { MerchantAuthenticationType authentication = new MerchantAuthenticationType(); authentication.name = loginID; authentication.transactionKey = transactionKey; return authentication; }
/// <summary> /// Process recurring payment /// </summary> /// <param name="paymentInfo">Payment info required for an order processing</param> /// <param name="customer">Customer</param> /// <param name="orderGuid">Unique order identifier</param> /// <param name="processPaymentResult">Process payment result</param> public void ProcessRecurringPayment(PaymentInfo paymentInfo, Customer customer, Guid orderGuid, ref ProcessPaymentResult processPaymentResult) { InitSettings(); MerchantAuthenticationType authentication = PopulateMerchantAuthentication(); if (!paymentInfo.IsRecurringPayment) { ARBSubscriptionType subscription = new ARBSubscriptionType(); NopSolutions.NopCommerce.Payment.Methods.AuthorizeNet.net.authorize.api.CreditCardType creditCard = new NopSolutions.NopCommerce.Payment.Methods.AuthorizeNet.net.authorize.api.CreditCardType(); subscription.name = orderGuid.ToString(); creditCard.cardNumber = paymentInfo.CreditCardNumber; creditCard.expirationDate = paymentInfo.CreditCardExpireYear + "-" + paymentInfo.CreditCardExpireMonth; // required format for API is YYYY-MM creditCard.cardCode = paymentInfo.CreditCardCvv2; subscription.payment = new PaymentType(); subscription.payment.Item = creditCard; subscription.billTo = new NameAndAddressType(); subscription.billTo.firstName = paymentInfo.BillingAddress.FirstName; subscription.billTo.lastName = paymentInfo.BillingAddress.LastName; subscription.billTo.address = paymentInfo.BillingAddress.Address1 + " " + paymentInfo.BillingAddress.Address2; subscription.billTo.city = paymentInfo.BillingAddress.City; if (paymentInfo.BillingAddress.StateProvince != null) { subscription.billTo.state = paymentInfo.BillingAddress.StateProvince.Abbreviation; } subscription.billTo.zip = paymentInfo.BillingAddress.ZipPostalCode; if (paymentInfo.ShippingAddress != null) { subscription.shipTo = new NameAndAddressType(); subscription.shipTo.firstName = paymentInfo.ShippingAddress.FirstName; subscription.shipTo.lastName = paymentInfo.ShippingAddress.LastName; subscription.shipTo.address = paymentInfo.ShippingAddress.Address1 + " " + paymentInfo.ShippingAddress.Address2; subscription.shipTo.city = paymentInfo.ShippingAddress.City; if (paymentInfo.ShippingAddress.StateProvince != null) { subscription.shipTo.state = paymentInfo.ShippingAddress.StateProvince.Abbreviation; } subscription.shipTo.zip = paymentInfo.ShippingAddress.ZipPostalCode; } subscription.customer = new CustomerType(); subscription.customer.email = customer.BillingAddress.Email; subscription.customer.phoneNumber = customer.BillingAddress.PhoneNumber; subscription.order = new OrderType(); subscription.order.description = string.Format("{0} {1}", IoC.Resolve <ISettingManager>().StoreName, "Recurring payment"); // Create a subscription that is leng of specified occurrences and interval is amount of days ad runs subscription.paymentSchedule = new PaymentScheduleType(); DateTime dtNow = DateTime.UtcNow; subscription.paymentSchedule.startDate = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day); subscription.paymentSchedule.startDateSpecified = true; subscription.paymentSchedule.totalOccurrences = Convert.ToInt16(paymentInfo.RecurringTotalCycles); subscription.paymentSchedule.totalOccurrencesSpecified = true; subscription.amount = paymentInfo.OrderTotal; subscription.amountSpecified = true; // Interval can't be updated once a subscription is created. subscription.paymentSchedule.interval = new PaymentScheduleTypeInterval(); switch (paymentInfo.RecurringCyclePeriod) { case (int)RecurringProductCyclePeriodEnum.Days: subscription.paymentSchedule.interval.length = Convert.ToInt16(paymentInfo.RecurringCycleLength); subscription.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.days; break; case (int)RecurringProductCyclePeriodEnum.Weeks: subscription.paymentSchedule.interval.length = Convert.ToInt16(paymentInfo.RecurringCycleLength * 7); subscription.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.days; break; case (int)RecurringProductCyclePeriodEnum.Months: subscription.paymentSchedule.interval.length = Convert.ToInt16(paymentInfo.RecurringCycleLength); subscription.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.months; break; case (int)RecurringProductCyclePeriodEnum.Years: subscription.paymentSchedule.interval.length = Convert.ToInt16(paymentInfo.RecurringCycleLength * 12); subscription.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.months; break; default: throw new NopException("Not supported cycle period"); } ARBCreateSubscriptionResponseType response = webService.ARBCreateSubscription(authentication, subscription); if (response.resultCode == MessageTypeEnum.Ok) { processPaymentResult.SubscriptionTransactionId = response.subscriptionId.ToString(); processPaymentResult.AuthorizationTransactionCode = response.resultCode.ToString(); processPaymentResult.AuthorizationTransactionResult = string.Format("Approved ({0}: {1})", response.resultCode.ToString(), response.subscriptionId.ToString()); } else { processPaymentResult.Error = string.Format("Error processing recurring payment. {0}", GetErrors(response)); processPaymentResult.FullError = string.Format("Error processing recurring payment. {0}", GetErrors(response)); } } }
/// <summary> /// Process recurring payment /// </summary> /// <param name="paymentInfo">Payment info required for an betting processing</param> /// <param name="bettingGuid">Unique order identifier</param> /// <param name="processPaymentResult">Process payment result</param> public void ProcessRecurringPayment(TransactionPayment transactionPayment, Guid bettingGuid, ref ProcessPaymentResult processPaymentResult) { InitSettings(); MerchantAuthenticationType authentication = PopulateMerchantAuthentication(); if (!transactionPayment.IsRecurringPayment) { ARBSubscriptionType subscription = new ARBSubscriptionType(); AuthorizeNet.net.authorize.api.CreditCardType creditCard = new AuthorizeNet.net.authorize.api.CreditCardType(); subscription.name = bettingGuid.ToString(); creditCard.cardNumber = transactionPayment.PaymentMenthod.CreditCardNumber; creditCard.expirationDate = transactionPayment.PaymentMenthod.CardExpirationYear + "-" + transactionPayment.PaymentMenthod.CardExpirationMonth; // required format for API is YYYY-MM creditCard.cardCode = transactionPayment.PaymentMenthod.CardCvv2; subscription.payment = new PaymentType(); subscription.payment.Item = creditCard; subscription.billTo = new NameAndAddressType(); subscription.billTo.firstName = transactionPayment.Customer.FirstName; subscription.billTo.lastName = transactionPayment.Customer.LastName; subscription.billTo.address = transactionPayment.Customer.Address; subscription.billTo.city = transactionPayment.Customer.City; subscription.billTo.zip = transactionPayment.Customer.PostalCode; subscription.customer = new CustomerType(); subscription.customer.email = transactionPayment.Customer.Email1; subscription.customer.phoneNumber = transactionPayment.Customer.Telephone; subscription.order = new OrderType(); subscription.order.description = Constant.Payment.STORENAME + " " + "Recurring payment"; // Create a subscription that is leng of specified occurrences and interval is amount of days ad runs subscription.paymentSchedule = new PaymentScheduleType(); DateTime dtNow = DateTime.UtcNow; subscription.paymentSchedule.startDate = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day); subscription.paymentSchedule.startDateSpecified = true; subscription.paymentSchedule.totalOccurrences = Convert.ToInt16(transactionPayment.RecurringTotalCycles); subscription.paymentSchedule.totalOccurrencesSpecified = true; subscription.amount = transactionPayment.TransactionPaymentTotal; subscription.amountSpecified = true; // Interval can't be updated once a subscription is created. subscription.paymentSchedule.interval = new PaymentScheduleTypeInterval(); switch (transactionPayment.RecurringCyclePeriod) { case (int)RecurringProductCyclePeriodEnum.Days: subscription.paymentSchedule.interval.length = Convert.ToInt16(transactionPayment.RecurringCycleLength); subscription.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.days; break; case (int)RecurringProductCyclePeriodEnum.Weeks: subscription.paymentSchedule.interval.length = Convert.ToInt16(transactionPayment.RecurringCycleLength * 7); subscription.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.days; break; case (int)RecurringProductCyclePeriodEnum.Months: subscription.paymentSchedule.interval.length = Convert.ToInt16(transactionPayment.RecurringCycleLength); subscription.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.months; break; case (int)RecurringProductCyclePeriodEnum.Years: subscription.paymentSchedule.interval.length = Convert.ToInt16(transactionPayment.RecurringCycleLength * 12); subscription.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.months; break; default: throw new Exception("Not supported cycle period"); } ARBCreateSubscriptionResponseType response = webService.ARBCreateSubscription(authentication, subscription); if (response.resultCode == MessageTypeEnum.Ok) { processPaymentResult.SubscriptionTransactionId = response.subscriptionId.ToString(); processPaymentResult.AuthorizationTransactionCode = response.resultCode.ToString(); processPaymentResult.AuthorizationTransactionResult = string.Format("Approved ({0}: {1})", response.resultCode.ToString(), response.subscriptionId.ToString()); } else { processPaymentResult.Error = string.Format("Error processing recurring payment. {0}", GetErrors(response)); processPaymentResult.FullError = string.Format("Error processing recurring payment. {0}", GetErrors(response)); } } }
public static bool CreateCustomerProfileTransactionRefund(SiteDT site, InvoiceDT invoice, TransactionDT transaction, CustomerDT customer, CreditCardDT creditCard, out long transactionId, out string message) { //This datetime is when system change. int deployYear = CastleClub.BusinessLogic.Data.GlobalParameters.DeployYear; int deployMonth = CastleClub.BusinessLogic.Data.GlobalParameters.DeployMonth; int deployDay = CastleClub.BusinessLogic.Data.GlobalParameters.DeployDay; if (invoice.BilledDate >= new DateTime(deployYear, deployMonth, deployDay)) { MerchantAuthenticationType merchantAT = new MerchantAuthenticationType(); merchantAT.name = site.AuthorizeLoginId; merchantAT.transactionKey = site.AuthorizeTransactionKey; ProfileTransactionType profileTT = new ProfileTransactionType(); ProfileTransRefundType profileTRT = new ProfileTransRefundType(); OrderExType orderET = new OrderExType(); orderET.invoiceNumber = invoice.Id.ToString(); profileTRT.amount = invoice.Amount; profileTRT.transId = transaction.AuthorizeTransactionId.ToString(); profileTRT.customerProfileId = customer.AuthorizeProfileId; profileTRT.customerProfileIdSpecified = true; profileTRT.customerPaymentProfileId = creditCard.AuthorizePaymentProfileId; profileTRT.customerPaymentProfileIdSpecified = true; profileTRT.order = orderET; profileTT.Item = profileTRT; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServiceSoapClient client = new ServiceSoapClient(); CreateCustomerProfileTransactionResponseType resp = client.CreateCustomerProfileTransaction(merchantAT, profileTT, String.Empty); if (resp.directResponse != null) { PaymentGatewayResponse paymentGatewayResponse = new PaymentGatewayResponse(resp.directResponse); transactionId = paymentGatewayResponse.TransactionId; message = paymentGatewayResponse.ResponseReasonText; } else { transactionId = 0; if (resp.messages.Length > 0) { message = resp.messages[0].text; } else { message = ""; } } return(resp.resultCode == MessageTypeEnum.Ok); } else { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; using (ServiceSoapClient client = new ServiceSoapClient()) { MerchantAuthenticationType merchant = new MerchantAuthenticationType() { name = site.AuthorizeLoginId, transactionKey = site.AuthorizeTransactionKey }; ProfileTransactionType profileTT = new ProfileTransactionType(); ProfileTransRefundType profileTRT = new ProfileTransRefundType(); profileTRT.amount = invoice.Amount; profileTRT.transId = transaction.AuthorizeTransactionId.ToString(); profileTRT.creditCardNumberMasked = "XXXX" + creditCard.LastFourDigit; profileTT.Item = profileTRT; var resp = client.CreateCustomerProfileTransaction(merchant, profileTT, string.Empty); if (resp.resultCode == MessageTypeEnum.Ok) { PaymentGatewayResponse paymentGatewayResponse = new PaymentGatewayResponse(resp.directResponse); transactionId = paymentGatewayResponse.TransactionId; message = paymentGatewayResponse.ResponseReasonText; } else { transactionId = 0; message = string.Empty; message = resp.messages != null && resp.messages.Count() > 0 ? resp.messages.Select(a => a.text).Aggregate((a, b) => a + " - " + b) : string.Empty; } return(resp.resultCode == MessageTypeEnum.Ok); } } }
public static bool CreateCustomerProfile(SiteDT site, CustomerDT customer, CreditCardDT cc, out long customerProfileId, out long customerPaymentProfileId) { // if (1 == 0) { MerchantAuthenticationType merchantAT = new MerchantAuthenticationType(); merchantAT.name = site.AuthorizeLoginId; merchantAT.transactionKey = site.AuthorizeTransactionKey; CustomerProfileType customerPT = new CustomerProfileType(); customerPT.merchantCustomerId = customer.Id.ToString(); customerPT.email = customer.Email; customerPT.paymentProfiles = new CustomerPaymentProfileType[1]; CustomerPaymentProfileType customerPPT = new CustomerPaymentProfileType(); customerPPT.customerType = CustomerTypeEnum.individual; customerPPT.customerTypeSpecified = true; customerPPT.billTo = new CustomerAddressType() { firstName = customer.FirstName, lastName = customer.LastName, address = customer.Address, city = customer.City, country = "USA", state = customer.StateId, zip = customer.ZipCode }; CreditCardType ccT = new CreditCardType(); ccT.cardNumber = cc.CardNumber; ccT.expirationDate = cc.ExpDate; ccT.cardCode = cc.CVV; PaymentType payment = new PaymentType(); payment.Item = ccT; customerPPT.payment = payment; customerPT.paymentProfiles[0] = customerPPT; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServiceSoapClient client = new ServiceSoapClient(); CreateCustomerProfileResponseType resp = client.CreateCustomerProfile(merchantAT, customerPT, ValidationModeEnum.testMode); customerProfileId = resp.customerProfileId; customerPaymentProfileId = resp.customerPaymentProfileIdList.Length == 1 ? resp.customerPaymentProfileIdList[0] : 0; if (resp.resultCode != MessageTypeEnum.Ok) { string errorValidate = resp.validationDirectResponseList != null && resp.validationDirectResponseList.Count() > 0 ? resp.validationDirectResponseList.ToList().Aggregate((a, b) => a + " || " + b) : string.Empty; string error = resp.messages != null && resp.messages.Count() > 0 ? resp.messages.ToList().Select(a => a.text).Aggregate((a, b) => a + " || " + b) : string.Empty; LoggingUtilities.Logger.LogEntry("Resp Error code:" + resp.resultCode.ToString() + ". Errors: " + error + "Error V: " + errorValidate); } return(resp.resultCode == MessageTypeEnum.Ok); /* } * * else * { * customerProfileId = 1; * customerPaymentProfileId = 1; * return true; * }*/ }
private IGatewayResponse SendUpdateSubscriptionRequest(AuthorizeDotNetRequest request) { var result = string.Empty; IGatewayResponse gatewayResponse = null; long id = long.Parse(request.KeyValues[AuthorizeDotNetApi.SubscriptionID]); var authentication = new MerchantAuthenticationType(); authentication.name = request.KeyValues[AuthorizeDotNetApi.ApiLogin]; authentication.transactionKey = request.KeyValues[AuthorizeDotNetApi.TransactionKey]; //do required first ARBSubscriptionType subscription = new ARBSubscriptionType(); subscription.amount = decimal.Parse(request.KeyValues[AuthorizeDotNetApi.Amount]); subscription.amountSpecified = true; subscription.name = request.KeyValues[AuthorizeDotNetApi.SubscriptionName]; PaymentType payment = new PaymentType(); var creditCard = new CreditCardType(); creditCard.cardCode = request.KeyValues[AuthorizeDotNetApi.CreditCardCode]; creditCard.cardNumber = request.KeyValues[AuthorizeDotNetApi.CreditCardNumber]; creditCard.expirationDate = request.KeyValues[AuthorizeDotNetApi.CreditCardExpiration]; payment.Item = creditCard; subscription.payment = payment; CustomerType customer = new CustomerType(); customer.id = request.KeyValues[AuthorizeDotNetApi.CustomerId]; if (request.KeyValues.ContainsKey(AuthorizeDotNetApi.Fax)) { customer.email = request.KeyValues[AuthorizeDotNetApi.Email]; } if (request.KeyValues.ContainsKey(AuthorizeDotNetApi.Fax)) { customer.faxNumber = request.KeyValues[AuthorizeDotNetApi.Fax]; } if (request.KeyValues.ContainsKey(AuthorizeDotNetApi.Phone)) { customer.phoneNumber = request.KeyValues[AuthorizeDotNetApi.Phone]; } //customer.type = CustomerTypeEnum.individual; customer.typeSpecified = false; //customer.taxId = request.KeyValues[AuthorizeDotNetApi.t]; //customer.driversLicense = request.KeyValues[AuthorizeDotNetApi.]; subscription.customer = customer; if (request.KeyValues.ContainsKey(AuthorizeDotNetApi.Address)) { NameAndAddressType customerBilling = new NameAndAddressType(); customerBilling.address = request.KeyValues[AuthorizeDotNetApi.Address]; customerBilling.city = request.KeyValues[AuthorizeDotNetApi.City]; if (request.KeyValues.ContainsKey(AuthorizeDotNetApi.Company)) { customerBilling.company = request.KeyValues[AuthorizeDotNetApi.Company]; } if (request.KeyValues.ContainsKey(AuthorizeDotNetApi.Country)) { customerBilling.country = request.KeyValues[AuthorizeDotNetApi.Country]; } customerBilling.firstName = request.KeyValues[AuthorizeDotNetApi.FirstName]; customerBilling.lastName = request.KeyValues[AuthorizeDotNetApi.LastName]; customerBilling.state = request.KeyValues[AuthorizeDotNetApi.State]; customerBilling.zip = request.KeyValues[AuthorizeDotNetApi.Zip]; subscription.billTo = customerBilling; } if (request.KeyValues.ContainsKey(AuthorizeDotNetApi.ShipAddress)) { NameAndAddressType shipping = new NameAndAddressType(); shipping.address = request.KeyValues[AuthorizeDotNetApi.ShipAddress]; shipping.city = request.KeyValues[AuthorizeDotNetApi.ShipCity]; if (request.KeyValues.ContainsKey(AuthorizeDotNetApi.ShipCompany)) { shipping.company = request.KeyValues[AuthorizeDotNetApi.ShipCompany]; } if (request.KeyValues.ContainsKey(AuthorizeDotNetApi.ShipCountry)) { shipping.country = request.KeyValues[AuthorizeDotNetApi.ShipCountry]; } shipping.firstName = request.KeyValues[AuthorizeDotNetApi.ShipFirstName]; shipping.lastName = request.KeyValues[AuthorizeDotNetApi.ShipLastName]; shipping.state = request.KeyValues[AuthorizeDotNetApi.ShipState]; shipping.zip = request.KeyValues[AuthorizeDotNetApi.ShipZip]; subscription.shipTo = shipping; } if (request.KeyValues.ContainsKey(AuthorizeDotNetApi.InvoiceNumber)) { OrderType order = new OrderType(); order.invoiceNumber = request.KeyValues[AuthorizeDotNetApi.InvoiceNumber]; subscription.order = order; } //PaymentScheduleType paymentSchedule = new PaymentScheduleType(); //PaymentScheduleTypeInterval paymentScheduleTypeInterval = new PaymentScheduleTypeInterval(); //paymentScheduleTypeInterval.length = short.Parse(request.KeyValues[AuthorizeDotNetApi.BillingCycles]); //paymentScheduleTypeInterval.unit = (ARBSubscriptionUnitEnum)Enum.Parse(typeof(ARBSubscriptionUnitEnum), request.KeyValues[AuthorizeDotNetApi.BillingInterval], true); //paymentSchedule.interval = paymentScheduleTypeInterval; //paymentSchedule.startDate = DateTime.Parse(request.KeyValues[AuthorizeDotNetApi.StartsOn].ToString()); //paymentSchedule.startDateSpecified = true; //paymentSchedule.totalOccurrencesSpecified = true; //paymentSchedule.totalOccurrences = short.Parse(request.KeyValues[AuthorizeDotNetApi.TotalOccurences].ToString()); //paymentSchedule.trialOccurrencesSpecified = false; subscription.trialAmountSpecified = false; if (request.KeyValues.ContainsKey(AuthorizeDotNetApi.TrialAmount)) { subscription.trialAmount = decimal.Parse(request.KeyValues[AuthorizeDotNetApi.TrialAmount]); subscription.trialAmountSpecified = true; //paymentSchedule.trialOccurrences = short.Parse(request.KeyValues[AuthorizeDotNetApi.TrialBillingCycles]); //paymentSchedule.trialOccurrencesSpecified = true; } //authorize does not allow us to update intervals... //subscription.paymentSchedule = paymentSchedule; using (var webService = new RevStack.AuthorizeDotNet.net.authorize.api.Service()) { webService.Url = request.PostUrl; var response = webService.ARBUpdateSubscription(authentication, id, subscription, null); if (response.resultCode != MessageTypeEnum.Ok) { char del = request.KeyValues[AuthorizeDotNetApi.DelimitCharacter].ToCharArray()[0]; IList <string> list = new List <string>(); for (int i = 0; i < response.messages.Length; i++) { result += response.messages[i].text + del; list.Add(response.messages[i].text); } result = result.TrimEnd(del); gatewayResponse = new GatewayResponse(result, del); gatewayResponse.SubscriptionResponse = list; } else { IList <string> list = new List <string>(); for (int i = 0; i < response.messages.Length; i++) { list.Add(response.messages[i].text); } gatewayResponse = new GatewayResponse(id.ToString()); gatewayResponse.SubscriptionResponse = list; } //if (response.resultCode == MessageTypeEnum.Ok) //{ // char del = request.KeyValues[AuthorizeDotNetApi.DelimitCharacter].ToCharArray()[0]; // for (int i = 0; i < response.messages.Length; i++) // { // result = response.messages[i].text + del; // } // result = result.TrimEnd(del); // gatewayResponse = new AuthorizeDotNetResponse(result, del); // gatewayResponse.SubscriptionId = id.ToString(); //} } return(gatewayResponse); }