internal static PaymentRequest paymentRequest(string paymentScenario, string currency, string amount, string token, string cardNumber, string expiryDateMMYY, string cardVerificationCode, string customerReference, string authorizationGuid) { PaymentRequest paymentRequest = new PaymentRequest(); paymentRequest.AuthorizationGuid = authorizationGuid; paymentRequest.PaymentScenario = paymentScenario; paymentRequest.Currency = currency; paymentRequest.Amount = amount; paymentRequest.Token = token; paymentRequest.CardNumber = cardNumber; paymentRequest.ExpiryDateMMYY = expiryDateMMYY; paymentRequest.CardVerificationCode = cardVerificationCode; paymentRequest.CustomerReference = customerReference; string validationErrors = validatePaymentRequest(paymentRequest); if (validationErrors != null) { throw new HpECommerceException("Message failed validation \n" + validationErrors); } return paymentRequest; }
internal HpEcommerce.messages.Payment sendPaymentRequest(PaymentRequest request) { HttpWebResponse response = client.sendPostRequest(UrlGenerator.getPaymentUrl(CardAcceptor, Environment), HpXmlSerializer.getMessage(typeof(PaymentRequest), request), SharedSecret); if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Forbidden) { return HpXmlSerializer.convertPayment(getResponsestring(response)); } else { throw new HpServerError("Payment declined.", HpXmlSerializer.convertErrorMessage(getResponsestring(response))); } }
private static string validatePaymentRequest(PaymentRequest request) { StringBuilder validationErrors = new StringBuilder(); ValidateCommonFields(request, validationErrors); if (!isValidPaymentRequest(request)) { validationErrors.Append("Request has invalid card data. It must have either Card Number and Expiry date or Token"); } if (validationErrors.Length == 0) { return null; } else { return validationErrors.ToString(); } }
private static bool isValidPaymentRequest(PaymentRequest message) { return (message.CardNumber != null && message.ExpiryDateMMYY != null) || message.Token != null || message.AuthorizationGuid != null; }