protected virtual bool ProcessOperation(string operation, string transactionId, out string message, PaymentMethod paymentMethod) { // Configuration values string merchantId = paymentMethod.DynamicProperty <string>().MerchantId; string password = paymentMethod.DynamicProperty <string>().Password; bool result; NetaxeptClient client = GetClient(paymentMethod); try { var response = client.Process(merchantId, password, new ProcessRequest { Operation = operation, TransactionId = transactionId }); message = response.ResponseText; result = response.ResponseCode.Equals("OK"); } catch (Exception ex) { message = ex.Message; result = false; } return(result); }
/// <summary> /// Processed the callback received from the payment provider. /// </summary> public override void ProcessCallback(Payment payment) { if (payment.PaymentStatus.PaymentStatusId != (int)PaymentStatusCode.PendingAuthorization) { return; } string transactionId = HttpContext.Current.Request["transactionId"]; string paymentResponseCode = HttpContext.Current.Request["responseCode"]; // Configuration values string cancelUrl = payment.PaymentMethod.DynamicProperty <string>().CancelUrl; string merchantId = payment.PaymentMethod.DynamicProperty <string>().MerchantId; string password = payment.PaymentMethod.DynamicProperty <string>().Password; string declineUrl = payment.PaymentMethod.DynamicProperty <string>().DeclineUrl; // Netaxept will return something other than OK if // the customer cancels at the remote end. if (!paymentResponseCode.Equals("OK")) { HttpContext.Current.Response.Redirect(new Uri(_absoluteUrlService.GetAbsoluteUrl(cancelUrl)) .AddOrderGuidParameter(payment.PurchaseOrder).ToString()); } bool authOK = false; NetaxeptClient client = GetClient(payment.PaymentMethod); try { //Authorization process var authResponse = client.Process(merchantId, password, new ProcessRequest { Operation = "AUTH", TransactionId = transactionId }); // PaymentClient.Process will cause an exception if something // goes wrong during auth. Thus authReponse will always // contain an "OK" value if execution continues to this // point. authOK = authResponse.ResponseCode == "OK"; if (authOK) { UpdatePaymentAndDisplayThankYouPage(payment, transactionId); } } catch (Exception ex) { _loggingService.Log <NetaxeptPaymentMethodService>(ex.Message); string uri = new Uri(_absoluteUrlService.GetAbsoluteUrl(declineUrl)) .AddOrderGuidParameter(payment.PurchaseOrder) .AddQueryStringParameter("exceptionMessage", ex.Message) .ToString(); HttpContext.Current.Response.Redirect(uri, false); } }
/// <summary> /// Public constructor /// </summary> public NetaxeptServiceClient(ClientConnection connection) { _connection = connection; _client = new NetaxeptClient(); if (connection.IsProduction) { _client.Endpoint.Address = new EndpointAddress(NetaxeptConstants.NetaxeptServiceProductionAddress); } else { _client.Endpoint.Address = new EndpointAddress(NetaxeptConstants.NetaxeptServiceTestAddress); } }
/// <summary> /// Validates that the currency matches the provider. Makes placeholder request. /// </summary> public override Payment RequestPayment(PaymentRequest paymentRequest) { Guard.Against.UnsupportedCurrencyInNetaxept(paymentRequest.Payment.PurchaseOrder.BillingCurrency); Guard.Against.Null(paymentRequest.Payment.PurchaseOrder.BillingAddress, "PurchaseOrder.BillingAddress must be supplied for Netaxept payments. Please make sure that you update the property prior to initiating payment either by using the API TransactionLibrary.EditBillingInformation() or setting the property directly."); if (paymentRequest.Payment == null) { paymentRequest.Payment = CreatePayment(paymentRequest); } Payment payment = paymentRequest.Payment; var billingAddress = payment.PurchaseOrder.GetBillingAddress(); string orderCurrency = paymentRequest.Payment.PurchaseOrder.BillingCurrency.ISOCode; string referenceId = payment.ReferenceId; int orderAmount = Convert.ToInt32(paymentRequest.Amount.Value.ToCents()); int orderTax = Convert.ToInt32(paymentRequest.PurchaseOrder.VAT.Value.ToCents()); string customerFirstName = billingAddress.FirstName; string customerLastName = billingAddress.LastName; string customerEmail = billingAddress.EmailAddress; string customerCompany = billingAddress.CompanyName; string customerStreet1 = billingAddress.Line1; string customerStreet2 = billingAddress.Line2; string customerPostalCode = billingAddress.PostalCode; string customerCity = billingAddress.City; string customerCountry = billingAddress.Country.Name; string customerPhone = string.Format("{0}, {1}", billingAddress.PhoneNumber, billingAddress.MobilePhoneNumber); // Configuration data string merchantId = paymentRequest.PaymentMethod.DynamicProperty <string>().MerchantId; string password = paymentRequest.PaymentMethod.DynamicProperty <string>().Password; string callbackUrl = paymentRequest.PaymentMethod.DynamicProperty <string>().CallbackUrl; string availablePaymentOptions = paymentRequest.PaymentMethod.DynamicProperty <string>().AvailablePaymentOptions; bool singlePageView = paymentRequest.PaymentMethod.DynamicProperty <bool>().SinglePageView; bool force3DSecure = paymentRequest.PaymentMethod.DynamicProperty <bool>().Force3DSecure; // Placeholder request NetaxeptClient client = GetClient(paymentRequest.PaymentMethod); RegisterResponse registerResponse = client.Register(merchantId, password, new RegisterRequest { Terminal = new Terminal { // Where to send the customer when the transaction has been registred at nets RedirectUrl = _callbackUrl.GetCallbackUrl(callbackUrl, paymentRequest.Payment), Language = GetLanguage(), PaymentMethodList = availablePaymentOptions, SinglePage = singlePageView.ToString(), Vat = orderTax.ToString() }, Order = new Order { Amount = orderAmount.ToString(), CurrencyCode = orderCurrency, OrderNumber = referenceId, Force3DSecure = force3DSecure.ToString() }, Customer = new Netaxept.NetaxeptBackendService.Customer { FirstName = customerFirstName, LastName = customerLastName, Email = customerEmail, CompanyName = customerCompany, Address1 = customerStreet1, Address2 = customerStreet2, Postcode = customerPostalCode, Town = customerCity, Country = customerCountry, PhoneNumber = customerPhone }, Environment = new Netaxept.NetaxeptBackendService.Environment { WebServicePlatform = "WCF" } }); RedirectCustomerToRemotePaymentPage(registerResponse.TransactionId, paymentRequest.PaymentMethod); return(payment); }