internal HpEcommerce.messages.Cancellation sendCancellationRequest(CancellationRequest request) { HttpWebResponse response = client.sendPostRequest(UrlGenerator.getCancellationUrl(CardAcceptor, Environment), HpXmlSerializer.getMessage(typeof(CancellationRequest), request), SharedSecret); if (response.StatusCode == HttpStatusCode.OK) { return HpXmlSerializer.convertCancellation(getResponsestring(response)); } else { throw new HpServerError("Cancellation declined.", HpXmlSerializer.convertErrorMessage(getResponsestring(response))); } }
internal static CancellationRequest cancellationRequest(string transactionType, string currency, string amount, string terminalDateTime) { CancellationRequest cancellationRequest = new CancellationRequest(); cancellationRequest.Amount = amount; cancellationRequest.Currency = currency; cancellationRequest.TransactionType = transactionType; cancellationRequest.TerminalDateTime = terminalDateTime; string validationErrors = validateCancellationRequest(cancellationRequest); if (validationErrors != null) { throw new HpECommerceException("Message failed validation \n" + validationErrors); } return cancellationRequest; }
private static string validateCancellationRequest(CancellationRequest request) { StringBuilder validationErrors = new StringBuilder(); if (request.Currency == null) { validationErrors.Append("Currency is required.\n"); } if (request.Amount == null) { validationErrors.Append("Amount is required.\n"); } if (request.TransactionType == null) { validationErrors.Append("Amount is required.\n"); } if (request.TerminalDateTime == null) { validationErrors.Append("Amount is required.\n"); } if (validationErrors.Length == 0) { return null; } else { return validationErrors.ToString(); } }